Support modern for loops over StringViews
authormmaxfield@apple.com <mmaxfield@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 3 Oct 2014 17:43:32 +0000 (17:43 +0000)
committermmaxfield@apple.com <mmaxfield@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 3 Oct 2014 17:43:32 +0000 (17:43 +0000)
commit6bc43bfd26959e0be6a75fbf2e7650f96cbf495d
treeca066abc9f6d2877827fad30bdfb7b63efbb2ed6
parent426ee763049a53fcb5ac87d7f35f2f2ce8123dd3
Support modern for loops over StringViews
https://bugs.webkit.org/show_bug.cgi?id=137165

Patch by Myles C. Maxfield <mmaxfield@apple.com> on 2014-10-03
Reviewed by Darin Adler.

This patch adds two functions, codePoints() and codeUnits(), on StringView.
These two functions return small objects which have begin() and end() functions,
which means it can be used by the modern for loop style. This small class also
has an inner iterator class which can be incremented, dereferenced, and
compared.

Using these new objects looks like this:
for (UChar codeunit : stringView.codeUnits()) { } and
for (UChar32 codepoint : stringView.codePoints()) { }.

* wtf/text/StringView.h:
(WTF::StringView::codepoints):
(WTF::StringView::codeunits):
(WTF::StringViewCodePointIterator::StringViewCodePointIterator):
(WTF::StringViewCodePointIterator::Iterator::Iterator):
(WTF::StringViewCodePointIterator::Iterator::operator*):
(WTF::StringViewCodePointIterator::Iterator::operator!=):
(WTF::StringViewCodeUnitIterator::StringViewCodeUnitIterator):
(WTF::StringViewCodeUnitIterator::Iterator::Iterator):
(WTF::StringViewCodeUnitIterator::Iterator::operator*):
(WTF::StringViewCodeUnitIterator::Iterator::operator!=):

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@174271 268f45cc-cd09-0410-ab3c-d52691b4dbfc
Source/WTF/ChangeLog
Source/WTF/wtf/text/StringView.h
Tools/TestWebKitAPI/Tests/WTF/StringView.cpp