| 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, |
| 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 // See the License for the specific language governing permissions and | 12 // See the License for the specific language governing permissions and |
| 13 // limitations under the License. | 13 // limitations under the License. |
| 14 | 14 |
| 15 #include <libaddressinput/address_ui.h> | 15 #include <libaddressinput/address_ui.h> |
| 16 | 16 |
| 17 #include <libaddressinput/address_field.h> | 17 #include <libaddressinput/address_field.h> |
| 18 #include <libaddressinput/address_ui_component.h> | 18 #include <libaddressinput/address_ui_component.h> |
| 19 #include <libaddressinput/localization.h> | |
| 20 | 19 |
| 21 #include <string> | 20 #include <string> |
| 22 #include <vector> | 21 #include <vector> |
| 23 | 22 |
| 24 #include "grit.h" | 23 #include "grit.h" |
| 25 #include "messages.h" | 24 #include "messages.h" |
| 26 #include "region_data_constants.h" | 25 #include "region_data_constants.h" |
| 27 #include "rule.h" | 26 #include "rule.h" |
| 28 | 27 |
| 29 namespace i18n { | 28 namespace i18n { |
| (...skipping 28 matching lines...) Expand all Loading... |
| 58 } | 57 } |
| 59 } | 58 } |
| 60 | 59 |
| 61 } // namespace | 60 } // namespace |
| 62 | 61 |
| 63 const std::vector<std::string>& GetRegionCodes() { | 62 const std::vector<std::string>& GetRegionCodes() { |
| 64 return RegionDataConstants::GetRegionCodes(); | 63 return RegionDataConstants::GetRegionCodes(); |
| 65 } | 64 } |
| 66 | 65 |
| 67 std::vector<AddressUiComponent> BuildComponents( | 66 std::vector<AddressUiComponent> BuildComponents( |
| 68 const std::string& region_code, | 67 const std::string& region_code) { |
| 69 const Localization& localization) { | |
| 70 std::vector<AddressUiComponent> result; | 68 std::vector<AddressUiComponent> result; |
| 71 | 69 |
| 72 Rule rule; | 70 Rule rule; |
| 73 rule.CopyFrom(Rule::GetDefault()); | 71 rule.CopyFrom(Rule::GetDefault()); |
| 74 if (!rule.ParseSerializedRule( | 72 if (!rule.ParseSerializedRule( |
| 75 RegionDataConstants::GetRegionData(region_code))) { | 73 RegionDataConstants::GetRegionData(region_code))) { |
| 76 return result; | 74 return result; |
| 77 } | 75 } |
| 78 | 76 |
| 79 for (std::vector<std::vector<AddressField> >::const_iterator | 77 for (std::vector<std::vector<AddressField> >::const_iterator |
| 80 line_it = rule.GetFormat().begin(); | 78 line_it = rule.GetFormat().begin(); |
| 81 line_it != rule.GetFormat().end(); | 79 line_it != rule.GetFormat().end(); |
| 82 ++line_it) { | 80 ++line_it) { |
| 83 for (std::vector<AddressField>::const_iterator field_it = line_it->begin(); | 81 for (std::vector<AddressField>::const_iterator field_it = line_it->begin(); |
| 84 field_it != line_it->end(); ++field_it) { | 82 field_it != line_it->end(); ++field_it) { |
| 85 AddressUiComponent component; | 83 AddressUiComponent component; |
| 86 component.length_hint = | 84 component.length_hint = |
| 87 line_it->size() == 1 ? AddressUiComponent::HINT_LONG | 85 line_it->size() == 1 ? AddressUiComponent::HINT_LONG |
| 88 : AddressUiComponent::HINT_SHORT; | 86 : AddressUiComponent::HINT_SHORT; |
| 89 component.field = *field_it; | 87 component.field = *field_it; |
| 90 component.name = localization.GetString( | 88 component.name_id = |
| 91 GetMessageIdForField(*field_it, rule.GetAdminAreaNameMessageId(), | 89 GetMessageIdForField(*field_it, |
| 92 rule.GetPostalCodeNameMessageId())); | 90 rule.GetAdminAreaNameMessageId(), |
| 91 rule.GetPostalCodeNameMessageId()); |
| 93 result.push_back(component); | 92 result.push_back(component); |
| 94 } | 93 } |
| 95 } | 94 } |
| 96 | 95 |
| 97 return result; | 96 return result; |
| 98 } | 97 } |
| 99 | 98 |
| 100 } // namespace addressinput | 99 } // namespace addressinput |
| 101 } // namespace i18n | 100 } // namespace i18n |
| OLD | NEW |