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

Unified Diff: Source/wtf/text/StringImpl.h

Issue 1129313003: Compare :lang value case-insensitive in ASCII range (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Use EXPECT instead of ASSERT Created 5 years, 7 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « Source/core/css/SelectorChecker.cpp ('k') | Source/wtf/text/WTFStringTest.cpp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: Source/wtf/text/StringImpl.h
diff --git a/Source/wtf/text/StringImpl.h b/Source/wtf/text/StringImpl.h
index 2713d6dcfc521ae250d5e10c407162b6f3114222..32c83bfd88c89bcae2505a54a3e327fa7c5c6851 100644
--- a/Source/wtf/text/StringImpl.h
+++ b/Source/wtf/text/StringImpl.h
@@ -504,6 +504,33 @@ WTF_EXPORT bool equalIgnoringCaseNonNull(const StringImpl*, const StringImpl*);
WTF_EXPORT bool equalIgnoringNullity(StringImpl*, StringImpl*);
+template<typename CharacterTypeA, typename CharacterTypeB>
+inline bool equalIgnoringASCIICase(const CharacterTypeA* a, const CharacterTypeB* b, unsigned length)
+{
+ for (unsigned i = 0; i < length; ++i) {
+ if (toASCIILower(a[i]) != toASCIILower(b[i]))
+ return false;
+ }
+ return true;
+}
+
+template<typename CharacterTypeA, typename CharacterTypeB>
+bool startsWithIgnoringASCIICase(const CharacterTypeA& reference, const CharacterTypeB& prefix)
+{
+ unsigned prefixLength = prefix.length();
+ if (prefixLength > reference.length())
+ return false;
+
+ if (reference.is8Bit()) {
+ if (prefix.is8Bit())
+ return equalIgnoringASCIICase(reference.characters8(), prefix.characters8(), prefixLength);
+ return equalIgnoringASCIICase(reference.characters8(), prefix.characters16(), prefixLength);
+ }
+ if (prefix.is8Bit())
+ return equalIgnoringASCIICase(reference.characters16(), prefix.characters8(), prefixLength);
+ return equalIgnoringASCIICase(reference.characters16(), prefix.characters16(), prefixLength);
+}
+
template<typename CharacterType>
inline size_t find(const CharacterType* characters, unsigned length, CharacterType matchCharacter, unsigned index = 0)
{
« no previous file with comments | « Source/core/css/SelectorChecker.cpp ('k') | Source/wtf/text/WTFStringTest.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698