Skip to content

Commit

Permalink
Strings: Make StringViewTokenizer remaining StringView available as a…
Browse files Browse the repository at this point in the history
… field
  • Loading branch information
Pagghiu committed Apr 7, 2024
1 parent ea5e2c0 commit ddb2c27
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
8 changes: 4 additions & 4 deletions Libraries/Strings/StringView.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -335,7 +335,7 @@ bool SC::StringView::isFloatingNumber() const
//-----------------------------------------------------------------------------------------------------------------------
// StringViewTokenizer
//-----------------------------------------------------------------------------------------------------------------------
[[nodiscard]] bool SC::StringViewTokenizer::isFinished() const { return current.isEmpty(); }
[[nodiscard]] bool SC::StringViewTokenizer::isFinished() const { return remaining.isEmpty(); }

bool SC::StringViewTokenizer::tokenizeNext(Span<const StringCodePoint> separators, Options options)
{
Expand All @@ -344,7 +344,7 @@ bool SC::StringViewTokenizer::tokenizeNext(Span<const StringCodePoint> separator
return false;
}
auto oldNonEmpty = numSplitsNonEmpty;
current.withIterator(
remaining.withIterator(
[&](auto iterator)
{
auto originalTextStart = originalText.getIterator<decltype(iterator)>();
Expand All @@ -355,7 +355,7 @@ bool SC::StringViewTokenizer::tokenizeNext(Span<const StringCodePoint> separator
component = StringView::fromIterators(componentStart, iterator);
processed = StringView::fromIterators(originalTextStart, iterator);
(void)iterator.stepForward();
current = StringView::fromIteratorUntilEnd(iterator);
remaining = StringView::fromIteratorUntilEnd(iterator);
numSplitsTotal++;
if (not component.isEmpty())
{
Expand All @@ -366,7 +366,7 @@ bool SC::StringViewTokenizer::tokenizeNext(Span<const StringCodePoint> separator
{
break;
}
} while (not current.isEmpty());
} while (not remaining.isEmpty());
});
return options == IncludeEmpty ? true : numSplitsNonEmpty > oldNonEmpty;
}
Expand Down
4 changes: 2 additions & 2 deletions Libraries/Strings/StringView.h
Original file line number Diff line number Diff line change
Expand Up @@ -536,6 +536,7 @@ struct SC::StringViewTokenizer

StringView component; ///< Current component that has been tokenized by tokenizeNext
StringView processed; ///< Substring of original string passed in constructor processed so far
StringView remaining; ///< Substring from current position until the end of original text

enum Options
{
Expand All @@ -544,7 +545,7 @@ struct SC::StringViewTokenizer
};

/// @brief Build a tokenizer operating on the given text string view
StringViewTokenizer(StringView text) : originalText(text), current(text) {}
StringViewTokenizer(StringView text) : originalText(text), remaining(text) {}

/// @brief Splits the string along a list of separators
/// @param separators List of separators
Expand Down Expand Up @@ -583,7 +584,6 @@ struct SC::StringViewTokenizer

private:
StringView originalText; // Original text as passed in the constructor
StringView current; // Substring from current position until the end of original text
};

/// @brief Algorithms operating on strings (glob / wildcard).
Expand Down

0 comments on commit ddb2c27

Please sign in to comment.