Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(83)

Side by Side Diff: third_party/WebKit/Source/wtf/text/StringImpl.cpp

Issue 2148423003: Use StringView for equalIgnoringCase. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: DCHECK is silly. Created 4 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 /* 1 /*
2 * Copyright (C) 1999 Lars Knoll (knoll@kde.org) 2 * Copyright (C) 1999 Lars Knoll (knoll@kde.org)
3 * (C) 1999 Antti Koivisto (koivisto@kde.org) 3 * (C) 1999 Antti Koivisto (koivisto@kde.org)
4 * (C) 2001 Dirk Mueller ( mueller@kde.org ) 4 * (C) 2001 Dirk Mueller ( mueller@kde.org )
5 * Copyright (C) 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2013 Apple Inc. All r ights reserved. 5 * Copyright (C) 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2013 Apple Inc. All r ights reserved.
6 * Copyright (C) 2006 Andrew Wellington (proton@wiretapped.net) 6 * Copyright (C) 2006 Andrew Wellington (proton@wiretapped.net)
7 * 7 *
8 * This library is free software; you can redistribute it and/or 8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Library General Public 9 * modify it under the terms of the GNU Library General Public
10 * License as published by the Free Software Foundation; either 10 * License as published by the Free Software Foundation; either
(...skipping 1110 matching lines...) Expand 10 before | Expand all | Expand 10 after
1121 0x00a0, 0x00a1, 0x00a2, 0x00a3, 0x00a4, 0x00a5, 0x00a6, 0x00a7, 0x00a8, 0x00 a9, 0x00aa, 0x00ab, 0x00ac, 0x00ad, 0x00ae, 0x00af, 1121 0x00a0, 0x00a1, 0x00a2, 0x00a3, 0x00a4, 0x00a5, 0x00a6, 0x00a7, 0x00a8, 0x00 a9, 0x00aa, 0x00ab, 0x00ac, 0x00ad, 0x00ae, 0x00af,
1122 0x00b0, 0x00b1, 0x00b2, 0x00b3, 0x00b4, 0x03bc, 0x00b6, 0x00b7, 0x00b8, 0x00 b9, 0x00ba, 0x00bb, 0x00bc, 0x00bd, 0x00be, 0x00bf, 1122 0x00b0, 0x00b1, 0x00b2, 0x00b3, 0x00b4, 0x03bc, 0x00b6, 0x00b7, 0x00b8, 0x00 b9, 0x00ba, 0x00bb, 0x00bc, 0x00bd, 0x00be, 0x00bf,
1123 0x00e0, 0x00e1, 0x00e2, 0x00e3, 0x00e4, 0x00e5, 0x00e6, 0x00e7, 0x00e8, 0x00 e9, 0x00ea, 0x00eb, 0x00ec, 0x00ed, 0x00ee, 0x00ef, 1123 0x00e0, 0x00e1, 0x00e2, 0x00e3, 0x00e4, 0x00e5, 0x00e6, 0x00e7, 0x00e8, 0x00 e9, 0x00ea, 0x00eb, 0x00ec, 0x00ed, 0x00ee, 0x00ef,
1124 0x00f0, 0x00f1, 0x00f2, 0x00f3, 0x00f4, 0x00f5, 0x00f6, 0x00d7, 0x00f8, 0x00 f9, 0x00fa, 0x00fb, 0x00fc, 0x00fd, 0x00fe, 0x00df, 1124 0x00f0, 0x00f1, 0x00f2, 0x00f3, 0x00f4, 0x00f5, 0x00f6, 0x00d7, 0x00f8, 0x00 f9, 0x00fa, 0x00fb, 0x00fc, 0x00fd, 0x00fe, 0x00df,
1125 0x00e0, 0x00e1, 0x00e2, 0x00e3, 0x00e4, 0x00e5, 0x00e6, 0x00e7, 0x00e8, 0x00 e9, 0x00ea, 0x00eb, 0x00ec, 0x00ed, 0x00ee, 0x00ef, 1125 0x00e0, 0x00e1, 0x00e2, 0x00e3, 0x00e4, 0x00e5, 0x00e6, 0x00e7, 0x00e8, 0x00 e9, 0x00ea, 0x00eb, 0x00ec, 0x00ed, 0x00ee, 0x00ef,
1126 0x00f0, 0x00f1, 0x00f2, 0x00f3, 0x00f4, 0x00f5, 0x00f6, 0x00f7, 0x00f8, 0x00 f9, 0x00fa, 0x00fb, 0x00fc, 0x00fd, 0x00fe, 0x00ff, 1126 0x00f0, 0x00f1, 0x00f2, 0x00f3, 0x00f4, 0x00f5, 0x00f6, 0x00f7, 0x00f8, 0x00 f9, 0x00fa, 0x00fb, 0x00fc, 0x00fd, 0x00fe, 0x00ff,
1127 }; 1127 };
1128 1128
1129 bool equalIgnoringCase(const LChar* a, const LChar* b, unsigned length) 1129 bool equalIgnoringCase(const LChar* a, const LChar* b, unsigned length)
1130 { 1130 {
1131 DCHECK_GE(length, 0u);
1132 if (a == b)
1133 return true;
1131 while (length--) { 1134 while (length--) {
1132 if (StringImpl::latin1CaseFoldTable[*a++] != StringImpl::latin1CaseFoldT able[*b++]) 1135 if (StringImpl::latin1CaseFoldTable[*a++] != StringImpl::latin1CaseFoldT able[*b++])
1133 return false; 1136 return false;
1134 } 1137 }
1135 return true; 1138 return true;
1136 } 1139 }
1137 1140
1141 bool equalIgnoringCase(const UChar* a, const UChar* b, unsigned length)
1142 {
1143 DCHECK_GE(length, 0u);
1144 if (a == b)
1145 return true;
1146 return !Unicode::umemcasecmp(a, b, length);
1147 }
1148
1138 bool equalIgnoringCase(const UChar* a, const LChar* b, unsigned length) 1149 bool equalIgnoringCase(const UChar* a, const LChar* b, unsigned length)
1139 { 1150 {
1140 while (length--) { 1151 while (length--) {
1141 if (foldCase(*a++) != StringImpl::latin1CaseFoldTable[*b++]) 1152 if (foldCase(*a++) != StringImpl::latin1CaseFoldTable[*b++])
1142 return false; 1153 return false;
1143 } 1154 }
1144 return true; 1155 return true;
1145 } 1156 }
1146 1157
1147 size_t StringImpl::find(CharacterMatchFunctionPtr matchFunction, unsigned start) 1158 size_t StringImpl::find(CharacterMatchFunctionPtr matchFunction, unsigned start)
(...skipping 915 matching lines...) Expand 10 before | Expand all | Expand 10 after
2063 2074
2064 bool equalNonNull(const StringImpl* a, const StringImpl* b) 2075 bool equalNonNull(const StringImpl* a, const StringImpl* b)
2065 { 2076 {
2066 ASSERT(a && b); 2077 ASSERT(a && b);
2067 if (a == b) 2078 if (a == b)
2068 return true; 2079 return true;
2069 2080
2070 return stringImplContentEqual(a, b); 2081 return stringImplContentEqual(a, b);
2071 } 2082 }
2072 2083
2073 bool equalIgnoringCase(const StringImpl* a, const StringImpl* b)
2074 {
2075 if (a == b)
2076 return true;
2077 if (!a || !b)
2078 return false;
2079
2080 return CaseFoldingHash::equal(a, b);
2081 }
2082
2083 bool equalIgnoringCase(const StringImpl* a, const LChar* b)
2084 {
2085 if (!a)
2086 return !b;
2087 if (!b)
2088 return !a;
2089
2090 unsigned length = a->length();
2091
2092 // Do a faster loop for the case where all the characters are ASCII.
2093 UChar ored = 0;
2094 bool equal = true;
2095 if (a->is8Bit()) {
2096 const LChar* as = a->characters8();
2097 for (unsigned i = 0; i != length; ++i) {
2098 LChar bc = b[i];
2099 if (!bc)
2100 return false;
2101 UChar ac = as[i];
2102 ored |= ac;
2103 equal = equal && (toASCIILower(ac) == toASCIILower(bc));
2104 }
2105
2106 // Do a slower implementation for cases that include non-ASCII character s.
2107 if (ored & ~0x7F) {
2108 equal = true;
2109 for (unsigned i = 0; i != length; ++i)
2110 equal = equal && (foldCase(as[i]) == foldCase(b[i]));
2111 }
2112
2113 return equal && !b[length];
2114 }
2115
2116 const UChar* as = a->characters16();
2117 for (unsigned i = 0; i != length; ++i) {
2118 LChar bc = b[i];
2119 if (!bc)
2120 return false;
2121 UChar ac = as[i];
2122 ored |= ac;
2123 equal = equal && (toASCIILower(ac) == toASCIILower(bc));
2124 }
2125
2126 // Do a slower implementation for cases that include non-ASCII characters.
2127 if (ored & ~0x7F) {
2128 equal = true;
2129 for (unsigned i = 0; i != length; ++i) {
2130 equal = equal && (foldCase(as[i]) == foldCase(b[i]));
2131 }
2132 }
2133
2134 return equal && !b[length];
2135 }
2136
2137 bool equalIgnoringCaseNonNull(const StringImpl* a, const StringImpl* b)
2138 {
2139 ASSERT(a && b);
2140 if (a == b)
2141 return true;
2142
2143 unsigned length = a->length();
2144 if (length != b->length())
2145 return false;
2146
2147 if (a->is8Bit()) {
2148 if (b->is8Bit())
2149 return equalIgnoringCase(a->characters8(), b->characters8(), length) ;
2150
2151 return equalIgnoringCase(b->characters16(), a->characters8(), length);
2152 }
2153
2154 if (b->is8Bit())
2155 return equalIgnoringCase(a->characters16(), b->characters8(), length);
2156
2157 return equalIgnoringCase(a->characters16(), b->characters16(), length);
2158 }
2159
2160 bool equalIgnoringNullity(StringImpl* a, StringImpl* b) 2084 bool equalIgnoringNullity(StringImpl* a, StringImpl* b)
2161 { 2085 {
2162 if (!a && b && !b->length()) 2086 if (!a && b && !b->length())
2163 return true; 2087 return true;
2164 if (!b && a && !a->length()) 2088 if (!b && a && !a->length())
2165 return true; 2089 return true;
2166 return equal(a, b); 2090 return equal(a, b);
2167 } 2091 }
2168 2092
2169 template<typename CharacterType1, typename CharacterType2> 2093 template<typename CharacterType1, typename CharacterType2>
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
2221 } else if (localeIdMatchesLang(localeIdentifier, "lt")) { 2145 } else if (localeIdMatchesLang(localeIdentifier, "lt")) {
2222 // TODO(rob.buis) implement upper-casing rules for lt 2146 // TODO(rob.buis) implement upper-casing rules for lt
2223 // like in StringImpl::upper(locale). 2147 // like in StringImpl::upper(locale).
2224 } 2148 }
2225 } 2149 }
2226 2150
2227 return toUpper(c); 2151 return toUpper(c);
2228 } 2152 }
2229 2153
2230 } // namespace WTF 2154 } // namespace WTF
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/wtf/text/StringImpl.h ('k') | third_party/WebKit/Source/wtf/text/StringView.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698