WebKit Bugzilla
New
Browse
Search+
Log In
×
Sign in with GitHub
or
Remember my login
Create Account
·
Forgot Password
Forgotten password account recovery
[patch]
Needs tests
bug-159598-20160709020752.patch (text/plain), 9.48 KB, created by
Myles C. Maxfield
on 2016-07-09 02:08:29 PDT
(
hide
)
Description:
Needs tests
Filename:
MIME Type:
Creator:
Myles C. Maxfield
Created:
2016-07-09 02:08:29 PDT
Size:
9.48 KB
patch
obsolete
>Subversion Revision: 203018 >diff --git a/Source/WTF/ChangeLog b/Source/WTF/ChangeLog >index 6f9fc756b6d6918be39cf40d0884f26f5d35756b..ea9998dd7c9d814dd36eb8c8e6f4610dee9bdd5c 100644 >--- a/Source/WTF/ChangeLog >+++ b/Source/WTF/ChangeLog >@@ -1,3 +1,24 @@ >+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!). >+ >+ * 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..2928da11938626a9913d07651340ce5315450a2b 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!). >+ >+ No new tests (OOPS!). >+ >+ * 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..be82acdf406f88114024cfabfb50071e238bb3d4 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, unsigned indexEnd) >+ : 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==(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(m_stringView), index)) >+{ >+} >+ >+StringView::GraphemeClusters::Iterator::~Iterator() >+{ >+} >+ >+StringView::GraphemeClusters::Iterator::Iterator(Iterator&& other) >+ : m_impl(WTFMove(other)) >+{ >+} >+ >+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:
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