⚠ Archived content — this site is no longer maintained.   Current WebKit documentation is at docs.webkit.org.

Changeset 181512 in webkit


Ignore:
Timestamp:
Mar 15, 2015, 12:43:18 PM (11 years ago)
Author:
benjamin@webkit.org
Message:

Change the exact attribute matching to be ASCII case-insensitive
https://bugs.webkit.org/show_bug.cgi?id=142609

Patch by Benjamin Poulain <bpoulain@apple.com> on 2015-03-15
Reviewed by Darin Adler.

Source/WebCore:

In CSS, testing attribute values should be ASCII case-insensitive,
previously we were using full unicode case conversion.

Test: fast/selectors/attribute-exact-value-match-is-ascii-case-insensitive.html

  • css/CSSParser.cpp:

(WebCore::CSSParser::parseKeyframeSelector):
The CSS parser has its own fast version for ASCII case insensitive.
This code was using the general equalIgnoringASCIICase() which was causing name conflicts,
change that to the normal CSS parser version.

  • css/SelectorCheckerTestFunctions.h:

(WebCore::equalIgnoringASCIICase): Deleted.

  • cssjit/SelectorCompiler.cpp:

(WebCore::SelectorCompiler::SelectorCodeGenerator::generateElementAttributeValueExactMatching):

Source/WTF:

Add support for ASCII case insensitive comparisons to all the string
classes.

The new file StringCommon.h has the common algorithm to avoid repeating
the same code with different types.

  • WTF.vcxproj/WTF.vcxproj:
  • WTF.vcxproj/WTF.vcxproj.filters:
  • wtf/ASCIICType.h:

(WTF::toASCIILower):

  • wtf/CMakeLists.txt:
  • wtf/text/AtomicString.h:

(WTF::equalIgnoringASCIICase):

  • wtf/text/StringCommon.h: Added.

(WTF::equalIgnoringASCIICase):
(WTF::equalIgnoringASCIICaseCommon):

  • wtf/text/StringImpl.cpp:

(WTF::equalIgnoringASCIICase):
(WTF::equalIgnoringASCIICaseNonNull):
(WTF::StringImpl::utf8Impl):
(WTF::StringImpl::defaultWritingDirection): Deleted.
(WTF::StringImpl::adopt): Deleted.
(WTF::StringImpl::sizeInBytes): Deleted.
(WTF::putUTF8Triple): Deleted.
(WTF::StringImpl::utf8): Deleted.

  • wtf/text/StringImpl.h:

(WTF::StringImpl::isSubString): Deleted.
(WTF::find): Deleted.

Tools:

  • TestWebKitAPI/Tests/WTF/StringImpl.cpp:
  • TestWebKitAPI/Tests/WTF/StringView.cpp:

LayoutTests:

  • fast/selectors/attribute-exact-value-match-is-ascii-case-insensitive-expected.txt: Added.
  • fast/selectors/attribute-exact-value-match-is-ascii-case-insensitive.html: Added.
