Title: [184341] trunk
Revision
184341
Author
mmaxfi...@apple.com
Date
2015-05-14 10:55:38 -0700 (Thu, 14 May 2015)

Log Message

Add String literal overloads to equalIgnoringASCIICase()
https://bugs.webkit.org/show_bug.cgi?id=145008

Patch by Myles C. Maxfield <mmaxfi...@apple.com> on 2015-05-14
Reviewed by Benjamin Poulain.

Source/WTF:

Create an overload for equalIgnoringASCIICase for string literals.

* wtf/text/StringImpl.h:
(WTF::equalIgnoringASCIICase): Use a non-templated helper function.
* wtf/text/StringImpl.cpp:
(WTF::equalIgnoringASCIICase): Implement it.
* wtf/text/StringView.h:
(WTF::equalIgnoringASCIICase): Use a non-templated helper function.
* wtf/text/StringView.cpp:
(WTF::equalIgnoringASCIICase): Implement it.
* wtf/text/WTFString.h:
(WTF::equalIgnoringASCIICase): Delegate to StringImpl's implementation.

Tools:

Test changes to WTF.

* TestWebKitAPI/Tests/WTF/StringImpl.cpp:
(WTF.StringImplEqualIgnoringASCIICaseBasic): Test const char*.
(WTF.StringImplEqualIgnoringASCIICaseWithLatin1Characters): Ditto.
* TestWebKitAPI/Tests/WTF/StringView.cpp:
(WTF.StringViewEqualIgnoringASCIICaseBasic): Ditto.
(WTF.StringViewEqualIgnoringASCIICaseWithLatin1Characters): Ditto.

Modified Paths

Diff

Modified: trunk/Source/WTF/ChangeLog (184340 => 184341)


--- trunk/Source/WTF/ChangeLog	2015-05-14 17:36:12 UTC (rev 184340)
+++ trunk/Source/WTF/ChangeLog	2015-05-14 17:55:38 UTC (rev 184341)
@@ -1,3 +1,23 @@
+2015-05-14  Myles C. Maxfield  <mmaxfi...@apple.com>
+
+        Add String literal overloads to equalIgnoringASCIICase()
+        https://bugs.webkit.org/show_bug.cgi?id=145008
+
+        Reviewed by Benjamin Poulain.
+
+        Create an overload for equalIgnoringASCIICase for string literals.
+
+        * wtf/text/StringImpl.h:
+        (WTF::equalIgnoringASCIICase): Use a non-templated helper function.
+        * wtf/text/StringImpl.cpp:
+        (WTF::equalIgnoringASCIICase): Implement it.
+        * wtf/text/StringView.h:
+        (WTF::equalIgnoringASCIICase): Use a non-templated helper function.
+        * wtf/text/StringView.cpp:
+        (WTF::equalIgnoringASCIICase): Implement it.
+        * wtf/text/WTFString.h:
+        (WTF::equalIgnoringASCIICase): Delegate to StringImpl's implementation.
+
 2015-05-14  Žan Doberšek  <zdober...@igalia.com>
 
         [GTK] RunLoop constructor should properly retrieve or establish the thread-default GMainContext

Modified: trunk/Source/WTF/wtf/text/StringImpl.cpp (184340 => 184341)


--- trunk/Source/WTF/wtf/text/StringImpl.cpp	2015-05-14 17:36:12 UTC (rev 184340)
+++ trunk/Source/WTF/wtf/text/StringImpl.cpp	2015-05-14 17:55:38 UTC (rev 184341)
@@ -2075,6 +2075,17 @@
     return equalIgnoringASCIICaseCommon(*a, *b);
 }
 
