| 306 | } |
| 307 | |
| 308 | void SplitStringIntoNPiecesAllowEmpty(const string& full, |
| 309 | const char* delim, |
| 310 | int pieces, |
| 311 | vector<string>* result) { |
| 312 | if (pieces == 0) { |
| 313 | // No limit when pieces is 0. |
| 314 | AppendTo(result, strings::Split(full, AnyOf(delim))); |
| 315 | } else { |
| 316 | // The input argument "pieces" specifies the max size that *result should |
| 317 | // be. However, the argument to the Limit() delimiter is the max number of |
| 318 | // delimiters, which should be one less than "pieces". Example: "a,b,c" has |
| 319 | // 3 pieces and two comma delimiters. |
| 320 | int limit = std::max(pieces - 1, 0); |
| 321 | AppendTo(result, strings::Split(full, Limit(AnyOf(delim), limit))); |
| 322 | } |
| 323 | } |
| 324 | |
| 325 | // ---------------------------------------------------------------------- |
| 326 | // SplitStringAllowEmpty |