| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 // | 4 // |
| 5 // This file defines utility functions for working with strings. | 5 // This file defines utility functions for working with strings. |
| 6 | 6 |
| 7 #ifndef BASE_STRINGS_STRING_UTIL_H_ | 7 #ifndef BASE_STRINGS_STRING_UTIL_H_ |
| 8 #define BASE_STRINGS_STRING_UTIL_H_ | 8 #define BASE_STRINGS_STRING_UTIL_H_ |
| 9 | 9 |
| 10 #include <ctype.h> | 10 #include <ctype.h> |
| (...skipping 298 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 309 const char* b_end); | 309 const char* b_end); |
| 310 BASE_EXPORT bool LowerCaseEqualsASCII(const char16* a_begin, | 310 BASE_EXPORT bool LowerCaseEqualsASCII(const char16* a_begin, |
| 311 const char16* a_end, | 311 const char16* a_end, |
| 312 const char* b); | 312 const char* b); |
| 313 | 313 |
| 314 // Performs a case-sensitive string compare. The behavior is undefined if both | 314 // Performs a case-sensitive string compare. The behavior is undefined if both |
| 315 // strings are not ASCII. | 315 // strings are not ASCII. |
| 316 BASE_EXPORT bool EqualsASCII(const string16& a, const StringPiece& b); | 316 BASE_EXPORT bool EqualsASCII(const string16& a, const StringPiece& b); |
| 317 | 317 |
| 318 // Returns true if str starts with search, or false otherwise. | 318 // Returns true if str starts with search, or false otherwise. |
| 319 // TODO(brettw) the case sensitive flag makes callsites difficult to read. |
| 320 // Consider splitting this out in two variants (few callers want |
| 321 // case-insensitive compares) or use an enum that makes this more explicit. |
| 319 BASE_EXPORT bool StartsWithASCII(const std::string& str, | 322 BASE_EXPORT bool StartsWithASCII(const std::string& str, |
| 320 const std::string& search, | 323 const std::string& search, |
| 321 bool case_sensitive); | 324 bool case_sensitive); |
| 322 BASE_EXPORT bool StartsWith(const base::string16& str, | 325 BASE_EXPORT bool StartsWith(const base::string16& str, |
| 323 const base::string16& search, | 326 const base::string16& search, |
| 324 bool case_sensitive); | 327 bool case_sensitive); |
| 325 | 328 |
| 329 // Returns true if str ends with search, or false otherwise. |
| 330 // TODO(brettw) case sensitive flag confusion, see StartsWith above. |
| 331 BASE_EXPORT bool EndsWith(const std::string& str, |
| 332 const std::string& search, |
| 333 bool case_sensitive); |
| 334 BASE_EXPORT bool EndsWith(const base::string16& str, |
| 335 const base::string16& search, |
| 336 bool case_sensitive); |
| 337 |
| 326 } // namespace base | 338 } // namespace base |
| 327 | 339 |
| 328 #if defined(OS_WIN) | 340 #if defined(OS_WIN) |
| 329 #include "base/strings/string_util_win.h" | 341 #include "base/strings/string_util_win.h" |
| 330 #elif defined(OS_POSIX) | 342 #elif defined(OS_POSIX) |
| 331 #include "base/strings/string_util_posix.h" | 343 #include "base/strings/string_util_posix.h" |
| 332 #else | 344 #else |
| 333 #error Define string operations appropriately for your platform | 345 #error Define string operations appropriately for your platform |
| 334 #endif | 346 #endif |
| 335 | 347 |
| 336 // Returns true if str ends with search, or false otherwise. | |
| 337 BASE_EXPORT bool EndsWith(const std::string& str, | |
| 338 const std::string& search, | |
| 339 bool case_sensitive); | |
| 340 BASE_EXPORT bool EndsWith(const base::string16& str, | |
| 341 const base::string16& search, | |
| 342 bool case_sensitive); | |
| 343 | |
| 344 | |
| 345 // Determines the type of ASCII character, independent of locale (the C | 348 // Determines the type of ASCII character, independent of locale (the C |
| 346 // library versions will change based on locale). | 349 // library versions will change based on locale). |
| 347 template <typename Char> | 350 template <typename Char> |
| 348 inline bool IsAsciiWhitespace(Char c) { | 351 inline bool IsAsciiWhitespace(Char c) { |
| 349 return c == ' ' || c == '\r' || c == '\n' || c == '\t'; | 352 return c == ' ' || c == '\r' || c == '\n' || c == '\t'; |
| 350 } | 353 } |
| 351 template <typename Char> | 354 template <typename Char> |
| 352 inline bool IsAsciiAlpha(Char c) { | 355 inline bool IsAsciiAlpha(Char c) { |
| 353 return ((c >= 'A') && (c <= 'Z')) || ((c >= 'a') && (c <= 'z')); | 356 return ((c >= 'A') && (c <= 'Z')) || ((c >= 'a') && (c <= 'z')); |
| 354 } | 357 } |
| (...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 498 // string can contain wildcards like * and ? | 501 // string can contain wildcards like * and ? |
| 499 // The backslash character (\) is an escape character for * and ? | 502 // The backslash character (\) is an escape character for * and ? |
| 500 // We limit the patterns to having a max of 16 * or ? characters. | 503 // We limit the patterns to having a max of 16 * or ? characters. |
| 501 // ? matches 0 or 1 character, while * matches 0 or more characters. | 504 // ? matches 0 or 1 character, while * matches 0 or more characters. |
| 502 BASE_EXPORT bool MatchPattern(const base::StringPiece& string, | 505 BASE_EXPORT bool MatchPattern(const base::StringPiece& string, |
| 503 const base::StringPiece& pattern); | 506 const base::StringPiece& pattern); |
| 504 BASE_EXPORT bool MatchPattern(const base::string16& string, | 507 BASE_EXPORT bool MatchPattern(const base::string16& string, |
| 505 const base::string16& pattern); | 508 const base::string16& pattern); |
| 506 | 509 |
| 507 #endif // BASE_STRINGS_STRING_UTIL_H_ | 510 #endif // BASE_STRINGS_STRING_UTIL_H_ |
| OLD | NEW |