Commit eba54290 authored by Guolin Ke's avatar Guolin Ke
Browse files

fix bug in string.split()

parent 804d3ada
...@@ -44,13 +44,17 @@ inline static std::string& RemoveQuotationSymbol(std::string& str) { ...@@ -44,13 +44,17 @@ inline static std::string& RemoveQuotationSymbol(std::string& str) {
return str; return str;
} }
inline static std::vector<std::string> Split(const char* str, char delimiter) { inline static std::vector<std::string> Split(const char* c_str, char delimiter) {
std::stringstream ss(str);
std::string tmp_str;
std::vector<std::string> ret; std::vector<std::string> ret;
while (std::getline(ss, tmp_str, delimiter)) { std::string str(c_str);
ret.push_back(tmp_str); size_t i = 0;
} size_t pos = str.find(delimiter);
while (pos != std::string::npos) {
ret.push_back(str.substr(i, pos - i));
i = ++pos;
pos = str.find(delimiter, pos);
}
ret.push_back(str.substr(i));
return ret; return ret;
} }
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment