diff options
26 files changed, 142 insertions, 141 deletions
diff --git a/app/app_base.gypi b/app/app_base.gypi index 60159ac..6b4e363 100644 --- a/app/app_base.gypi +++ b/app/app_base.gypi @@ -122,7 +122,6 @@ 'drag_drop_types.h', 'event_synthesis_gtk.cc', 'event_synthesis_gtk.h', - 'file_download_interface.h', 'gfx/font_util.h', 'gfx/font_util.cc', 'gfx/gl/gl_bindings.h', @@ -163,6 +162,7 @@ 'keyboard_codes_posix.h', 'l10n_util.cc', 'l10n_util.h', + 'l10n_util_collator.h', 'l10n_util_mac.h', 'l10n_util_mac.mm', 'l10n_util_posix.cc', diff --git a/app/gfx/font_util.cc b/app/gfx/font_util.cc index 1c3cfca..a977f57 100644 --- a/app/gfx/font_util.cc +++ b/app/gfx/font_util.cc @@ -15,8 +15,7 @@ namespace gfx { int GetLocalizedContentsWidthForFont(int col_resource_id, const gfx::Font& font) { double chars = 0; - base::StringToDouble(WideToUTF8(l10n_util::GetString(col_resource_id)), - &chars); + base::StringToDouble(l10n_util::GetStringUTF8(col_resource_id), &chars); int width = font.GetExpectedTextWidth(static_cast<int>(chars)); DCHECK_GT(width, 0); return width; @@ -25,8 +24,7 @@ int GetLocalizedContentsWidthForFont(int col_resource_id, int GetLocalizedContentsHeightForFont(int row_resource_id, const gfx::Font& font) { double lines = 0; - base::StringToDouble(WideToUTF8(l10n_util::GetString(row_resource_id)), - &lines); + base::StringToDouble(l10n_util::GetStringUTF8(row_resource_id), &lines); int height = static_cast<int>(font.GetHeight() * lines); DCHECK_GT(height, 0); return height; diff --git a/app/l10n_util.cc b/app/l10n_util.cc index 28b16b2..6add000 100644 --- a/app/l10n_util.cc +++ b/app/l10n_util.cc @@ -568,9 +568,11 @@ bool IsValidLocaleSyntax(const std::string& locale) { return true; } +#if CRBUG_9911_OBSOLETE_GOING_AWAY std::wstring GetString(int message_id) { return UTF16ToWide(GetStringUTF16(message_id)); } +#endif std::string GetStringUTF8(int message_id) { return UTF16ToUTF8(GetStringUTF16(message_id)); @@ -628,6 +630,7 @@ static string16 GetStringF(int message_id, return formatted; } +#if CRBUG_9911_OBSOLETE_GOING_AWAY #if !defined(WCHAR_T_IS_UTF16) std::wstring GetStringF(int message_id, const std::wstring& a) { return UTF16ToWide(GetStringFUTF16(message_id, WideToUTF16(a))); @@ -657,6 +660,7 @@ std::wstring GetStringF(int message_id, WideToUTF16(c), WideToUTF16(d))); } #endif +#endif std::string GetStringFUTF8(int message_id, const string16& a) { @@ -721,6 +725,7 @@ string16 GetStringFUTF16(int message_id, return GetStringF(message_id, replacements, NULL); } +#if CRBUG_9911_OBSOLETE_GOING_AWAY std::wstring GetStringF(int message_id, const std::wstring& a, size_t* offset) { DCHECK(offset); std::vector<size_t> offsets; @@ -741,6 +746,7 @@ std::wstring GetStringF(int message_id, replacements.push_back(WideToUTF16(b)); return UTF16ToWide(GetStringF(message_id, replacements, offsets)); } +#endif string16 GetStringFUTF16(int message_id, const string16& a, size_t* offset) { DCHECK(offset); @@ -763,6 +769,7 @@ string16 GetStringFUTF16(int message_id, return GetStringF(message_id, replacements, offsets); } +#if CRBUG_9911_OBSOLETE_GOING_AWAY std::wstring GetStringF(int message_id, int a) { return GetStringF(message_id, UTF8ToWide(base::IntToString(a))); } @@ -770,6 +777,15 @@ std::wstring GetStringF(int message_id, int a) { std::wstring GetStringF(int message_id, int64 a) { return GetStringF(message_id, UTF8ToWide(base::Int64ToString(a))); } +#endif + +string16 GetStringFUTF16(int message_id, int a) { + return GetStringFUTF16(message_id, UTF8ToUTF16(base::IntToString(a))); +} + +string16 GetStringFUTF16(int message_id, int64 a) { + return GetStringFUTF16(message_id, UTF8ToUTF16(base::Int64ToString(a))); +} string16 TruncateString(const string16& string, size_t length) { if (string.size() <= length) @@ -887,18 +903,6 @@ UCollationResult CompareStringWithCollator(const icu::Collator* collator, return result; } -// Specialization of operator() method for std::wstring version. -template <> -bool StringComparator<std::wstring>::operator()(const std::wstring& lhs, - const std::wstring& rhs) { - // If we can not get collator instance for specified locale, just do simple - // string compare. - if (!collator_) - return lhs < rhs; - return CompareStringWithCollator(collator_, lhs, rhs) == UCOL_LESS; -}; - -#if !defined(WCHAR_T_IS_UTF16) // Specialization of operator() method for string16 version. template <> bool StringComparator<string16>::operator()(const string16& lhs, @@ -909,12 +913,6 @@ bool StringComparator<string16>::operator()(const string16& lhs, return lhs < rhs; return CompareString16WithCollator(collator_, lhs, rhs) == UCOL_LESS; }; -#endif // !defined(WCHAR_T_IS_UTF16) - -void SortStrings(const std::string& locale, - std::vector<std::wstring>* strings) { - SortVectorWithStringKey(locale, strings, false); -} void SortStrings16(const std::string& locale, std::vector<string16>* strings) { diff --git a/app/l10n_util.h b/app/l10n_util.h index a71c21c..57fd690 100644 --- a/app/l10n_util.h +++ b/app/l10n_util.h @@ -25,6 +25,10 @@ #include "app/l10n_util_mac.h" #endif // OS_MACOSX +// http://crbug.com/9911 . Any functions bracketed by this define are going +// away; this define exists to allow compiler assistance in removing their use. +#define CRBUG_9911_OBSOLETE_GOING_AWAY 1 + namespace l10n_util { // This method is responsible for determining the locale as defined below. In @@ -80,7 +84,9 @@ bool IsValidLocaleSyntax(const std::string& locale); // // Pulls resource string from the string bundle and returns it. +#if CRBUG_9911_OBSOLETE_GOING_AWAY std::wstring GetString(int message_id); +#endif std::string GetStringUTF8(int message_id); string16 GetStringUTF16(int message_id); @@ -100,6 +106,7 @@ string16 GetStringFUTF16(int message_id, const string16& b, const string16& c, const string16& d); +#if CRBUG_9911_OBSOLETE_GOING_AWAY #if defined(WCHAR_T_IS_UTF16) inline std::wstring GetStringF(int message_id, const std::wstring& a) { @@ -139,6 +146,7 @@ std::wstring GetStringF(int message_id, const std::wstring& c, const std::wstring& d); #endif +#endif std::string GetStringFUTF8(int message_id, const string16& a); std::string GetStringFUTF8(int message_id, @@ -158,6 +166,7 @@ std::string GetStringFUTF8(int message_id, // vector based version returns offsets ordered by parameter. For example if // invoked with a and b offsets[0] gives the offset for a and offsets[1] the // offset of b regardless of where the parameters end up in the string. +#if CRBUG_9911_OBSOLETE_GOING_AWAY std::wstring GetStringF(int message_id, const std::wstring& a, size_t* offset); @@ -165,6 +174,7 @@ std::wstring GetStringF(int message_id, const std::wstring& a, const std::wstring& b, std::vector<size_t>* offsets); +#endif string16 GetStringFUTF16(int message_id, const string16& a, size_t* offset); @@ -174,8 +184,12 @@ string16 GetStringFUTF16(int message_id, std::vector<size_t>* offsets); // Convenience formatters for a single number. +#if CRBUG_9911_OBSOLETE_GOING_AWAY std::wstring GetStringF(int message_id, int a); std::wstring GetStringF(int message_id, int64 a); +#endif +string16 GetStringFUTF16(int message_id, int a); +string16 GetStringFUTF16(int message_id, int64 a); // Truncates the string to length characters. This breaks the string at // the first word break before length, adding the horizontal ellipsis @@ -190,10 +204,6 @@ string16 ToLower(const string16& string); // Returns the upper case equivalent of string. string16 ToUpper(const string16& string); -// In place sorting of std::wstring strings using collation rules for |locale|. -void SortStrings(const std::string& locale, - std::vector<std::wstring>* strings); - // In place sorting of string16 strings using collation rules for |locale|. void SortStrings16(const std::string& locale, std::vector<string16>* strings); diff --git a/app/l10n_util_collator.h b/app/l10n_util_collator.h index d5b3f81..f934863 100644 --- a/app/l10n_util_collator.h +++ b/app/l10n_util_collator.h @@ -28,8 +28,8 @@ UCollationResult CompareString16WithCollator(const icu::Collator* collator, // operator (), comparing the string results using a collator. template <class T, class Method> class StringMethodComparatorWithCollator - : public std::binary_function<const std::wstring&, - const std::wstring&, + : public std::binary_function<const string16&, + const string16&, bool> { public: StringMethodComparatorWithCollator(icu::Collator* collator, Method method) @@ -38,8 +38,8 @@ class StringMethodComparatorWithCollator // Returns true if lhs preceeds rhs. bool operator() (T* lhs_t, T* rhs_t) { - return CompareStringWithCollator(collator_, (lhs_t->*method_)(), - (rhs_t->*method_)()) == UCOL_LESS; + return CompareString16WithCollator(collator_, (lhs_t->*method_)(), + (rhs_t->*method_)()) == UCOL_LESS; } private: @@ -50,8 +50,8 @@ class StringMethodComparatorWithCollator // Used by SortStringsUsingMethod. Invokes a method on the objects passed to // operator (), comparing the string results using <. template <class T, class Method> -class StringMethodComparator : public std::binary_function<const std::wstring&, - const std::wstring&, +class StringMethodComparator : public std::binary_function<const string16&, + const string16&, bool> { public: explicit StringMethodComparator(Method method) : method_(method) { } @@ -69,11 +69,11 @@ class StringMethodComparator : public std::binary_function<const std::wstring&, // a string. Sorting is done using a collator, unless a collator can not be // found in which case the strings are sorted using the operator <. template <class T, class Method> -void SortStringsUsingMethod(const std::wstring& locale, +void SortStringsUsingMethod(const std::string& locale, std::vector<T*>* elements, Method method) { UErrorCode error = U_ZERO_ERROR; - icu::Locale loc(WideToUTF8(locale).c_str()); + icu::Locale loc(locale.c_str()); scoped_ptr<icu::Collator> collator(icu::Collator::createInstance(loc, error)); if (U_FAILURE(error)) { sort(elements->begin(), elements->end(), @@ -88,7 +88,7 @@ void SortStringsUsingMethod(const std::wstring& locale, // Compares two elements' string keys and returns true if the first element's // string key is less than the second element's string key. The Element must // have a method like the follow format to return the string key. -// const std::wstring& GetStringKey() const; +// const string16& GetStringKey() const; // This uses the locale specified in the constructor. template <class Element> class StringComparator : public std::binary_function<const Element&, @@ -100,28 +100,21 @@ class StringComparator : public std::binary_function<const Element&, // Returns true if lhs precedes rhs. bool operator()(const Element& lhs, const Element& rhs) { - const std::wstring& lhs_string_key = lhs.GetStringKey(); - const std::wstring& rhs_string_key = rhs.GetStringKey(); + const string16& lhs_string_key = lhs.GetStringKey(); + const string16& rhs_string_key = rhs.GetStringKey(); - return StringComparator<std::wstring>(collator_)(lhs_string_key, - rhs_string_key); + return StringComparator<string16>(collator_)(lhs_string_key, + rhs_string_key); } private: icu::Collator* collator_; }; -// Specialization of operator() method for std::wstring version. -template <> -bool StringComparator<std::wstring>::operator()(const std::wstring& lhs, - const std::wstring& rhs); - -#if !defined(WCHAR_T_IS_UTF16) // Specialization of operator() method for string16 version. template <> bool StringComparator<string16>::operator()(const string16& lhs, const string16& rhs); -#endif // !defined(WCHAR_T_IS_UTF16) // In place sorting of |elements| of a vector according to the string key of // each element in the vector by using collation rules for |locale|. diff --git a/app/l10n_util_unittest.cc b/app/l10n_util_unittest.cc index 23ff698..b6c6b9b 100644 --- a/app/l10n_util_unittest.cc +++ b/app/l10n_util_unittest.cc @@ -32,11 +32,11 @@ namespace { class StringWrapper { public: - explicit StringWrapper(const std::wstring& string) : string_(string) {} - const std::wstring& string() const { return string_; } + explicit StringWrapper(const string16& string) : string_(string) {} + const string16& string() const { return string_; } private: - std::wstring string_; + string16 string_; DISALLOW_COPY_AND_ASSIGN(StringWrapper); }; @@ -49,14 +49,16 @@ class L10nUtilTest : public PlatformTest { #if defined(OS_WIN) // TODO(beng): disabled until app strings move to app. TEST_F(L10nUtilTest, DISABLED_GetString) { - std::wstring s = l10n_util::GetString(IDS_SIMPLE); - EXPECT_EQ(std::wstring(L"Hello World!"), s); + std::string s = l10n_util::GetStringUTF8(IDS_SIMPLE); + EXPECT_EQ(std::string("Hello World!"), s); - s = l10n_util::GetStringF(IDS_PLACEHOLDERS, L"chrome", L"10"); - EXPECT_EQ(std::wstring(L"Hello, chrome. Your number is 10."), s); + s = l10n_util::GetStringFUTF8(IDS_PLACEHOLDERS, + UTF8ToUTF16("chrome"), + UTF8ToUTF16("10")); + EXPECT_EQ(std::string("Hello, chrome. Your number is 10."), s); - s = l10n_util::GetStringF(IDS_PLACEHOLDERS_2, 20); - EXPECT_EQ(std::wstring(L"You owe me $20."), s); + string16 s16 = l10n_util::GetStringFUTF16(IDS_PLACEHOLDERS_2, 20); + EXPECT_EQ(UTF8ToUTF16("You owe me $20."), s16); } #endif // defined(OS_WIN) @@ -285,15 +287,17 @@ TEST_F(L10nUtilTest, GetAppLocale) { TEST_F(L10nUtilTest, SortStringsUsingFunction) { std::vector<StringWrapper*> strings; - strings.push_back(new StringWrapper(L"C")); - strings.push_back(new StringWrapper(L"d")); - strings.push_back(new StringWrapper(L"b")); - strings.push_back(new StringWrapper(L"a")); - l10n_util::SortStringsUsingMethod(L"en-US", &strings, &StringWrapper::string); - ASSERT_TRUE(L"a" == strings[0]->string()); - ASSERT_TRUE(L"b" == strings[1]->string()); - ASSERT_TRUE(L"C" == strings[2]->string()); - ASSERT_TRUE(L"d" == strings[3]->string()); + strings.push_back(new StringWrapper(UTF8ToUTF16("C"))); + strings.push_back(new StringWrapper(UTF8ToUTF16("d"))); + strings.push_back(new StringWrapper(UTF8ToUTF16("b"))); + strings.push_back(new StringWrapper(UTF8ToUTF16("a"))); + l10n_util::SortStringsUsingMethod("en-US", + &strings, + &StringWrapper::string); + ASSERT_TRUE(UTF8ToUTF16("a") == strings[0]->string()); + ASSERT_TRUE(UTF8ToUTF16("b") == strings[1]->string()); + ASSERT_TRUE(UTF8ToUTF16("C") == strings[2]->string()); + ASSERT_TRUE(UTF8ToUTF16("d") == strings[3]->string()); STLDeleteElements(&strings); } diff --git a/app/table_model.cc b/app/table_model.cc index 4800f6a..4ce5ebb 100644 --- a/app/table_model.cc +++ b/app/table_model.cc @@ -54,7 +54,7 @@ TableColumn::TableColumn(int id, Alignment alignment, int width) percent(0), min_visible_width(0), sortable(false) { - title = l10n_util::GetString(id); + title = UTF16ToWide(l10n_util::GetStringUTF16(id)); } TableColumn::TableColumn(int id, Alignment alignment, int width, float percent) @@ -64,7 +64,7 @@ TableColumn::TableColumn(int id, Alignment alignment, int width, float percent) percent(percent), min_visible_width(0), sortable(false) { - title = l10n_util::GetString(id); + title = UTF16ToWide(l10n_util::GetStringUTF16(id)); } // TableModel ----------------------------------------------------------------- diff --git a/chrome/browser/character_encoding.cc b/chrome/browser/character_encoding.cc index 80bfc6b..4b0f92f 100644 --- a/chrome/browser/character_encoding.cc +++ b/chrome/browser/character_encoding.cc @@ -293,9 +293,9 @@ std::string GetEncodingCategoryStringByCommandId(int id) { CharacterEncoding::EncodingInfo::EncodingInfo(int id) : encoding_id(id) { - encoding_category_name = UTF8ToWide(GetEncodingCategoryStringByCommandId(id)); - encoding_display_name = UTF16ToWideHack( - GetCanonicalEncodingDisplayNameByCommandId(id)); + encoding_category_name = + UTF8ToUTF16(GetEncodingCategoryStringByCommandId(id)); + encoding_display_name = GetCanonicalEncodingDisplayNameByCommandId(id); } // Static. diff --git a/chrome/browser/character_encoding.h b/chrome/browser/character_encoding.h index ae1a6f1..7aa98a3 100644 --- a/chrome/browser/character_encoding.h +++ b/chrome/browser/character_encoding.h @@ -25,14 +25,14 @@ class CharacterEncoding { // l10n_util::SortVectorWithStringKey to sort the encoding menu items // by current locale character sequence. We need to keep the order within // encoding category name, that's why we use category name as key. - const std::wstring& GetStringKey() const { return encoding_category_name; } + const string16& GetStringKey() const { return encoding_category_name; } // Encoding command id. int encoding_id; // Encoding display name. - std::wstring encoding_display_name; + string16 encoding_display_name; // Encoding category name. - std::wstring encoding_category_name; + string16 encoding_category_name; }; // Return canonical encoding name according to the command ID. diff --git a/chrome/browser/chromeos/dom_ui/language_options_handler.cc b/chrome/browser/chromeos/dom_ui/language_options_handler.cc index cd81ada..b4c1b19 100644 --- a/chrome/browser/chromeos/dom_ui/language_options_handler.cc +++ b/chrome/browser/chromeos/dom_ui/language_options_handler.cc @@ -196,18 +196,18 @@ ListValue* LanguageOptionsHandler::GetLanguageList( // In theory, we should be able to create a map that is sorted by // display names using ICU comparator, but doing it is hard, thus we'll // use an auxiliary vector to achieve the same result. - typedef std::pair<std::string, std::wstring> LanguagePair; - typedef std::map<std::wstring, LanguagePair> LanguageMap; + typedef std::pair<std::string, string16> LanguagePair; + typedef std::map<string16, LanguagePair> LanguageMap; LanguageMap language_map; // The auxiliary vector mentioned above. - std::vector<std::wstring> display_names; + std::vector<string16> display_names; // Build the list of display names, and build the language map. for (std::set<std::string>::const_iterator iter = language_codes.begin(); iter != language_codes.end(); ++iter) { - const std::wstring display_name = + const string16 display_name = input_method::GetLanguageDisplayNameFromCode(*iter); - const std::wstring native_display_name = + const string16 native_display_name = input_method::GetLanguageNativeDisplayNameFromCode(*iter); display_names.push_back(display_name); language_map[display_name] = @@ -216,8 +216,8 @@ ListValue* LanguageOptionsHandler::GetLanguageList( DCHECK_EQ(display_names.size(), language_map.size()); // Sort display names using locale specific sorter. - l10n_util::SortStrings(g_browser_process->GetApplicationLocale(), - &display_names); + l10n_util::SortStrings16(g_browser_process->GetApplicationLocale(), + &display_names); // Build the language list from the language map. ListValue* language_list = new ListValue(); @@ -225,8 +225,8 @@ ListValue* LanguageOptionsHandler::GetLanguageList( const LanguagePair& pair = language_map[display_names[i]]; DictionaryValue* dictionary = new DictionaryValue(); dictionary->SetString("code", pair.first); - dictionary->SetString("displayName", WideToUTF16Hack(display_names[i])); - dictionary->SetString("nativeDisplayName", WideToUTF16Hack(pair.second)); + dictionary->SetString("displayName", display_names[i]); + dictionary->SetString("nativeDisplayName", pair.second); language_list->Append(dictionary); } diff --git a/chrome/browser/chromeos/input_method/input_method_util.cc b/chrome/browser/chromeos/input_method/input_method_util.cc index 67fcb5b..ced79ea 100644 --- a/chrome/browser/chromeos/input_method/input_method_util.cc +++ b/chrome/browser/chromeos/input_method/input_method_util.cc @@ -349,11 +349,11 @@ struct CompareLanguageCodesByLanguageName // efficient, but acceptable as the function is cheap, and the language // list is short (about 40 at most). bool operator()(const std::string& s1, const std::string& s2) const { - const std::wstring key1 = + const string16 key1 = chromeos::input_method::GetLanguageDisplayNameFromCode(s1); - const std::wstring key2 = + const string16 key2 = chromeos::input_method::GetLanguageDisplayNameFromCode(s2); - return l10n_util::StringComparator<std::wstring>(collator_)(key1, key2); + return l10n_util::StringComparator<string16>(collator_)(key1, key2); } private: @@ -578,18 +578,17 @@ std::string GetInputMethodDisplayNameFromId( kDefaultDisplayName : iter->second; } -std::wstring GetLanguageDisplayNameFromCode(const std::string& language_code) { +string16 GetLanguageDisplayNameFromCode(const std::string& language_code) { if (!g_browser_process) { - return L""; + return string16(); } - return UTF16ToWide(l10n_util::GetDisplayNameForLocale( - language_code, g_browser_process->GetApplicationLocale(), true)); + return l10n_util::GetDisplayNameForLocale( + language_code, g_browser_process->GetApplicationLocale(), true); } -std::wstring GetLanguageNativeDisplayNameFromCode( +string16 GetLanguageNativeDisplayNameFromCode( const std::string& language_code) { - return UTF16ToWide(l10n_util::GetDisplayNameForLocale( - language_code, language_code, true)); + return l10n_util::GetDisplayNameForLocale(language_code, language_code, true); } void SortLanguageCodesByNames(std::vector<std::string>* language_codes) { diff --git a/chrome/browser/chromeos/input_method/input_method_util.h b/chrome/browser/chromeos/input_method/input_method_util.h index a4bea55..66ba95f 100644 --- a/chrome/browser/chromeos/input_method/input_method_util.h +++ b/chrome/browser/chromeos/input_method/input_method_util.h @@ -105,14 +105,13 @@ std::string GetInputMethodDisplayNameFromId(const std::string& input_method_id); // internally. // Examples: "fi" => "Finnish" // "en-US" => "English (United States)" -std::wstring GetLanguageDisplayNameFromCode(const std::string& language_code); +string16 GetLanguageDisplayNameFromCode(const std::string& language_code); // Converts a language code to a language native display name. // MaybeRewriteLanguageName() is called internally. // Examples: "fi" => "suomi" (rather than Finnish) // "en-US" => "English (United States)" -std::wstring GetLanguageNativeDisplayNameFromCode( - const std::string& language_code); +string16 GetLanguageNativeDisplayNameFromCode(const std::string& language_code); // Sorts the given language codes by their corresponding language names, // using the unicode string comparator. Uses unstable sorting. diff --git a/chrome/browser/chromeos/input_method/input_method_util_unittest.cc b/chrome/browser/chromeos/input_method/input_method_util_unittest.cc index 7d4c246..55cf34b 100644 --- a/chrome/browser/chromeos/input_method/input_method_util_unittest.cc +++ b/chrome/browser/chromeos/input_method/input_method_util_unittest.cc @@ -212,11 +212,11 @@ TEST(InputMethodUtilTest, GetKeyboardOverlayId) { } TEST(InputMethodUtilTest, GetLanguageDisplayNameFromCode) { - EXPECT_EQ(L"Finnish", GetLanguageDisplayNameFromCode("fi")); + EXPECT_EQ(UTF8ToUTF16("Finnish"), GetLanguageDisplayNameFromCode("fi")); } TEST(InputMethodUtilTest, GetLanguageNativeDisplayNameFromCode) { - EXPECT_EQ(L"suomi", GetLanguageNativeDisplayNameFromCode("fi")); + EXPECT_EQ(UTF8ToUTF16("suomi"), GetLanguageNativeDisplayNameFromCode("fi")); } TEST(InputMethodUtilTest, SortLanguageCodesByNames) { diff --git a/chrome/browser/chromeos/login/keyboard_switch_menu.cc b/chrome/browser/chromeos/login/keyboard_switch_menu.cc index ff11bee..62a37cc 100644 --- a/chrome/browser/chromeos/login/keyboard_switch_menu.cc +++ b/chrome/browser/chromeos/login/keyboard_switch_menu.cc @@ -49,11 +49,11 @@ void KeyboardSwitchMenu::RunMenu(views::View* source, const gfx::Point& pt) { input_method_menu().RunMenuAt(new_pt, views::Menu2::ALIGN_TOPLEFT); } -std::wstring KeyboardSwitchMenu::GetCurrentKeyboardName() const { +string16 KeyboardSwitchMenu::GetCurrentKeyboardName() const { const int count = GetItemCount(); for (int i = 0; i < count; ++i) { if (IsItemCheckedAt(i)) - return UTF16ToWide(GetLabelAt(i)); + return GetLabelAt(i); } VLOG(1) << "The input method menu is not ready yet. Show a language name " "that matches the hardware keyboard layout"; diff --git a/chrome/browser/chromeos/login/keyboard_switch_menu.h b/chrome/browser/chromeos/login/keyboard_switch_menu.h index 48c0982..d2692fc 100644 --- a/chrome/browser/chromeos/login/keyboard_switch_menu.h +++ b/chrome/browser/chromeos/login/keyboard_switch_menu.h @@ -35,7 +35,7 @@ class KeyboardSwitchMenu : public InputMethodMenu { virtual void RunMenu(views::View* source, const gfx::Point& pt); // Returns current keyboard name to be placed on the keyboard menu-button. - std::wstring GetCurrentKeyboardName() const; + string16 GetCurrentKeyboardName() const; private: DISALLOW_COPY_AND_ASSIGN(KeyboardSwitchMenu); diff --git a/chrome/browser/chromeos/login/language_switch_menu.cc b/chrome/browser/chromeos/login/language_switch_menu.cc index 5e25f23..595515a 100644 --- a/chrome/browser/chromeos/login/language_switch_menu.cc +++ b/chrome/browser/chromeos/login/language_switch_menu.cc @@ -47,8 +47,7 @@ void LanguageSwitchMenu::InitLanguageMenu() { // Fill menu items with updated items. for (int line = 0; line != kLanguageMainMenuSize; line++) { - menu_model_.AddItem( - line, WideToUTF16(language_list_->GetLanguageNameAt(line))); + menu_model_.AddItem(line, language_list_->GetLanguageNameAt(line)); } menu_model_.AddSeparator(); menu_model_.AddSubMenuWithStringId(kMoreLanguagesSubMenu, @@ -57,14 +56,14 @@ void LanguageSwitchMenu::InitLanguageMenu() { for (int line = kLanguageMainMenuSize; line != language_list_->get_languages_count(); line++) { menu_model_submenu_.AddItem( - line, WideToUTF16(language_list_->GetLanguageNameAt(line))); + line, language_list_->GetLanguageNameAt(line)); } // Initialize menu here so it appears fast when called. menu_.reset(new views::Menu2(&menu_model_)); } -std::wstring LanguageSwitchMenu::GetCurrentLocaleName() const { +string16 LanguageSwitchMenu::GetCurrentLocaleName() const { DCHECK(g_browser_process); const std::string locale = g_browser_process->GetApplicationLocale(); int index = language_list_->GetIndexFromLocale(locale); diff --git a/chrome/browser/chromeos/login/language_switch_menu.h b/chrome/browser/chromeos/login/language_switch_menu.h index cbb562d..6455a1a 100644 --- a/chrome/browser/chromeos/login/language_switch_menu.h +++ b/chrome/browser/chromeos/login/language_switch_menu.h @@ -36,7 +36,7 @@ class LanguageSwitchMenu : public views::ViewMenuDelegate, } // Returns current locale name to be placed on the language menu-button. - std::wstring GetCurrentLocaleName() const; + string16 GetCurrentLocaleName() const; // Sets the minimum width of the first level menu to be shown. void SetFirstLevelMenuWidth(int width); diff --git a/chrome/browser/chromeos/login/network_selection_view.cc b/chrome/browser/chromeos/login/network_selection_view.cc index 6a31e6f..04eb840 100644 --- a/chrome/browser/chromeos/login/network_selection_view.cc +++ b/chrome/browser/chromeos/login/network_selection_view.cc @@ -331,9 +331,9 @@ void NetworkSelectionView::Init() { void NetworkSelectionView::UpdateLocalizedStrings() { languages_menubutton_->SetText( - delegate_->language_switch_menu()->GetCurrentLocaleName()); + UTF16ToWide(delegate_->language_switch_menu()->GetCurrentLocaleName())); keyboards_menubutton_->SetText( - delegate_->keyboard_switch_menu()->GetCurrentKeyboardName()); + UTF16ToWide(delegate_->keyboard_switch_menu()->GetCurrentKeyboardName())); welcome_label_->SetText(l10n_util::GetString(IDS_NETWORK_SELECTION_TITLE)); select_language_label_->SetText( l10n_util::GetString(IDS_LANGUAGE_SELECTION_SELECT)); diff --git a/chrome/browser/chromeos/login/new_user_view.cc b/chrome/browser/chromeos/login/new_user_view.cc index d340a0b..cb96ee3 100644 --- a/chrome/browser/chromeos/login/new_user_view.cc +++ b/chrome/browser/chromeos/login/new_user_view.cc @@ -287,7 +287,8 @@ void NewUserView::UpdateLocalizedStrings() { l10n_util::GetString(IDS_BROWSE_WITHOUT_SIGNING_IN_BUTTON)); } delegate_->ClearErrors(); - languages_menubutton_->SetText(language_switch_menu_.GetCurrentLocaleName()); + languages_menubutton_->SetText( + UTF16ToWide(language_switch_menu_.GetCurrentLocaleName())); } void NewUserView::OnLocaleChanged() { diff --git a/chrome/browser/chromeos/options/language_config_model.cc b/chrome/browser/chromeos/options/language_config_model.cc index 0335fa2..cd400e5 100644 --- a/chrome/browser/chromeos/options/language_config_model.cc +++ b/chrome/browser/chromeos/options/language_config_model.cc @@ -38,7 +38,7 @@ string16 AddLanguageComboboxModel::GetItemAt(int index) { return l10n_util::GetStringUTF16( IDS_OPTIONS_SETTINGS_LANGUAGES_ADD_LANGUAGE_COMBOBOX); } - return WideToUTF16Hack(GetLanguageNameAt(GetLanguageIndex(index))); + return GetLanguageNameAt(GetLanguageIndex(index)); } int AddLanguageComboboxModel::GetLanguageIndex(int index) const { diff --git a/chrome/browser/chromeos/options/language_config_view.cc b/chrome/browser/chromeos/options/language_config_view.cc index d4b1f62..5646f9a 100644 --- a/chrome/browser/chromeos/options/language_config_view.cc +++ b/chrome/browser/chromeos/options/language_config_view.cc @@ -239,8 +239,8 @@ void LanguageConfigView::OnSelectionChanged() { std::wstring LanguageConfigView::GetText(int row, int column_id) { if (row >= 0 && row < static_cast<int>( model_.num_preferred_language_codes())) { - return input_method::GetLanguageDisplayNameFromCode( - model_.preferred_language_code_at(row)); + return UTF16ToWide(input_method::GetLanguageDisplayNameFromCode( + model_.preferred_language_code_at(row))); } NOTREACHED(); return L""; diff --git a/chrome/browser/default_encoding_combo_model.cc b/chrome/browser/default_encoding_combo_model.cc index 67dc183..22746ac 100644 --- a/chrome/browser/default_encoding_combo_model.cc +++ b/chrome/browser/default_encoding_combo_model.cc @@ -33,7 +33,7 @@ int DefaultEncodingComboboxModel::GetItemCount() { string16 DefaultEncodingComboboxModel::GetItemAt(int index) { DCHECK(index >= 0 && index < GetItemCount()); - return WideToUTF16Hack(sorted_encoding_list_[index].encoding_display_name); + return sorted_encoding_list_[index].encoding_display_name; } std::string DefaultEncodingComboboxModel::GetEncodingCharsetByIndex(int index) { diff --git a/chrome/browser/language_combobox_model.cc b/chrome/browser/language_combobox_model.cc index 69a3e11..6366d59 100644 --- a/chrome/browser/language_combobox_model.cc +++ b/chrome/browser/language_combobox_model.cc @@ -50,14 +50,14 @@ void LanguageList::InitNativeNames( string16 name_native = l10n_util::GetDisplayNameForLocale(locale_code, locale_code, false); - locale_names_.push_back(UTF16ToWideHack(name_in_current_ui)); - native_names_[UTF16ToWideHack(name_in_current_ui)] = LocaleData( - UTF16ToWideHack(name_native), locale_codes[i]); + locale_names_.push_back(name_in_current_ui); + native_names_[name_in_current_ui] = + LocaleData(name_native, locale_codes[i]); } // Sort using locale specific sorter. - l10n_util::SortStrings(g_browser_process->GetApplicationLocale(), - &locale_names_); + l10n_util::SortStrings16(g_browser_process->GetApplicationLocale(), + &locale_names_); } void LanguageList::CopySpecifiedLanguagesUp(const std::string& locale_codes) { @@ -76,7 +76,7 @@ int LanguageList::get_languages_count() const { return static_cast<int>(locale_names_.size()); } -std::wstring LanguageList::GetLanguageNameAt(int index) const { +string16 LanguageList::GetLanguageNameAt(int index) const { DCHECK(static_cast<int>(locale_names_.size()) > index); LocaleDataMap::const_iterator it = native_names_.find(locale_names_[index]); @@ -90,24 +90,25 @@ std::wstring LanguageList::GetLanguageNameAt(int index) const { // We must add directionality formatting to both the native name and the // locale name in order to avoid text rendering problems such as misplaced // parentheses or languages appearing in the wrong order. - std::wstring locale_name = locale_names_[index]; + string16 locale_name = locale_names_[index]; base::i18n::AdjustStringForLocaleDirection(&locale_name); - std::wstring native_name = it->second.native_name; + string16 native_name = it->second.native_name; base::i18n::AdjustStringForLocaleDirection(&native_name); // We used to have a localizable template here, but none of translators // changed the format. We also want to switch the order of locale_name // and native_name without going back to translators. - std::wstring formatted_item; - base::SStringPrintf(&formatted_item, L"%ls - %ls", locale_name.c_str(), - native_name.c_str()); + std::string formatted_item; + base::SStringPrintf(&formatted_item, "%s - %s", + UTF16ToUTF8(locale_name).c_str(), + UTF16ToUTF8(native_name).c_str()); if (base::i18n::IsRTL()) // Somehow combo box (even with LAYOUTRTL flag) doesn't get this // right so we add RTL BDO (U+202E) to set the direction // explicitly. - formatted_item.insert(0, L"\x202E"); - return formatted_item; + formatted_item.insert(0, "\xE2\x80\xAE"); // U+202E = UTF-8 0xE280AE + return UTF8ToUTF16(formatted_item); } // Return the locale for the given index. E.g., may return pt-BR. @@ -152,7 +153,7 @@ int LanguageComboboxModel::GetItemCount() { } string16 LanguageComboboxModel::GetItemAt(int index) { - return WideToUTF16Hack(GetLanguageNameAt(index)); + return GetLanguageNameAt(index); } // Returns the index of the language currently specified in the user's diff --git a/chrome/browser/language_combobox_model.h b/chrome/browser/language_combobox_model.h index a3fdf77..7844311 100644 --- a/chrome/browser/language_combobox_model.h +++ b/chrome/browser/language_combobox_model.h @@ -24,13 +24,13 @@ class LanguageList { public: struct LocaleData { LocaleData() { } - LocaleData(const std::wstring& name, const std::string& code) + LocaleData(const string16& name, const std::string& code) : native_name(name), locale_code(code) { } - std::wstring native_name; + string16 native_name; std::string locale_code; // E.g., en-us. }; - typedef std::map<std::wstring, LocaleData> LocaleDataMap; + typedef std::map<string16, LocaleData> LocaleDataMap; LanguageList(); @@ -44,7 +44,7 @@ class LanguageList { int get_languages_count() const; - std::wstring GetLanguageNameAt(int index) const; + string16 GetLanguageNameAt(int index) const; // Return the locale for the given index. E.g., may return pt-BR. std::string GetLocaleFromIndex(int index) const; @@ -55,7 +55,7 @@ class LanguageList { private: // The names of all the locales in the current application locale. - std::vector<std::wstring> locale_names_; + std::vector<string16> locale_names_; // A map of some extra data (LocaleData) keyed off the name of the locale. LocaleDataMap native_names_; diff --git a/chrome/browser/ui/toolbar/encoding_menu_controller.cc b/chrome/browser/ui/toolbar/encoding_menu_controller.cc index c93fb1e..177aa28 100644 --- a/chrome/browser/ui/toolbar/encoding_menu_controller.cc +++ b/chrome/browser/ui/toolbar/encoding_menu_controller.cc @@ -102,16 +102,16 @@ bool EncodingMenuController::IsItemChecked( } void EncodingMenuController::GetEncodingMenuItems(Profile* profile, - EncodingMenuItemList* menuItems) { + EncodingMenuItemList* menu_items) { - DCHECK(menuItems); + DCHECK(menu_items); EncodingMenuItem separator(0, string16()); - menuItems->clear(); - menuItems->push_back( + menu_items->clear(); + menu_items->push_back( EncodingMenuItem(IDC_ENCODING_AUTO_DETECT, l10n_util::GetStringUTF16(IDS_ENCODING_AUTO_DETECT))); - menuItems->push_back(separator); + menu_items->push_back(separator); // Create current display encoding list. const std::vector<CharacterEncoding::EncodingInfo>* encodings; @@ -130,12 +130,11 @@ void EncodingMenuController::GetEncodingMenuItems(Profile* profile, std::vector<CharacterEncoding::EncodingInfo>::const_iterator it; for (it = encodings->begin(); it != encodings->end(); ++it) { if (it->encoding_id) { - std::wstring encoding = it->encoding_display_name; + string16 encoding = it->encoding_display_name; base::i18n::AdjustStringForLocaleDirection(&encoding); - menuItems->push_back(EncodingMenuItem(it->encoding_id, - WideToUTF16(encoding))); + menu_items->push_back(EncodingMenuItem(it->encoding_id, encoding)); } else { - menuItems->push_back(separator); + menu_items->push_back(separator); } } } diff --git a/chrome/browser/ui/toolbar/encoding_menu_controller.h b/chrome/browser/ui/toolbar/encoding_menu_controller.h index bfa8c57..b927778 100644 --- a/chrome/browser/ui/toolbar/encoding_menu_controller.h +++ b/chrome/browser/ui/toolbar/encoding_menu_controller.h @@ -42,7 +42,7 @@ class EncodingMenuController { // Fills in a list of menu items in the order they should appear in the menu. // Items whose ids are 0 are separators. void GetEncodingMenuItems(Profile* profile, - EncodingMenuItemList* menuItems); + EncodingMenuItemList* menu_items); private: // List of all valid encoding GUI IDs. |