Split a string content using an arbitrary separator.
| 170 | |
| 171 | // Split a string content using an arbitrary separator. |
| 172 | inline StringVec Split(const std::string & str, char separator) |
| 173 | { |
| 174 | if (str.empty()) return {""}; |
| 175 | |
| 176 | StringVec results; |
| 177 | |
| 178 | std::stringstream ss(str); |
| 179 | std::string item; |
| 180 | while (std::getline(ss, item, separator)) |
| 181 | { |
| 182 | results.push_back(std::move(item)); |
| 183 | } |
| 184 | |
| 185 | if (EndsWith(str, std::string(1, separator))) |
| 186 | { |
| 187 | results.push_back(""); |
| 188 | } |
| 189 | |
| 190 | return results; |
| 191 | } |
| 192 | |
| 193 | // Join a list of strings using an arbitrary separator. |
| 194 | inline std::string Join(const StringVec & strings, char separator) |