| 5 | #include "common/base/string_ext.h" |
| 6 | |
| 7 | void SplitString(const std::string& full, const std::string& delim, |
| 8 | std::vector<std::string>* result) { |
| 9 | result->clear(); |
| 10 | if (full.empty()) { |
| 11 | return; |
| 12 | } |
| 13 | |
| 14 | std::string tmp; |
| 15 | std::string::size_type pos_begin = full.find_first_not_of(delim); |
| 16 | std::string::size_type comma_pos = 0; |
| 17 | |
| 18 | while (pos_begin != std::string::npos) { |
| 19 | comma_pos = full.find(delim, pos_begin); |
| 20 | if (comma_pos != std::string::npos) { |
| 21 | tmp = full.substr(pos_begin, comma_pos - pos_begin); |
| 22 | pos_begin = comma_pos + delim.length(); |
| 23 | } else { |
| 24 | tmp = full.substr(pos_begin); |
| 25 | pos_begin = comma_pos; |
| 26 | } |
| 27 | |
| 28 | if (!tmp.empty()) { |
| 29 | result->push_back(tmp); |
| 30 | tmp.clear(); |
| 31 | } |
| 32 | } |
| 33 | } |
| 34 | |
| 35 | void SplitStringEnd(const std::string& full, std::string* begin_part, std::string* end_part, |
| 36 | std::string delim) { |