Iteration-Style Searches
In iterator-style searches, RWUStringSearch, like RWUBreakSearch, maintains a “current” position within the source string. Immediately after construction, the current position has no meaning. A call to first() or last() sets the current position to the code unit offset just past that of the first or last match, and returns the location of the beginning of the match. The next() method advances the current position to the code unit offset immediately following that of the next match, and returns the location of the beginning of the match. The previous() method moves the current position to the beginning of the previous match, and returns the same location.
For example, this code counts the number of occurrences of pattern in text:
 
RWUStringSearch searcher(pattern, text, collator);
 
int count = 0;
while (searcher.next() != text.endCodePointIterator()) ++count;
std::cout << "Pattern was found " << count << " times."
<< std::endl;