| 119 | // split string by delim |
| 120 | template <class T = std::string> |
| 121 | std::vector<T> split_string(const std::string& str, const std::string& delim) { |
| 122 | size_t pre_pos = 0; |
| 123 | size_t pos = 0; |
| 124 | std::string tmp_str; |
| 125 | std::vector<T> res_list; |
| 126 | res_list.clear(); |
| 127 | if (str.empty()) { |
| 128 | return res_list; |
| 129 | } |
| 130 | while ((pos = str.find(delim, pre_pos)) != std::string::npos) { |
| 131 | tmp_str.assign(str, pre_pos, pos - pre_pos); |
| 132 | res_list.push_back(tmp_str); |
| 133 | pre_pos = pos + delim.size(); |
| 134 | } |
| 135 | tmp_str.assign(str, pre_pos, str.length() - pre_pos); |
| 136 | res_list.push_back(tmp_str); |
| 137 | return res_list; |
| 138 | } |
| 139 | |
| 140 | // split string by spaces. Leading and tailing spaces are ignored. Consecutive |
| 141 | // spaces are treated as one delim. |
no test coverage detected