Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 2052 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2063 | 2063 |
| 2064 bool equalNonNull(const StringImpl* a, const StringImpl* b) | 2064 bool equalNonNull(const StringImpl* a, const StringImpl* b) |
| 2065 { | 2065 { |
| 2066 ASSERT(a && b); | 2066 ASSERT(a && b); |
| 2067 if (a == b) | 2067 if (a == b) |
| 2068 return true; | 2068 return true; |
| 2069 | 2069 |
| 2070 return stringImplContentEqual(a, b); | 2070 return stringImplContentEqual(a, b); |
| 2071 } | 2071 } |
| 2072 | 2072 |
| 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)); | |
|
esprehn
2016/08/04 08:43:06
We lose this fancy ASCII path and end up doing:
| |
| 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])); | |
|
esprehn
2016/08/04 08:43:06
We also lose this ASCII fast path and end up doing
| |
| 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) | 2073 bool equalIgnoringNullity(StringImpl* a, StringImpl* b) |
| 2161 { | 2074 { |
| 2162 if (!a && b && !b->length()) | 2075 if (!a && b && !b->length()) |
| 2163 return true; | 2076 return true; |
| 2164 if (!b && a && !a->length()) | 2077 if (!b && a && !a->length()) |
| 2165 return true; | 2078 return true; |
| 2166 return equal(a, b); | 2079 return equal(a, b); |
| 2167 } | 2080 } |
| 2168 | 2081 |
| 2169 template<typename CharacterType1, typename CharacterType2> | 2082 template<typename CharacterType1, typename CharacterType2> |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2221 } else if (localeIdMatchesLang(localeIdentifier, "lt")) { | 2134 } else if (localeIdMatchesLang(localeIdentifier, "lt")) { |
| 2222 // TODO(rob.buis) implement upper-casing rules for lt | 2135 // TODO(rob.buis) implement upper-casing rules for lt |
| 2223 // like in StringImpl::upper(locale). | 2136 // like in StringImpl::upper(locale). |
| 2224 } | 2137 } |
| 2225 } | 2138 } |
| 2226 | 2139 |
| 2227 return toUpper(c); | 2140 return toUpper(c); |
| 2228 } | 2141 } |
| 2229 | 2142 |
| 2230 } // namespace WTF | 2143 } // namespace WTF |
| OLD | NEW |