| OLD | NEW |
| 1 // Copyright (C) 2013 Google Inc. | 1 // Copyright (C) 2013 Google Inc. |
| 2 // | 2 // |
| 3 // Licensed under the Apache License, Version 2.0 (the "License"); | 3 // Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 // you may not use this file except in compliance with the License. | 4 // you may not use this file except in compliance with the License. |
| 5 // You may obtain a copy of the License at | 5 // You may obtain a copy of the License at |
| 6 // | 6 // |
| 7 // http://www.apache.org/licenses/LICENSE-2.0 | 7 // http://www.apache.org/licenses/LICENSE-2.0 |
| 8 // | 8 // |
| 9 // Unless required by applicable law or agreed to in writing, software | 9 // Unless required by applicable law or agreed to in writing, software |
| 10 // distributed under the License is distributed on an "AS IS" BASIS, | 10 // distributed under the License is distributed on an "AS IS" BASIS, |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 69 const Localization& localization) { | 69 const Localization& localization) { |
| 70 std::vector<AddressUiComponent> result; | 70 std::vector<AddressUiComponent> result; |
| 71 | 71 |
| 72 Rule rule; | 72 Rule rule; |
| 73 rule.CopyFrom(Rule::GetDefault()); | 73 rule.CopyFrom(Rule::GetDefault()); |
| 74 if (!rule.ParseSerializedRule( | 74 if (!rule.ParseSerializedRule( |
| 75 RegionDataConstants::GetRegionData(region_code))) { | 75 RegionDataConstants::GetRegionData(region_code))) { |
| 76 return result; | 76 return result; |
| 77 } | 77 } |
| 78 | 78 |
| 79 for (std::vector<std::vector<AddressField> >::const_iterator | 79 for (std::vector<std::vector<FormatElement> >::const_iterator |
| 80 line_it = rule.GetFormat().begin(); | 80 line_it = rule.GetFormat().begin(); |
| 81 line_it != rule.GetFormat().end(); | 81 line_it != rule.GetFormat().end(); |
| 82 ++line_it) { | 82 ++line_it) { |
| 83 for (std::vector<AddressField>::const_iterator field_it = line_it->begin(); | 83 int num_fields = 0; |
| 84 field_it != line_it->end(); ++field_it) { | 84 for (std::vector<FormatElement>::const_iterator element_it = |
| 85 line_it->begin(); |
| 86 element_it != line_it->end(); |
| 87 ++element_it) { |
| 88 if (element_it->type == FormatElement::FIELD) { |
| 89 ++num_fields; |
| 90 } |
| 91 } |
| 92 |
| 93 for (std::vector<FormatElement>::const_iterator element_it = |
| 94 line_it->begin(); |
| 95 element_it != line_it->end(); |
| 96 ++element_it) { |
| 97 if (element_it->type != FormatElement::FIELD) { |
| 98 continue; |
| 99 } |
| 100 |
| 85 AddressUiComponent component; | 101 AddressUiComponent component; |
| 86 component.length_hint = | 102 component.length_hint = |
| 87 line_it->size() == 1 ? AddressUiComponent::HINT_LONG | 103 num_fields == 1 ? AddressUiComponent::HINT_LONG |
| 88 : AddressUiComponent::HINT_SHORT; | 104 : AddressUiComponent::HINT_SHORT; |
| 89 component.field = *field_it; | 105 component.field = element_it->field; |
| 90 component.name = localization.GetString( | 106 component.name = localization.GetString( |
| 91 GetMessageIdForField(*field_it, rule.GetAdminAreaNameMessageId(), | 107 GetMessageIdForField(element_it->field, |
| 92 rule.GetPostalCodeNameMessageId())); | 108 rule.GetAdminAreaNameMessageId(), |
| 109 rule.GetPostalCodeNameMessageId())); |
| 93 result.push_back(component); | 110 result.push_back(component); |
| 94 } | 111 } |
| 95 } | 112 } |
| 96 | 113 |
| 97 return result; | 114 return result; |
| 98 } | 115 } |
| 99 | 116 |
| 100 } // namespace addressinput | 117 } // namespace addressinput |
| 101 } // namespace i18n | 118 } // namespace i18n |
| OLD | NEW |