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

Unified Diff: base/string_util.cc

Issue 197018: Strip .plugin off of Mac plugin names when showing the crash info bar. (Closed)
Patch Set: Add a test with the match in the middle Created 11 years, 3 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/string_util.cc
diff --git a/base/string_util.cc b/base/string_util.cc
index 1edc0d98ac74dcbb6e2724bea3f18d3f28a1f0cd..82b6c0b0488e75c93ef3847a73d88168c0f47034 100644
--- a/base/string_util.cc
+++ b/base/string_util.cc
@@ -773,6 +773,22 @@ bool StartsWith(const std::wstring& str,
}
}
+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();
+ if (search_length > str_length)
+ return false;
+ if (case_sensitive) {
+ return str.compare(str_length - search_length, search_length, search) == 0;
+ } else {
+ return std::equal(search.begin(), search.end(),
+ str.begin() + (str_length - search_length),
+ CaseInsensitiveCompare<wchar_t>());
+ }
+}
+
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].
« no previous file with comments | « base/string_util.h ('k') | base/string_util_unittest.cc » ('j') | base/string_util_unittest.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698