Chromium Code Reviews| Index: base/string_util.cc |
| =================================================================== |
| --- base/string_util.cc (revision 29143) |
| +++ base/string_util.cc (working copy) |
| @@ -751,6 +751,12 @@ |
| return DoLowerCaseEqualsASCII(a.begin(), a.end(), b); |
| } |
| +#if !defined(WCHAR_T_IS_UTF16) |
|
Matt Perry
2009/10/15 23:06:16
This confused me for a minute. Can you add a comme
darin (slow to review)
2009/10/15 23:13:15
This #if pattern appears throughout this file. It
Matt Perry
2009/10/15 23:18:47
I didn't realize it was a common pattern. In that
|
| +bool LowerCaseEqualsASCII(const string16& a, const char* b) { |
| + return DoLowerCaseEqualsASCII(a.begin(), a.end(), b); |
| +} |
| +#endif |
| + |
| bool LowerCaseEqualsASCII(std::string::const_iterator a_begin, |
| std::string::const_iterator a_end, |
| const char* b) { |
| @@ -762,17 +768,35 @@ |
| const char* b) { |
| return DoLowerCaseEqualsASCII(a_begin, a_end, b); |
| } |
| + |
| +#if !defined(WCHAR_T_IS_UTF16) |
| +bool LowerCaseEqualsASCII(string16::const_iterator a_begin, |
| + string16::const_iterator a_end, |
| + const char* b) { |
| + return DoLowerCaseEqualsASCII(a_begin, a_end, b); |
| +} |
| +#endif |
| + |
| bool LowerCaseEqualsASCII(const char* a_begin, |
| const char* a_end, |
| const char* b) { |
| return DoLowerCaseEqualsASCII(a_begin, a_end, b); |
| } |
| + |
| bool LowerCaseEqualsASCII(const wchar_t* a_begin, |
| const wchar_t* a_end, |
| const char* b) { |
| return DoLowerCaseEqualsASCII(a_begin, a_end, b); |
| } |
| +#if !defined(WCHAR_T_IS_UTF16) |
| +bool LowerCaseEqualsASCII(const char16* a_begin, |
| + const char16* a_end, |
| + const char* b) { |
| + return DoLowerCaseEqualsASCII(a_begin, a_end, b); |
| +} |
| +#endif |
| + |
| bool EqualsASCII(const string16& a, const base::StringPiece& b) { |
| if (a.length() != b.length()) |
| return false; |
| @@ -788,24 +812,34 @@ |
| return base::strncasecmp(str.c_str(), search.c_str(), search.length()) == 0; |
| } |
| -bool StartsWith(const std::wstring& str, |
| - const std::wstring& search, |
| - bool case_sensitive) { |
| +template <typename STR> |
| +bool StartsWithT(const STR& str, const STR& search, bool case_sensitive) { |
| if (case_sensitive) |
| return str.compare(0, search.length(), search) == 0; |
| else { |
| if (search.size() > str.size()) |
| return false; |
| return std::equal(search.begin(), search.end(), str.begin(), |
| - CaseInsensitiveCompare<wchar_t>()); |
| + CaseInsensitiveCompare<typename STR::value_type>()); |
| } |
| } |
| -bool EndsWith(const std::wstring& str, |
| - const std::wstring& search, |
| - bool case_sensitive) { |
| - std::wstring::size_type str_length = str.length(); |
| - std::wstring::size_type search_length = search.length(); |
| +bool StartsWith(const std::wstring& str, const std::wstring& search, |
| + bool case_sensitive) { |
| + return StartsWithT(str, search, case_sensitive); |
| +} |
| + |
| +#if !defined(WCHAR_T_IS_UTF16) |
| +bool StartsWith(const string16& str, const string16& search, |
| + bool case_sensitive) { |
| + return StartsWithT(str, search, case_sensitive); |
| +} |
| +#endif |
| + |
| +template <typename STR> |
| +bool EndsWithT(const STR& str, const STR& search, bool case_sensitive) { |
| + typename STR::size_type str_length = str.length(); |
| + typename STR::size_type search_length = search.length(); |
| if (search_length > str_length) |
| return false; |
| if (case_sensitive) { |
| @@ -813,10 +847,22 @@ |
| } else { |
| return std::equal(search.begin(), search.end(), |
| str.begin() + (str_length - search_length), |
| - CaseInsensitiveCompare<wchar_t>()); |
| + CaseInsensitiveCompare<typename STR::value_type>()); |
| } |
| } |
| +bool EndsWith(const std::wstring& str, const std::wstring& search, |
| + bool case_sensitive) { |
| + return EndsWithT(str, search, case_sensitive); |
| +} |
| + |
| +#if !defined(WCHAR_T_IS_UTF16) |
| +bool EndsWith(const string16& str, const string16& search, |
| + bool case_sensitive) { |
| + return EndsWithT(str, search, case_sensitive); |
| +} |
| +#endif |
| + |
| DataUnits GetByteDisplayUnits(int64 bytes) { |
| // The byte thresholds at which we display amounts. A byte count is displayed |
| // in unit U when kUnitThresholds[U] <= bytes < kUnitThresholds[U+1]. |