Chromium Code Reviews| Index: base/strings/string_util.h |
| diff --git a/base/strings/string_util.h b/base/strings/string_util.h |
| index c2316099c9484bfb24b11c1f9a49ab4fbe7e4164..d1cdcc54e2fb675d3895321c7b898890ea5c2051 100644 |
| --- a/base/strings/string_util.h |
| +++ b/base/strings/string_util.h |
| @@ -21,20 +21,10 @@ |
| namespace base { |
| -// C standard-library functions like "strncasecmp" and "snprintf" that aren't |
| -// cross-platform are provided as "base::strncasecmp", and their prototypes |
| -// are listed below. These functions are then implemented as inline calls |
| -// to the platform-specific equivalents in the platform-specific headers. |
| - |
| -// Compares the two strings s1 and s2 without regard to case using |
| -// the current locale; returns 0 if they are equal, 1 if s1 > s2, and -1 if |
| -// s2 > s1 according to a lexicographic comparison. |
| -int strcasecmp(const char* s1, const char* s2); |
| - |
| -// Compares up to count characters of s1 and s2 without regard to case using |
| -// the current locale; returns 0 if they are equal, 1 if s1 > s2, and -1 if |
| -// s2 > s1 according to a lexicographic comparison. |
| -int strncasecmp(const char* s1, const char* s2, size_t count); |
| +// C standard-library functions that aren't cross-platform are provided as |
| +// "base::...", and their prototypes are listed below. These functions are |
| +// then implemented as inline calls to the platform-specific equivalents in the |
| +// platform-specific headers. |
| // Same as strncmp but for char16 strings. |
| int strncmp16(const char16* s1, const char16* s2, size_t count); |
| @@ -105,6 +95,7 @@ template <class Char> inline Char ToUpperASCII(Char c) { |
| // Function objects to aid in comparing/searching strings. |
| +// DO NOT USE. tolower() will given incorrect results for non-ASCII characters. |
|
Nico
2015/07/08 21:58:23
suggest what to do instead?
|
| template<typename Char> struct CaseInsensitiveCompare { |
| public: |
| bool operator()(Char x, Char y) const { |
| @@ -121,6 +112,22 @@ template<typename Char> struct CaseInsensitiveCompareASCII { |
| } |
| }; |
| +// Like strcasecmp for case-insensitive ASCII characters only. Returns: |
| +// -1 (a < b) |
| +// 0 (a == b) |
| +// 1 (a > b) |
| +// (unlike strcasecmp which can return values greater or less than 1/-1). For |
| +// full Unicode support, use base::i18n::ToLower or base::i18h::FoldCase |
| +// and then just call the normal string operators on the result. |
| +BASE_EXPORT int CompareCaseInsensitiveASCII(StringPiece a, StringPiece b); |
| +BASE_EXPORT int CompareCaseInsensitiveASCII(StringPiece16 a, StringPiece16 b); |
| + |
| +// Equality for ASCII case-insensitive comparisons. For full Unicode support, |
| +// use base::i18n::ToLower or base::i18h::FoldCase and then compare with either |
| +// == or !=. |
| +BASE_EXPORT bool EqualsCaseInsensitiveASCII(StringPiece a, StringPiece b); |
| +BASE_EXPORT bool EqualsCaseInsensitiveASCII(StringPiece16 a, StringPiece16 b); |
| + |
| // These threadsafe functions return references to globally unique empty |
| // strings. |
| // |