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

Unified Diff: third_party/WebKit/Source/wtf/text/StringImpl.cpp

Issue 1507763003: Drop TextCaseSensitivity from {start,end}sWith(const char*, ...) (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « third_party/WebKit/Source/wtf/text/StringImpl.h ('k') | third_party/WebKit/Source/wtf/text/WTFString.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: third_party/WebKit/Source/wtf/text/StringImpl.cpp
diff --git a/third_party/WebKit/Source/wtf/text/StringImpl.cpp b/third_party/WebKit/Source/wtf/text/StringImpl.cpp
index 64bae95694bafcc6f7cbb224805a7a8969eb86fe..c5871328cc891ac11d8f45916c9ca5a919bc4d8d 100644
--- a/third_party/WebKit/Source/wtf/text/StringImpl.cpp
+++ b/third_party/WebKit/Source/wtf/text/StringImpl.cpp
@@ -651,23 +651,26 @@ upconvert:
return newImpl.release();
}
-static bool inline localeIdMatchesLang(const AtomicString& localeId, const char* lang)
+ALWAYS_INLINE static bool startsWithIgnoringCase(const StringImpl* stringImpl, const LChar* prefix, unsigned prefixLength)
{
- if (equalIgnoringCase(localeId, lang))
- return true;
- static char localeIdPrefix[4];
- static const char delimeter[4] = "-_@";
+ ASSERT(stringImpl);
+ if (prefixLength > stringImpl->length())
+ return false;
+ if (stringImpl->is8Bit())
+ return equalIgnoringCase(stringImpl->characters8(), prefix, prefixLength);
+ return equalIgnoringCase(stringImpl->characters16(), prefix, prefixLength);
+}
+static inline bool localeIdMatchesLang(const AtomicString& localeId, const char* lang)
+{
size_t langLength = strlen(lang);
RELEASE_ASSERT(langLength >= 2 && langLength <= 3);
- strncpy(localeIdPrefix, lang, langLength);
- for (int i = 0; i < 3; ++i) {
- localeIdPrefix[langLength] = delimeter[i];
- // case-insensitive comparison
- if (localeId.impl() && localeId.impl()->startsWith(localeIdPrefix, langLength + 1, TextCaseInsensitive))
- return true;
- }
- return false;
+ if (!localeId.impl() || !startsWithIgnoringCase(localeId.impl(), reinterpret_cast<const LChar*>(lang), langLength))
+ return false;
+ if (localeId.impl()->length() == langLength)
+ return true;
+ const UChar maybeDelimiter = (*localeId.impl())[langLength];
+ return maybeDelimiter == '-' || maybeDelimiter == '_' || maybeDelimiter == '@';
}
typedef int32_t (*icuCaseConverter)(UChar*, int32_t, const UChar*, int32_t, const char*, UErrorCode*);
@@ -1463,20 +1466,15 @@ size_t StringImpl::reverseFindIgnoringCase(StringImpl* matchString, unsigned ind
return reverseFindIgnoringCaseInner(characters16(), matchString->characters16(), index, ourLength, matchLength);
}
-ALWAYS_INLINE static bool equalInner(const StringImpl* stringImpl, unsigned startOffset, const char* matchString, unsigned matchLength, TextCaseSensitivity caseSensitivity)
+ALWAYS_INLINE static bool equalInner(const StringImpl* stringImpl, unsigned startOffset, const LChar* matchString, unsigned matchLength)
{
ASSERT(stringImpl);
ASSERT(matchLength <= stringImpl->length());
ASSERT(startOffset + matchLength <= stringImpl->length());
- if (caseSensitivity == TextCaseSensitive) {
- if (stringImpl->is8Bit())
- return equal(stringImpl->characters8() + startOffset, reinterpret_cast<const LChar*>(matchString), matchLength);
- return equal(stringImpl->characters16() + startOffset, reinterpret_cast<const LChar*>(matchString), matchLength);
- }
if (stringImpl->is8Bit())
- return equalIgnoringCase(stringImpl->characters8() + startOffset, reinterpret_cast<const LChar*>(matchString), matchLength);
- return equalIgnoringCase(stringImpl->characters16() + startOffset, reinterpret_cast<const LChar*>(matchString), matchLength);
+ return equal(stringImpl->characters8() + startOffset, matchString, matchLength);
+ return equal(stringImpl->characters16() + startOffset, matchString, matchLength);
}
bool StringImpl::startsWith(UChar character) const
@@ -1484,12 +1482,12 @@ bool StringImpl::startsWith(UChar character) const
return m_length && (*this)[0] == character;
}
-bool StringImpl::startsWith(const char* matchString, unsigned matchLength, TextCaseSensitivity caseSensitivity) const
+bool StringImpl::startsWith(const char* matchString, unsigned matchLength) const
{
ASSERT(matchLength);
if (matchLength > length())
return false;
- return equalInner(this, 0, matchString, matchLength, caseSensitivity);
+ return equalInner(this, 0, reinterpret_cast<const LChar*>(matchString), matchLength);
}
bool StringImpl::endsWith(StringImpl* matchString, TextCaseSensitivity caseSensitivity)
@@ -1509,13 +1507,12 @@ bool StringImpl::endsWith(UChar character) const
return m_length && (*this)[m_length - 1] == character;
}
-bool StringImpl::endsWith(const char* matchString, unsigned matchLength, TextCaseSensitivity caseSensitivity) const
+bool StringImpl::endsWith(const char* matchString, unsigned matchLength) const
{
ASSERT(matchLength);
if (matchLength > length())
return false;
- unsigned startOffset = length() - matchLength;
- return equalInner(this, startOffset, matchString, matchLength, caseSensitivity);
+ return equalInner(this, length() - matchLength, reinterpret_cast<const LChar*>(matchString), matchLength);
}
PassRefPtr<StringImpl> StringImpl::replace(UChar oldC, UChar newC)
« no previous file with comments | « third_party/WebKit/Source/wtf/text/StringImpl.h ('k') | third_party/WebKit/Source/wtf/text/WTFString.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698