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

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

Issue 2146163003: Use StringView for startsWith and endsWith. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 5 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
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 365 matching lines...) Expand 10 before | Expand all | Expand 10 after
376 size_t find(StringImpl*, unsigned index); 376 size_t find(StringImpl*, unsigned index);
377 size_t findIgnoringCase(const LChar*, unsigned index = 0); 377 size_t findIgnoringCase(const LChar*, unsigned index = 0);
378 ALWAYS_INLINE size_t findIgnoringCase(const char* s, unsigned index = 0) { r eturn findIgnoringCase(reinterpret_cast<const LChar*>(s), index); } 378 ALWAYS_INLINE size_t findIgnoringCase(const char* s, unsigned index = 0) { r eturn findIgnoringCase(reinterpret_cast<const LChar*>(s), index); }
379 size_t findIgnoringCase(StringImpl*, unsigned index = 0); 379 size_t findIgnoringCase(StringImpl*, unsigned index = 0);
380 size_t findIgnoringASCIICase(StringImpl*, unsigned index = 0); 380 size_t findIgnoringASCIICase(StringImpl*, unsigned index = 0);
381 381
382 size_t reverseFind(UChar, unsigned index = UINT_MAX); 382 size_t reverseFind(UChar, unsigned index = UINT_MAX);
383 size_t reverseFind(StringImpl*, unsigned index = UINT_MAX); 383 size_t reverseFind(StringImpl*, unsigned index = UINT_MAX);
384 384
385 bool startsWith(UChar) const; 385 bool startsWith(UChar) const;
386 bool startsWith(const char*, unsigned prefixLength) const; 386 bool startsWith(const StringView&) const;
387 bool startsWith(const StringImpl*) const; 387 bool startsWithIgnoringCase(const StringView&) const;
388 bool startsWithIgnoringCase(const char*, unsigned prefixLength) const; 388 bool startsWithIgnoringASCIICase(const StringView&) const;
389 bool startsWithIgnoringCase(const StringImpl*) const;
390 bool startsWithIgnoringASCIICase(const char*, unsigned prefixLength) const;
391 bool startsWithIgnoringASCIICase(const StringImpl*) const;
392 389
393 bool endsWith(UChar) const; 390 bool endsWith(UChar) const;
394 bool endsWith(const char*, unsigned suffixLength) const; 391 bool endsWith(const StringView&) const;
395 bool endsWith(const StringImpl*) const; 392 bool endsWithIgnoringCase(const StringView&) const;
396 bool endsWithIgnoringCase(const char*, unsigned suffixLength) const; 393 bool endsWithIgnoringASCIICase(const StringView&) const;
397 bool endsWithIgnoringCase(const StringImpl*) const;
398 bool endsWithIgnoringASCIICase(const char*, unsigned suffixLength) const;
399 bool endsWithIgnoringASCIICase(const StringImpl*) const;
400 394
401 PassRefPtr<StringImpl> replace(UChar, UChar); 395 PassRefPtr<StringImpl> replace(UChar, UChar);
402 PassRefPtr<StringImpl> replace(UChar, StringImpl*); 396 PassRefPtr<StringImpl> replace(UChar, StringImpl*);
403 ALWAYS_INLINE PassRefPtr<StringImpl> replace(UChar pattern, const char* repl acement, unsigned replacementLength) { return replace(pattern, reinterpret_cast< const LChar*>(replacement), replacementLength); } 397 ALWAYS_INLINE PassRefPtr<StringImpl> replace(UChar pattern, const char* repl acement, unsigned replacementLength) { return replace(pattern, reinterpret_cast< const LChar*>(replacement), replacementLength); }
404 PassRefPtr<StringImpl> replace(UChar, const LChar*, unsigned replacementLeng th); 398 PassRefPtr<StringImpl> replace(UChar, const LChar*, unsigned replacementLeng th);
405 PassRefPtr<StringImpl> replace(UChar, const UChar*, unsigned replacementLeng th); 399 PassRefPtr<StringImpl> replace(UChar, const UChar*, unsigned replacementLeng th);
406 PassRefPtr<StringImpl> replace(StringImpl*, StringImpl*); 400 PassRefPtr<StringImpl> replace(StringImpl*, StringImpl*);
407 PassRefPtr<StringImpl> replace(unsigned index, unsigned len, StringImpl*); 401 PassRefPtr<StringImpl> replace(unsigned index, unsigned len, StringImpl*);
408 PassRefPtr<StringImpl> upconvertedString(); 402 PassRefPtr<StringImpl> upconvertedString();
409 403
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after
504 template<typename CharacterTypeA, typename CharacterTypeB> 498 template<typename CharacterTypeA, typename CharacterTypeB>
505 inline bool equalIgnoringASCIICase(const CharacterTypeA* a, const CharacterTypeB * b, unsigned length) 499 inline bool equalIgnoringASCIICase(const CharacterTypeA* a, const CharacterTypeB * b, unsigned length)
506 { 500 {
507 for (unsigned i = 0; i < length; ++i) { 501 for (unsigned i = 0; i < length; ++i) {
508 if (toASCIILower(a[i]) != toASCIILower(b[i])) 502 if (toASCIILower(a[i]) != toASCIILower(b[i]))
509 return false; 503 return false;
510 } 504 }
511 return true; 505 return true;
512 } 506 }
513 507
514 WTF_EXPORT bool equalIgnoringASCIICase(const StringImpl*, const StringImpl*);
515 WTF_EXPORT bool equalIgnoringASCIICase(const StringImpl*, const LChar*, unsigned length);
516 inline bool equalIgnoringASCIICase(const StringImpl* a, const char* b, unsigned length) { return equalIgnoringASCIICase(a, reinterpret_cast<const LChar*>(b), le ngth); }
517 inline bool equalIgnoringASCIICase(const StringImpl* a, const LChar* b)
518 {
519 size_t length = b ? strlen(reinterpret_cast<const char*>(b)) : 0;
520 return equalIgnoringASCIICase(a, b, length);
521 }
522 inline bool equalIgnoringASCIICase(const StringImpl* a, const char* b) { return equalIgnoringASCIICase(a, reinterpret_cast<const LChar*>(b)); }
esprehn 2016/07/13 23:42:56 These are all handled by the one defined in String
523
524 WTF_EXPORT int codePointCompareIgnoringASCIICase(const StringImpl*, const LChar* ); 508 WTF_EXPORT int codePointCompareIgnoringASCIICase(const StringImpl*, const LChar* );
525 509
526 inline size_t find(const LChar* characters, unsigned length, LChar matchCharacte r, unsigned index = 0) 510 inline size_t find(const LChar* characters, unsigned length, LChar matchCharacte r, unsigned index = 0)
527 { 511 {
528 // Some clients rely on being able to pass index >= length. 512 // Some clients rely on being able to pass index >= length.
529 if (index >= length) 513 if (index >= length)
530 return kNotFound; 514 return kNotFound;
531 const LChar* found = static_cast<const LChar*>( 515 const LChar* found = static_cast<const LChar*>(
532 memchr(characters + index, matchCharacter, length - index)); 516 memchr(characters + index, matchCharacter, length - index));
533 return found ? found - characters : kNotFound; 517 return found ? found - characters : kNotFound;
(...skipping 201 matching lines...) Expand 10 before | Expand all | Expand 10 after
735 719
736 using WTF::StringImpl; 720 using WTF::StringImpl;
737 using WTF::equal; 721 using WTF::equal;
738 using WTF::equalNonNull; 722 using WTF::equalNonNull;
739 using WTF::TextCaseSensitivity; 723 using WTF::TextCaseSensitivity;
740 using WTF::TextCaseSensitive; 724 using WTF::TextCaseSensitive;
741 using WTF::TextCaseASCIIInsensitive; 725 using WTF::TextCaseASCIIInsensitive;
742 using WTF::TextCaseInsensitive; 726 using WTF::TextCaseInsensitive;
743 727
744 #endif 728 #endif
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698