diff options
author | Rouslan Solomakhin <rouslan@chromium.org> | 2014-04-03 17:37:55 +0000 |
---|---|---|
committer | Fredrik Roubert <roubert@google.com> | 2014-09-01 19:20:42 +0200 |
commit | 44757b2af1ddb7b3710f7cb7b37d97d992720120 (patch) | |
tree | 3143d1e6b26ca4f372f45c53a2b4c522961215cd /cpp/src/address_ui.cc | |
parent | 85d4bb3d565e0490880194a4d3a049a6ba1d8d86 (diff) | |
download | src-44757b2af1ddb7b3710f7cb7b37d97d992720120.tar.gz |
BuildComponents() should return at most one component per field type.
Addresses in some regions display the same field multiple times on an
envelope. For example, CI addresses display CEDEX twice. The
BuildComponents() function should not return multiple UI components for
the same field, because these components are used to display input
fields. There should be exactly one input field per field type.
R=lararennie@google.com, roubert@google.com
Review URL: https://codereview.appspot.com/83790043
Diffstat (limited to 'cpp/src/address_ui.cc')
-rw-r--r-- | cpp/src/address_ui.cc | 10 |
1 files changed, 9 insertions, 1 deletions
diff --git a/cpp/src/address_ui.cc b/cpp/src/address_ui.cc index 0fac86f..15f3c61 100644 --- a/cpp/src/address_ui.cc +++ b/cpp/src/address_ui.cc @@ -18,6 +18,7 @@ #include <libaddressinput/address_ui_component.h> #include <libaddressinput/localization.h> +#include <set> #include <string> #include <vector> @@ -76,10 +77,14 @@ std::vector<AddressUiComponent> BuildComponents( Rule rule; rule.CopyFrom(Rule::GetDefault()); if (!rule.ParseSerializedRule( - RegionDataConstants::GetRegionData(region_code))) { + RegionDataConstants::GetRegionData(region_code))) { return result; } + // For avoiding showing an input field twice, when the field is displayed + // twice on an envelope. + std::set<AddressField> fields; + bool previous_field_is_newline = true; bool next_field_is_newline = true; for (std::vector<AddressField>::const_iterator field_it = @@ -89,6 +94,9 @@ std::vector<AddressUiComponent> BuildComponents( previous_field_is_newline = true; continue; } + if (!fields.insert(*field_it).second) { + continue; + } AddressUiComponent component; std::vector<AddressField>::const_iterator next_field_it = field_it + 1; next_field_is_newline = |