| 312 | } |
| 313 | |
| 314 | void StringRef::split(SmallVectorImpl<StringRef> &A, |
| 315 | StringRef Separator, int MaxSplit, |
| 316 | bool KeepEmpty) const { |
| 317 | StringRef S = *this; |
| 318 | |
| 319 | // Count down from MaxSplit. When MaxSplit is -1, this will just split |
| 320 | // "forever". This doesn't support splitting more than 2^31 times |
| 321 | // intentionally; if we ever want that we can make MaxSplit a 64-bit integer |
| 322 | // but that seems unlikely to be useful. |
| 323 | while (MaxSplit-- != 0) { |
| 324 | size_t Idx = S.find(Separator); |
| 325 | if (Idx == npos) |
| 326 | break; |
| 327 | |
| 328 | // Push this split. |
| 329 | if (KeepEmpty || Idx > 0) |
| 330 | A.push_back(S.slice(0, Idx)); |
| 331 | |
| 332 | // Jump forward. |
| 333 | S = S.slice(Idx + Separator.size(), npos); |
| 334 | } |
| 335 | |
| 336 | // Push the tail. |
| 337 | if (KeepEmpty || !S.empty()) |
| 338 | A.push_back(S); |
| 339 | } |
| 340 | |
| 341 | void StringRef::split(SmallVectorImpl<StringRef> &A, char Separator, |
| 342 | int MaxSplit, bool KeepEmpty) const { |