Chromium Code Reviews| Index: third_party/libaddressinput/chromium/chrome_address_validator.cc |
| diff --git a/third_party/libaddressinput/chromium/chrome_address_validator.cc b/third_party/libaddressinput/chromium/chrome_address_validator.cc |
| index f76bcbd15fda6b170d7941f5f63842d5ea49afff..d923e01be919be531a3b6fd2a7be4205de975b96 100644 |
| --- a/third_party/libaddressinput/chromium/chrome_address_validator.cc |
| +++ b/third_party/libaddressinput/chromium/chrome_address_validator.cc |
| @@ -60,18 +60,24 @@ void AddressValidator::LoadRules(const std::string& region_code) { |
| supplier_->LoadRules(region_code, *rules_loaded_); |
| } |
| -std::vector<std::string> AddressValidator::GetRegionSubKeys( |
| - const std::string& region_code) { |
| +std::vector<std::pair<std::string, std::string>> |
| +AddressValidator::GetRegionSubKeys(const std::string& region_code) { |
| + std::vector<std::pair<std::string, std::string>> subkeys_codes_names; |
| if (!AreRulesLoadedForRegion(region_code)) |
| - return std::vector<std::string>(); |
| + return subkeys_codes_names; |
| auto rules = supplier_->GetRulesForRegion(region_code); |
| - auto rule_iterator = rules.find("data/" + region_code); |
| - if (rule_iterator == rules.end() || !rule_iterator->second) |
| - return std::vector<std::string>(); |
| + std::string code_prefix = "data/" + region_code + "/"; |
| + size_t code_prefix_size = code_prefix.size(); |
|
Mathieu
2017/07/05 16:07:15
nit: code_prefix_size = region_code.size() + 6;
Parastoo
2017/07/07 15:53:23
Done.
|
| - return rule_iterator->second->GetSubKeys(); |
| + for (auto r : rules) { |
| + if (r.first.size() <= code_prefix_size) |
|
Mathieu
2017/07/05 16:07:15
Could we get in a situation where the key is data/
Parastoo
2017/07/07 15:53:23
Done.
|
| + continue; |
| + subkeys_codes_names.push_back( |
| + std::make_pair(r.first.substr(code_prefix_size), r.second->GetName())); |
| + } |
| + return subkeys_codes_names; |
| } |
| AddressValidator::Status AddressValidator::ValidateAddress( |