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

Unified 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 side-by-side diff with in-line comments
Download patch
Index: base/strings/string_util.h
diff --git a/base/strings/string_util.h b/base/strings/string_util.h
index 9628c67cbea9514cac4268c98f6ca9e129b107be..530fd04b100401d2cd20e520418392acdace3f2e 100644
--- a/base/strings/string_util.h
+++ b/base/strings/string_util.h
@@ -329,24 +329,48 @@ BASE_EXPORT bool LowerCaseEqualsASCII(const char16* a_begin,
// strings are not ASCII.
BASE_EXPORT bool EqualsASCII(const string16& a, const StringPiece& b);
-// Returns true if str starts with search, or false otherwise.
-// TODO(brettw) the case sensitive flag makes callsites difficult to read.
-// Consider splitting this out in two variants (few callers want
-// case-insensitive compares) or use an enum that makes this more explicit.
-BASE_EXPORT bool StartsWithASCII(const std::string& str,
- const std::string& search,
- bool case_sensitive);
-BASE_EXPORT bool StartsWith(const base::string16& str,
- const base::string16& search,
- bool case_sensitive);
+// Indicates case insensitivity of comparisons. Only ASCII case insensitivity
Peter Kasting 2015/06/15 20:41:40 Nit: insensitivity -> sensitivity
+// 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
+// base/i18n so it can use ICU.
Peter Kasting 2015/06/15 20:41:40 Nit: "so it can use" -> "and be implemented using"
+enum class CompareCase {
+ SENSITIVE,
+ INSENSITIVE_ASCII,
+};
-// Returns true if str ends with search, or false otherwise.
-// TODO(brettw) case sensitive flag confusion, see StartsWith above.
-BASE_EXPORT bool EndsWith(const std::string& str,
- const std::string& search,
- bool case_sensitive);
-BASE_EXPORT bool EndsWith(const base::string16& str,
- const base::string16& search,
+BASE_EXPORT bool StartsWith(StringPiece str,
+ StringPiece search_for,
+ CompareCase case_sensitivity);
+BASE_EXPORT bool StartsWith(StringPiece16 str,
+ StringPiece16 search_for,
+ CompareCase case_sensitivity);
+BASE_EXPORT bool EndsWith(StringPiece str,
+ StringPiece search_for,
+ CompareCase case_sensitivity);
+BASE_EXPORT bool EndsWith(StringPiece16 str,
+ StringPiece16 search_for,
+ CompareCase case_sensitivity);
+
+// Returns true if str starts/ends with search, or false otherwise.
+// 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
+inline bool StartsWithASCII(const std::string& str,
+ const std::string& search,
+ bool case_sensitive) {
+ return StartsWith(StringPiece(str), StringPiece(search),
+ case_sensitive ? CompareCase::SENSITIVE
+ : CompareCase::INSENSITIVE_ASCII);
+}
+BASE_EXPORT bool StartsWith(const string16& str,
+ const string16& search,
+ bool case_sensitive);
+inline bool EndsWith(const std::string& str,
+ const std::string& search,
+ bool case_sensitive) {
+ return EndsWith(StringPiece(str), StringPiece(search),
+ case_sensitive ? CompareCase::SENSITIVE
+ : CompareCase::INSENSITIVE_ASCII);
+}
+BASE_EXPORT bool EndsWith(const string16& str,
+ const string16& search,
bool case_sensitive);
} // namespace base

Powered by Google App Engine
This is Rietveld 408576698