Modified: trunk/Source/WTF/wtf/text/StringImpl.cpp (131654 => 131655)
--- trunk/Source/WTF/wtf/text/StringImpl.cpp 2012-10-17 22:14:41 UTC (rev 131654)
+++ trunk/Source/WTF/wtf/text/StringImpl.cpp 2012-10-17 22:16:12 UTC (rev 131655)
@@ -1048,6 +1048,22 @@
return findInner(characters16() + index, matchString->characters16(), index, searchLength, matchLength);
}
+template <typename SearchCharacterType, typename MatchCharacterType>
+ALWAYS_INLINE static size_t findIgnoringCaseInner(const SearchCharacterType* searchCharacters, const MatchCharacterType* matchCharacters, unsigned index, unsigned searchLength, unsigned matchLength)
+{
+ // delta is the number of additional times to test; delta == 0 means test only once.
+ unsigned delta = searchLength - matchLength;
+
+ unsigned i = 0;
+ // keep looping until we match
+ while (!equalIgnoringCase(searchCharacters + i, matchCharacters, matchLength)) {
+ if (i == delta)
+ return notFound;
+ ++i;
+ }
+ return index + i;
+}
+
size_t StringImpl::findIgnoringCase(StringImpl* matchString, unsigned index)
{
// Check for null or empty string to match against
@@ -1063,20 +1079,17 @@
unsigned searchLength = length() - index;
if (matchLength > searchLength)
return notFound;
- // delta is the number of additional times to test; delta == 0 means test only once.
- unsigned delta = searchLength - matchLength;
- const UChar* searchCharacters = characters() + index;
- const UChar* matchCharacters = matchString->characters();
+ if (is8Bit()) {
+ if (matchString->is8Bit())
+ return findIgnoringCaseInner(characters8() + index, matchString->characters8(), index, length(), matchLength);
+ return findIgnoringCaseInner(characters8() + index, matchString->characters16(), index, length(), matchLength);
+ }
- unsigned i = 0;
- // keep looping until we match
- while (!equalIgnoringCase(searchCharacters + i, matchCharacters, matchLength)) {
- if (i == delta)
- return notFound;
- ++i;
- }
- return index + i;
+ if (matchString->is8Bit())
+ return findIgnoringCaseInner(characters16() + index, matchString->characters8(), index, length(), matchLength);
+
+ return findIgnoringCaseInner(characters16() + index, matchString->characters16(), index, length(), matchLength);
}
size_t StringImpl::reverseFind(UChar c, unsigned index)
@@ -1146,44 +1159,45 @@
return reverseFindInner(characters16(), matchString->characters16(), index, ourLength, matchLength);
}
+template <typename SearchCharacterType, typename MatchCharacterType>
+ALWAYS_INLINE static size_t reverseFindIgnoringCaseInner(const SearchCharacterType* searchCharacters, const MatchCharacterType* matchCharacters, unsigned index, unsigned length, unsigned matchLength)
+{
+ // delta is the number of additional times to test; delta == 0 means test only once.
+ unsigned delta = min(index, length - matchLength);
+
+ // keep looping until we match
+ while (!equalIgnoringCase(searchCharacters + delta, matchCharacters, matchLength)) {
+ if (!delta)
+ return notFound;
+ delta--;
+ }
+ return delta;
+}
+
size_t StringImpl::reverseFindIgnoringCase(StringImpl* matchString, unsigned index)
{
// Check for null or empty string to match against
if (!matchString)
return notFound;
unsigned matchLength = matchString->length();
+ unsigned ourLength = length();
if (!matchLength)
- return min(index, length());
+ return min(index, ourLength);
// Check index & matchLength are in range.
- if (matchLength > length())
+ if (matchLength > ourLength)
return notFound;
- // delta is the number of additional times to test; delta == 0 means test only once.
- unsigned delta = min(index, length() - matchLength);
- if (is8Bit() && matchString->is8Bit()) {
- const LChar *searchCharacters = characters8();
- const LChar *matchCharacters = matchString->characters8();
-
- // keep looping until we match
- while (!equalIgnoringCase(searchCharacters + delta, matchCharacters, matchLength)) {
- if (!delta)
- return notFound;
- delta--;
- }
- return delta;
+ if (is8Bit()) {
+ if (matchString->is8Bit())
+ return reverseFindIgnoringCaseInner(characters8(), matchString->characters8(), index, ourLength, matchLength);
+ return reverseFindIgnoringCaseInner(characters8(), matchString->characters16(), index, ourLength, matchLength);
}
- const UChar *searchCharacters = characters();
- const UChar *matchCharacters = matchString->characters();
+ if (matchString->is8Bit())
+ return reverseFindIgnoringCaseInner(characters16(), matchString->characters8(), index, ourLength, matchLength);
- // keep looping until we match
- while (!equalIgnoringCase(searchCharacters + delta, matchCharacters, matchLength)) {
- if (!delta)
- return notFound;
- delta--;
- }
- return delta;
+ return reverseFindIgnoringCaseInner(characters16(), matchString->characters16(), index, ourLength, matchLength);
}
ALWAYS_INLINE static bool equalInner(const StringImpl* stringImpl, unsigned startOffset, const char* matchString, unsigned matchLength, bool caseSensitive)