diff --git a/ext/native/base/stringutil.cpp b/ext/native/base/stringutil.cpp index e814cc9aad..d2dc16d22b 100644 --- a/ext/native/base/stringutil.cpp +++ b/ext/native/base/stringutil.cpp @@ -250,13 +250,20 @@ bool TryParse(const std::string &str, bool *const output) void SplitString(const std::string& str, const char delim, std::vector& output) { - std::istringstream iss(str); - output.resize(1); + size_t next = 0; + for (size_t pos = 0, len = str.length(); pos < len; ++pos) { + if (str[pos] == delim) { + output.push_back(str.substr(next, pos - next)); + // Skip the delimiter itself. + next = pos + 1; + } + } - while (std::getline(iss, *output.rbegin(), delim)) - output.push_back(""); - - output.pop_back(); + if (next == 0) { + output.push_back(str); + } else if (next < str.length()) { + output.push_back(str.substr(next)); + } } std::string ReplaceAll(std::string result, const std::string& src, const std::string& dest) @@ -281,4 +288,4 @@ int strcmpIgnore(std::string str1, std::string str2, std::string ignorestr1, std str1 = ReplaceAll(str1, ignorestr1, ignorestr2); str2 = ReplaceAll(str2, ignorestr1, ignorestr2); return strcmp(str1.c_str(),str2.c_str()); -} \ No newline at end of file +}