| 484 | |
| 485 | template<typename Haystack, typename Needle> |
| 486 | auto QStringTokenizerBase<Haystack, Needle>::next(tokenizer_state state) const noexcept -> next_result |
| 487 | { |
| 488 | while (true) |
| 489 | { |
| 490 | if (state.end < 0) |
| 491 | { |
| 492 | // already at end: |
| 493 | return {{}, false, state}; |
| 494 | } |
| 495 | state.end = m_haystack.indexOf(m_needle, state.start + state.extra, m_cs); |
| 496 | Haystack result; |
| 497 | if (state.end >= 0) |
| 498 | { |
| 499 | // token separator found => return intermediate element: |
| 500 | result = m_haystack.mid(state.start, state.end - state.start); |
| 501 | const auto ns = KDToolBoxPrivate::Tok::size(m_needle); |
| 502 | state.start = state.end + ns; |
| 503 | state.extra = (ns == 0 ? 1 : 0); |
| 504 | } |
| 505 | else |
| 506 | { |
| 507 | // token separator not found => return final element: |
| 508 | result = m_haystack.mid(state.start); |
| 509 | } |
| 510 | if ((m_sb & Qt::SkipEmptyParts) && result.isEmpty()) |
| 511 | continue; |
| 512 | return {result, true, state}; |
| 513 | } |
| 514 | } |
| 515 | |
| 516 | #endif /* QSTRINGTOKENIZER_H */ |