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 358 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
369 case DEPENDENT_LOCALITY: | 369 case DEPENDENT_LOCALITY: |
370 return IDS_LIBADDRESSINPUT_I18N_INVALID_DEPENDENT_LOCALITY_LABEL; | 370 return IDS_LIBADDRESSINPUT_I18N_INVALID_DEPENDENT_LOCALITY_LABEL; |
371 case POSTAL_CODE: | 371 case POSTAL_CODE: |
372 return invalid_postal_code_message_id_; | 372 return invalid_postal_code_message_id_; |
373 default: | 373 default: |
374 return IDS_LIBADDRESSINPUT_I18N_INVALID_ENTRY; | 374 return IDS_LIBADDRESSINPUT_I18N_INVALID_ENTRY; |
375 } | 375 } |
376 } | 376 } |
377 | 377 |
378 bool Rule::CanonicalizeSubKey(const std::string& user_input, | 378 bool Rule::CanonicalizeSubKey(const std::string& user_input, |
| 379 bool canonicalize_latin_name, |
379 std::string* sub_key) const { | 380 std::string* sub_key) const { |
380 if (sub_keys_.empty()) { | 381 if (sub_keys_.empty()) { |
381 *sub_key = user_input; | 382 *sub_key = user_input; |
382 return true; | 383 return true; |
383 } | 384 } |
384 | 385 |
385 return GetMatchingSubKey(user_input, sub_keys_, sub_key) || | 386 return GetMatchingSubKey(user_input, sub_keys_, sub_key) || |
386 GetMatchingSubKey(user_input, sub_names_, sub_key) || | 387 GetMatchingSubKey(user_input, sub_names_, sub_key) || |
387 GetMatchingSubKey(user_input, sub_lnames_, sub_key); | 388 GetMatchingSubKey(user_input, sub_lnames_, |
| 389 canonicalize_latin_name ? sub_key : NULL); |
388 } | 390 } |
389 | 391 |
390 bool Rule::GetMatchingSubKey(const std::string& target, | 392 bool Rule::GetMatchingSubKey(const std::string& target, |
391 const std::vector<std::string>& values, | 393 const std::vector<std::string>& values, |
392 std::string* sub_key) const { | 394 std::string* sub_key) const { |
393 for (size_t i = 0; i < values.size(); ++i) { | 395 for (size_t i = 0; i < values.size(); ++i) { |
394 if (LooseStringCompare(values[i], target)) { | 396 if (LooseStringCompare(values[i], target)) { |
395 *sub_key = sub_keys_[i]; | 397 if (sub_key != NULL) { |
| 398 *sub_key = sub_keys_[i]; |
| 399 } |
396 return true; | 400 return true; |
397 } | 401 } |
398 } | 402 } |
399 return false; | 403 return false; |
400 } | 404 } |
401 | 405 |
402 } // namespace addressinput | 406 } // namespace addressinput |
403 } // namespace i18n | 407 } // namespace i18n |
OLD | NEW |