Chromium Code Reviews| Index: third_party/WebKit/Source/wtf/text/StringImpl.h |
| diff --git a/third_party/WebKit/Source/wtf/text/StringImpl.h b/third_party/WebKit/Source/wtf/text/StringImpl.h |
| index 49c950eba9e480fbc88facdc5565a5b7dfd4e510..22897f18998bd09c2e5588c9f36090b7af8920bc 100644 |
| --- a/third_party/WebKit/Source/wtf/text/StringImpl.h |
| +++ b/third_party/WebKit/Source/wtf/text/StringImpl.h |
| @@ -31,6 +31,7 @@ |
| #include "wtf/WTFExport.h" |
| #include "wtf/text/Unicode.h" |
| #include <limits.h> |
| +#include <string.h> |
| #if OS(MACOSX) |
| typedef const struct __CFString * CFStringRef; |
| @@ -526,8 +527,17 @@ inline bool equalIgnoringASCIICase(const StringImpl* a, const char* b) { return |
| WTF_EXPORT int codePointCompareIgnoringASCIICase(const StringImpl*, const LChar*); |
| -template<typename CharacterType> |
| -inline size_t find(const CharacterType* characters, unsigned length, CharacterType matchCharacter, unsigned index = 0) |
| +inline size_t find(const LChar* characters, unsigned length, LChar matchCharacter, unsigned index = 0) |
| +{ |
| + // Some clients rely on being able to pass index >= length. |
|
Nico
2016/06/10 19:09:14
should the clients be fixed instead?
jbroman
2016/06/10 19:15:13
In my ideal world (in which nobody passes out-of-r
|
| + if (index >= length) |
| + return kNotFound; |
| + const LChar* found = static_cast<const LChar*>( |
| + memchr(characters + index, matchCharacter, length - index)); |
| + return found ? found - characters : kNotFound; |
| +} |
| + |
| +inline size_t find(const UChar* characters, unsigned length, UChar matchCharacter, unsigned index = 0) |
| { |
| while (index < length) { |
| if (characters[index] == matchCharacter) |
| @@ -549,6 +559,12 @@ inline size_t find(const LChar* characters, unsigned length, UChar matchCharacte |
| return find(characters, length, static_cast<LChar>(matchCharacter), index); |
| } |
| +template <typename CharacterType> |
| +inline size_t find(const CharacterType* characters, unsigned length, char matchCharacter, unsigned index = 0) |
| +{ |
| + return find(characters, length, static_cast<LChar>(matchCharacter), index); |
| +} |
| + |
| inline size_t find(const LChar* characters, unsigned length, CharacterMatchFunctionPtr matchFunction, unsigned index = 0) |
| { |
| while (index < length) { |