Changeset 184341 in webkit


Ignore:
Timestamp:
May 14, 2015 10:55:38 AM (9 years ago)
Author:
mmaxfield@apple.com
Message:

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

Patch by Myles C. Maxfield <mmaxfield@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.

Location:
trunk
Files:
9 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WTF/ChangeLog

    r184333 r184341  
     12015-05-14  Myles C. Maxfield  <mmaxfield@apple.com>
     2
     3        Add String literal overloads to equalIgnoringASCIICase()
     4        https://bugs.webkit.org/show_bug.cgi?id=145008
     5
     6        Reviewed by Benjamin Poulain.
     7
     8        Create an overload for equalIgnoringASCIICase for string literals.
     9
     10        * wtf/text/StringImpl.h:
     11        (WTF::equalIgnoringASCIICase): Use a non-templated helper function.
     12        * wtf/text/StringImpl.cpp:
     13        (WTF::equalIgnoringASCIICase): Implement it.
     14        * wtf/text/StringView.h:
     15        (WTF::equalIgnoringASCIICase): Use a non-templated helper function.
     16        * wtf/text/StringView.cpp:
     17        (WTF::equalIgnoringASCIICase): Implement it.
     18        * wtf/text/WTFString.h:
     19        (WTF::equalIgnoringASCIICase): Delegate to StringImpl's implementation.
     20
    1212015-05-14  Žan Doberšek  <zdobersek@igalia.com>
    222
  • trunk/Source/WTF/wtf/text/StringImpl.cpp

    r183624 r184341  
    20762076}
    20772077
     2078bool equalIgnoringASCIICase(const StringImpl& a, const char* b, unsigned bLength)
     2079{
     2080    if (bLength != a.length())
     2081        return false;
     2082
     2083    if (a.is8Bit())
     2084        return equalIgnoringASCIICase(a.characters8(), b, bLength);
     2085
     2086    return equalIgnoringASCIICase(a.characters16(), b, bLength);
     2087}
     2088
    20782089bool equalIgnoringASCIICaseNonNull(const StringImpl* a, const StringImpl* b)
    20792090{
  • trunk/Source/WTF/wtf/text/StringImpl.h

    r183723 r184341  
    973973WTF_EXPORT_STRING_API bool equalIgnoringASCIICase(const StringImpl&, const StringImpl&);
    974974WTF_EXPORT_STRING_API bool equalIgnoringASCIICase(const StringImpl*, const StringImpl*);
     975WTF_EXPORT_STRING_API bool equalIgnoringASCIICase(const StringImpl& a, const char* b, unsigned bLength);
    975976WTF_EXPORT_STRING_API bool equalIgnoringASCIICaseNonNull(const StringImpl*, const StringImpl*);
     977
     978template<unsigned charactersCount>
     979bool equalIgnoringASCIICase(const StringImpl* a, const char (&b)[charactersCount])
     980{
     981    return a ? equalIgnoringASCIICase(*a, b, charactersCount - 1) : false;
     982}
    976983
    977984template<typename CharacterType>
  • trunk/Source/WTF/wtf/text/StringView.cpp

    r181845 r184341  
    7272{
    7373    return ::WTF::endsWithIgnoringASCIICase(*this, suffix);
     74}
     75
     76bool equalIgnoringASCIICase(StringView a, const char* b, unsigned bLength)
     77{
     78    if (bLength != a.length())
     79        return false;
     80
     81    if (a.is8Bit())
     82        return equalIgnoringASCIICase(a.characters8(), b, bLength);
     83
     84    return equalIgnoringASCIICase(a.characters16(), b, bLength);
    7485}
    7586
  • trunk/Source/WTF/wtf/text/StringView.h

    r184037 r184341  
    157157bool equal(StringView, const char*);
    158158bool equalIgnoringASCIICase(StringView, StringView);
     159WTF_EXPORT_STRING_API bool equalIgnoringASCIICase(StringView a, const char* b, unsigned bLength);
     160template<unsigned charactersCount>
     161bool equalIgnoringASCIICase(StringView a, const char (&b)[charactersCount])
     162{
     163    return equalIgnoringASCIICase(a, b, charactersCount - 1);
     164}
    159165
    160166inline bool operator==(StringView a, StringView b) { return equal(a, b); }
  • trunk/Source/WTF/wtf/text/WTFString.h

    r181845 r184341  
    510510
    511511inline bool equalIgnoringASCIICase(const String& a, const String& b) { return equalIgnoringASCIICase(a.impl(), b.impl()); }
     512template<unsigned charactersCount>
     513inline bool equalIgnoringASCIICase(const String& a, const char (&b)[charactersCount]) { return equalIgnoringASCIICase<charactersCount>(a.impl(), b); }
    512514
    513515inline bool equalPossiblyIgnoringCase(const String& a, const String& b, bool ignoreCase)
  • trunk/Tools/ChangeLog

    r184331 r184341  
     12015-05-14  Myles C. Maxfield  <mmaxfield@apple.com>
     2
     3        Add String literal overloads to equalIgnoringASCIICase()
     4        https://bugs.webkit.org/show_bug.cgi?id=145008
     5
     6        Reviewed by Benjamin Poulain.
     7
     8        Test changes to WTF.
     9
     10        * TestWebKitAPI/Tests/WTF/StringImpl.cpp:
     11        (WTF.StringImplEqualIgnoringASCIICaseBasic): Test const char*.
     12        (WTF.StringImplEqualIgnoringASCIICaseWithLatin1Characters): Ditto.
     13        * TestWebKitAPI/Tests/WTF/StringView.cpp:
     14        (WTF.StringViewEqualIgnoringASCIICaseBasic): Ditto.
     15        (WTF.StringViewEqualIgnoringASCIICaseWithLatin1Characters): Ditto.
     16
    1172015-05-14  Youenn Fablet  <youenn.fablet@crf.canon.fr>
    218
  • trunk/Tools/TestWebKitAPI/Tests/WTF/StringImpl.cpp

    r182205 r184341  
    105105    RefPtr<StringImpl> b = StringImpl::createFromLiteral("ABCDEFG");
    106106    RefPtr<StringImpl> c = StringImpl::createFromLiteral("abcdefg");
     107    const char d[] = "aBcDeFG";
    107108    RefPtr<StringImpl> empty = StringImpl::create(reinterpret_cast<const LChar*>(""));
    108109    RefPtr<StringImpl> shorter = StringImpl::createFromLiteral("abcdef");
     110    RefPtr<StringImpl> different = StringImpl::createFromLiteral("abcrefg");
    109111
    110112    // Identity.
     
    112114    ASSERT_TRUE(equalIgnoringASCIICase(b.get(), b.get()));
    113115    ASSERT_TRUE(equalIgnoringASCIICase(c.get(), c.get()));
     116    ASSERT_TRUE(equalIgnoringASCIICase(a.get(), d));
     117    ASSERT_TRUE(equalIgnoringASCIICase(b.get(), d));
     118    ASSERT_TRUE(equalIgnoringASCIICase(c.get(), d));
    114119
    115120    // Transitivity.
     
    125130    ASSERT_FALSE(equalIgnoringASCIICase(b.get(), shorter.get()));
    126131    ASSERT_FALSE(equalIgnoringASCIICase(c.get(), shorter.get()));
     132    ASSERT_FALSE(equalIgnoringASCIICase(a.get(), different.get()));
     133    ASSERT_FALSE(equalIgnoringASCIICase(b.get(), different.get()));
     134    ASSERT_FALSE(equalIgnoringASCIICase(c.get(), different.get()));
     135    ASSERT_FALSE(equalIgnoringASCIICase(empty.get(), d));
     136    ASSERT_FALSE(equalIgnoringASCIICase(shorter.get(), d));
     137    ASSERT_FALSE(equalIgnoringASCIICase(different.get(), d));
    127138}
    128139
     
    154165    RefPtr<StringImpl> c = stringFromUTF8("ABCéEFG");
    155166    RefPtr<StringImpl> d = stringFromUTF8("abcéefg");
     167    const char e[] = "aBcéeFG";
    156168
    157169    // Identity.
     
    168180    ASSERT_FALSE(equalIgnoringASCIICase(b.get(), d.get()));
    169181    ASSERT_TRUE(equalIgnoringASCIICase(c.get(), d.get()));
     182    ASSERT_FALSE(equalIgnoringASCIICase(a.get(), e));
     183    ASSERT_FALSE(equalIgnoringASCIICase(b.get(), e));
     184    ASSERT_FALSE(equalIgnoringASCIICase(c.get(), e));
     185    ASSERT_FALSE(equalIgnoringASCIICase(d.get(), e));
    170186}
    171187
  • trunk/Tools/TestWebKitAPI/Tests/WTF/StringView.cpp

    r184037 r184341  
    148148    RefPtr<StringImpl> b = StringImpl::createFromLiteral("ABCDEFG");
    149149    RefPtr<StringImpl> c = StringImpl::createFromLiteral("abcdefg");
     150    const char d[] = "aBcDeFG";
    150151    RefPtr<StringImpl> empty = StringImpl::create(reinterpret_cast<const LChar*>(""));
    151152    RefPtr<StringImpl> shorter = StringImpl::createFromLiteral("abcdef");
     153    RefPtr<StringImpl> different = StringImpl::createFromLiteral("abcrefg");
    152154
    153155    StringView stringViewA(*a.get());
     
    156158    StringView emptyStringView(*empty.get());
    157159    StringView shorterStringView(*shorter.get());
     160    StringView differentStringView(*different.get());
    158161
    159162    ASSERT_TRUE(equalIgnoringASCIICase(stringViewA, stringViewB));
    160163    ASSERT_TRUE(equalIgnoringASCIICase(stringViewB, stringViewC));
    161164    ASSERT_TRUE(equalIgnoringASCIICase(stringViewB, stringViewC));
     165    ASSERT_TRUE(equalIgnoringASCIICase(stringViewA, d));
     166    ASSERT_TRUE(equalIgnoringASCIICase(stringViewB, d));
     167    ASSERT_TRUE(equalIgnoringASCIICase(stringViewC, d));
    162168
    163169    // Identity.
     
    178184    ASSERT_FALSE(equalIgnoringASCIICase(stringViewB, shorterStringView));
    179185    ASSERT_FALSE(equalIgnoringASCIICase(stringViewC, shorterStringView));
     186    ASSERT_FALSE(equalIgnoringASCIICase(stringViewA, differentStringView));
     187    ASSERT_FALSE(equalIgnoringASCIICase(stringViewB, differentStringView));
     188    ASSERT_FALSE(equalIgnoringASCIICase(stringViewC, differentStringView));
     189    ASSERT_FALSE(equalIgnoringASCIICase(emptyStringView, d));
     190    ASSERT_FALSE(equalIgnoringASCIICase(shorterStringView, d));
     191    ASSERT_FALSE(equalIgnoringASCIICase(differentStringView, d));
    180192}
    181193
     
    196208    RefPtr<StringImpl> c = StringImpl::create(reinterpret_cast<const LChar*>("ABCéEFG"));
    197209    RefPtr<StringImpl> d = StringImpl::create(reinterpret_cast<const LChar*>("abcéefg"));
     210    const char e[] = "aBcéeFG";
    198211    StringView stringViewA(*a.get());
    199212    StringView stringViewB(*b.get());
     
    214227    ASSERT_FALSE(equalIgnoringASCIICase(stringViewB, stringViewD));
    215228    ASSERT_TRUE(equalIgnoringASCIICase(stringViewC, stringViewD));
     229    ASSERT_FALSE(equalIgnoringASCIICase(stringViewA, e));
     230    ASSERT_FALSE(equalIgnoringASCIICase(stringViewB, e));
     231    ASSERT_FALSE(equalIgnoringASCIICase(stringViewC, e));
     232    ASSERT_FALSE(equalIgnoringASCIICase(stringViewD, e));
    216233}
    217234
Note: See TracChangeset for help on using the changeset viewer.