WebKit Bugzilla
New
Browse
Search+
Log In
×
Sign in with GitHub
or
Remember my login
Create Account
·
Forgot Password
Forgotten password account recovery
[patch]
Patch
bug-159598-20160709194705.patch (text/plain), 15.50 KB, created by
Myles C. Maxfield
on 2016-07-09 19:47:43 PDT
(
hide
)
Description:
Patch
Filename:
MIME Type:
Creator:
Myles C. Maxfield
Created:
2016-07-09 19:47:43 PDT
Size:
15.50 KB
patch
obsolete
>Subversion Revision: 203018 >diff --git a/Source/WTF/ChangeLog b/Source/WTF/ChangeLog >index 6f9fc756b6d6918be39cf40d0884f26f5d35756b..61cd7802c46fbbb1d5b7cfd8fb661c16ede03c89 100644 >--- a/Source/WTF/ChangeLog >+++ b/Source/WTF/ChangeLog >@@ -1,3 +1,26 @@ >+2016-07-09 Myles C. Maxfield <mmaxfield@apple.com> >+ >+ Implement grapheme cluster iterator on StringView >+ https://bugs.webkit.org/show_bug.cgi?id=159598 >+ >+ Reviewed by NOBODY (OOPS!). >+ >+ This is in preparation for honoring the second argument to FontFaceSet.load(). >+ >+ * wtf/text/StringView.cpp: >+ (WTF::StringView::GraphemeClusters::Iterator::Impl::Impl): >+ (WTF::StringView::GraphemeClusters::Iterator::Impl::operator++): >+ (WTF::StringView::GraphemeClusters::Iterator::Impl::operator*): >+ (WTF::StringView::GraphemeClusters::Iterator::Impl::operator==): >+ (WTF::StringView::GraphemeClusters::Iterator::Impl::computeIndexEnd): >+ (WTF::StringView::GraphemeClusters::Iterator::Iterator): >+ (WTF::StringView::GraphemeClusters::Iterator::~Iterator): >+ (WTF::StringView::GraphemeClusters::Iterator::operator*): >+ (WTF::StringView::GraphemeClusters::Iterator::operator==): >+ (WTF::StringView::GraphemeClusters::Iterator::operator!=): >+ * wtf/text/StringView.h: >+ (WTF::StringView::GraphemeClusters::GraphemeClusters): >+ > 2016-07-08 Commit Queue <commit-queue@webkit.org> > > Unreviewed, rolling out r202799. >diff --git a/Source/WebCore/ChangeLog b/Source/WebCore/ChangeLog >index 1094e74b0c444ba4820aa2a3ae60371ddf51fe2a..7d00f023be45d92f185db5a6a7465b546e8b16e5 100644 >--- a/Source/WebCore/ChangeLog >+++ b/Source/WebCore/ChangeLog >@@ -1,3 +1,16 @@ >+2016-07-09 Myles C. Maxfield <mmaxfield@apple.com> >+ >+ Implement grapheme cluster iterator on StringView >+ https://bugs.webkit.org/show_bug.cgi?id=159598 >+ >+ Reviewed by NOBODY (OOPS!). >+ >+ This is in preparation for honoring the second argument to FontFaceSet.load(). >+ >+ * platform/text/TextBreakIterator.cpp: >+ (WebCore::NonSharedCharacterBreakIterator::NonSharedCharacterBreakIterator): >+ * platform/text/TextBreakIterator.h: >+ > 2016-07-08 Chris Dumez <cdumez@apple.com> > > adoptNode() changes css class to lowercase for document loaded with XHR responseType = "document" >diff --git a/Source/WTF/wtf/text/StringView.cpp b/Source/WTF/wtf/text/StringView.cpp >index e206717c071289c6d6037cc34083ace3d9db04b8..efacc0bc846f7f23a8d68620f54f58e3a43496e8 100644 >--- a/Source/WTF/wtf/text/StringView.cpp >+++ b/Source/WTF/wtf/text/StringView.cpp >@@ -31,6 +31,7 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. > #include <wtf/HashMap.h> > #include <wtf/Lock.h> > #include <wtf/NeverDestroyed.h> >+#include <wtf/text/TextBreakIterator.h> > #include <wtf/unicode/UTF8.h> > > namespace WTF { >@@ -91,6 +92,87 @@ size_t StringView::find(StringView matchString, unsigned start) const > return findCommon(*this, matchString, start); > } > >+class StringView::GraphemeClusters::Iterator::Impl { >+public: >+ Impl(const StringView& stringView, NonSharedCharacterBreakIterator&& iterator, unsigned index) >+ : m_stringView(stringView) >+ , m_iterator(WTFMove(iterator)) >+ , m_index(index) >+ , m_indexEnd(computeIndexEnd()) >+ { >+ } >+ >+ void operator++() >+ { >+ ASSERT(m_indexEnd > m_index); >+ m_index = m_indexEnd; >+ m_indexEnd = computeIndexEnd(); >+ } >+ >+ StringView operator*() const >+ { >+ if (m_stringView.is8Bit()) >+ return StringView(m_stringView.characters8() + m_index, m_indexEnd - m_index); >+ return StringView(m_stringView.characters16() + m_index, m_indexEnd - m_index); >+ } >+ >+ bool operator==(const Impl& other) const >+ { >+ ASSERT(&m_stringView == &other.m_stringView); >+ auto result = m_index == other.m_index; >+ ASSERT(!result || m_indexEnd == other.m_indexEnd); >+ return result; >+ } >+ >+ unsigned computeIndexEnd() >+ { >+ if (m_index == m_stringView.length()) >+ return m_index; >+ return textBreakFollowing(m_iterator, m_index); >+ } >+ >+private: >+ const StringView& m_stringView; >+ NonSharedCharacterBreakIterator m_iterator; >+ unsigned m_index; >+ unsigned m_indexEnd; >+}; >+ >+StringView::GraphemeClusters::Iterator::Iterator(const StringView& stringView, unsigned index) >+ : m_impl(std::make_unique<Impl>(stringView, NonSharedCharacterBreakIterator(stringView), index)) >+{ >+} >+ >+StringView::GraphemeClusters::Iterator::~Iterator() >+{ >+} >+ >+StringView::GraphemeClusters::Iterator::Iterator(Iterator&& other) >+ : m_impl(WTFMove(other.m_impl)) >+{ >+} >+ >+auto StringView::GraphemeClusters::Iterator::operator++() -> Iterator& >+{ >+ ++(*m_impl); >+ return *this; >+} >+ >+StringView StringView::GraphemeClusters::Iterator::operator*() const >+{ >+ return **m_impl; >+} >+ >+bool StringView::GraphemeClusters::Iterator::operator==(const Iterator& other) const >+{ >+ return *m_impl == *(other.m_impl); >+} >+ >+bool StringView::GraphemeClusters::Iterator::operator!=(const Iterator& other) const >+{ >+ return !(*this == other); >+} >+ > #if CHECK_STRINGVIEW_LIFETIME > > // Manage reference count manually so UnderlyingString does not need to be defined in the header. >diff --git a/Source/WTF/wtf/text/StringView.h b/Source/WTF/wtf/text/StringView.h >index 3aef4dbbf8947fdaa185742f8a927a74939e082e..3bf0cef2a00d43378a35f1f61de5a936fdd66da3 100644 >--- a/Source/WTF/wtf/text/StringView.h >+++ b/Source/WTF/wtf/text/StringView.h >@@ -82,6 +82,9 @@ public: > class CodePoints; > CodePoints codePoints() const; > >+ class GraphemeClusters; >+ GraphemeClusters graphemeClusters() const; >+ > bool is8Bit() const; > const LChar* characters8() const; > const UChar* characters16() const; >@@ -580,6 +583,18 @@ inline bool equalIgnoringASCIICase(StringView a, const char* b) > return equalIgnoringASCIICaseCommon(a, b); > } > >+class StringView::GraphemeClusters { >+public: >+ explicit GraphemeClusters(const StringView&); >+ >+ class Iterator; >+ Iterator begin() const; >+ Iterator end() const; >+ >+private: >+ StringView m_stringView; >+}; >+ > class StringView::CodePoints { > public: > explicit CodePoints(const StringView&); >@@ -604,6 +619,29 @@ private: > StringView m_stringView; > }; > >+class StringView::GraphemeClusters::Iterator { >+public: >+ WTF_EXPORT_PRIVATE Iterator() = delete; >+ WTF_EXPORT_PRIVATE Iterator(const StringView&, unsigned index); >+ WTF_EXPORT_PRIVATE ~Iterator(); >+ >+ Iterator(const Iterator&) = delete; >+ WTF_EXPORT_PRIVATE Iterator(Iterator&&); >+ Iterator& operator=(const Iterator&) = delete; >+ Iterator& operator=(Iterator&&) = delete; >+ >+ WTF_EXPORT_PRIVATE StringView operator*() const; >+ WTF_EXPORT_PRIVATE Iterator& operator++(); >+ >+ WTF_EXPORT_PRIVATE bool operator==(const Iterator&) const; >+ WTF_EXPORT_PRIVATE bool operator!=(const Iterator&) const; >+ >+private: >+ class Impl; >+ >+ std::unique_ptr<Impl> m_impl; >+}; >+ > class StringView::CodePoints::Iterator { > public: > Iterator(const StringView&, unsigned index); >@@ -637,6 +675,11 @@ private: > unsigned m_index; > }; > >+inline auto StringView::graphemeClusters() const -> GraphemeClusters >+{ >+ return GraphemeClusters(*this); >+} >+ > inline auto StringView::codePoints() const -> CodePoints > { > return CodePoints(*this); >@@ -647,6 +690,21 @@ inline auto StringView::codeUnits() const -> CodeUnits > return CodeUnits(*this); > } > >+inline StringView::GraphemeClusters::GraphemeClusters(const StringView& stringView) >+ : m_stringView(stringView) >+{ >+} >+ >+inline auto StringView::GraphemeClusters::begin() const -> Iterator >+{ >+ return Iterator(m_stringView, 0); >+} >+ >+inline auto StringView::GraphemeClusters::end() const -> Iterator >+{ >+ return Iterator(m_stringView, m_stringView.length()); >+} >+ > inline StringView::CodePoints::CodePoints(const StringView& stringView) > : m_stringView(stringView) > { >diff --git a/Source/WebCore/platform/text/TextBreakIterator.cpp b/Source/WebCore/platform/text/TextBreakIterator.cpp >index a0a66ce0b7ed147ae7c6b3d7b9709823e7fe325f..796ad08bbefd70179e5b79d4f49f27ec746c6e3a 100644 >--- a/Source/WebCore/platform/text/TextBreakIterator.cpp >+++ b/Source/WebCore/platform/text/TextBreakIterator.cpp >@@ -819,7 +819,7 @@ NonSharedCharacterBreakIterator::NonSharedCharacterBreakIterator(StringView stri > { > m_iterator = nonSharedCharacterBreakIterator; > >- bool createdIterator = m_iterator && compareAndSwapNonSharedCharacterBreakIterator(m_iterator, 0); >+ bool createdIterator = m_iterator && compareAndSwapNonSharedCharacterBreakIterator(m_iterator, nullptr); > if (!createdIterator) > m_iterator = initializeIterator(UBRK_CHARACTER); > if (!m_iterator) >@@ -834,6 +834,12 @@ NonSharedCharacterBreakIterator::~NonSharedCharacterBreakIterator() > ubrk_close(reinterpret_cast<UBreakIterator*>(m_iterator)); > } > >+NonSharedCharacterBreakIterator::NonSharedCharacterBreakIterator(NonSharedCharacterBreakIterator&& other) >+ : m_iterator(nullptr) >+{ >+ std::swap(m_iterator, other.m_iterator); >+} >+ > > // Iterator implemenation. > >diff --git a/Source/WebCore/platform/text/TextBreakIterator.h b/Source/WebCore/platform/text/TextBreakIterator.h >index 6a1c2350b4767d6ce1c34de2c34c22d43522c58e..ec2fa64b7bb5e9a491817c91a1f5ab0a3d643bc2 100644 >--- a/Source/WebCore/platform/text/TextBreakIterator.h >+++ b/Source/WebCore/platform/text/TextBreakIterator.h >@@ -198,6 +198,8 @@ public: > WEBCORE_EXPORT NonSharedCharacterBreakIterator(StringView); > WEBCORE_EXPORT ~NonSharedCharacterBreakIterator(); > >+ NonSharedCharacterBreakIterator(NonSharedCharacterBreakIterator&&); >+ > operator TextBreakIterator*() const { return m_iterator; } > > private: >diff --git a/Tools/ChangeLog b/Tools/ChangeLog >index 3ac306cb3cbbdfc784523e839f76444cb60dd681..5c5fcb75d0d37afc30517863c08c1effca900333 100644 >--- a/Tools/ChangeLog >+++ b/Tools/ChangeLog >@@ -1,3 +1,16 @@ >+2016-07-09 Myles C. Maxfield <mmaxfield@apple.com> >+ >+ Implement grapheme cluster iterator on StringView >+ https://bugs.webkit.org/show_bug.cgi?id=159598 >+ >+ Reviewed by NOBODY (OOPS!). >+ >+ This is in preparation for honoring the second argument to FontFaceSet.load(). >+ >+ * TestWebKitAPI/Tests/WTF/StringView.cpp: >+ (TestWebKitAPI::compareLoopIterations): >+ (TestWebKitAPI::TEST): >+ > 2016-07-08 Andy Estes <aestes@apple.com> > > [Content Filtering] Load blocked pages more like other error pages are loaded >diff --git a/Tools/TestWebKitAPI/Tests/WTF/StringView.cpp b/Tools/TestWebKitAPI/Tests/WTF/StringView.cpp >index 408cc642eb7617980ab46f80f5456e328ef602f0..9988ddcd4cf5b902447783566229d6b3491b8e0c 100644 >--- a/Tools/TestWebKitAPI/Tests/WTF/StringView.cpp >+++ b/Tools/TestWebKitAPI/Tests/WTF/StringView.cpp >@@ -78,6 +78,14 @@ TEST(WTF, StringViewEmptyVsNull) > SUCCEED(); > } > >+bool compareLoopIterations(StringView::GraphemeClusters graphemeClusters, std::vector<StringView> expected) >+{ >+ std::vector<StringView> actual; >+ for (auto graphemeCluster : graphemeClusters) >+ actual.push_back(graphemeCluster); >+ return actual == expected; >+} >+ > bool compareLoopIterations(StringView::CodePoints codePoints, std::vector<UChar32> expected) > { > std::vector<UChar32> actual; >@@ -116,30 +124,63 @@ TEST(WTF, StringViewIterators) > build(b, {0xD800, 0xDD55}); // Surrogates for unicode code point U+10155 > EXPECT_TRUE(compareLoopIterations(StringView(b.toString()).codePoints(), {0x10155})); > EXPECT_TRUE(compareLoopIterations(StringView(b.toString()).codeUnits(), {0xD800, 0xDD55})); >+ EXPECT_TRUE(compareLoopIterations(StringView(b.toString()).graphemeClusters(), {StringView(b.toString())})); > > build(b, {0xD800}); // Leading surrogate only > EXPECT_TRUE(compareLoopIterations(StringView(b.toString()).codePoints(), {0xD800})); > EXPECT_TRUE(compareLoopIterations(StringView(b.toString()).codeUnits(), {0xD800})); >+ EXPECT_TRUE(compareLoopIterations(StringView(b.toString()).graphemeClusters(), {StringView(b.toString())})); > > build(b, {0xD800, 0xD801}); // Two leading surrogates > EXPECT_TRUE(compareLoopIterations(StringView(b.toString()).codePoints(), {0xD800, 0xD801})); > EXPECT_TRUE(compareLoopIterations(StringView(b.toString()).codeUnits(), {0xD800, 0xD801})); >+ EXPECT_TRUE(compareLoopIterations(StringView(b.toString()).graphemeClusters(), {StringView(b.characters16(), 1), StringView(b.characters16() + 1, 1)})); > > build(b, {0xDD55}); // Trailing surrogate only > EXPECT_TRUE(compareLoopIterations(StringView(b.toString()).codePoints(), {0xDD55})); > EXPECT_TRUE(compareLoopIterations(StringView(b.toString()).codeUnits(), {0xDD55})); >+ EXPECT_TRUE(compareLoopIterations(StringView(b.toString()).graphemeClusters(), {StringView(b.toString())})); > > build(b, {0xD800, 'h'}); // Leading surrogate followed by non-surrogate > EXPECT_TRUE(compareLoopIterations(StringView(b.toString()).codePoints(), {0xD800, 'h'})); > EXPECT_TRUE(compareLoopIterations(StringView(b.toString()).codeUnits(), {0xD800, 'h'})); >+ EXPECT_TRUE(compareLoopIterations(StringView(b.toString()).graphemeClusters(), {StringView(b.characters16(), 1), StringView(b.characters16() + 1, 1)})); > > build(b, {0x0306}); // "COMBINING BREVE" > EXPECT_TRUE(compareLoopIterations(StringView(b.toString()).codePoints(), {0x0306})); > EXPECT_TRUE(compareLoopIterations(StringView(b.toString()).codeUnits(), {0x0306})); >+ EXPECT_TRUE(compareLoopIterations(StringView(b.toString()).graphemeClusters(), {StringView(b.toString())})); > > build(b, {0x0306, 0xD800, 0xDD55, 'h', 'e', 'l', 'o'}); // Mix of single code unit and multi code unit code points > EXPECT_TRUE(compareLoopIterations(StringView(b.toString()).codePoints(), {0x0306, 0x10155, 'h', 'e', 'l', 'o'})); > EXPECT_TRUE(compareLoopIterations(StringView(b.toString()).codeUnits(), {0x0306, 0xD800, 0xDD55, 'h', 'e', 'l', 'o'})); >+ EXPECT_TRUE(compareLoopIterations(StringView(b.toString()).graphemeClusters(), { >+ StringView(b.characters16(), 1), >+ StringView(b.characters16() + 1, 2), >+ StringView(b.characters16() + 3, 1), >+ StringView(b.characters16() + 4, 1), >+ StringView(b.characters16() + 5, 1), >+ StringView(b.characters16() + 6, 1)})); >+ >+ build(b, {'e', 0x0301}); // "COMBINING ACUTE" >+ EXPECT_TRUE(compareLoopIterations(StringView(b.toString()).codePoints(), {'e', 0x0301})); >+ EXPECT_TRUE(compareLoopIterations(StringView(b.toString()).codeUnits(), {'e', 0x0301})); >+ EXPECT_TRUE(compareLoopIterations(StringView(b.toString()).graphemeClusters(), {StringView(b.toString())})); >+ >+ build(b, {'e', 0x0301, 0x0306, 'a'}); // "COMBINING ACUTE" "COMBINING BREVE" >+ EXPECT_TRUE(compareLoopIterations(StringView(b.toString()).codePoints(), {'e', 0x0301, 0x0306, 'a'})); >+ EXPECT_TRUE(compareLoopIterations(StringView(b.toString()).codeUnits(), {'e', 0x0301, 0x0306, 'a'})); >+ EXPECT_TRUE(compareLoopIterations(StringView(b.toString()).graphemeClusters(), { >+ StringView(b.characters16(), 3), >+ StringView(b.characters16() + 3, 1), >+ })); >+ >+ build(b, {0x1112, 0x116f, 0x11b6, 0x1107, 0x1161, 0x11B8}); // Korean combining Jamo >+ EXPECT_TRUE(compareLoopIterations(StringView(b.toString()).codePoints(), {0x1112, 0x116f, 0x11b6, 0x1107, 0x1161, 0x11B8})); >+ EXPECT_TRUE(compareLoopIterations(StringView(b.toString()).codeUnits(), {0x1112, 0x116f, 0x11b6, 0x1107, 0x1161, 0x11B8})); >+ EXPECT_TRUE(compareLoopIterations(StringView(b.toString()).graphemeClusters(), { >+ StringView(b.characters16(), 3), >+ StringView(b.characters16() + 3, 3)})); > } > > TEST(WTF, StringViewEqualIgnoringASCIICaseBasic)
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Formatted Diff
|
Diff
Attachments on
bug 159598
:
283253
|
283254
|
283278
|
283287
|
283289