StrVec Split(const string &s, char c, bool inclue_empty_value) {
return Split(s.c_str(), s.length(), c, include_empty_value);
}
StrVec Split(const char *s, size_t len, char c, bool include_empty_value) {
StrVec vec;
if (s == NULL) {
return vec;
}
for (int last = -1, cur = 0; cur <= len; ++cur) {
char cur_c = (cur < len) ? s[cur] : 0;
if (cur == len || cur_c == c) {
if (cur - last == 1 && include_empty_value) {
vec.push_back(string(""));
} else {
vec.push_back(string((s + last + 1), (cur - last - 1)));
}
last = cur;
}
}
return vec;
}
return Split(s.c_str(), s.length(), c, include_empty_value);
}
StrVec Split(const char *s, size_t len, char c, bool include_empty_value) {
StrVec vec;
if (s == NULL) {
return vec;
}
for (int last = -1, cur = 0; cur <= len; ++cur) {
char cur_c = (cur < len) ? s[cur] : 0;
if (cur == len || cur_c == c) {
if (cur - last == 1 && include_empty_value) {
vec.push_back(string(""));
} else {
vec.push_back(string((s + last + 1), (cur - last - 1)));
}
last = cur;
}
}
return vec;
}