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 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
108 const Ruleset* ruleset = ruleset_it->second; | 108 const Ruleset* ruleset = ruleset_it->second; |
109 assert(ruleset != NULL); | 109 assert(ruleset != NULL); |
110 const Rule& country_rule = | 110 const Rule& country_rule = |
111 ruleset->GetLanguageCodeRule(address.language_code); | 111 ruleset->GetLanguageCodeRule(address.language_code); |
112 | 112 |
113 // Validate required fields. | 113 // Validate required fields. |
114 for (std::vector<AddressField>::const_iterator | 114 for (std::vector<AddressField>::const_iterator |
115 field_it = country_rule.GetRequired().begin(); | 115 field_it = country_rule.GetRequired().begin(); |
116 field_it != country_rule.GetRequired().end(); | 116 field_it != country_rule.GetRequired().end(); |
117 ++field_it) { | 117 ++field_it) { |
118 if (address.GetField(*field_it).empty() && | 118 if (address.GetFieldValue(*field_it).empty() && |
119 FilterAllows( | 119 FilterAllows( |
120 filter, *field_it, AddressProblem::MISSING_REQUIRED_FIELD)) { | 120 filter, *field_it, AddressProblem::MISSING_REQUIRED_FIELD)) { |
121 problems->push_back(AddressProblem( | 121 problems->push_back(AddressProblem( |
122 *field_it, | 122 *field_it, |
123 AddressProblem::MISSING_REQUIRED_FIELD, | 123 AddressProblem::MISSING_REQUIRED_FIELD, |
124 IDS_LIBADDRESSINPUT_I18N_MISSING_REQUIRED_FIELD)); | 124 IDS_LIBADDRESSINPUT_I18N_MISSING_REQUIRED_FIELD)); |
125 } | 125 } |
126 } | 126 } |
127 | 127 |
128 // Validate general postal code format. A country-level rule specifies the | 128 // Validate general postal code format. A country-level rule specifies the |
(...skipping 10 matching lines...) Expand all Loading... |
139 AddressProblem::UNRECOGNIZED_FORMAT, | 139 AddressProblem::UNRECOGNIZED_FORMAT, |
140 country_rule.GetInvalidPostalCodeMessageId())); | 140 country_rule.GetInvalidPostalCodeMessageId())); |
141 } | 141 } |
142 | 142 |
143 while (ruleset != NULL) { | 143 while (ruleset != NULL) { |
144 const Rule& rule = ruleset->GetLanguageCodeRule(address.language_code); | 144 const Rule& rule = ruleset->GetLanguageCodeRule(address.language_code); |
145 | 145 |
146 // Validate the field values, e.g. state names in US. | 146 // Validate the field values, e.g. state names in US. |
147 AddressField sub_field_type = | 147 AddressField sub_field_type = |
148 static_cast<AddressField>(ruleset->field() + 1); | 148 static_cast<AddressField>(ruleset->field() + 1); |
149 const std::string& sub_field = address.GetField(sub_field_type); | 149 const std::string& sub_field = address.GetFieldValue(sub_field_type); |
150 const std::vector<std::string>& sub_keys = rule.GetSubKeys(); | 150 const std::vector<std::string>& sub_keys = rule.GetSubKeys(); |
151 if (!sub_field.empty() && | 151 if (!sub_field.empty() && |
152 !sub_keys.empty() && | 152 !sub_keys.empty() && |
153 FilterAllows(filter, sub_field_type, AddressProblem::UNKNOWN_VALUE) && | 153 FilterAllows(filter, sub_field_type, AddressProblem::UNKNOWN_VALUE) && |
154 std::find(sub_keys.begin(), sub_keys.end(), sub_field) == | 154 std::find(sub_keys.begin(), sub_keys.end(), sub_field) == |
155 sub_keys.end()) { | 155 sub_keys.end()) { |
156 problems->push_back(AddressProblem( | 156 problems->push_back(AddressProblem( |
157 sub_field_type, | 157 sub_field_type, |
158 AddressProblem::UNKNOWN_VALUE, | 158 AddressProblem::UNKNOWN_VALUE, |
159 country_rule.GetInvalidFieldMessageId(sub_field_type))); | 159 country_rule.GetInvalidFieldMessageId(sub_field_type))); |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
226 scoped_ptr<AddressValidator> AddressValidator::Build( | 226 scoped_ptr<AddressValidator> AddressValidator::Build( |
227 scoped_ptr<Downloader> downloader, | 227 scoped_ptr<Downloader> downloader, |
228 scoped_ptr<Storage> storage, | 228 scoped_ptr<Storage> storage, |
229 LoadRulesDelegate* load_rules_delegate) { | 229 LoadRulesDelegate* load_rules_delegate) { |
230 return scoped_ptr<AddressValidator>(new AddressValidatorImpl( | 230 return scoped_ptr<AddressValidator>(new AddressValidatorImpl( |
231 downloader.Pass(), storage.Pass(), load_rules_delegate)); | 231 downloader.Pass(), storage.Pass(), load_rules_delegate)); |
232 } | 232 } |
233 | 233 |
234 } // namespace addressinput | 234 } // namespace addressinput |
235 } // namespace i18n | 235 } // namespace i18n |
OLD | NEW |