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

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: Fix save_package using 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
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 insensitivity of comparisons. Only ASCII case insensitivity
Peter Kasting 2015/06/15 20:41:40 Nit: insensitivity -> sensitivity
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
Peter Kasting 2015/06/15 20:41:40 So, does the "would" here mean there aren't approp
brettw 2015/06/15 23:00:47 Correct, there are not equivalent replacements. My
334 // Consider splitting this out in two variants (few callers want 334 // base/i18n so it can use ICU.
Peter Kasting 2015/06/15 20:41:40 Nit: "so it can use" -> "and be implemented using"
335 // case-insensitive compares) or use an enum that makes this more explicit. 335 enum class CompareCase {
336 BASE_EXPORT bool StartsWithASCII(const std::string& str, 336 SENSITIVE,
337 const std::string& search, 337 INSENSITIVE_ASCII,
338 bool case_sensitive); 338 };
339 BASE_EXPORT bool StartsWith(const base::string16& str, 339
340 const base::string16& search, 340 BASE_EXPORT bool StartsWith(StringPiece str,
341 StringPiece search_for,
342 CompareCase case_sensitivity);
343 BASE_EXPORT bool StartsWith(StringPiece16 str,
344 StringPiece16 search_for,
345 CompareCase case_sensitivity);
346 BASE_EXPORT bool EndsWith(StringPiece str,
347 StringPiece search_for,
348 CompareCase case_sensitivity);
349 BASE_EXPORT bool EndsWith(StringPiece16 str,
350 StringPiece16 search_for,
351 CompareCase case_sensitivity);
352
353 // Returns true if str starts/ends with search, or false otherwise.
354 // DEPRECATED. TODO(brettw) remove in favor of the "enum" versions above.
Peter Kasting 2015/06/15 20:41:40 Tiny nit: I'd say "DEPRECATED: Returns true..." an
355 inline bool StartsWithASCII(const std::string& str,
356 const std::string& search,
357 bool case_sensitive) {
358 return StartsWith(StringPiece(str), StringPiece(search),
359 case_sensitive ? CompareCase::SENSITIVE
360 : CompareCase::INSENSITIVE_ASCII);
361 }
362 BASE_EXPORT bool StartsWith(const string16& str,
363 const string16& search,
341 bool case_sensitive); 364 bool case_sensitive);
342 365 inline bool EndsWith(const std::string& str,
343 // Returns true if str ends with search, or false otherwise. 366 const std::string& search,
344 // TODO(brettw) case sensitive flag confusion, see StartsWith above. 367 bool case_sensitive) {
345 BASE_EXPORT bool EndsWith(const std::string& str, 368 return EndsWith(StringPiece(str), StringPiece(search),
346 const std::string& search, 369 case_sensitive ? CompareCase::SENSITIVE
347 bool case_sensitive); 370 : CompareCase::INSENSITIVE_ASCII);
348 BASE_EXPORT bool EndsWith(const base::string16& str, 371 }
349 const base::string16& search, 372 BASE_EXPORT bool EndsWith(const string16& str,
373 const string16& search,
350 bool case_sensitive); 374 bool case_sensitive);
351 375
352 } // namespace base 376 } // namespace base
353 377
354 #if defined(OS_WIN) 378 #if defined(OS_WIN)
355 #include "base/strings/string_util_win.h" 379 #include "base/strings/string_util_win.h"
356 #elif defined(OS_POSIX) 380 #elif defined(OS_POSIX)
357 #include "base/strings/string_util_posix.h" 381 #include "base/strings/string_util_posix.h"
358 #else 382 #else
359 #error Define string operations appropriately for your platform 383 #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 ? 542 // string can contain wildcards like * and ?
519 // The backslash character (\) is an escape character for * and ? 543 // The backslash character (\) is an escape character for * and ?
520 // We limit the patterns to having a max of 16 * or ? characters. 544 // We limit the patterns to having a max of 16 * or ? characters.
521 // ? matches 0 or 1 character, while * matches 0 or more characters. 545 // ? matches 0 or 1 character, while * matches 0 or more characters.
522 BASE_EXPORT bool MatchPattern(const base::StringPiece& string, 546 BASE_EXPORT bool MatchPattern(const base::StringPiece& string,
523 const base::StringPiece& pattern); 547 const base::StringPiece& pattern);
524 BASE_EXPORT bool MatchPattern(const base::string16& string, 548 BASE_EXPORT bool MatchPattern(const base::string16& string,
525 const base::string16& pattern); 549 const base::string16& pattern);
526 550
527 #endif // BASE_STRINGS_STRING_UTIL_H_ 551 #endif // BASE_STRINGS_STRING_UTIL_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698