mirror of
https://gitlab.com/mbunkus/mkvtoolnix.git
synced 2024-12-24 20:01:53 +00:00
Added a function for stripping a string or a vector<string> from leading and trailing white spaces.
This commit is contained in:
parent
175bcdfb53
commit
d52e2f51bf
30
common.cpp
30
common.cpp
@ -608,6 +608,36 @@ vector<string> 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<string> &v) {
|
||||
int i;
|
||||
|
||||
for (i = 0; i < v.size(); i++)
|
||||
strip(v[i]);
|
||||
}
|
||||
|
||||
/*
|
||||
* Integer parsing
|
||||
*/
|
||||
|
2
common.h
2
common.h
@ -105,6 +105,8 @@ void *_saferealloc(void *mem, size_t size, const char *file, int line);
|
||||
|
||||
vector<string> split(const char *src, const char *pattern = ",",
|
||||
int max_num = -1);
|
||||
void strip(string &s);
|
||||
void strip(vector<string> &v);
|
||||
|
||||
UTFstring cstr_to_UTFstring(const char *c);
|
||||
char *UTFstring_to_cstr(const UTFstring &u);
|
||||
|
Loading…
Reference in New Issue
Block a user