diff options
author | paul@chromium.org <paul@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-09-09 22:55:04 +0000 |
---|---|---|
committer | paul@chromium.org <paul@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-09-09 22:55:04 +0000 |
commit | bcc9ae958d2f957a8deb766f994b3039758e4ee6 (patch) | |
tree | 03d62d7bfa6add64039a3873d3e205e4e1b69f9b /app | |
parent | f3edc51bfb87650346ec6f3a39086cbaded71c0b (diff) | |
download | chromium_src-bcc9ae958d2f957a8deb766f994b3039758e4ee6.zip chromium_src-bcc9ae958d2f957a8deb766f994b3039758e4ee6.tar.gz chromium_src-bcc9ae958d2f957a8deb766f994b3039758e4ee6.tar.bz2 |
Add a "ToUpper" method.
BUG=None.
TEST=Covered by new unittest.
Review URL: http://codereview.chromium.org/194060
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@25809 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'app')
-rw-r--r-- | app/l10n_util.cc | 9 | ||||
-rw-r--r-- | app/l10n_util.h | 3 | ||||
-rw-r--r-- | app/l10n_util_unittest.cc | 14 |
3 files changed, 26 insertions, 0 deletions
diff --git a/app/l10n_util.cc b/app/l10n_util.cc index d22425b..a58defb 100644 --- a/app/l10n_util.cc +++ b/app/l10n_util.cc @@ -647,6 +647,15 @@ string16 ToLower(const string16& string) { return result; } +string16 ToUpper(const string16& string) { + icu::UnicodeString upper_u_str( + icu::UnicodeString(string.c_str()).toUpper(icu::Locale::getDefault())); + string16 result; + upper_u_str.extract(0, upper_u_str.length(), + WriteInto(&result, upper_u_str.length() + 1)); + return result; +} + // Returns the text direction for the default ICU locale. It is assumed // that SetICUDefaultLocale has been called to set the default locale to // the UI locale of Chrome. diff --git a/app/l10n_util.h b/app/l10n_util.h index eacb329..85fa36b 100644 --- a/app/l10n_util.h +++ b/app/l10n_util.h @@ -179,6 +179,9 @@ std::wstring ToLower(const std::wstring& string); #endif // defined(WCHAR_T_IS_UTF32) string16 ToLower(const string16& string); +// Returns the upper case equivalent of string. +string16 ToUpper(const string16& string); + // Represents the text direction returned by the GetTextDirection() function. enum TextDirection { UNKNOWN_DIRECTION, diff --git a/app/l10n_util_unittest.cc b/app/l10n_util_unittest.cc index db7d342..18a568c 100644 --- a/app/l10n_util_unittest.cc +++ b/app/l10n_util_unittest.cc @@ -439,3 +439,17 @@ TEST_F(L10nUtilTest, GetTextDirection) { // Japanese that uses multiple scripts EXPECT_EQ(l10n_util::LEFT_TO_RIGHT, GetTextDirection("ja")); } + +// Test upper and lower case string conversion. +TEST_F(L10nUtilTest, UpperLower) { + string16 mixed(ASCIIToUTF16("Text with UPPer & lowER casE.")); + const string16 expected_lower(ASCIIToUTF16("text with upper & lower case.")); + const string16 expected_upper(ASCIIToUTF16("TEXT WITH UPPER & LOWER CASE.")); + + string16 result = l10n_util::ToLower(mixed); + EXPECT_EQ(result, expected_lower); + + result = l10n_util::ToUpper(mixed); + EXPECT_EQ(result, expected_upper); +} + |