diff --git a/common.cpp b/common.cpp index 0b1405d40..2351f87a2 100644 --- a/common.cpp +++ b/common.cpp @@ -608,6 +608,36 @@ vector split(const char *src, const char *pattern, int max_num) { return v; } +void strip(string &s) { + int i, len; + const char *c; + + c = s.c_str(); + i = 0; + while ((c[i] != 0) && isspace(c[i])) + i++; + + if (i > 0) + s.erase(0, i); + + c = s.c_str(); + len = s.length(); + i = 0; + + while ((i < len) && isspace(c[len - i - 1])) + i++; + + if (i > 0) + s.erase(len - i, i); +} + +void strip(vector &v) { + int i; + + for (i = 0; i < v.size(); i++) + strip(v[i]); +} + /* * Integer parsing */ diff --git a/common.h b/common.h index 985ef8d2d..13823b2b6 100644 --- a/common.h +++ b/common.h @@ -105,6 +105,8 @@ void *_saferealloc(void *mem, size_t size, const char *file, int line); vector split(const char *src, const char *pattern = ",", int max_num = -1); +void strip(string &s); +void strip(vector &v); UTFstring cstr_to_UTFstring(const char *c); char *UTFstring_to_cstr(const UTFstring &u);