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

Side by Side Diff: base/strings/string_util.h

Issue 1182453004: Write new Starts/EndsWith and convert FilePath functions to StringPiece. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@string_util
Patch Set: default back Created 5 years, 6 months 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 unified diff | Download patch
« no previous file with comments | « base/files/file_path.cc ('k') | base/strings/string_util.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 311 matching lines...) Expand 10 before | Expand all | Expand 10 after
322 const char* b_begin, 322 const char* b_begin,
323 const char* b_end); 323 const char* b_end);
324 BASE_EXPORT bool LowerCaseEqualsASCII(const char16* a_begin, 324 BASE_EXPORT bool LowerCaseEqualsASCII(const char16* a_begin,
325 const char16* a_end, 325 const char16* a_end,
326 const char* b); 326 const char* b);
327 327
328 // Performs a case-sensitive string compare. The behavior is undefined if both 328 // Performs a case-sensitive string compare. The behavior is undefined if both
329 // strings are not ASCII. 329 // strings are not ASCII.
330 BASE_EXPORT bool EqualsASCII(const string16& a, const StringPiece& b); 330 BASE_EXPORT bool EqualsASCII(const string16& a, const StringPiece& b);
331 331
332 // Returns true if str starts with search, or false otherwise. 332 // Indicates case sensitivity of comparisons. Only ASCII case insensitivity
333 // TODO(brettw) the case sensitive flag makes callsites difficult to read. 333 // is supported. Full Unicode case-insensitive conversions would need to go in
334 // Consider splitting this out in two variants (few callers want 334 // base/i18n so it can use ICU.
335 // case-insensitive compares) or use an enum that makes this more explicit. 335 //
336 BASE_EXPORT bool StartsWithASCII(const std::string& str, 336 // If you need to do Unicode-aware case-insensitive StartsWith/EndsWith, it's
337 const std::string& search, 337 // best to just call base::i18n::ToLower() on the arguements, and then use the
338 bool case_sensitive); 338 // results to a case-sensitive comparison.
Nico 2015/07/06 17:29:37 This suggestion won't do the right thing for strin
brettw 2015/07/06 17:48:14 Good find! I'll follow up with Jungskik on writing
339 BASE_EXPORT bool StartsWith(const base::string16& str, 339 enum class CompareCase {
340 const base::string16& search, 340 SENSITIVE,
341 INSENSITIVE_ASCII,
342 };
343
344 BASE_EXPORT bool StartsWith(StringPiece str,
345 StringPiece search_for,
346 CompareCase case_sensitivity);
347 BASE_EXPORT bool StartsWith(StringPiece16 str,
348 StringPiece16 search_for,
349 CompareCase case_sensitivity);
350 BASE_EXPORT bool EndsWith(StringPiece str,
351 StringPiece search_for,
352 CompareCase case_sensitivity);
353 BASE_EXPORT bool EndsWith(StringPiece16 str,
354 StringPiece16 search_for,
355 CompareCase case_sensitivity);
356
357 // DEPRECATED. Returns true if str starts/ends with search, or false otherwise.
358 // TODO(brettw) remove in favor of the "enum" versions above.
359 inline bool StartsWithASCII(const std::string& str,
360 const std::string& search,
361 bool case_sensitive) {
362 return StartsWith(StringPiece(str), StringPiece(search),
363 case_sensitive ? CompareCase::SENSITIVE
364 : CompareCase::INSENSITIVE_ASCII);
365 }
366 BASE_EXPORT bool StartsWith(const string16& str,
367 const string16& search,
341 bool case_sensitive); 368 bool case_sensitive);
342 369 inline bool EndsWith(const std::string& str,
343 // Returns true if str ends with search, or false otherwise. 370 const std::string& search,
344 // TODO(brettw) case sensitive flag confusion, see StartsWith above. 371 bool case_sensitive) {
345 BASE_EXPORT bool EndsWith(const std::string& str, 372 return EndsWith(StringPiece(str), StringPiece(search),
346 const std::string& search, 373 case_sensitive ? CompareCase::SENSITIVE
347 bool case_sensitive); 374 : CompareCase::INSENSITIVE_ASCII);
348 BASE_EXPORT bool EndsWith(const base::string16& str, 375 }
349 const base::string16& search, 376 BASE_EXPORT bool EndsWith(const string16& str,
377 const string16& search,
350 bool case_sensitive); 378 bool case_sensitive);
351 379
352 } // namespace base 380 } // namespace base
353 381
354 #if defined(OS_WIN) 382 #if defined(OS_WIN)
355 #include "base/strings/string_util_win.h" 383 #include "base/strings/string_util_win.h"
356 #elif defined(OS_POSIX) 384 #elif defined(OS_POSIX)
357 #include "base/strings/string_util_posix.h" 385 #include "base/strings/string_util_posix.h"
358 #else 386 #else
359 #error Define string operations appropriately for your platform 387 #error Define string operations appropriately for your platform
(...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after
518 // string can contain wildcards like * and ? 546 // string can contain wildcards like * and ?
519 // The backslash character (\) is an escape character for * and ? 547 // The backslash character (\) is an escape character for * and ?
520 // We limit the patterns to having a max of 16 * or ? characters. 548 // We limit the patterns to having a max of 16 * or ? characters.
521 // ? matches 0 or 1 character, while * matches 0 or more characters. 549 // ? matches 0 or 1 character, while * matches 0 or more characters.
522 BASE_EXPORT bool MatchPattern(const base::StringPiece& string, 550 BASE_EXPORT bool MatchPattern(const base::StringPiece& string,
523 const base::StringPiece& pattern); 551 const base::StringPiece& pattern);
524 BASE_EXPORT bool MatchPattern(const base::string16& string, 552 BASE_EXPORT bool MatchPattern(const base::string16& string,
525 const base::string16& pattern); 553 const base::string16& pattern);
526 554
527 #endif // BASE_STRINGS_STRING_UTIL_H_ 555 #endif // BASE_STRINGS_STRING_UTIL_H_
OLDNEW
« no previous file with comments | « base/files/file_path.cc ('k') | base/strings/string_util.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698