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

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

Issue 1511813004: Refactor StringImpl::{start,end}sWith(StringImpl*, ...) (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 unified diff | Download patch
« no previous file with comments | « third_party/WebKit/Source/wtf/text/StringImpl.cpp ('k') | no next file » | 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 * (C) 1999 Lars Knoll (knoll@kde.org) 2 * (C) 1999 Lars Knoll (knoll@kde.org)
3 * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2012, 2013 Apple Inc. All rights reserved. 3 * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2012, 2013 Apple Inc. All rights reserved.
4 * 4 *
5 * This library is free software; you can redistribute it and/or 5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Library General Public 6 * modify it under the terms of the GNU Library General Public
7 * License as published by the Free Software Foundation; either 7 * License as published by the Free Software Foundation; either
8 * version 2 of the License, or (at your option) any later version. 8 * version 2 of the License, or (at your option) any later version.
9 * 9 *
10 * This library is distributed in the hope that it will be useful, 10 * This library is distributed in the hope that it will be useful,
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
78 KeepTrailingZeros, 78 KeepTrailingZeros,
79 TruncateTrailingZeros 79 TruncateTrailingZeros
80 }; 80 };
81 81
82 enum UTF8ConversionMode { 82 enum UTF8ConversionMode {
83 LenientUTF8Conversion, 83 LenientUTF8Conversion,
84 StrictUTF8Conversion, 84 StrictUTF8Conversion,
85 StrictUTF8ConversionReplacingUnpairedSurrogatesWithFFFD 85 StrictUTF8ConversionReplacingUnpairedSurrogatesWithFFFD
86 }; 86 };
87 87
88 #define DISPATCH_CASE_OP(caseSensitivity, op, args) \
89 ((caseSensitivity == TextCaseSensitive) ? op args : \
90 op##IgnoringCase args)
91
88 template<bool isSpecialCharacter(UChar), typename CharacterType> 92 template<bool isSpecialCharacter(UChar), typename CharacterType>
89 bool isAllSpecialCharacters(const CharacterType*, size_t); 93 bool isAllSpecialCharacters(const CharacterType*, size_t);
90 94
91 // You can find documentation about this class in this doc: 95 // You can find documentation about this class in this doc:
92 // https://docs.google.com/document/d/1kOCUlJdh2WJMJGDf-WoEQhmnjKLaOYRbiHz5TiGJl 14/edit?usp=sharing 96 // https://docs.google.com/document/d/1kOCUlJdh2WJMJGDf-WoEQhmnjKLaOYRbiHz5TiGJl 14/edit?usp=sharing
93 class WTF_EXPORT String { 97 class WTF_EXPORT String {
94 public: 98 public:
95 // Construct a null string, distinguishable from an empty string. 99 // Construct a null string, distinguishable from an empty string.
96 String() { } 100 String() { }
97 101
(...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after
229 // Case insensitive string matching. 233 // Case insensitive string matching.
230 size_t findIgnoringCase(const LChar* str, unsigned start = 0) const 234 size_t findIgnoringCase(const LChar* str, unsigned start = 0) const
231 { return m_impl ? m_impl->findIgnoringCase(str, start) : kNotFound; } 235 { return m_impl ? m_impl->findIgnoringCase(str, start) : kNotFound; }
232 size_t findIgnoringCase(const String& str, unsigned start = 0) const 236 size_t findIgnoringCase(const String& str, unsigned start = 0) const
233 { return m_impl ? m_impl->findIgnoringCase(str.impl(), start) : kNotFoun d; } 237 { return m_impl ? m_impl->findIgnoringCase(str.impl(), start) : kNotFoun d; }
234 size_t reverseFindIgnoringCase(const String& str, unsigned start = UINT_MAX) const 238 size_t reverseFindIgnoringCase(const String& str, unsigned start = UINT_MAX) const
235 { return m_impl ? m_impl->reverseFindIgnoringCase(str.impl(), start) : k NotFound; } 239 { return m_impl ? m_impl->reverseFindIgnoringCase(str.impl(), start) : k NotFound; }
236 240
237 // Wrappers for find & reverseFind adding dynamic sensitivity check. 241 // Wrappers for find & reverseFind adding dynamic sensitivity check.
238 size_t find(const LChar* str, unsigned start, TextCaseSensitivity caseSensit ivity) const 242 size_t find(const LChar* str, unsigned start, TextCaseSensitivity caseSensit ivity) const
239 { return (caseSensitivity == TextCaseSensitive) ? find(str, start) : fin dIgnoringCase(str, start); } 243 { return DISPATCH_CASE_OP(caseSensitivity, find, (str, start)); }
240 size_t find(const String& str, unsigned start, TextCaseSensitivity caseSensi tivity) const 244 size_t find(const String& str, unsigned start, TextCaseSensitivity caseSensi tivity) const
241 { return (caseSensitivity == TextCaseSensitive) ? find(str, start) : fin dIgnoringCase(str, start); } 245 { return DISPATCH_CASE_OP(caseSensitivity, find, (str, start)); }
242 size_t reverseFind(const String& str, unsigned start, TextCaseSensitivity ca seSensitivity) const 246 size_t reverseFind(const String& str, unsigned start, TextCaseSensitivity ca seSensitivity) const
243 { return (caseSensitivity == TextCaseSensitive) ? reverseFind(str, start ) : reverseFindIgnoringCase(str, start); } 247 { return (caseSensitivity == TextCaseSensitive) ? reverseFind(str, start ) : reverseFindIgnoringCase(str, start); }
244 248
245 Vector<UChar> charactersWithNullTermination() const; 249 Vector<UChar> charactersWithNullTermination() const;
246 unsigned copyTo(UChar* buffer, unsigned pos, unsigned maxLength) const; 250 unsigned copyTo(UChar* buffer, unsigned pos, unsigned maxLength) const;
247 251
248 template<size_t inlineCapacity> 252 template<size_t inlineCapacity>
249 void appendTo(Vector<UChar, inlineCapacity>&, unsigned pos = 0, unsigned len = UINT_MAX) const; 253 void appendTo(Vector<UChar, inlineCapacity>&, unsigned pos = 0, unsigned len = UINT_MAX) const;
250 254
251 template<typename BufferType> 255 template<typename BufferType>
252 void appendTo(BufferType&, unsigned pos = 0, unsigned len = UINT_MAX) const; 256 void appendTo(BufferType&, unsigned pos = 0, unsigned len = UINT_MAX) const;
253 257
254 template<size_t inlineCapacity> 258 template<size_t inlineCapacity>
255 void prependTo(Vector<UChar, inlineCapacity>&, unsigned pos = 0, unsigned le n = UINT_MAX) const; 259 void prependTo(Vector<UChar, inlineCapacity>&, unsigned pos = 0, unsigned le n = UINT_MAX) const;
256 260
257 UChar32 characterStartingAt(unsigned) const; 261 UChar32 characterStartingAt(unsigned) const;
258 template<typename CharacterType> 262 template<typename CharacterType>
259 bool contains(CharacterType c) const { return find(c) != kNotFound; } 263 bool contains(CharacterType c) const { return find(c) != kNotFound; }
260 bool contains(const LChar* str, TextCaseSensitivity caseSensitivity = TextCa seSensitive) const { return find(str, 0, caseSensitivity) != kNotFound; } 264 bool contains(const LChar* str, TextCaseSensitivity caseSensitivity = TextCa seSensitive) const { return find(str, 0, caseSensitivity) != kNotFound; }
261 bool contains(const String& str, TextCaseSensitivity caseSensitivity = TextC aseSensitive) const { return find(str, 0, caseSensitivity) != kNotFound; } 265 bool contains(const String& str, TextCaseSensitivity caseSensitivity = TextC aseSensitive) const { return find(str, 0, caseSensitivity) != kNotFound; }
262 266
263 bool startsWith(const String& s, TextCaseSensitivity caseSensitivity = TextC aseSensitive) const 267 bool startsWith(const String& s, TextCaseSensitivity caseSensitivity = TextC aseSensitive) const
264 { return m_impl ? m_impl->startsWith(s.impl(), caseSensitivity) : s.isEm pty(); } 268 { return m_impl ? DISPATCH_CASE_OP(caseSensitivity, m_impl->startsWith, (s.impl())) : s.isEmpty(); }
265 bool startsWith(UChar character) const 269 bool startsWith(UChar character) const
266 { return m_impl ? m_impl->startsWith(character) : false; } 270 { return m_impl ? m_impl->startsWith(character) : false; }
267 template<unsigned matchLength> 271 template<unsigned matchLength>
268 bool startsWith(const char (&prefix)[matchLength]) const 272 bool startsWith(const char (&prefix)[matchLength]) const
269 { return m_impl ? m_impl->startsWith(prefix, matchLength - 1) : !matchLe ngth; } 273 { return m_impl ? m_impl->startsWith(prefix, matchLength - 1) : !matchLe ngth; }
270 274
271 bool endsWith(const String& s, TextCaseSensitivity caseSensitivity = TextCas eSensitive) const 275 bool endsWith(const String& s, TextCaseSensitivity caseSensitivity = TextCas eSensitive) const
272 { return m_impl ? m_impl->endsWith(s.impl(), caseSensitivity) : s.isEmpt y(); } 276 { return m_impl ? DISPATCH_CASE_OP(caseSensitivity, m_impl->endsWith, (s .impl())) : s.isEmpty(); }
273 bool endsWith(UChar character) const 277 bool endsWith(UChar character) const
274 { return m_impl ? m_impl->endsWith(character) : false; } 278 { return m_impl ? m_impl->endsWith(character) : false; }
275 template<unsigned matchLength> 279 template<unsigned matchLength>
276 bool endsWith(const char (&prefix)[matchLength]) const 280 bool endsWith(const char (&prefix)[matchLength]) const
277 { return m_impl ? m_impl->endsWith(prefix, matchLength - 1) : !matchLeng th; } 281 { return m_impl ? m_impl->endsWith(prefix, matchLength - 1) : !matchLeng th; }
278 282
279 void append(const String&); 283 void append(const String&);
280 void append(LChar); 284 void append(LChar);
281 void append(char c) { append(static_cast<LChar>(c)); } 285 void append(char c) { append(static_cast<LChar>(c)); }
282 void append(UChar); 286 void append(UChar);
(...skipping 176 matching lines...) Expand 10 before | Expand all | Expand 10 after
459 463
460 template <typename CharacterType> 464 template <typename CharacterType>
461 void removeInternal(const CharacterType*, unsigned, int); 465 void removeInternal(const CharacterType*, unsigned, int);
462 466
463 template <typename CharacterType> 467 template <typename CharacterType>
464 void appendInternal(CharacterType); 468 void appendInternal(CharacterType);
465 469
466 RefPtr<StringImpl> m_impl; 470 RefPtr<StringImpl> m_impl;
467 }; 471 };
468 472
473 #undef DISPATCH_CASE_OP
474
469 inline bool operator==(const String& a, const String& b) { return equal(a.impl() , b.impl()); } 475 inline bool operator==(const String& a, const String& b) { return equal(a.impl() , b.impl()); }
470 inline bool operator==(const String& a, const LChar* b) { return equal(a.impl(), b); } 476 inline bool operator==(const String& a, const LChar* b) { return equal(a.impl(), b); }
471 inline bool operator==(const String& a, const char* b) { return equal(a.impl(), reinterpret_cast<const LChar*>(b)); } 477 inline bool operator==(const String& a, const char* b) { return equal(a.impl(), reinterpret_cast<const LChar*>(b)); }
472 inline bool operator==(const LChar* a, const String& b) { return equal(a, b.impl ()); } 478 inline bool operator==(const LChar* a, const String& b) { return equal(a, b.impl ()); }
473 inline bool operator==(const char* a, const String& b) { return equal(reinterpre t_cast<const LChar*>(a), b.impl()); } 479 inline bool operator==(const char* a, const String& b) { return equal(reinterpre t_cast<const LChar*>(a), b.impl()); }
474 template<size_t inlineCapacity> 480 template<size_t inlineCapacity>
475 inline bool operator==(const Vector<char, inlineCapacity>& a, const String& b) { return equal(b.impl(), a.data(), a.size()); } 481 inline bool operator==(const Vector<char, inlineCapacity>& a, const String& b) { return equal(b.impl(), a.data(), a.size()); }
476 template<size_t inlineCapacity> 482 template<size_t inlineCapacity>
477 inline bool operator==(const String& a, const Vector<char, inlineCapacity>& b) { return b == a; } 483 inline bool operator==(const String& a, const Vector<char, inlineCapacity>& b) { return b == a; }
478 484
(...skipping 214 matching lines...) Expand 10 before | Expand all | Expand 10 after
693 using WTF::charactersToFloat; 699 using WTF::charactersToFloat;
694 using WTF::equal; 700 using WTF::equal;
695 using WTF::equalIgnoringCase; 701 using WTF::equalIgnoringCase;
696 using WTF::find; 702 using WTF::find;
697 using WTF::isAllSpecialCharacters; 703 using WTF::isAllSpecialCharacters;
698 using WTF::isSpaceOrNewline; 704 using WTF::isSpaceOrNewline;
699 using WTF::reverseFind; 705 using WTF::reverseFind;
700 706
701 #include "wtf/text/AtomicString.h" 707 #include "wtf/text/AtomicString.h"
702 #endif // WTFString_h 708 #endif // WTFString_h
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/wtf/text/StringImpl.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698