+bool equalIgnoringASCIICase(const StringImpl& a, const char* b, unsigned bLength)
+{
+    if (bLength != a.length())
+        return false;
+
+    if (a.is8Bit())
+        return equalIgnoringASCIICase(a.characters8(), b, bLength);
+
+    return equalIgnoringASCIICase(a.characters16(), b, bLength);
+}
+
 bool equalIgnoringASCIICaseNonNull(const StringImpl* a, const StringImpl* b)
 {
     ASSERT(a);

Modified: trunk/Source/WTF/wtf/text/StringImpl.h (184340 => 184341)


--- trunk/Source/WTF/wtf/text/StringImpl.h	2015-05-14 17:36:12 UTC (rev 184340)
+++ trunk/Source/WTF/wtf/text/StringImpl.h	2015-05-14 17:55:38 UTC (rev 184341)
@@ -972,8 +972,15 @@
 
 WTF_EXPORT_STRING_API bool equalIgnoringASCIICase(const StringImpl&, const StringImpl&);
 WTF_EXPORT_STRING_API bool equalIgnoringASCIICase(const StringImpl*, const StringImpl*);
+WTF_EXPORT_STRING_API bool equalIgnoringASCIICase(const StringImpl& a, const char* b, unsigned bLength);
 WTF_EXPORT_STRING_API bool equalIgnoringASCIICaseNonNull(const StringImpl*, const StringImpl*);
 
+template<unsigned charactersCount>
+bool equalIgnoringASCIICase(const StringImpl* a, const char (&b)[charactersCount])
+{
+    return a ? equalIgnoringASCIICase(*a, b, charactersCount - 1) : false;
+}
+
 template<typename CharacterType>
 inline size_t find(const CharacterType* characters, unsigned length, CharacterType matchCharacter, unsigned index = 0)
 {

Modified: trunk/Source/WTF/wtf/text/StringView.cpp (184340 => 184341)


--- trunk/Source/WTF/wtf/text/StringView.cpp	2015-05-14 17:36:12 UTC (rev 184340)
+++ trunk/Source/WTF/wtf/text/StringView.cpp	2015-05-14 17:55:38 UTC (rev 184341)
@@ -73,6 +73,17 @@
     return ::WTF::endsWithIgnoringASCIICase(*this, suffix);
 }
 
+bool equalIgnoringASCIICase(StringView a, const char* b, unsigned bLength)
+{
+    if (bLength != a.length())
+        return false;
+
+    if (a.is8Bit())
+        return equalIgnoringASCIICase(a.characters8(), b, bLength);
+
+    return equalIgnoringASCIICase(a.characters16(), b, bLength);
+}
+
 #if CHECK_STRINGVIEW_LIFETIME
 
 // Manage reference count manually so UnderlyingString does not need to be defined in the header.

Modified: trunk/Source/WTF/wtf/text/StringView.h (184340 => 184341)


--- trunk/Source/WTF/wtf/text/StringView.h	2015-05-14 17:36:12 UTC (rev 184340)
+++ trunk/Source/WTF/wtf/text/StringView.h	2015-05-14 17:55:38 UTC (rev 184341)
@@ -156,6 +156,12 @@
 bool equal(StringView, const LChar*);
 bool equal(StringView, const char*);
 bool equalIgnoringASCIICase(StringView, StringView);
+WTF_EXPORT_STRING_API bool equalIgnoringASCIICase(StringView a, const char* b, unsigned bLength);
+template<unsigned charactersCount>
+bool equalIgnoringASCIICase(StringView a, const char (&b)[charactersCount])
+{
+    return equalIgnoringASCIICase(a, b, charactersCount - 1);
+}
 
 inline bool operator==(StringView a, StringView b) { return equal(a, b); }
 inline bool operator==(StringView a, const LChar* b) { return equal(a, b); }

Modified: trunk/Source/WTF/wtf/text/WTFString.h (184340 => 184341)


--- trunk/Source/WTF/wtf/text/WTFString.h	2015-05-14 17:36:12 UTC (rev 184340)
+++ trunk/Source/WTF/wtf/text/WTFString.h	2015-05-14 17:55:38 UTC (rev 184341)
@@ -509,6 +509,8 @@
 inline bool equalIgnoringCase(const char* a, const String& b) { return equalIgnoringCase(reinterpret_cast<const LChar*>(a), b.impl()); }
 
 inline bool equalIgnoringASCIICase(const String& a, const String& b) { return equalIgnoringASCIICase(a.impl(), b.impl()); }
+template<unsigned charactersCount>
+inline bool equalIgnoringASCIICase(const String& a, const char (&b)[charactersCount]) { return equalIgnoringASCIICase<charactersCount>(a.impl(), b); }
 
 inline bool equalPossiblyIgnoringCase(const String& a, const String& b, bool ignoreCase) 
 {

Modified: trunk/Tools/ChangeLog (184340 => 184341)


--- trunk/Tools/ChangeLog	2015-05-14 17:36:12 UTC (rev 184340)
+++ trunk/Tools/ChangeLog	2015-05-14 17:55:38 UTC (rev 184341)
@@ -1,3 +1,19 @@
+2015-05-14  Myles C. Maxfield  <mmaxfi...@apple.com>
+
+        Add String literal overloads to equalIgnoringASCIICase()
+        https://bugs.webkit.org/show_bug.cgi?id=145008
+
+        Reviewed by Benjamin Poulain.
+
+        Test changes to WTF.
+
+        * TestWebKitAPI/Tests/WTF/StringImpl.cpp:
+        (WTF.StringImplEqualIgnoringASCIICaseBasic): Test const char*.
+        (WTF.StringImplEqualIgnoringASCIICaseWithLatin1Characters): Ditto.
+        * TestWebKitAPI/Tests/WTF/StringView.cpp:
+        (WTF.StringViewEqualIgnoringASCIICaseBasic): Ditto.
+        (WTF.StringViewEqualIgnoringASCIICaseWithLatin1Characters): Ditto.
+
 2015-05-14  Youenn Fablet  <youenn.fab...@crf.canon.fr>
 
         SharedBuffer::createWithContentsOfFile should use map file routines

Modified: trunk/Tools/TestWebKitAPI/Tests/WTF/StringImpl.cpp (184340 => 184341)


--- trunk/Tools/TestWebKitAPI/Tests/WTF/StringImpl.cpp	2015-05-14 17:36:12 UTC (rev 184340)
+++ trunk/Tools/TestWebKitAPI/Tests/WTF/StringImpl.cpp	2015-05-14 17:55:38 UTC (rev 184341)
@@ -104,13 +104,18 @@
     RefPtr<StringImpl> a = StringImpl::createFromLiteral("aBcDeFG");
     RefPtr<StringImpl> b = StringImpl::createFromLiteral("ABCDEFG");
     RefPtr<StringImpl> c = StringImpl::createFromLiteral("abcdefg");
+    const char d[] = "aBcDeFG";
     RefPtr<StringImpl> empty = StringImpl::create(reinterpret_cast<const LChar*>(""));
     RefPtr<StringImpl> shorter = StringImpl::createFromLiteral("abcdef");
+    RefPtr<StringImpl> different = StringImpl::createFromLiteral("abcrefg");
 
     // Identity.
     ASSERT_TRUE(equalIgnoringASCIICase(a.get(), a.get()));
     ASSERT_TRUE(equalIgnoringASCIICase(b.get(), b.get()));
     ASSERT_TRUE(equalIgnoringASCIICase(c.get(), c.get()));
+    ASSERT_TRUE(equalIgnoringASCIICase(a.get(), d));
+    ASSERT_TRUE(equalIgnoringASCIICase(b.get(), d));
+    ASSERT_TRUE(equalIgnoringASCIICase(c.get(), d));
 
     // Transitivity.
     ASSERT_TRUE(equalIgnoringASCIICase(a.get(), b.get()));
@@ -124,6 +129,12 @@
     ASSERT_FALSE(equalIgnoringASCIICase(a.get(), shorter.get()));
     ASSERT_FALSE(equalIgnoringASCIICase(b.get(), shorter.get()));
     ASSERT_FALSE(equalIgnoringASCIICase(c.get(), shorter.get()));
+    ASSERT_FALSE(equalIgnoringASCIICase(a.get(), different.get()));
+    ASSERT_FALSE(equalIgnoringASCIICase(b.get(), different.get()));
+    ASSERT_FALSE(equalIgnoringASCIICase(c.get(), different.get()));
+    ASSERT_FALSE(equalIgnoringASCIICase(empty.get(), d));
+    ASSERT_FALSE(equalIgnoringASCIICase(shorter.get(), d));
+    ASSERT_FALSE(equalIgnoringASCIICase(different.get(), d));
 }
 
 TEST(WTF, StringImplEqualIgnoringASCIICaseWithNull)
@@ -153,6 +164,7 @@
     RefPtr<StringImpl> b = stringFromUTF8("ABCÉEFG");
     RefPtr<StringImpl> c = stringFromUTF8("ABCéEFG");
     RefPtr<StringImpl> d = stringFromUTF8("abcéefg");
+    const char e[] = "aBcéeFG";
 
     // Identity.
     ASSERT_TRUE(equalIgnoringASCIICase(a.get(), a.get()));
@@ -167,6 +179,10 @@
     ASSERT_FALSE(equalIgnoringASCIICase(b.get(), c.get()));
     ASSERT_FALSE(equalIgnoringASCIICase(b.get(), d.get()));
     ASSERT_TRUE(equalIgnoringASCIICase(c.get(), d.get()));
+    ASSERT_FALSE(equalIgnoringASCIICase(a.get(), e));
+    ASSERT_FALSE(equalIgnoringASCIICase(b.get(), e));
+    ASSERT_FALSE(equalIgnoringASCIICase(c.get(), e));
+    ASSERT_FALSE(equalIgnoringASCIICase(d.get(), e));
 }
 
 TEST(WTF, StringImplFindIgnoringASCIICaseBasic)

