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

Side by Side Diff: third_party/WebKit/Source/wtf/text/StringImpl.h

Issue 2508953003: WTF: Add comments and tests for Unicode aware case-insensitive string operations. (Closed)
Patch Set: Created 4 years, 1 month 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
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 3 * Copyright (C) 2005, 2006, 2007, 2008, 2009, 2010, 2013 Apple Inc. All rights
4 * reserved. 4 * reserved.
5 * Copyright (C) 2009 Google Inc. All rights reserved. 5 * Copyright (C) 2009 Google Inc. All rights reserved.
6 * 6 *
7 * This library is free software; you can redistribute it and/or 7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Library General Public 8 * modify it under the terms of the GNU Library General Public
9 * License as published by the Free Software Foundation; either 9 * License as published by the Free Software Foundation; either
10 * version 2 of the License, or (at your option) any later version. 10 * version 2 of the License, or (at your option) any later version.
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
44 44
45 namespace WTF { 45 namespace WTF {
46 46
47 struct AlreadyHashed; 47 struct AlreadyHashed;
48 template <typename> 48 template <typename>
49 class RetainPtr; 49 class RetainPtr;
50 50
51 enum TextCaseSensitivity { 51 enum TextCaseSensitivity {
52 TextCaseSensitive, 52 TextCaseSensitive,
53 TextCaseASCIIInsensitive, 53 TextCaseASCIIInsensitive,
54
55 // Unicode aware case insensitive matching. Non-ASCII characters might match
56 // to ASCII characters. This flag is rarely used to implement web platform
57 // features.
54 TextCaseInsensitive 58 TextCaseInsensitive
55 }; 59 };
56 60
57 enum StripBehavior { StripExtraWhiteSpace, DoNotStripWhiteSpace }; 61 enum StripBehavior { StripExtraWhiteSpace, DoNotStripWhiteSpace };
58 62
59 typedef bool (*CharacterMatchFunctionPtr)(UChar); 63 typedef bool (*CharacterMatchFunctionPtr)(UChar);
60 typedef bool (*IsWhiteSpaceFunctionPtr)(UChar); 64 typedef bool (*IsWhiteSpaceFunctionPtr)(UChar);
61 typedef HashMap<unsigned, StringImpl*, AlreadyHashed> StaticStringsTable; 65 typedef HashMap<unsigned, StringImpl*, AlreadyHashed> StaticStringsTable;
62 66
63 // Define STRING_STATS to turn on run time statistics of string sizes and memory 67 // Define STRING_STATS to turn on run time statistics of string sizes and memory
(...skipping 313 matching lines...) Expand 10 before | Expand all | Expand 10 after
377 PassRefPtr<StringImpl> remove(unsigned start, unsigned lengthToRemove = 1); 381 PassRefPtr<StringImpl> remove(unsigned start, unsigned lengthToRemove = 1);
378 382
379 // Find characters. 383 // Find characters.
380 size_t find(LChar character, unsigned start = 0); 384 size_t find(LChar character, unsigned start = 0);
381 size_t find(char character, unsigned start = 0); 385 size_t find(char character, unsigned start = 0);
382 size_t find(UChar character, unsigned start = 0); 386 size_t find(UChar character, unsigned start = 0);
383 size_t find(CharacterMatchFunctionPtr, unsigned index = 0); 387 size_t find(CharacterMatchFunctionPtr, unsigned index = 0);
384 388
385 // Find substrings. 389 // Find substrings.
386 size_t find(const StringView&, unsigned index = 0); 390 size_t find(const StringView&, unsigned index = 0);
391 // Unicode aware case insensitive string matching. Non-ASCII characters might
392 // match to ASCII characters. This function is rarely used to implement web
393 // platform features.
387 size_t findIgnoringCase(const StringView&, unsigned index = 0); 394 size_t findIgnoringCase(const StringView&, unsigned index = 0);
388 size_t findIgnoringASCIICase(const StringView&, unsigned index = 0); 395 size_t findIgnoringASCIICase(const StringView&, unsigned index = 0);
389 396
390 size_t reverseFind(UChar, unsigned index = UINT_MAX); 397 size_t reverseFind(UChar, unsigned index = UINT_MAX);
391 size_t reverseFind(const StringView&, unsigned index = UINT_MAX); 398 size_t reverseFind(const StringView&, unsigned index = UINT_MAX);
392 399
393 bool startsWith(UChar) const; 400 bool startsWith(UChar) const;
394 bool startsWith(const StringView&) const; 401 bool startsWith(const StringView&) const;
395 bool startsWithIgnoringCase(const StringView&) const; 402 bool startsWithIgnoringCase(const StringView&) const;
396 bool startsWithIgnoringASCIICase(const StringView&) const; 403 bool startsWithIgnoringASCIICase(const StringView&) const;
(...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after
536 if (a[i] != b[i]) 543 if (a[i] != b[i])
537 return false; 544 return false;
538 } 545 }
539 return true; 546 return true;
540 } 547 }
541 548
542 ALWAYS_INLINE bool equal(const UChar* a, const LChar* b, unsigned length) { 549 ALWAYS_INLINE bool equal(const UChar* a, const LChar* b, unsigned length) {
543 return equal(b, a, length); 550 return equal(b, a, length);
544 } 551 }
545 552
553 // Unicode aware case insensitive string matching. Non-ASCII characters might
554 // match to ASCII characters. These functions are rarely used to implement web
555 // platform features.
546 WTF_EXPORT bool equalIgnoringCase(const LChar*, const LChar*, unsigned length); 556 WTF_EXPORT bool equalIgnoringCase(const LChar*, const LChar*, unsigned length);
547 WTF_EXPORT bool equalIgnoringCase(const UChar*, const LChar*, unsigned length); 557 WTF_EXPORT bool equalIgnoringCase(const UChar*, const LChar*, unsigned length);
548 inline bool equalIgnoringCase(const LChar* a, const UChar* b, unsigned length) { 558 inline bool equalIgnoringCase(const LChar* a, const UChar* b, unsigned length) {
549 return equalIgnoringCase(b, a, length); 559 return equalIgnoringCase(b, a, length);
550 } 560 }
551
552 WTF_EXPORT bool equalIgnoringCase(const UChar*, const UChar*, unsigned length); 561 WTF_EXPORT bool equalIgnoringCase(const UChar*, const UChar*, unsigned length);
553 562
554 WTF_EXPORT bool equalIgnoringNullity(StringImpl*, StringImpl*); 563 WTF_EXPORT bool equalIgnoringNullity(StringImpl*, StringImpl*);
555 564
556 template <typename CharacterTypeA, typename CharacterTypeB> 565 template <typename CharacterTypeA, typename CharacterTypeB>
557 inline bool equalIgnoringASCIICase(const CharacterTypeA* a, 566 inline bool equalIgnoringASCIICase(const CharacterTypeA* a,
558 const CharacterTypeB* b, 567 const CharacterTypeB* b,
559 unsigned length) { 568 unsigned length) {
560 for (unsigned i = 0; i < length; ++i) { 569 for (unsigned i = 0; i < length; ++i) {
561 if (toASCIILower(a[i]) != toASCIILower(b[i])) 570 if (toASCIILower(a[i]) != toASCIILower(b[i]))
(...skipping 271 matching lines...) Expand 10 before | Expand all | Expand 10 after
833 using WTF::TextCaseASCIIInsensitive; 842 using WTF::TextCaseASCIIInsensitive;
834 using WTF::TextCaseInsensitive; 843 using WTF::TextCaseInsensitive;
835 using WTF::TextCaseSensitive; 844 using WTF::TextCaseSensitive;
836 using WTF::TextCaseSensitivity; 845 using WTF::TextCaseSensitivity;
837 using WTF::equal; 846 using WTF::equal;
838 using WTF::equalNonNull; 847 using WTF::equalNonNull;
839 using WTF::lengthOfNullTerminatedString; 848 using WTF::lengthOfNullTerminatedString;
840 using WTF::reverseFind; 849 using WTF::reverseFind;
841 850
842 #endif 851 #endif
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/wtf/text/StringBuilder.h ('k') | third_party/WebKit/Source/wtf/text/StringView.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698