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

Unified 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « third_party/WebKit/Source/wtf/text/StringImpl.cpp ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: third_party/WebKit/Source/wtf/text/WTFString.h
diff --git a/third_party/WebKit/Source/wtf/text/WTFString.h b/third_party/WebKit/Source/wtf/text/WTFString.h
index aff113819f4b8f4b0e8ca4d80b9d6435dcc0451f..2f4be9107c5bfd27b7c44138a5eb2f9152799e62 100644
--- a/third_party/WebKit/Source/wtf/text/WTFString.h
+++ b/third_party/WebKit/Source/wtf/text/WTFString.h
@@ -85,6 +85,10 @@ enum UTF8ConversionMode {
StrictUTF8ConversionReplacingUnpairedSurrogatesWithFFFD
};
+#define DISPATCH_CASE_OP(caseSensitivity, op, args) \
+ ((caseSensitivity == TextCaseSensitive) ? op args : \
+ op##IgnoringCase args)
+
template<bool isSpecialCharacter(UChar), typename CharacterType>
bool isAllSpecialCharacters(const CharacterType*, size_t);
@@ -236,9 +240,9 @@ public:
// Wrappers for find & reverseFind adding dynamic sensitivity check.
size_t find(const LChar* str, unsigned start, TextCaseSensitivity caseSensitivity) const
- { return (caseSensitivity == TextCaseSensitive) ? find(str, start) : findIgnoringCase(str, start); }
+ { return DISPATCH_CASE_OP(caseSensitivity, find, (str, start)); }
size_t find(const String& str, unsigned start, TextCaseSensitivity caseSensitivity) const
- { return (caseSensitivity == TextCaseSensitive) ? find(str, start) : findIgnoringCase(str, start); }
+ { return DISPATCH_CASE_OP(caseSensitivity, find, (str, start)); }
size_t reverseFind(const String& str, unsigned start, TextCaseSensitivity caseSensitivity) const
{ return (caseSensitivity == TextCaseSensitive) ? reverseFind(str, start) : reverseFindIgnoringCase(str, start); }
@@ -261,7 +265,7 @@ public:
bool contains(const String& str, TextCaseSensitivity caseSensitivity = TextCaseSensitive) const { return find(str, 0, caseSensitivity) != kNotFound; }
bool startsWith(const String& s, TextCaseSensitivity caseSensitivity = TextCaseSensitive) const
- { return m_impl ? m_impl->startsWith(s.impl(), caseSensitivity) : s.isEmpty(); }
+ { return m_impl ? DISPATCH_CASE_OP(caseSensitivity, m_impl->startsWith, (s.impl())) : s.isEmpty(); }
bool startsWith(UChar character) const
{ return m_impl ? m_impl->startsWith(character) : false; }
template<unsigned matchLength>
@@ -269,7 +273,7 @@ public:
{ return m_impl ? m_impl->startsWith(prefix, matchLength - 1) : !matchLength; }
bool endsWith(const String& s, TextCaseSensitivity caseSensitivity = TextCaseSensitive) const
- { return m_impl ? m_impl->endsWith(s.impl(), caseSensitivity) : s.isEmpty(); }
+ { return m_impl ? DISPATCH_CASE_OP(caseSensitivity, m_impl->endsWith, (s.impl())) : s.isEmpty(); }
bool endsWith(UChar character) const
{ return m_impl ? m_impl->endsWith(character) : false; }
template<unsigned matchLength>
@@ -466,6 +470,8 @@ private:
RefPtr<StringImpl> m_impl;
};
+#undef DISPATCH_CASE_OP
+
inline bool operator==(const String& a, const String& b) { return equal(a.impl(), b.impl()); }
inline bool operator==(const String& a, const LChar* b) { return equal(a.impl(), b); }
inline bool operator==(const String& a, const char* b) { return equal(a.impl(), reinterpret_cast<const LChar*>(b)); }
« 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