Modified: trunk/Tools/TestWebKitAPI/Tests/WTF/StringView.cpp (184340 => 184341)


--- trunk/Tools/TestWebKitAPI/Tests/WTF/StringView.cpp	2015-05-14 17:36:12 UTC (rev 184340)
+++ trunk/Tools/TestWebKitAPI/Tests/WTF/StringView.cpp	2015-05-14 17:55:38 UTC (rev 184341)
@@ -147,18 +147,24 @@
     RefPtr<StringImpl> a = StringImpl::createFromLiteral("aBcDeFG");
     RefPtr<StringImpl> b = StringImpl::createFromLiteral("ABCDEFG");
     RefPtr<StringImpl> c = StringImpl::createFromLiteral("abcdefg");
+    const char d[] = "aBcDeFG";
     RefPtr<StringImpl> empty = StringImpl::create(reinterpret_cast<const LChar*>(""));
     RefPtr<StringImpl> shorter = StringImpl::createFromLiteral("abcdef");
+    RefPtr<StringImpl> different = StringImpl::createFromLiteral("abcrefg");
 
     StringView stringViewA(*a.get());
     StringView stringViewB(*b.get());
     StringView stringViewC(*c.get());
     StringView emptyStringView(*empty.get());
     StringView shorterStringView(*shorter.get());
