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 202 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
213 while (ruleset != NULL) { | 213 while (ruleset != NULL) { |
214 const Rule& rule = ruleset->GetLanguageCodeRule(address.language_code); | 214 const Rule& rule = ruleset->GetLanguageCodeRule(address.language_code); |
215 | 215 |
216 // Validate the field values, e.g. state names in US. | 216 // Validate the field values, e.g. state names in US. |
217 AddressField sub_field_type = | 217 AddressField sub_field_type = |
218 static_cast<AddressField>(ruleset->field() + 1); | 218 static_cast<AddressField>(ruleset->field() + 1); |
219 std::string sub_key; | 219 std::string sub_key; |
220 const std::string& user_input = address.GetFieldValue(sub_field_type); | 220 const std::string& user_input = address.GetFieldValue(sub_field_type); |
221 if (!user_input.empty() && | 221 if (!user_input.empty() && |
222 FilterAllows(filter, sub_field_type, AddressProblem::UNKNOWN_VALUE) && | 222 FilterAllows(filter, sub_field_type, AddressProblem::UNKNOWN_VALUE) && |
223 !rule.CanonicalizeSubKey(user_input, &sub_key)) { | 223 !rule.CanonicalizeSubKey(user_input, false, &sub_key)) { |
224 problems->push_back(AddressProblem( | 224 problems->push_back(AddressProblem( |
225 sub_field_type, | 225 sub_field_type, |
226 AddressProblem::UNKNOWN_VALUE, | 226 AddressProblem::UNKNOWN_VALUE, |
227 country_rule.GetInvalidFieldMessageId(sub_field_type))); | 227 country_rule.GetInvalidFieldMessageId(sub_field_type))); |
228 } | 228 } |
229 | 229 |
230 // Validate sub-region specific postal code format. A sub-region specifies | 230 // Validate sub-region specific postal code format. A sub-region specifies |
231 // the regular expression for a prefix of the postal code. | 231 // the regular expression for a prefix of the postal code. |
232 if (ruleset->field() > COUNTRY && | 232 if (ruleset->field() > COUNTRY && |
233 !address.postal_code.empty() && | 233 !address.postal_code.empty() && |
(...skipping 202 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
436 virtual bool CanonicalizeAdministrativeArea(AddressData* address_data) const { | 436 virtual bool CanonicalizeAdministrativeArea(AddressData* address_data) const { |
437 std::map<std::string, Ruleset*>::const_iterator ruleset_it = | 437 std::map<std::string, Ruleset*>::const_iterator ruleset_it = |
438 rules_.find(address_data->country_code); | 438 rules_.find(address_data->country_code); |
439 if (ruleset_it == rules_.end()) { | 439 if (ruleset_it == rules_.end()) { |
440 return false; | 440 return false; |
441 } | 441 } |
442 const Rule& rule = | 442 const Rule& rule = |
443 ruleset_it->second->GetLanguageCodeRule(address_data->language_code); | 443 ruleset_it->second->GetLanguageCodeRule(address_data->language_code); |
444 | 444 |
445 return rule.CanonicalizeSubKey(address_data->administrative_area, | 445 return rule.CanonicalizeSubKey(address_data->administrative_area, |
| 446 true, // Keep input latin. |
446 &address_data->administrative_area); | 447 &address_data->administrative_area); |
447 } | 448 } |
448 | 449 |
449 private: | 450 private: |
450 // Called when CountryRulesAggregator::AggregateRules loads the |ruleset| for | 451 // Called when CountryRulesAggregator::AggregateRules loads the |ruleset| for |
451 // the |country_code|. | 452 // the |country_code|. |
452 void OnRulesLoaded(bool success, | 453 void OnRulesLoaded(bool success, |
453 const std::string& country_code, | 454 const std::string& country_code, |
454 scoped_ptr<Ruleset> ruleset) { | 455 scoped_ptr<Ruleset> ruleset) { |
455 assert(rules_.find(country_code) == rules_.end()); | 456 assert(rules_.find(country_code) == rules_.end()); |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
523 scoped_ptr<Downloader> downloader, | 524 scoped_ptr<Downloader> downloader, |
524 scoped_ptr<Storage> storage, | 525 scoped_ptr<Storage> storage, |
525 LoadRulesDelegate* load_rules_delegate) { | 526 LoadRulesDelegate* load_rules_delegate) { |
526 return scoped_ptr<AddressValidator>(new AddressValidatorImpl( | 527 return scoped_ptr<AddressValidator>(new AddressValidatorImpl( |
527 validation_data_url, downloader.Pass(), storage.Pass(), | 528 validation_data_url, downloader.Pass(), storage.Pass(), |
528 load_rules_delegate)); | 529 load_rules_delegate)); |
529 } | 530 } |
530 | 531 |
531 } // namespace addressinput | 532 } // namespace addressinput |
532 } // namespace i18n | 533 } // namespace i18n |
OLD | NEW |