| 309 | } |
| 310 | |
| 311 | vector<string> SplitStringBounded(unsigned max_chunks, const string &str, |
| 312 | char delim) { |
| 313 | vector<string> result; |
| 314 | |
| 315 | // edge case... one chunk is always the whole string |
| 316 | if (1 == max_chunks) { |
| 317 | result.push_back(str); |
| 318 | return result; |
| 319 | } |
| 320 | |
| 321 | // split the string |
| 322 | const unsigned size = str.size(); |
| 323 | unsigned marker = 0; |
| 324 | unsigned chunks = 1; |
| 325 | unsigned i; |
| 326 | for (i = 0; i < size; ++i) { |
| 327 | if (str[i] == delim) { |
| 328 | result.push_back(str.substr(marker, i - marker)); |
| 329 | marker = i + 1; |
| 330 | |
| 331 | // we got what we want... good bye |
| 332 | if (++chunks == max_chunks) |
| 333 | break; |
| 334 | } |
| 335 | } |
| 336 | |
| 337 | // push the remainings of the string and return |
| 338 | result.push_back(str.substr(marker)); |
| 339 | return result; |
| 340 | } |
| 341 | |
| 342 | vector<string> SplitStringMultiChar(const string &str, const string &delim) { |
| 343 | size_t pos_start = 0, pos_end = 0, delim_len = delim.length(); |
no test coverage detected