+    StringView differentStringView(*different.get());
 
     ASSERT_TRUE(equalIgnoringASCIICase(stringViewA, stringViewB));
     ASSERT_TRUE(equalIgnoringASCIICase(stringViewB, stringViewC));
     ASSERT_TRUE(equalIgnoringASCIICase(stringViewB, stringViewC));
+    ASSERT_TRUE(equalIgnoringASCIICase(stringViewA, d));
+    ASSERT_TRUE(equalIgnoringASCIICase(stringViewB, d));
+    ASSERT_TRUE(equalIgnoringASCIICase(stringViewC, d));
 
     // Identity.
     ASSERT_TRUE(equalIgnoringASCIICase(stringViewA, stringViewA));
@@ -177,6 +183,12 @@
     ASSERT_FALSE(equalIgnoringASCIICase(stringViewA, shorterStringView));
     ASSERT_FALSE(equalIgnoringASCIICase(stringViewB, shorterStringView));
     ASSERT_FALSE(equalIgnoringASCIICase(stringViewC, shorterStringView));
+    ASSERT_FALSE(equalIgnoringASCIICase(stringViewA, differentStringView));
+    ASSERT_FALSE(equalIgnoringASCIICase(stringViewB, differentStringView));
+    ASSERT_FALSE(equalIgnoringASCIICase(stringViewC, differentStringView));
+    ASSERT_FALSE(equalIgnoringASCIICase(emptyStringView, d));
+    ASSERT_FALSE(equalIgnoringASCIICase(shorterStringView, d));
+    ASSERT_FALSE(equalIgnoringASCIICase(differentStringView, d));
 }
 
 TEST(WTF, StringViewEqualIgnoringASCIICaseWithEmpty)
@@ -195,6 +207,7 @@
     RefPtr<StringImpl> b = StringImpl::create(reinterpret_cast<const LChar*>("ABCÉEFG"));
     RefPtr<StringImpl> c = StringImpl::create(reinterpret_cast<const LChar*>("ABCéEFG"));
     RefPtr<StringImpl> d = StringImpl::create(reinterpret_cast<const LChar*>("abcéefg"));
+    const char e[] = "aBcéeFG";
     StringView stringViewA(*a.get());
     StringView stringViewB(*b.get());
     StringView stringViewC(*c.get());
@@ -213,6 +226,10 @@
     ASSERT_FALSE(equalIgnoringASCIICase(stringViewB, stringViewC));
     ASSERT_FALSE(equalIgnoringASCIICase(stringViewB, stringViewD));
     ASSERT_TRUE(equalIgnoringASCIICase(stringViewC, stringViewD));
+    ASSERT_FALSE(equalIgnoringASCIICase(stringViewA, e));
+    ASSERT_FALSE(equalIgnoringASCIICase(stringViewB, e));
+    ASSERT_FALSE(equalIgnoringASCIICase(stringViewC, e));
+    ASSERT_FALSE(equalIgnoringASCIICase(stringViewD, e));
 }
 
 StringView stringViewFromLiteral(const char* characters)
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to