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

Side by Side 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 unified diff | Download patch
« no previous file with comments | « Source/core/css/SelectorChecker.cpp ('k') | Source/wtf/text/WTFStringTest.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright (C) 1999 Lars Knoll (knoll@kde.org) 2 * Copyright (C) 1999 Lars Knoll (knoll@kde.org)
3 * Copyright (C) 2005, 2006, 2007, 2008, 2009, 2010, 2013 Apple Inc. All rights reserved. 3 * Copyright (C) 2005, 2006, 2007, 2008, 2009, 2010, 2013 Apple Inc. All rights reserved.
4 * Copyright (C) 2009 Google Inc. All rights reserved. 4 * Copyright (C) 2009 Google Inc. All rights reserved.
5 * 5 *
6 * This library is free software; you can redistribute it and/or 6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Library General Public 7 * modify it under the terms of the GNU Library General Public
8 * License as published by the Free Software Foundation; either 8 * License as published by the Free Software Foundation; either
9 * version 2 of the License, or (at your option) any later version. 9 * version 2 of the License, or (at your option) any later version.
10 * 10 *
(...skipping 486 matching lines...) Expand 10 before | Expand all | Expand 10 after
497 inline bool equalIgnoringCase(const char* a, const LChar* b, unsigned length) { return equalIgnoringCase(b, reinterpret_cast<const LChar*>(a), length); } 497 inline bool equalIgnoringCase(const char* a, const LChar* b, unsigned length) { return equalIgnoringCase(b, reinterpret_cast<const LChar*>(a), length); }
498 inline bool equalIgnoringCase(const UChar* a, const UChar* b, int length) 498 inline bool equalIgnoringCase(const UChar* a, const UChar* b, int length)
499 { 499 {
500 ASSERT(length >= 0); 500 ASSERT(length >= 0);
501 return !Unicode::umemcasecmp(a, b, length); 501 return !Unicode::umemcasecmp(a, b, length);
502 } 502 }
503 WTF_EXPORT bool equalIgnoringCaseNonNull(const StringImpl*, const StringImpl*); 503 WTF_EXPORT bool equalIgnoringCaseNonNull(const StringImpl*, const StringImpl*);
504 504
505 WTF_EXPORT bool equalIgnoringNullity(StringImpl*, StringImpl*); 505 WTF_EXPORT bool equalIgnoringNullity(StringImpl*, StringImpl*);
506 506
507 template<typename CharacterTypeA, typename CharacterTypeB>
508 inline bool equalIgnoringASCIICase(const CharacterTypeA* a, const CharacterTypeB * b, unsigned length)
509 {
510 for (unsigned i = 0; i < length; ++i) {
511 if (toASCIILower(a[i]) != toASCIILower(b[i]))
512 return false;
513 }
514 return true;
515 }
516
517 template<typename CharacterTypeA, typename CharacterTypeB>
518 bool startsWithIgnoringASCIICase(const CharacterTypeA& reference, const Characte rTypeB& prefix)
519 {
520 unsigned prefixLength = prefix.length();
521 if (prefixLength > reference.length())
522 return false;
523
524 if (reference.is8Bit()) {
525 if (prefix.is8Bit())
526 return equalIgnoringASCIICase(reference.characters8(), prefix.charac ters8(), prefixLength);
527 return equalIgnoringASCIICase(reference.characters8(), prefix.characters 16(), prefixLength);
528 }
529 if (prefix.is8Bit())
530 return equalIgnoringASCIICase(reference.characters16(), prefix.character s8(), prefixLength);
531 return equalIgnoringASCIICase(reference.characters16(), prefix.characters16( ), prefixLength);
532 }
533
507 template<typename CharacterType> 534 template<typename CharacterType>
508 inline size_t find(const CharacterType* characters, unsigned length, CharacterTy pe matchCharacter, unsigned index = 0) 535 inline size_t find(const CharacterType* characters, unsigned length, CharacterTy pe matchCharacter, unsigned index = 0)
509 { 536 {
510 while (index < length) { 537 while (index < length) {
511 if (characters[index] == matchCharacter) 538 if (characters[index] == matchCharacter)
512 return index; 539 return index;
513 ++index; 540 ++index;
514 } 541 }
515 return kNotFound; 542 return kNotFound;
516 } 543 }
(...skipping 226 matching lines...) Expand 10 before | Expand all | Expand 10 after
743 } 770 }
744 771
745 using WTF::StringImpl; 772 using WTF::StringImpl;
746 using WTF::equal; 773 using WTF::equal;
747 using WTF::equalNonNull; 774 using WTF::equalNonNull;
748 using WTF::TextCaseSensitivity; 775 using WTF::TextCaseSensitivity;
749 using WTF::TextCaseSensitive; 776 using WTF::TextCaseSensitive;
750 using WTF::TextCaseInsensitive; 777 using WTF::TextCaseInsensitive;
751 778
752 #endif 779 #endif
OLDNEW
« 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