| Index: chrome/browser/autofill/autofill_country.cc
|
| ===================================================================
|
| --- chrome/browser/autofill/autofill_country.cc (revision 135489)
|
| +++ chrome/browser/autofill/autofill_country.cc (working copy)
|
| @@ -1,4 +1,4 @@
|
| -// Copyright (c) 2012 The Chromium Authors. All rights reserved.
|
| +// Copyright (c) 2011 The Chromium Authors. All rights reserved.
|
| // Use of this source code is governed by a BSD-style license that can be
|
| // found in the LICENSE file.
|
|
|
| @@ -390,7 +390,7 @@
|
| // effect. |buffer_size| should specify the |buffer|'s size, and is updated if
|
| // the |buffer| is resized.
|
| const std::string GetSortKey(const icu::Collator& collator,
|
| - const string16& str,
|
| + const icu::UnicodeString& str,
|
| scoped_array<uint8_t>* buffer,
|
| int32_t* buffer_size) const;
|
|
|
| @@ -482,7 +482,10 @@
|
| return;
|
|
|
| std::map<std::string, std::string> localized_names;
|
| +
|
| + icu::Locale icu_locale(locale.c_str());
|
| const icu::Collator* collator = GetCollatorForLocale(locale);
|
| +
|
| int32_t buffer_size = 1000;
|
| scoped_array<uint8_t> buffer(new uint8_t[buffer_size]);
|
|
|
| @@ -490,8 +493,10 @@
|
| it != CountryDataMap::End();
|
| ++it) {
|
| const std::string& country_code = it->first;
|
| - string16 country_name = l10n_util::GetDisplayNameForCountry(country_code,
|
| - locale);
|
| +
|
| + icu::Locale country_locale(NULL, country_code.c_str());
|
| + icu::UnicodeString country_name;
|
| + country_locale.getDisplayName(icu_locale, country_name);
|
| std::string sort_key = GetSortKey(*collator,
|
| country_name,
|
| &buffer,
|
| @@ -516,7 +521,7 @@
|
| int32_t buffer_size = country_name.size() * 4;
|
| scoped_array<uint8_t> buffer(new uint8_t[buffer_size]);
|
| std::string sort_key = GetSortKey(*collator,
|
| - country_name,
|
| + country_name.c_str(),
|
| &buffer,
|
| &buffer_size);
|
|
|
| @@ -550,28 +555,38 @@
|
| }
|
|
|
| const std::string CountryNames::GetSortKey(const icu::Collator& collator,
|
| - const string16& str,
|
| + const icu::UnicodeString& str,
|
| scoped_array<uint8_t>* buffer,
|
| int32_t* buffer_size) const {
|
| DCHECK(buffer);
|
| DCHECK(buffer_size);
|
|
|
| - icu::UnicodeString icu_str(str.c_str(), str.length());
|
| - int32_t expected_size = collator.getSortKey(icu_str, buffer->get(),
|
| - *buffer_size);
|
| + int32_t expected_size = collator.getSortKey(str, buffer->get(), *buffer_size);
|
| if (expected_size > *buffer_size) {
|
| // If there wasn't enough space, grow the buffer and try again.
|
| *buffer_size = expected_size;
|
| buffer->reset(new uint8_t[*buffer_size]);
|
| DCHECK(buffer->get());
|
|
|
| - expected_size = collator.getSortKey(icu_str, buffer->get(), *buffer_size);
|
| + expected_size = collator.getSortKey(str, buffer->get(), *buffer_size);
|
| DCHECK_EQ(*buffer_size, expected_size);
|
| }
|
|
|
| return std::string(reinterpret_cast<const char*>(buffer->get()));
|
| }
|
|
|
| +// Returns the country name corresponding to |country_code|, localized to the
|
| +// |display_locale|.
|
| +string16 GetDisplayName(const std::string& country_code,
|
| + const icu::Locale& display_locale) {
|
| + icu::Locale country_locale(NULL, country_code.c_str());
|
| + icu::UnicodeString name;
|
| + country_locale.getDisplayName(display_locale, name);
|
| +
|
| + DCHECK_GT(name.length(), 0);
|
| + return string16(name.getBuffer(), name.length());
|
| +}
|
| +
|
| } // namespace
|
|
|
| AutofillCountry::AutofillCountry(const std::string& country_code,
|
| @@ -581,7 +596,7 @@
|
| const CountryData& data = result->second;
|
|
|
| country_code_ = country_code;
|
| - name_ = l10n_util::GetDisplayNameForCountry(country_code, locale);
|
| + name_ = GetDisplayName(country_code, icu::Locale(locale.c_str()));
|
| postal_code_label_ = l10n_util::GetStringUTF16(data.postal_code_label_id);
|
| state_label_ = l10n_util::GetStringUTF16(data.state_label_id);
|
| }
|
|
|