Location:
trunk
Files:
3 added
19 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r181509 r181512  
     12015-03-15  Benjamin Poulain  <bpoulain@apple.com>
     2
     3        Change the exact attribute matching to be ASCII case-insensitive
     4        https://bugs.webkit.org/show_bug.cgi?id=142609
     5
     6        Reviewed by Darin Adler.
     7
     8        * fast/selectors/attribute-exact-value-match-is-ascii-case-insensitive-expected.txt: Added.
     9        * fast/selectors/attribute-exact-value-match-is-ascii-case-insensitive.html: Added.
     10
    1112015-03-15  Brent Fulgham  <bfulgham@apple.com>
    212
  • trunk/Source/WTF/ChangeLog

    r181501 r181512  
     12015-03-15  Benjamin Poulain  <bpoulain@apple.com>
     2
     3        Change the exact attribute matching to be ASCII case-insensitive
     4        https://bugs.webkit.org/show_bug.cgi?id=142609
     5
     6        Reviewed by Darin Adler.
     7
     8        Add support for ASCII case insensitive comparisons to all the string
     9        classes.
     10
     11        The new file StringCommon.h has the common algorithm to avoid repeating
     12        the same code with different types.
     13
     14        * WTF.vcxproj/WTF.vcxproj:
     15        * WTF.vcxproj/WTF.vcxproj.filters:
     16        * wtf/ASCIICType.h:
     17        (WTF::toASCIILower):
     18        * wtf/CMakeLists.txt:
     19        * wtf/text/AtomicString.h:
     20        (WTF::equalIgnoringASCIICase):
     21        * wtf/text/StringCommon.h: Added.
     22        (WTF::equalIgnoringASCIICase):
     23        (WTF::equalIgnoringASCIICaseCommon):
     24        * wtf/text/StringImpl.cpp:
     25        (WTF::equalIgnoringASCIICase):
     26        (WTF::equalIgnoringASCIICaseNonNull):
     27        (WTF::StringImpl::utf8Impl):
     28        (WTF::StringImpl::defaultWritingDirection): Deleted.
     29        (WTF::StringImpl::adopt): Deleted.
     30        (WTF::StringImpl::sizeInBytes): Deleted.
     31        (WTF::putUTF8Triple): Deleted.
     32        (WTF::StringImpl::utf8): Deleted.
     33        * wtf/text/StringImpl.h:
     34        (WTF::StringImpl::isSubString): Deleted.
     35        (WTF::find): Deleted.
     36
    1372015-03-14  Michael Saboff  <msaboff@apple.com>
    238
  • trunk/Source/WTF/WTF.vcxproj/WTF.vcxproj

    r181485 r181512  
    292292    <ClInclude Include="..\wtf\text\StringBuffer.h" />
    293293    <ClInclude Include="..\wtf\text\StringBuilder.h" />
     294    <ClInclude Include="..\wtf\text\StringCommon.h" />
    294295    <ClInclude Include="..\wtf\text\StringConcatenate.h" />
    295296    <ClInclude Include="..\wtf\text\StringHash.h" />
  • trunk/Source/WTF/WTF.vcxproj/WTF.vcxproj.filters

    r181485 r181512  
    326326    </ClInclude>
    327327    <ClInclude Include="..\wtf\text\StringBuilder.h">
     328      <Filter>text</Filter>
     329    </ClInclude>
     330    <ClInclude Include="..\wtf\text\StringCommon.h">
    328331      <Filter>text</Filter>
    329332    </ClInclude>
  • trunk/Source/WTF/WTF.xcodeproj/project.pbxproj

    r181485 r181512  
    7474                2CDED0F318115C85004DBA70 /* RunLoop.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 2CDED0F118115C85004DBA70 /* RunLoop.cpp */; };
    7575                2CDED0F418115C85004DBA70 /* RunLoop.h in Headers */ = {isa = PBXBuildFile; fileRef = 2CDED0F218115C85004DBA70 /* RunLoop.h */; };
     76                430B47891AAAAC1A001223DA /* StringCommon.h in Headers */ = {isa = PBXBuildFile; fileRef = 430B47871AAAAC1A001223DA /* StringCommon.h */; };
    7677                7CBBA07419BB7FDC00BBF025 /* OSObjectPtr.h in Headers */ = {isa = PBXBuildFile; fileRef = 7CBBA07319BB7FDC00BBF025 /* OSObjectPtr.h */; };
    7778                7CDD7FF8186D291E007433CD /* IteratorAdaptors.h in Headers */ = {isa = PBXBuildFile; fileRef = 7CDD7FF7186D291E007433CD /* IteratorAdaptors.h */; };
     
    358359                2CDED0F118115C85004DBA70 /* RunLoop.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = RunLoop.cpp; sourceTree = "<group>"; };
    359360                2CDED0F218115C85004DBA70 /* RunLoop.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RunLoop.h; sourceTree = "<group>"; };
     361                430B47871AAAAC1A001223DA /* StringCommon.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = StringCommon.h; sourceTree = "<group>"; };
    360362                5D247B6214689B8600E78B76 /* libWTF.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = libWTF.a; sourceTree = BUILT_PRODUCTS_DIR; };
    361363                5D247B6E14689C4700E78B76 /* Base.xcconfig */ = {isa = PBXFileReference; lastKnownFileType = text.xcconfig; path = Base.xcconfig; sourceTree = "<group>"; };
     
    950952                                A8A47324151A825B004123FF /* StringBuilder.cpp */,
    951953                                A8A47325151A825B004123FF /* StringBuilder.h */,
     954                                430B47871AAAAC1A001223DA /* StringCommon.h */,
    952955                                A8A47326151A825B004123FF /* StringConcatenate.h */,
    953956                                A8A47327151A825B004123FF /* StringHash.h */,
     
    11971200                                1A6EB1E0187D0BD30030126F /* StringView.h in Headers */,
    11981201                                A8A47433151A825B004123FF /* TemporaryChange.h in Headers */,
     1202                                430B47891AAAAC1A001223DA /* StringCommon.h in Headers */,
    11991203                                A8A47444151A825B004123FF /* TextPosition.h in Headers */,
    12001204                                A8A47447151A825B004123FF /* ThreadFunctionInvocation.h in Headers */,
  • trunk/Source/WTF/wtf/ASCIICType.h

    r181497 r181512  
    3131
    3232#include <wtf/Assertions.h>
     33#include <wtf/text/LChar.h>
    3334
    3435// The behavior of many of the functions in the <ctype.h> header is dependent
     
    4344
    4445namespace WTF {
     46
     47const unsigned char asciiCaseFoldTable[256] = {
     48    0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f,
     49    0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f,
     50    0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27, 0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x2d, 0x2e, 0x2f,
     51    0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38, 0x39, 0x3a, 0x3b, 0x3c, 0x3d, 0x3e, 0x3f,
     52    0x40, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67, 0x68, 0x69, 0x6a, 0x6b, 0x6c, 0x6d, 0x6e, 0x6f,
     53    0x70, 0x71, 0x72, 0x73, 0x74, 0x75, 0x76, 0x77, 0x78, 0x79, 0x7a, 0x5b, 0x5c, 0x5d, 0x5e, 0x5f,
     54    0x60, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67, 0x68, 0x69, 0x6a, 0x6b, 0x6c, 0x6d, 0x6e, 0x6f,
     55    0x70, 0x71, 0x72, 0x73, 0x74, 0x75, 0x76, 0x77, 0x78, 0x79, 0x7a, 0x7b, 0x7c, 0x7d, 0x7e, 0x7f,
     56    0x80, 0x81, 0x82, 0x83, 0x84, 0x85, 0x86, 0x87, 0x88, 0x89, 0x8a, 0x8b, 0x8c, 0x8d, 0x8e, 0x8f,
     57    0x90, 0x91, 0x92, 0x93, 0x94, 0x95, 0x96, 0x97, 0x98, 0x99, 0x9a, 0x9b, 0x9c, 0x9d, 0x9e, 0x9f,
     58    0xa0, 0xa1, 0xa2, 0xa3, 0xa4, 0xa5, 0xa6, 0xa7, 0xa8, 0xa9, 0xaa, 0xab, 0xac, 0xad, 0xae, 0xaf,
     59    0xb0, 0xb1, 0xb2, 0xb3, 0xb4, 0xb5, 0xb6, 0xb7, 0xb8, 0xb9, 0xba, 0xbb, 0xbc, 0xbd, 0xbe, 0xbf,
     60    0xc0, 0xc1, 0xc2, 0xc3, 0xc4, 0xc5, 0xc6, 0xc7, 0xc8, 0xc9, 0xca, 0xcb, 0xcc, 0xcd, 0xce, 0xcf,
     61    0xd0, 0xd1, 0xd2, 0xd3, 0xd4, 0xd5, 0xd6, 0xd7, 0xd8, 0xd9, 0xda, 0xdb, 0xdc, 0xdd, 0xde, 0xdf,
     62    0xe0, 0xe1, 0xe2, 0xe3, 0xe4, 0xe5, 0xe6, 0xe7, 0xe8, 0xe9, 0xea, 0xeb, 0xec, 0xed, 0xee, 0xef,
     63    0xf0, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7, 0xf8, 0xf9, 0xfa, 0xfb, 0xfc, 0xfd, 0xfe, 0xff
     64};
    4565
    4666template<typename CharType> inline bool isASCII(CharType c)
     
    115135{
    116136    return c | ((c >= 'A' && c <= 'Z') << 5);
     137}
     138
     139template<>
     140inline char toASCIILower(char c)
     141{
     142    return static_cast<char>(asciiCaseFoldTable[static_cast<unsigned char>(c)]);
     143}
     144
     145template<>
     146inline LChar toASCIILower(LChar c)
     147{
     148    return asciiCaseFoldTable[c];
    117149}
    118150
  • trunk/Source/WTF/wtf/CMakeLists.txt

    r181485 r181512  
    130130    text/LChar.h
    131131    text/StringBuffer.h
     132    text/StringCommon.h
    132133    text/StringHash.h
    133134    text/StringImpl.h
  • trunk/Source/WTF/wtf/text/AtomicString.h

    r179429 r181512  
    248248inline bool equalIgnoringCase(const String& a, const AtomicString& b) { return equalIgnoringCase(a.impl(), b.impl()); }
    249249
     250inline bool equalIgnoringASCIICase(const AtomicString& a, const AtomicString& b) { return equalIgnoringASCIICase(a.impl(), b.impl()); }
     251inline bool equalIgnoringASCIICase(const AtomicString& a, const String& b) { return equalIgnoringASCIICase(a.impl(), b.impl()); }
     252inline bool equalIgnoringASCIICase(const String& a, const AtomicString& b) { return equalIgnoringASCIICase(a.impl(), b.impl()); }
     253
    250254// Define external global variables for the commonly used atomic strings.
    251255// These are only usable from the main thread.
  • trunk/Source/WTF/wtf/text/StringImpl.cpp

    r181105 r181512  
    20192019}
    20202020
     2021bool equalIgnoringASCIICase(const StringImpl& a, const StringImpl& b)
     2022{
     2023    return equalIgnoringASCIICaseCommon(a, b);
     2024}
     2025
     2026bool equalIgnoringASCIICase(const StringImpl* a, const StringImpl*b)
     2027{
     2028    if (a == b)
     2029        return true;
     2030    if (!a || !b)
     2031        return false;
     2032    return equalIgnoringASCIICaseCommon(*a, *b);
     2033}
     2034
     2035bool equalIgnoringASCIICaseNonNull(const StringImpl* a, const StringImpl* b)
     2036{
     2037    ASSERT(a);
     2038    ASSERT(b);
     2039    return equalIgnoringASCIICaseCommon(*a, *b);
     2040}
     2041
    20212042UCharDirection StringImpl::defaultWritingDirection(bool* hasStrongDirectionality)
    20222043{
  • trunk/Source/WTF/wtf/text/StringImpl.h

    r181105 r181512  
    11331133WTF_EXPORT_STRING_API bool equalIgnoringNullity(const UChar*, size_t length, StringImpl*);
    11341134
     1135WTF_EXPORT_STRING_API bool equalIgnoringASCIICase(const StringImpl&, const StringImpl&);
     1136WTF_EXPORT_STRING_API bool equalIgnoringASCIICase(const StringImpl*, const StringImpl*);
     1137WTF_EXPORT_STRING_API bool equalIgnoringASCIICaseNonNull(const StringImpl*, const StringImpl*);
     1138
    11351139template<typename CharacterType>
    11361140inline size_t find(const CharacterType* characters, unsigned length, CharacterType matchCharacter, unsigned index = 0)
     
    13751379using WTF::StringImpl;
    13761380using WTF::equal;
     1381using WTF::equalIgnoringASCIICase;
    13771382using WTF::TextCaseSensitivity;
    13781383using WTF::TextCaseSensitive;
  • trunk/Source/WTF/wtf/text/StringView.h

    r179532 r181512  
    3232#include <wtf/Vector.h>
    3333#include <wtf/text/LChar.h>
     34#include <wtf/text/StringCommon.h>
    3435
    3536// FIXME: Enabling the StringView lifetime checking causes the MSVC build to fail. Figure out why.
     
    506507inline bool equalIgnoringASCIICase(StringView a, StringView b)
    507508{
    508     unsigned aLength = a.length();
    509     if (aLength != b.length())
    510         return false;
    511     for (size_t i = 0; i < aLength; ++i) {
    512         if (toASCIILower(a[i]) != toASCIILower(b[i]))
    513             return false;
    514     }
    515     return true;
     509    return equalIgnoringASCIICaseCommon(a, b);
    516510}
    517511
  • trunk/Source/WTF/wtf/text/WTFString.h

    r181105 r181512  
    492492inline bool equalIgnoringCase(const LChar* a, const String& b) { return equalIgnoringCase(a, b.impl()); }
    493493inline bool equalIgnoringCase(const char* a, const String& b) { return equalIgnoringCase(reinterpret_cast<const LChar*>(a), b.impl()); }
     494
     495inline bool equalIgnoringASCIICase(const String& a, const String& b) { return equalIgnoringASCIICase(a.impl(), b.impl()); }
    494496
    495497inline bool equalPossiblyIgnoringCase(const String& a, const String& b, bool ignoreCase)
  • trunk/Source/WebCore/ChangeLog

    r181510 r181512  
     12015-03-15  Benjamin Poulain  <bpoulain@apple.com>
     2
     3        Change the exact attribute matching to be ASCII case-insensitive
     4        https://bugs.webkit.org/show_bug.cgi?id=142609
     5
     6        Reviewed by Darin Adler.
     7
     8        In CSS, testing attribute values should be ASCII case-insensitive,
     9        previously we were using full unicode case conversion.
     10
     11        Test: fast/selectors/attribute-exact-value-match-is-ascii-case-insensitive.html
     12
     13        * css/CSSParser.cpp:
     14        (WebCore::CSSParser::parseKeyframeSelector):
     15        The CSS parser has its own fast version for ASCII case insensitive.
     16        This code was using the general equalIgnoringASCIICase() which was causing name conflicts,
     17        change that to the normal CSS parser version.
     18
     19        * css/SelectorCheckerTestFunctions.h:
     20        (WebCore::equalIgnoringASCIICase): Deleted.
     21        * cssjit/SelectorCompiler.cpp:
     22        (WebCore::SelectorCompiler::SelectorCodeGenerator::generateElementAttributeValueExactMatching):
     23
    1242015-03-15  Brent Fulgham  <bfulgham@apple.com>
    225
  • trunk/Source/WebCore/css/CSSParser.cpp

    r181426 r181512  
    47754775
    47764776        // For now the syntax MUST be 'xxx%' or 'from' or 'to', where xxx is a legal floating point number
    4777         if (equalIgnoringASCIICase(cur, "from"))
     4777        if (equalIgnoringCase(cur, "from"))
    47784778            key = 0;
    4779         else if (equalIgnoringASCIICase(cur, "to"))
     4779        else if (equalIgnoringCase(cur, "to"))
    47804780            key = 1;
    47814781        else if (cur.endsWith('%')) {
  • trunk/Source/WebCore/css/SelectorCheckerTestFunctions.h

    r181408 r181512  
    121121}
    122122
    123 ALWAYS_INLINE bool equalIgnoringASCIICase(const String& a, const String& b)
    124 {
    125     if (a.length() != b.length())
    126         return false;
    127     for (size_t i = 0; i < a.length(); ++i) {
    128         if (toASCIILower(a[i]) != toASCIILower(b[i]))
    129             return false;
    130     }
    131     return true;
    132 }
    133 
    134123ALWAYS_INLINE bool containslanguageSubtagMatchingRange(StringView language, StringView range, unsigned languageLength, unsigned& position)
    135124{
  • trunk/Source/WebCore/cssjit/SelectorCompiler.cpp

    r181283 r181512  
    29352935
    29362936        FunctionCall functionCall(m_assembler, m_registerAllocator, m_stackAllocator, m_functionCalls);
    2937         functionCall.setFunctionAddress(WTF::equalIgnoringCaseNonNull);
     2937        functionCall.setFunctionAddress(WTF::equalIgnoringASCIICaseNonNull);
    29382938        functionCall.setTwoArguments(valueStringImpl, expectedValueRegister);
    29392939        failureCases.append(functionCall.callAndBranchOnBooleanReturnValue(Assembler::Zero));
     
    29482948        Assembler::Jump skipCaseInsensitiveComparison = m_assembler.branchPtr(Assembler::Equal, valueStringImpl, expectedValueRegister);
    29492949        FunctionCall functionCall(m_assembler, m_registerAllocator, m_stackAllocator, m_functionCalls);
    2950         functionCall.setFunctionAddress(WTF::equalIgnoringCaseNonNull);
     2950        functionCall.setFunctionAddress(WTF::equalIgnoringASCIICaseNonNull);
    29512951        functionCall.setTwoArguments(valueStringImpl, expectedValueRegister);
    29522952        failureCases.append(functionCall.callAndBranchOnBooleanReturnValue(Assembler::Zero));
  • trunk/Tools/ChangeLog

    r181479 r181512  
     12015-03-15  Benjamin Poulain  <bpoulain@apple.com>
     2
     3        Change the exact attribute matching to be ASCII case-insensitive
     4        https://bugs.webkit.org/show_bug.cgi?id=142609
     5
     6        Reviewed by Darin Adler.
     7
     8        * TestWebKitAPI/Tests/WTF/StringImpl.cpp:
     9        * TestWebKitAPI/Tests/WTF/StringView.cpp:
     10
    1112015-03-13  Youenn Fablet  <youenn.fablet@crf.canon.fr>
    212
  • trunk/Tools/TestWebKitAPI/Tests/WTF/StringImpl.cpp

    r166076 r181512  
    100100}
    101101
     102TEST(WTF, StringImplEqualIgnoringASCIICaseBasic)
     103{
     104    RefPtr<StringImpl> a = StringImpl::createFromLiteral("aBcDeFG");
     105    RefPtr<StringImpl> b = StringImpl::createFromLiteral("ABCDEFG");
     106    RefPtr<StringImpl> c = StringImpl::createFromLiteral("abcdefg");
     107    RefPtr<StringImpl> empty = StringImpl::create(reinterpret_cast<const LChar*>(""));
     108    RefPtr<StringImpl> shorter = StringImpl::createFromLiteral("abcdef");
     109
     110    // Identity.
     111    ASSERT_TRUE(equalIgnoringASCIICase(a.get(), a.get()));
     112    ASSERT_TRUE(equalIgnoringASCIICase(b.get(), b.get()));
     113    ASSERT_TRUE(equalIgnoringASCIICase(c.get(), c.get()));
     114
     115    // Transitivity.
     116    ASSERT_TRUE(equalIgnoringASCIICase(a.get(), b.get()));
     117    ASSERT_TRUE(equalIgnoringASCIICase(b.get(), c.get()));
     118    ASSERT_TRUE(equalIgnoringASCIICase(a.get(), c.get()));
     119
     120    // Negative cases.
     121    ASSERT_FALSE(equalIgnoringASCIICase(a.get(), empty.get()));
     122    ASSERT_FALSE(equalIgnoringASCIICase(b.get(), empty.get()));
     123    ASSERT_FALSE(equalIgnoringASCIICase(c.get(), empty.get()));
     124    ASSERT_FALSE(equalIgnoringASCIICase(a.get(), shorter.get()));
     125    ASSERT_FALSE(equalIgnoringASCIICase(b.get(), shorter.get()));
     126    ASSERT_FALSE(equalIgnoringASCIICase(c.get(), shorter.get()));
     127}
     128
     129TEST(WTF, StringImplEqualIgnoringASCIICaseWithNull)
     130{
     131    RefPtr<StringImpl> reference = StringImpl::createFromLiteral("aBcDeFG");
     132    ASSERT_FALSE(equalIgnoringASCIICase(nullptr, reference.get()));
     133    ASSERT_FALSE(equalIgnoringASCIICase(reference.get(), nullptr));
     134    ASSERT_TRUE(equalIgnoringASCIICase(nullptr, nullptr));
     135}
     136
     137TEST(WTF, StringImplEqualIgnoringASCIICaseWithEmpty)
     138{
     139    RefPtr<StringImpl> a = StringImpl::create(reinterpret_cast<const LChar*>(""));
     140    RefPtr<StringImpl> b = StringImpl::create(reinterpret_cast<const LChar*>(""));
     141    ASSERT_TRUE(equalIgnoringASCIICase(a.get(), b.get()));
     142    ASSERT_TRUE(equalIgnoringASCIICase(b.get(), a.get()));
     143}
     144
     145TEST(WTF, StringImplEqualIgnoringASCIICaseWithLatin1Characters)
     146{
     147    RefPtr<StringImpl> a = StringImpl::create(reinterpret_cast<const LChar*>("aBcéeFG"));
     148    RefPtr<StringImpl> b = StringImpl::create(reinterpret_cast<const LChar*>("ABCÉEFG"));
     149    RefPtr<StringImpl> c = StringImpl::create(reinterpret_cast<const LChar*>("ABCéEFG"));
     150    RefPtr<StringImpl> d = StringImpl::create(reinterpret_cast<const LChar*>("abcéefg"));
     151
     152    // Identity.
     153    ASSERT_TRUE(equalIgnoringASCIICase(a.get(), a.get()));
     154    ASSERT_TRUE(equalIgnoringASCIICase(b.get(), b.get()));
     155    ASSERT_TRUE(equalIgnoringASCIICase(c.get(), c.get()));
     156    ASSERT_TRUE(equalIgnoringASCIICase(d.get(), d.get()));
     157
     158    // All combination.
     159    ASSERT_FALSE(equalIgnoringASCIICase(a.get(), b.get()));
     160    ASSERT_TRUE(equalIgnoringASCIICase(a.get(), c.get()));
     161    ASSERT_TRUE(equalIgnoringASCIICase(a.get(), d.get()));
     162    ASSERT_FALSE(equalIgnoringASCIICase(b.get(), c.get()));
     163    ASSERT_FALSE(equalIgnoringASCIICase(b.get(), d.get()));
     164    ASSERT_TRUE(equalIgnoringASCIICase(c.get(), d.get()));
     165}
     166
    102167} // namespace TestWebKitAPI
  • trunk/Tools/TestWebKitAPI/Tests/WTF/StringView.cpp

    r174271 r181512  
    143143}
    144144
     145TEST(WTF, StringViewEqualIgnoringASCIICaseBasic)
     146{
     147    RefPtr<StringImpl> a = StringImpl::createFromLiteral("aBcDeFG");
     148    RefPtr<StringImpl> b = StringImpl::createFromLiteral("ABCDEFG");
     149    RefPtr<StringImpl> c = StringImpl::createFromLiteral("abcdefg");
     150    RefPtr<StringImpl> empty = StringImpl::create(reinterpret_cast<const LChar*>(""));
     151    RefPtr<StringImpl> shorter = StringImpl::createFromLiteral("abcdef");
     152
     153    StringView stringViewA(*a.get());
     154    StringView stringViewB(*b.get());
     155    StringView stringViewC(*c.get());
     156    StringView emptyStringView(*empty.get());
     157    StringView shorterStringView(*shorter.get());
     158
     159    ASSERT_TRUE(equalIgnoringASCIICase(stringViewA, stringViewB));
     160    ASSERT_TRUE(equalIgnoringASCIICase(stringViewB, stringViewC));
     161    ASSERT_TRUE(equalIgnoringASCIICase(stringViewB, stringViewC));
     162
     163    // Identity.
     164    ASSERT_TRUE(equalIgnoringASCIICase(stringViewA, stringViewA));
     165    ASSERT_TRUE(equalIgnoringASCIICase(stringViewB, stringViewB));
     166    ASSERT_TRUE(equalIgnoringASCIICase(stringViewC, stringViewC));
     167
     168    // Transitivity.
     169    ASSERT_TRUE(equalIgnoringASCIICase(stringViewA, stringViewB));
     170    ASSERT_TRUE(equalIgnoringASCIICase(stringViewB, stringViewC));
     171    ASSERT_TRUE(equalIgnoringASCIICase(stringViewA, stringViewC));
     172
     173    // Negative cases.
     174    ASSERT_FALSE(equalIgnoringASCIICase(stringViewA, emptyStringView));
     175    ASSERT_FALSE(equalIgnoringASCIICase(stringViewB, emptyStringView));
     176    ASSERT_FALSE(equalIgnoringASCIICase(stringViewC, emptyStringView));
     177    ASSERT_FALSE(equalIgnoringASCIICase(stringViewA, shorterStringView));
     178    ASSERT_FALSE(equalIgnoringASCIICase(stringViewB, shorterStringView));
     179    ASSERT_FALSE(equalIgnoringASCIICase(stringViewC, shorterStringView));
     180}
     181
     182TEST(WTF, StringViewEqualIgnoringASCIICaseWithEmpty)
     183{
     184    RefPtr<StringImpl> a = StringImpl::create(reinterpret_cast<const LChar*>(""));
     185    RefPtr<StringImpl> b = StringImpl::create(reinterpret_cast<const LChar*>(""));
     186    StringView stringViewA(*a.get());
     187    StringView stringViewB(*b.get());
     188    ASSERT_TRUE(equalIgnoringASCIICase(stringViewA, stringViewB));
     189    ASSERT_TRUE(equalIgnoringASCIICase(stringViewB, stringViewA));
     190}
     191
     192TEST(WTF, StringViewEqualIgnoringASCIICaseWithLatin1Characters)
     193{
     194    RefPtr<StringImpl> a = StringImpl::create(reinterpret_cast<const LChar*>("aBcéeFG"));
     195    RefPtr<StringImpl> b = StringImpl::create(reinterpret_cast<const LChar*>("ABCÉEFG"));
     196    RefPtr<StringImpl> c = StringImpl::create(reinterpret_cast<const LChar*>("ABCéEFG"));
     197    RefPtr<StringImpl> d = StringImpl::create(reinterpret_cast<const LChar*>("abcéefg"));
     198    StringView stringViewA(*a.get());
     199    StringView stringViewB(*b.get());
     200    StringView stringViewC(*c.get());
     201    StringView stringViewD(*d.get());
     202
     203    // Identity.
     204    ASSERT_TRUE(equalIgnoringASCIICase(stringViewA, stringViewA));
     205    ASSERT_TRUE(equalIgnoringASCIICase(stringViewB, stringViewB));
     206    ASSERT_TRUE(equalIgnoringASCIICase(stringViewC, stringViewC));
     207    ASSERT_TRUE(equalIgnoringASCIICase(stringViewD, stringViewD));
     208
     209    // All combination.
     210    ASSERT_FALSE(equalIgnoringASCIICase(stringViewA, stringViewB));
     211    ASSERT_TRUE(equalIgnoringASCIICase(stringViewA, stringViewC));
     212    ASSERT_TRUE(equalIgnoringASCIICase(stringViewA, stringViewD));
     213    ASSERT_FALSE(equalIgnoringASCIICase(stringViewB, stringViewC));
     214    ASSERT_FALSE(equalIgnoringASCIICase(stringViewB, stringViewD));
     215    ASSERT_TRUE(equalIgnoringASCIICase(stringViewC, stringViewD));
     216}
     217
    145218} // namespace TestWebKitAPI
Note: See TracChangeset for help on using the changeset viewer.