Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(598)

Unified Diff: third_party/libaddressinput/chromium/cpp/src/rule.cc

Issue 237693002: requestAutocomplete should not unlatinize administrative region names. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Address comments. Created 6 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: third_party/libaddressinput/chromium/cpp/src/rule.cc
diff --git a/third_party/libaddressinput/chromium/cpp/src/rule.cc b/third_party/libaddressinput/chromium/cpp/src/rule.cc
index 791ac9eca651bbba4d68945ffad93ffaafe454c4..d0af74679ee31b9356be382d70a4459819d10523 100644
--- a/third_party/libaddressinput/chromium/cpp/src/rule.cc
+++ b/third_party/libaddressinput/chromium/cpp/src/rule.cc
@@ -197,6 +197,25 @@ int GetPostalCodeMessageId(const std::string& postal_code_type, bool error) {
return INVALID_MESSAGE_ID;
}
+// Finds |target| in |values_to_compare| and sets |sub_key| to the associated
+// value from |values_to_pick_from|. Returns false if |target| is not in
+// |values_to_compare|. |sub_key| should not be NULL. |values_to_compare| should
+// not be larger than |values_to_pick_from|.
+bool GetMatchingSubKey(const std::string& target,
+ const std::vector<std::string>& values_to_compare,
+ const std::vector<std::string>& values_to_pick_from,
+ 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.
+ assert(sub_key != NULL);
+ assert(values_to_pick_from.size() >= values_to_compare.size());
+ for (size_t i = 0; i < values_to_compare.size(); ++i) {
+ if (LooseStringCompare(values_to_compare[i], target)) {
+ *sub_key = values_to_pick_from[i];
+ return true;
+ }
+ }
+ return false;
+}
+
} // namespace
FormatElement::FormatElement(AddressField field)
@@ -376,27 +395,20 @@ int Rule::GetInvalidFieldMessageId(AddressField field) const {
}
bool Rule::CanonicalizeSubKey(const std::string& user_input,
+ bool keep_input_latin,
std::string* sub_key) const {
+ assert(sub_key != NULL);
+
if (sub_keys_.empty()) {
*sub_key = user_input;
return true;
}
- return GetMatchingSubKey(user_input, sub_keys_, sub_key) ||
- GetMatchingSubKey(user_input, sub_names_, sub_key) ||
- GetMatchingSubKey(user_input, sub_lnames_, sub_key);
-}
-
-bool Rule::GetMatchingSubKey(const std::string& target,
- const std::vector<std::string>& values,
- std::string* sub_key) const {
- for (size_t i = 0; i < values.size(); ++i) {
- if (LooseStringCompare(values[i], target)) {
- *sub_key = sub_keys_[i];
- return true;
- }
- }
- return false;
+ return GetMatchingSubKey(user_input, sub_keys_, sub_keys_, sub_key) ||
+ GetMatchingSubKey(user_input, sub_names_, sub_keys_, sub_key) ||
+ (keep_input_latin &&
+ GetMatchingSubKey(user_input, sub_lnames_, sub_lnames_, sub_key)) ||
+ GetMatchingSubKey(user_input, sub_lnames_, sub_keys_, sub_key);
}
} // namespace addressinput

Powered by Google App Engine
This is Rietveld 408576698