Chromium Code Reviews| 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 179 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 190 return error ? IDS_LIBADDRESSINPUT_I18N_INVALID_POSTAL_CODE_LABEL | 190 return error ? IDS_LIBADDRESSINPUT_I18N_INVALID_POSTAL_CODE_LABEL |
| 191 : IDS_LIBADDRESSINPUT_I18N_POSTAL_CODE_LABEL; | 191 : IDS_LIBADDRESSINPUT_I18N_POSTAL_CODE_LABEL; |
| 192 } | 192 } |
| 193 if (postal_code_type == "zip") { | 193 if (postal_code_type == "zip") { |
| 194 return error ? IDS_LIBADDRESSINPUT_I18N_INVALID_ZIP_CODE_LABEL | 194 return error ? IDS_LIBADDRESSINPUT_I18N_INVALID_ZIP_CODE_LABEL |
| 195 : IDS_LIBADDRESSINPUT_I18N_ZIP_CODE_LABEL; | 195 : IDS_LIBADDRESSINPUT_I18N_ZIP_CODE_LABEL; |
| 196 } | 196 } |
| 197 return INVALID_MESSAGE_ID; | 197 return INVALID_MESSAGE_ID; |
| 198 } | 198 } |
| 199 | 199 |
| 200 // Finds |target| in |values_to_compare| and sets |sub_key| to the associated | |
| 201 // value from |values_to_pick_from|. Returns false if |target| is not in | |
| 202 // |values_to_compare|. |sub_key| should not be NULL. |values_to_compare| should | |
| 203 // not be larger than |values_to_pick_from|. | |
| 204 bool GetMatchingSubKey(const std::string& target, | |
| 205 const std::vector<std::string>& values_to_compare, | |
| 206 const std::vector<std::string>& values_to_pick_from, | |
| 207 std::string* sub_key) { | |
|
Evan Stade
2014/04/16 23:32:32
s/SubKey/Value
s/sub_key/output_value or picked_va
please use gerrit instead
2014/04/17 00:40:46
Done.
| |
| 208 assert(sub_key != NULL); | |
| 209 assert(values_to_pick_from.size() >= values_to_compare.size()); | |
| 210 for (size_t i = 0; i < values_to_compare.size(); ++i) { | |
| 211 if (LooseStringCompare(values_to_compare[i], target)) { | |
| 212 *sub_key = values_to_pick_from[i]; | |
| 213 return true; | |
| 214 } | |
| 215 } | |
| 216 return false; | |
| 217 } | |
| 218 | |
| 200 } // namespace | 219 } // namespace |
| 201 | 220 |
| 202 FormatElement::FormatElement(AddressField field) | 221 FormatElement::FormatElement(AddressField field) |
| 203 : field(field), literal() {} | 222 : field(field), literal() {} |
| 204 | 223 |
| 205 FormatElement::FormatElement(const std::string& literal) | 224 FormatElement::FormatElement(const std::string& literal) |
| 206 : field(COUNTRY), literal(literal) { | 225 : field(COUNTRY), literal(literal) { |
| 207 assert(!literal.empty()); | 226 assert(!literal.empty()); |
| 208 } | 227 } |
| 209 | 228 |
| (...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 369 case DEPENDENT_LOCALITY: | 388 case DEPENDENT_LOCALITY: |
| 370 return IDS_LIBADDRESSINPUT_I18N_INVALID_DEPENDENT_LOCALITY_LABEL; | 389 return IDS_LIBADDRESSINPUT_I18N_INVALID_DEPENDENT_LOCALITY_LABEL; |
| 371 case POSTAL_CODE: | 390 case POSTAL_CODE: |
| 372 return invalid_postal_code_message_id_; | 391 return invalid_postal_code_message_id_; |
| 373 default: | 392 default: |
| 374 return IDS_LIBADDRESSINPUT_I18N_INVALID_ENTRY; | 393 return IDS_LIBADDRESSINPUT_I18N_INVALID_ENTRY; |
| 375 } | 394 } |
| 376 } | 395 } |
| 377 | 396 |
| 378 bool Rule::CanonicalizeSubKey(const std::string& user_input, | 397 bool Rule::CanonicalizeSubKey(const std::string& user_input, |
| 398 bool keep_input_latin, | |
| 379 std::string* sub_key) const { | 399 std::string* sub_key) const { |
| 400 assert(sub_key != NULL); | |
| 401 | |
| 380 if (sub_keys_.empty()) { | 402 if (sub_keys_.empty()) { |
| 381 *sub_key = user_input; | 403 *sub_key = user_input; |
| 382 return true; | 404 return true; |
| 383 } | 405 } |
| 384 | 406 |
| 385 return GetMatchingSubKey(user_input, sub_keys_, sub_key) || | 407 return GetMatchingSubKey(user_input, sub_keys_, sub_keys_, sub_key) || |
| 386 GetMatchingSubKey(user_input, sub_names_, sub_key) || | 408 GetMatchingSubKey(user_input, sub_names_, sub_keys_, sub_key) || |
| 387 GetMatchingSubKey(user_input, sub_lnames_, sub_key); | 409 (keep_input_latin && |
| 388 } | 410 GetMatchingSubKey(user_input, sub_lnames_, sub_lnames_, sub_key)) || |
| 389 | 411 GetMatchingSubKey(user_input, sub_lnames_, sub_keys_, sub_key); |
| 390 bool Rule::GetMatchingSubKey(const std::string& target, | |
| 391 const std::vector<std::string>& values, | |
| 392 std::string* sub_key) const { | |
| 393 for (size_t i = 0; i < values.size(); ++i) { | |
| 394 if (LooseStringCompare(values[i], target)) { | |
| 395 *sub_key = sub_keys_[i]; | |
| 396 return true; | |
| 397 } | |
| 398 } | |
| 399 return false; | |
| 400 } | 412 } |
| 401 | 413 |
| 402 } // namespace addressinput | 414 } // namespace addressinput |
| 403 } // namespace i18n | 415 } // namespace i18n |
| OLD | NEW |