| Index: third_party/libaddressinput/chromium/cpp/src/address_ui.cc
|
| diff --git a/third_party/libaddressinput/chromium/cpp/src/address_ui.cc b/third_party/libaddressinput/chromium/cpp/src/address_ui.cc
|
| index cf57543bb743e2e9012f72e2bad16732dd799083..0310af9601e0186324f7882e50296c44b1b7f2fa 100644
|
| --- a/third_party/libaddressinput/chromium/cpp/src/address_ui.cc
|
| +++ b/third_party/libaddressinput/chromium/cpp/src/address_ui.cc
|
| @@ -18,6 +18,8 @@
|
| #include <libaddressinput/address_ui_component.h>
|
| #include <libaddressinput/localization.h>
|
|
|
| +#include <algorithm>
|
| +#include <set>
|
| #include <string>
|
| #include <vector>
|
|
|
| @@ -76,20 +78,40 @@ std::vector<AddressUiComponent> BuildComponents(
|
| return result;
|
| }
|
|
|
| - for (std::vector<std::vector<AddressField> >::const_iterator
|
| - line_it = rule.GetFormat().begin();
|
| + std::set<AddressField> fields;
|
| + for (std::vector<std::vector<FormatElement> >::const_iterator
|
| + line_it = rule.GetFormat().begin();
|
| line_it != rule.GetFormat().end();
|
| ++line_it) {
|
| - for (std::vector<AddressField>::const_iterator field_it = line_it->begin();
|
| - field_it != line_it->end(); ++field_it) {
|
| + int num_fields = 0;
|
| + for (std::vector<FormatElement>::const_iterator element_it =
|
| + line_it->begin();
|
| + element_it != line_it->end();
|
| + ++element_it) {
|
| + if (element_it->type == FormatElement::FIELD) {
|
| + ++num_fields;
|
| + }
|
| + }
|
| +
|
| + for (std::vector<FormatElement>::const_iterator element_it =
|
| + line_it->begin();
|
| + element_it != line_it->end();
|
| + ++element_it) {
|
| + if (element_it->type != FormatElement::FIELD ||
|
| + fields.find(element_it->field) != fields.end()) {
|
| + continue;
|
| + }
|
| + fields.insert(element_it->field);
|
| +
|
| AddressUiComponent component;
|
| component.length_hint =
|
| - line_it->size() == 1 ? AddressUiComponent::HINT_LONG
|
| - : AddressUiComponent::HINT_SHORT;
|
| - component.field = *field_it;
|
| + num_fields == 1 ? AddressUiComponent::HINT_LONG
|
| + : AddressUiComponent::HINT_SHORT;
|
| + component.field = element_it->field;
|
| component.name = localization.GetString(
|
| - GetMessageIdForField(*field_it, rule.GetAdminAreaNameMessageId(),
|
| - rule.GetPostalCodeNameMessageId()));
|
| + GetMessageIdForField(element_it->field,
|
| + rule.GetAdminAreaNameMessageId(),
|
| + rule.GetPostalCodeNameMessageId()));
|
| result.push_back(component);
|
| }
|
| }
|
| @@ -97,5 +119,31 @@ std::vector<AddressUiComponent> BuildComponents(
|
| return result;
|
| }
|
|
|
| +const std::string& GetCompactAddressLinesSeparator(
|
| + const std::string& language_code,
|
| + const std::string& country_code) {
|
| + Rule rule;
|
| + rule.CopyFrom(Rule::GetDefault());
|
| + if (!rule.ParseSerializedRule(
|
| + RegionDataConstants::GetRegionData(country_code))) {
|
| + return RegionDataConstants::GetLanguageCompactLineSeparator(language_code);
|
| + }
|
| +
|
| + std::vector<std::string>::const_iterator lang_it =
|
| + std::find(rule.GetLanguages().begin(),
|
| + rule.GetLanguages().end(),
|
| + language_code);
|
| + if (lang_it != rule.GetLanguages().end()) {
|
| + return RegionDataConstants::GetLanguageCompactLineSeparator(*lang_it);
|
| + }
|
| +
|
| + if (!rule.GetLanguage().empty()) {
|
| + return RegionDataConstants::GetLanguageCompactLineSeparator(
|
| + rule.GetLanguage());
|
| + }
|
| +
|
| + return RegionDataConstants::GetCountryCompactLineSeparator(country_code);
|
| +}
|
| +
|
| } // namespace addressinput
|
| } // namespace i18n
|
|
|