<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>[211087] trunk</title>
</head>
<body>
<style type="text/css"><!--
#msg dl.meta { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dl.meta dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer, #logmsg { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; }
#msg dl a { font-weight: bold}
#msg dl a:link { color:#fc3; }
#msg dl a:active { color:#ff0; }
#msg dl a:visited { color:#cc6; }
h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; }
#msg pre { overflow: auto; background: #ffc; border: 1px #fa0 solid; padding: 6px; }
#logmsg { background: #ffc; border: 1px #fa0 solid; padding: 1em 1em 0 1em; }
#logmsg p, #logmsg pre, #logmsg blockquote { margin: 0 0 1em 0; }
#logmsg p, #logmsg li, #logmsg dt, #logmsg dd { line-height: 14pt; }
#logmsg h1, #logmsg h2, #logmsg h3, #logmsg h4, #logmsg h5, #logmsg h6 { margin: .5em 0; }
#logmsg h1:first-child, #logmsg h2:first-child, #logmsg h3:first-child, #logmsg h4:first-child, #logmsg h5:first-child, #logmsg h6:first-child { margin-top: 0; }
#logmsg ul, #logmsg ol { padding: 0; list-style-position: inside; margin: 0 0 0 1em; }
#logmsg ul { text-indent: -1em; padding-left: 1em; }#logmsg ol { text-indent: -1.5em; padding-left: 1.5em; }
#logmsg > ul, #logmsg > ol { margin: 0 0 1em 0; }
#logmsg pre { background: #eee; padding: 1em; }
#logmsg blockquote { border: 1px solid #fa0; border-left-width: 10px; padding: 1em 1em 0 1em; background: white;}
#logmsg dl { margin: 0; }
#logmsg dt { font-weight: bold; }
#logmsg dd { margin: 0; padding: 0 0 0.5em 0; }
#logmsg dd:before { content:'\00bb';}
#logmsg table { border-spacing: 0px; border-collapse: collapse; border-top: 4px solid #fa0; border-bottom: 1px solid #fa0; background: #fff; }
#logmsg table th { text-align: left; font-weight: normal; padding: 0.2em 0.5em; border-top: 1px dotted #fa0; }
#logmsg table td { text-align: right; border-top: 1px dotted #fa0; padding: 0.2em 0.5em; }
#logmsg table thead th { text-align: center; border-bottom: 1px solid #fa0; }
#logmsg table th.Corner { text-align: left; }
#logmsg hr { border: none 0; border-top: 2px dashed #fa0; height: 1px; }
#header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: 6px; }
#patch { width: 100%; }
#patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;}
#patch .propset h4, #patch .binary h4 {margin:0;}
#patch pre {padding:0;line-height:1.2em;margin:0;}
#patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;}
#patch .propset .diff, #patch .binary .diff {padding:10px 0;}
#patch span {display:block;padding:0 10px;}
#patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;}
#patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;}
#patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;}
#patch .lines, .info {color:#888;background:#fff;}
--></style>
<div id="msg">
<dl class="meta">
<dt>Revision</dt> <dd><a href="http://trac.webkit.org/projects/webkit/changeset/211087">211087</a></dd>
<dt>Author</dt> <dd>dbates@webkit.org</dd>
<dt>Date</dt> <dd>2017-01-24 09:44:50 -0800 (Tue, 24 Jan 2017)</dd>
</dl>
<h3>Log Message</h3>
<pre>StringView.split() should use an iterator design pattern instead of allocating a Vector
https://bugs.webkit.org/show_bug.cgi?id=163225
Reviewed by Darin Adler.
Source/WebCore:
Update code to use the new iterator-style StringView.split().
* platform/URLParser.cpp:
Source/WTF:
Implement StringView.split() using an iterator design.
Using an iterator design avoids the need to allocate a Vector of StringView objects,
which is space-inefficient and error prone as the returned Vector may outlive the
lifetime of the underlying string associated with the split (as StringView is a non-
owning reference to a string).
StringView.split() now returns a StringView::SplitResult object that implements begin()/end()
to support iterating over StringView substrings delimited by the specified separator
character. For example, to iterate over the 'c'-separated substrings of a StringView v,
you can write:
for (StringView substring : v.split('c'))
// Do something with substring.
* wtf/text/StringView.cpp:
(WTF::StringView::SplitResult::Iterator::findNextSubstring): Advances the iterator to point to the
next substring.
(WTF::StringView::split): Modified to return a SplitResult::Iterator object instead of a Vector<StringView>.
* wtf/text/StringView.h:
(WTF::StringView::SplitResult::SplitResult):
(WTF::StringView::SplitResult::Iterator::Iterator):
(WTF::StringView::SplitResult::Iterator::operator*):
(WTF::StringView::SplitResult::Iterator::operator==):
(WTF::StringView::SplitResult::Iterator::operator!=):
Implements the iterator interface.
Tools:
Add unit tests for StringView.split().
* TestWebKitAPI/Tests/WTF/StringView.cpp:
(TestWebKitAPI::stringViewFromLiteral): Moved to the top of the file so that it can be
used in the StringView.split() unit tests.
(TestWebKitAPI::stringViewFromUTF8): Ditto.
(TestWebKitAPI::vectorFromSplitResult): Convenience function to convert a StringView::SplitResult
object to a Vector of String objects.
(TestWebKitAPI::TEST): Added the following tests:
- WTF.StringViewSplitEmptyAndNullStrings
- WTF.StringViewSplitBasic
- WTF.StringViewSplitWithConsecutiveSeparators</pre>
<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkSourceWTFChangeLog">trunk/Source/WTF/ChangeLog</a></li>
<li><a href="#trunkSourceWTFwtftextStringViewcpp">trunk/Source/WTF/wtf/text/StringView.cpp</a></li>
<li><a href="#trunkSourceWTFwtftextStringViewh">trunk/Source/WTF/wtf/text/StringView.h</a></li>
<li><a href="#trunkSourceWebCoreChangeLog">trunk/Source/WebCore/ChangeLog</a></li>
<li><a href="#trunkSourceWebCoreplatformURLParsercpp">trunk/Source/WebCore/platform/URLParser.cpp</a></li>
<li><a href="#trunkToolsChangeLog">trunk/Tools/ChangeLog</a></li>
<li><a href="#trunkToolsTestWebKitAPITestsWTFStringViewcpp">trunk/Tools/TestWebKitAPI/Tests/WTF/StringView.cpp</a></li>
</ul>
</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkSourceWTFChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Source/WTF/ChangeLog (211086 => 211087)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WTF/ChangeLog        2017-01-24 17:29:13 UTC (rev 211086)
+++ trunk/Source/WTF/ChangeLog        2017-01-24 17:44:50 UTC (rev 211087)
</span><span class="lines">@@ -1,3 +1,37 @@
</span><ins>+2017-01-24 Daniel Bates <dabates@apple.com>
+
+ StringView.split() should use an iterator design pattern instead of allocating a Vector
+ https://bugs.webkit.org/show_bug.cgi?id=163225
+
+ Reviewed by Darin Adler.
+
+ Implement StringView.split() using an iterator design.
+
+ Using an iterator design avoids the need to allocate a Vector of StringView objects,
+ which is space-inefficient and error prone as the returned Vector may outlive the
+ lifetime of the underlying string associated with the split (as StringView is a non-
+ owning reference to a string).
+
+ StringView.split() now returns a StringView::SplitResult object that implements begin()/end()
+ to support iterating over StringView substrings delimited by the specified separator
+ character. For example, to iterate over the 'c'-separated substrings of a StringView v,
+ you can write:
+
+ for (StringView substring : v.split('c'))
+ // Do something with substring.
+
+ * wtf/text/StringView.cpp:
+ (WTF::StringView::SplitResult::Iterator::findNextSubstring): Advances the iterator to point to the
+ next substring.
+ (WTF::StringView::split): Modified to return a SplitResult::Iterator object instead of a Vector<StringView>.
+ * wtf/text/StringView.h:
+ (WTF::StringView::SplitResult::SplitResult):
+ (WTF::StringView::SplitResult::Iterator::Iterator):
+ (WTF::StringView::SplitResult::Iterator::operator*):
+ (WTF::StringView::SplitResult::Iterator::operator==):
+ (WTF::StringView::SplitResult::Iterator::operator!=):
+ Implements the iterator interface.
+
</ins><span class="cx"> 2017-01-20 Joseph Pecoraro <pecoraro@apple.com>
</span><span class="cx">
</span><span class="cx"> Remove outdated ENABLE(CSP_NEXT) build flag
</span></span></pre></div>
<a id="trunkSourceWTFwtftextStringViewcpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WTF/wtf/text/StringView.cpp (211086 => 211087)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WTF/wtf/text/StringView.cpp        2017-01-24 17:29:13 UTC (rev 211086)
+++ trunk/Source/WTF/wtf/text/StringView.cpp        2017-01-24 17:44:50 UTC (rev 211087)
</span><span class="lines">@@ -1,6 +1,6 @@
</span><span class="cx"> /*
</span><span class="cx">
</span><del>-Copyright (C) 2014, 2016 Apple Inc. All rights reserved.
</del><ins>+Copyright (C) 2014-2017 Apple Inc. All rights reserved.
</ins><span class="cx">
</span><span class="cx"> Redistribution and use in source and binary forms, with or without
</span><span class="cx"> modification, are permitted provided that the following conditions
</span><span class="lines">@@ -94,6 +94,28 @@
</span><span class="cx"> return findCommon(*this, matchString, start);
</span><span class="cx"> }
</span><span class="cx">
</span><ins>+void StringView::SplitResult::Iterator::findNextSubstring()
+{
+ for (size_t separatorPosition; (separatorPosition = m_result.m_string.find(m_result.m_separator, m_position)) != notFound; ++m_position) {
+ if (separatorPosition > m_position) {
+ m_length = separatorPosition - m_position;
+ return;
+ }
+ }
+ m_length = m_result.m_string.length() - m_position;
+}
+
+auto StringView::SplitResult::Iterator::operator++() -> Iterator&
+{
+ ASSERT(m_position < m_result.m_string.length());
+ m_position += m_length;
+ if (m_position < m_result.m_string.length()) {
+ ++m_position;
+ findNextSubstring();
+ }
+ return *this;
+}
+
</ins><span class="cx"> class StringView::GraphemeClusters::Iterator::Impl {
</span><span class="cx"> public:
</span><span class="cx"> Impl(const StringView& stringView, std::optional<NonSharedCharacterBreakIterator>&& iterator, unsigned index)
</span><span class="lines">@@ -142,21 +164,6 @@
</span><span class="cx"> unsigned m_indexEnd;
</span><span class="cx"> };
</span><span class="cx">
</span><del>-Vector<StringView> StringView::split(UChar separator)
-{
- Vector<StringView> result;
- unsigned startPos = 0;
- size_t endPos;
- while ((endPos = find(separator, startPos)) != notFound) {
- if (startPos != endPos)
- result.append(substring(startPos, endPos - startPos));
- startPos = endPos + 1;
- }
- if (startPos != length())
- result.append(substring(startPos));
- return result;
-}
-
</del><span class="cx"> StringView::GraphemeClusters::Iterator::Iterator(const StringView& stringView, unsigned index)
</span><span class="cx"> : m_impl(std::make_unique<Impl>(stringView, stringView.isNull() ? std::nullopt : std::optional<NonSharedCharacterBreakIterator>(NonSharedCharacterBreakIterator(stringView)), index))
</span><span class="cx"> {
</span></span></pre></div>
<a id="trunkSourceWTFwtftextStringViewh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WTF/wtf/text/StringView.h (211086 => 211087)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WTF/wtf/text/StringView.h        2017-01-24 17:29:13 UTC (rev 211086)
+++ trunk/Source/WTF/wtf/text/StringView.h        2017-01-24 17:44:50 UTC (rev 211087)
</span><span class="lines">@@ -1,5 +1,5 @@
</span><span class="cx"> /*
</span><del>- * Copyright (C) 2014-2016 Apple Inc. All rights reserved.
</del><ins>+ * Copyright (C) 2014-2017 Apple Inc. All rights reserved.
</ins><span class="cx"> *
</span><span class="cx"> * Redistribution and use in source and binary forms, with or without
</span><span class="cx"> * modification, are permitted provided that the following conditions
</span><span class="lines">@@ -117,8 +117,10 @@
</span><span class="cx"> StringView substring(unsigned start, unsigned length = std::numeric_limits<unsigned>::max()) const;
</span><span class="cx"> StringView left(unsigned len) const { return substring(0, len); }
</span><span class="cx"> StringView right(unsigned len) const { return substring(length() - len, len); }
</span><del>- WTF_EXPORT_STRING_API Vector<StringView> split(UChar);
</del><span class="cx">
</span><ins>+ class SplitResult;
+ SplitResult split(UChar) const;
+
</ins><span class="cx"> size_t find(UChar, unsigned start = 0) const;
</span><span class="cx"> size_t find(CharacterMatchFunction, unsigned start = 0) const;
</span><span class="cx">
</span><span class="lines">@@ -613,6 +615,19 @@
</span><span class="cx"> return equalIgnoringASCIICaseCommon(a, b);
</span><span class="cx"> }
</span><span class="cx">
</span><ins>+class StringView::SplitResult {
+public:
+ explicit SplitResult(StringView, UChar separator);
+
+ class Iterator;
+ Iterator begin() const;
+ Iterator end() const;
+
+private:
+ StringView m_string;
+ UChar m_separator;
+};
+
</ins><span class="cx"> class StringView::GraphemeClusters {
</span><span class="cx"> public:
</span><span class="cx"> explicit GraphemeClusters(const StringView&);
</span><span class="lines">@@ -649,6 +664,29 @@
</span><span class="cx"> StringView m_stringView;
</span><span class="cx"> };
</span><span class="cx">
</span><ins>+class StringView::SplitResult::Iterator {
+public:
+ StringView operator*() const;
+
+ WTF_EXPORT_PRIVATE Iterator& operator++();
+
+ bool operator==(const Iterator&) const;
+ bool operator!=(const Iterator&) const;
+
+private:
+ enum PositionTag { AtEnd };
+ Iterator(const SplitResult&);
+ Iterator(const SplitResult&, PositionTag);
+
+ WTF_EXPORT_PRIVATE void findNextSubstring();
+
+ friend SplitResult;
+
+ const SplitResult& m_result;
+ unsigned m_position { 0 };
+ unsigned m_length;
+};
+
</ins><span class="cx"> class StringView::GraphemeClusters::Iterator {
</span><span class="cx"> public:
</span><span class="cx"> WTF_EXPORT_PRIVATE Iterator() = delete;
</span><span class="lines">@@ -839,6 +877,56 @@
</span><span class="cx"> return Iterator(m_stringView, m_stringView.length());
</span><span class="cx"> }
</span><span class="cx">
</span><ins>+inline auto StringView::split(UChar separator) const -> SplitResult
+{
+ return SplitResult { *this, separator };
+}
+
+inline StringView::SplitResult::SplitResult(StringView stringView, UChar separator)
+ : m_string { stringView }
+ , m_separator { separator }
+{
+}
+
+inline auto StringView::SplitResult::begin() const -> Iterator
+{
+ return Iterator { *this };
+}
+
+inline auto StringView::SplitResult::end() const -> Iterator
+{
+ return Iterator { *this, Iterator::AtEnd };
+}
+
+inline StringView::SplitResult::Iterator::Iterator(const SplitResult& result)
+ : m_result { result }
+{
+ findNextSubstring();
+}
+
+inline StringView::SplitResult::Iterator::Iterator(const SplitResult& result, PositionTag)
+ : m_result { result }
+ , m_position { result.m_string.length() }
+{
+}
+
+inline StringView StringView::SplitResult::Iterator::operator*() const
+{
+ ASSERT(m_position < m_result.m_string.length());
+ return m_result.m_string.substring(m_position, m_length);
+}
+
+inline bool StringView::SplitResult::Iterator::operator==(const Iterator& other) const
+{
+ ASSERT(&m_result == &other.m_result);
+ return m_position == other.m_position;
+}
+
+inline bool StringView::SplitResult::Iterator::operator!=(const Iterator& other) const
+{
+ return !(*this == other);
+}
+
</ins><span class="cx"> template<unsigned length> inline bool equalLettersIgnoringASCIICase(StringView string, const char (&lowercaseLetters)[length])
</span><span class="cx"> {
</span><span class="cx"> return equalLettersIgnoringASCIICaseCommon(string, lowercaseLetters);
</span></span></pre></div>
<a id="trunkSourceWebCoreChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/ChangeLog (211086 => 211087)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/ChangeLog        2017-01-24 17:29:13 UTC (rev 211086)
+++ trunk/Source/WebCore/ChangeLog        2017-01-24 17:44:50 UTC (rev 211087)
</span><span class="lines">@@ -1,3 +1,14 @@
</span><ins>+2017-01-24 Daniel Bates <dabates@apple.com>
+
+ StringView.split() should use an iterator design pattern instead of allocating a Vector
+ https://bugs.webkit.org/show_bug.cgi?id=163225
+
+ Reviewed by Darin Adler.
+
+ Update code to use the new iterator-style StringView.split().
+
+ * platform/URLParser.cpp:
+
</ins><span class="cx"> 2017-01-24 Joseph Pecoraro <pecoraro@apple.com>
</span><span class="cx">
</span><span class="cx"> Remove always true openGLMultisamplingEnabled setting
</span></span></pre></div>
<a id="trunkSourceWebCoreplatformURLParsercpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/platform/URLParser.cpp (211086 => 211087)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/platform/URLParser.cpp        2017-01-24 17:29:13 UTC (rev 211086)
+++ trunk/Source/WebCore/platform/URLParser.cpp        2017-01-24 17:44:50 UTC (rev 211087)
</span><span class="lines">@@ -2721,10 +2721,8 @@
</span><span class="cx">
</span><span class="cx"> auto URLParser::parseURLEncodedForm(StringView input) -> URLEncodedForm
</span><span class="cx"> {
</span><del>- Vector<StringView> sequences = input.split('&');
-
</del><span class="cx"> URLEncodedForm output;
</span><del>- for (auto& bytes : sequences) {
</del><ins>+ for (StringView bytes : input.split('&')) {
</ins><span class="cx"> auto valueStart = bytes.find('=');
</span><span class="cx"> if (valueStart == notFound) {
</span><span class="cx"> if (auto name = formURLDecode(bytes))
</span></span></pre></div>
<a id="trunkToolsChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Tools/ChangeLog (211086 => 211087)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Tools/ChangeLog        2017-01-24 17:29:13 UTC (rev 211086)
+++ trunk/Tools/ChangeLog        2017-01-24 17:44:50 UTC (rev 211087)
</span><span class="lines">@@ -1,3 +1,23 @@
</span><ins>+2017-01-24 Daniel Bates <dabates@apple.com>
+
+ StringView.split() should use an iterator design pattern instead of allocating a Vector
+ https://bugs.webkit.org/show_bug.cgi?id=163225
+
+ Reviewed by Darin Adler.
+
+ Add unit tests for StringView.split().
+
+ * TestWebKitAPI/Tests/WTF/StringView.cpp:
+ (TestWebKitAPI::stringViewFromLiteral): Moved to the top of the file so that it can be
+ used in the StringView.split() unit tests.
+ (TestWebKitAPI::stringViewFromUTF8): Ditto.
+ (TestWebKitAPI::vectorFromSplitResult): Convenience function to convert a StringView::SplitResult
+ object to a Vector of String objects.
+ (TestWebKitAPI::TEST): Added the following tests:
+ - WTF.StringViewSplitEmptyAndNullStrings
+ - WTF.StringViewSplitBasic
+ - WTF.StringViewSplitWithConsecutiveSeparators
+
</ins><span class="cx"> 2017-01-23 Anders Carlsson <andersca@apple.com>
</span><span class="cx">
</span><span class="cx"> The Score Esports crashes on launch
</span></span></pre></div>
<a id="trunkToolsTestWebKitAPITestsWTFStringViewcpp"></a>
<div class="modfile"><h4>Modified: trunk/Tools/TestWebKitAPI/Tests/WTF/StringView.cpp (211086 => 211087)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Tools/TestWebKitAPI/Tests/WTF/StringView.cpp        2017-01-24 17:29:13 UTC (rev 211086)
+++ trunk/Tools/TestWebKitAPI/Tests/WTF/StringView.cpp        2017-01-24 17:44:50 UTC (rev 211087)
</span><span class="lines">@@ -30,6 +30,17 @@
</span><span class="cx">
</span><span class="cx"> namespace TestWebKitAPI {
</span><span class="cx">
</span><ins>+StringView stringViewFromLiteral(const char* characters)
+{
+ return StringView(reinterpret_cast<const LChar*>(characters), strlen(characters));
+}
+
+StringView stringViewFromUTF8(String &ref, const char* characters)
+{
+ ref = String::fromUTF8(characters);
+ return ref;
+}
+
</ins><span class="cx"> TEST(WTF, StringViewEmptyVsNull)
</span><span class="cx"> {
</span><span class="cx"> StringView nullView;
</span><span class="lines">@@ -214,6 +225,79 @@
</span><span class="cx"> StringView(b.characters16() + 3, 3)}));
</span><span class="cx"> }
</span><span class="cx">
</span><ins>+static Vector<String> vectorFromSplitResult(const StringView::SplitResult& substrings)
+{
+ Vector<String> result;
+ for (StringView substring : substrings)
+ result.append(substring.toString());
+ return result;
+}
+
+TEST(WTF, StringViewSplitEmptyAndNullStrings)
+{
+ StringView a = emptyString();
+ auto splitResult = a.split('b');
+ EXPECT_TRUE(splitResult.begin() == splitResult.end());
+
+ a = { String { } };
+ splitResult = a.split('b');
+ EXPECT_TRUE(splitResult.begin() == splitResult.end());
+
+ a = { };
+ splitResult = a.split('b');
+ EXPECT_TRUE(splitResult.begin() == splitResult.end());
+}
+
+TEST(WTF, StringViewSplitBasic)
+{
+ String referenceHolder;
+ StringView a = stringViewFromUTF8(referenceHolder, "This is a sentence.");
+
+ // Simple
+ Vector<String> actual = vectorFromSplitResult(a.split('T'));
+ Vector<String> expected({ "his is a sentence." });
+ ASSERT_EQ(expected.size(), actual.size());
+ for (size_t i = 0; i < actual.size(); ++i)
+ EXPECT_STREQ(expected[i].utf8().data(), actual[i].utf8().data()) << "Vectors differ at index " << i;
+
+ actual = vectorFromSplitResult(a.split('.'));
+ expected = { "This is a sentence" };
+ ASSERT_EQ(expected.size(), actual.size());
+ for (size_t i = 0; i < actual.size(); ++i)
+ EXPECT_STREQ(expected[i].utf8().data(), actual[i].utf8().data()) << "Vectors differ at index " << i;
+
+ actual = vectorFromSplitResult(a.split('a'));
+ expected = { "This is ", " sentence." };
+ ASSERT_EQ(expected.size(), actual.size());
+ for (size_t i = 0; i < actual.size(); ++i)
+ EXPECT_STREQ(expected[i].utf8().data(), actual[i].utf8().data()) << "Vectors differ at index " << i;
+
+ actual = vectorFromSplitResult(a.split(' '));
+ expected = { "This", "is", "a", "sentence." };
+ ASSERT_EQ(expected.size(), actual.size());
+ for (size_t i = 0; i < actual.size(); ++i)
+ EXPECT_STREQ(expected[i].utf8().data(), actual[i].utf8().data()) << "Vectors differ at index " << i;
+
+ // Non-existent separator
+ actual = vectorFromSplitResult(a.split('z'));
+ expected = { "This is a sentence." };
+ ASSERT_EQ(expected.size(), actual.size());
+ for (size_t i = 0; i < actual.size(); ++i)
+ EXPECT_STREQ(expected[i].utf8().data(), actual[i].utf8().data()) << "Vectors differ at index " << i;
+}
+
+TEST(WTF, StringViewSplitWithConsecutiveSeparators)
+{
+ String referenceHolder;
+ StringView a = stringViewFromUTF8(referenceHolder, "This is a sentence.");
+
+ Vector<String> actual = vectorFromSplitResult(a.split(' '));
+ Vector<String> expected({ "This", "is", "a", "sentence." });
+ ASSERT_EQ(expected.size(), actual.size());
+ for (size_t i = 0; i < actual.size(); ++i)
+ EXPECT_STREQ(expected[i].utf8().data(), actual[i].utf8().data()) << "Vectors differ at index " << i;
+}
+
</ins><span class="cx"> TEST(WTF, StringViewEqualIgnoringASCIICaseBasic)
</span><span class="cx"> {
</span><span class="cx"> RefPtr<StringImpl> a = StringImpl::createFromLiteral("aBcDeFG");
</span><span class="lines">@@ -304,17 +388,6 @@
</span><span class="cx"> ASSERT_FALSE(equalIgnoringASCIICase(stringViewD, e));
</span><span class="cx"> }
</span><span class="cx">
</span><del>-StringView stringViewFromLiteral(const char* characters)
-{
- return StringView(reinterpret_cast<const LChar*>(characters), strlen(characters));
-}
-
-StringView stringViewFromUTF8(String &ref, const char* characters)
-{
- ref = String::fromUTF8(characters);
- return ref;
-}
-
</del><span class="cx"> TEST(WTF, StringViewFindIgnoringASCIICaseBasic)
</span><span class="cx"> {
</span><span class="cx"> String referenceAHolder;
</span></span></pre>
</div>
</div>
</body>
</html>