diff options
author | stuartmorgan@google.com <stuartmorgan@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-09-04 19:12:37 +0000 |
---|---|---|
committer | stuartmorgan@google.com <stuartmorgan@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-09-04 19:12:37 +0000 |
commit | 996fd703fb7229e931203edc77df436aea9bc9a5 (patch) | |
tree | e52458f9e43ec4762ce58c3b15a235ad31e3d667 /base | |
parent | f62a8906648ddfcee0ffa9604939d4c7f66891aa (diff) | |
download | chromium_src-996fd703fb7229e931203edc77df436aea9bc9a5.zip chromium_src-996fd703fb7229e931203edc77df436aea9bc9a5.tar.gz chromium_src-996fd703fb7229e931203edc77df436aea9bc9a5.tar.bz2 |
Strip .plugin off of Mac plugin names when showing the crash info bar.
BUG=21029
TEST=Kill a plugin process; the plugin crash info bar shouldn't have ".plugin" in the plugin name.
Review URL: http://codereview.chromium.org/197018
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@25487 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'base')
-rw-r--r-- | base/string_util.cc | 16 | ||||
-rw-r--r-- | base/string_util.h | 6 | ||||
-rw-r--r-- | base/string_util_unittest.cc | 19 |
3 files changed, 41 insertions, 0 deletions
diff --git a/base/string_util.cc b/base/string_util.cc index 1edc0d9..82b6c0b 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]. diff --git a/base/string_util.h b/base/string_util.h index c7f3115..0ae0185 100644 --- a/base/string_util.h +++ b/base/string_util.h @@ -363,6 +363,12 @@ bool StartsWith(const std::wstring& str, const std::wstring& search, bool case_sensitive); +// Returns true if str ends with search, or false otherwise. +bool EndsWith(const std::wstring& str, + const std::wstring& search, + bool case_sensitive); + + // Determines the type of ASCII character, independent of locale (the C // library versions will change based on locale). template <typename Char> diff --git a/base/string_util_unittest.cc b/base/string_util_unittest.cc index 35c58d6..b11a999 100644 --- a/base/string_util_unittest.cc +++ b/base/string_util_unittest.cc @@ -1576,6 +1576,25 @@ TEST(StringUtilTest, StartsWith) { EXPECT_TRUE(StartsWith(L"java", L"", true)); } +TEST(StringUtilTest, EndsWith) { + EXPECT_TRUE(EndsWith(L"Foo.plugin", L".plugin", true)); + EXPECT_FALSE(EndsWith(L"Foo.Plugin", L".plugin", true)); + EXPECT_TRUE(EndsWith(L"Foo.plugin", L".plugin", false)); + EXPECT_TRUE(EndsWith(L"Foo.Plugin", L".plugin", false)); + EXPECT_FALSE(EndsWith(L".plug", L".plugin", true)); + EXPECT_FALSE(EndsWith(L".plug", L".plugin", false)); + EXPECT_FALSE(EndsWith(L"Foo.plugin Bar", L".plugin", true)); + EXPECT_FALSE(EndsWith(L"Foo.plugin Bar", L".plugin", false)); + EXPECT_FALSE(EndsWith(L"", L".plugin", false)); + EXPECT_FALSE(EndsWith(L"", L".plugin", true)); + EXPECT_TRUE(EndsWith(L"Foo.plugin", L"", false)); + EXPECT_TRUE(EndsWith(L"Foo.plugin", L"", true)); + EXPECT_TRUE(EndsWith(L".plugin", L".plugin", false)); + EXPECT_TRUE(EndsWith(L".plugin", L".plugin", true)); + EXPECT_TRUE(EndsWith(L"", L"", false)); + EXPECT_TRUE(EndsWith(L"", L"", true)); +} + TEST(StringUtilTest, GetStringFWithOffsets) { std::vector<string16> subst; subst.push_back(ASCIIToUTF16("1")); |