- Revision
- 127887
- Author
- msab...@apple.com
- Date
- 2012-09-07 10:46:43 -0700 (Fri, 07 Sep 2012)
Log Message
equalIgnoringCase of two StringImpls doesn't handle 8 bit strings
https://bugs.webkit.org/show_bug.cgi?id=96028
Reviewed by Benjamin Poulain.
Added 8 bit checks and paths to CaseFoldingHash::equal. Also cleaned up StringHash::equal(), removing
obvious and in one case wrong comments. Moved equalIgnoringCase(UChar*, UChar*) from StringImpl.cpp
to StringImpl.h.
* wtf/text/StringHash.h:
(WTF::StringHash::equal):
(WTF::CaseFoldingHash::equal):
* wtf/text/StringImpl.cpp:
* wtf/text/StringImpl.h:
(WTF::equalIgnoringCase):
Modified Paths
Diff
Modified: trunk/Source/WTF/ChangeLog (127886 => 127887)
--- trunk/Source/WTF/ChangeLog 2012-09-07 17:25:52 UTC (rev 127886)
+++ trunk/Source/WTF/ChangeLog 2012-09-07 17:46:43 UTC (rev 127887)
@@ -1,3 +1,21 @@
+2012-09-07 Michael Saboff <msab...@apple.com>
+
+ equalIgnoringCase of two StringImpls doesn't handle 8 bit strings
+ https://bugs.webkit.org/show_bug.cgi?id=96028
+
+ Reviewed by Benjamin Poulain.
+
+ Added 8 bit checks and paths to CaseFoldingHash::equal. Also cleaned up StringHash::equal(), removing
+ obvious and in one case wrong comments. Moved equalIgnoringCase(UChar*, UChar*) from StringImpl.cpp
+ to StringImpl.h.
+
+ * wtf/text/StringHash.h:
+ (WTF::StringHash::equal):
+ (WTF::CaseFoldingHash::equal):
+ * wtf/text/StringImpl.cpp:
+ * wtf/text/StringImpl.h:
+ (WTF::equalIgnoringCase):
+
2012-09-07 Patrick Gansterer <par...@webkit.org>
[WIN] Deprecate String += operator
Modified: trunk/Source/WTF/wtf/text/StringHash.h (127886 => 127887)
--- trunk/Source/WTF/wtf/text/StringHash.h 2012-09-07 17:25:52 UTC (rev 127886)
+++ trunk/Source/WTF/wtf/text/StringHash.h 2012-09-07 17:46:43 UTC (rev 127887)
@@ -56,19 +56,14 @@
return false;
if (a->is8Bit()) {
- if (b->is8Bit()) {
- // Both a & b are 8 bit.
+ if (b->is8Bit())
return WTF::equal(a->characters8(), b->characters8(), aLength);
- }
- // We know that a is 8 bit & b is 16 bit.
return WTF::equal(a->characters8(), b->characters16(), aLength);
}
- if (b->is8Bit()) {
- // We know that a is 8 bit and b is 16 bit.
+ if (b->is8Bit())
return WTF::equal(a->characters16(), b->characters8(), aLength);
- }
return WTF::equal(a->characters16(), b->characters16(), aLength);
}
@@ -126,7 +121,18 @@
unsigned length = a->length();
if (length != b->length())
return false;
- return WTF::Unicode::umemcasecmp(a->characters(), b->characters(), length) == 0;
+
+ if (a->is8Bit()) {
+ if (b->is8Bit())
+ return equalIgnoringCase(a->characters8(), b->characters8(), length);
+
+ return equalIgnoringCase(b->characters16(), a->characters8(), length);
+ }
+
+ if (b->is8Bit())
+ return equalIgnoringCase(a->characters16(), b->characters8(), length);
+
+ return equalIgnoringCase(a->characters16(), b->characters16(), length);
}
static unsigned hash(const RefPtr<StringImpl>& key)
Modified: trunk/Source/WTF/wtf/text/StringImpl.cpp (127886 => 127887)
--- trunk/Source/WTF/wtf/text/StringImpl.cpp 2012-09-07 17:25:52 UTC (rev 127886)
+++ trunk/Source/WTF/wtf/text/StringImpl.cpp 2012-09-07 17:46:43 UTC (rev 127887)
@@ -855,12 +855,6 @@
return true;
}
-static inline bool equalIgnoringCase(const UChar* a, const UChar* b, int length)
-{
- ASSERT(length >= 0);
- return umemcasecmp(a, b, length) == 0;
-}
-
size_t StringImpl::find(CharacterMatchFunctionPtr matchFunction, unsigned start)
{
if (is8Bit())
Modified: trunk/Source/WTF/wtf/text/StringImpl.h (127886 => 127887)
--- trunk/Source/WTF/wtf/text/StringImpl.h 2012-09-07 17:25:52 UTC (rev 127886)
+++ trunk/Source/WTF/wtf/text/StringImpl.h 2012-09-07 17:46:43 UTC (rev 127887)
@@ -942,6 +942,11 @@
inline bool equalIgnoringCase(const LChar* a, const UChar* b, unsigned length) { return equalIgnoringCase(b, a, length); }
inline bool equalIgnoringCase(const char* a, const UChar* b, unsigned length) { return equalIgnoringCase(b, reinterpret_cast<const LChar*>(a), length); }
inline bool equalIgnoringCase(const char* a, const LChar* b, unsigned length) { return equalIgnoringCase(b, reinterpret_cast<const LChar*>(a), length); }
+inline bool equalIgnoringCase(const UChar* a, const UChar* b, int length)
+{
+ ASSERT(length >= 0);
+ return !Unicode::umemcasecmp(a, b, length);
+}
WTF_EXPORT_STRING_API bool equalIgnoringNullity(StringImpl*, StringImpl*);