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

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

Issue 116363003: [rac] Validate an address. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Addressed comments. Created 6 years, 11 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/ruleset.cc
diff --git a/third_party/libaddressinput/chromium/cpp/src/ruleset.cc b/third_party/libaddressinput/chromium/cpp/src/ruleset.cc
index 9090279ca27399f6b7ae892ee56525359b75ab2f..72c1e1219de0cc4866759fb73af1e1b4b81c7ec9 100644
--- a/third_party/libaddressinput/chromium/cpp/src/ruleset.cc
+++ b/third_party/libaddressinput/chromium/cpp/src/ruleset.cc
@@ -14,6 +14,8 @@
#include "ruleset.h"
+#include <libaddressinput/address_data.h>
+#include <libaddressinput/address_field.h>
#include <libaddressinput/util/scoped_ptr.h>
#include <cassert>
@@ -68,5 +70,28 @@ const Rule* Ruleset::GetLanguageCode(const std::string& language_code) const {
return it == language_codes_.end() ? NULL : it->second;
}
+std::map<AddressField, const Rule*> Ruleset::BuildRulesForAddress(
Evan Stade 2014/01/08 21:29:34 I don't really understand the purpose for this fun
please use gerrit instead 2014/01/09 19:42:00 Done.
+ const AddressData& address) const {
+ std::map<AddressField, const Rule*> result;
+ if (address.country_code.empty()) {
+ result.insert(std::make_pair(COUNTRY, &Rule::GetDefault()));
+ return result;
+ }
+
+ AddressField field = COUNTRY;
+ for (const Ruleset* ruleset = this;
+ ruleset != NULL && field <= DEPENDENT_LOCALITY;
+ ruleset = ruleset->GetSubRegion(address.GetField(field))) {
+ const Rule* language_specific =
+ ruleset->GetLanguageCode(address.language_code);
+ result.insert(std::make_pair(
+ field,
+ language_specific != NULL ? language_specific : &ruleset->rule()));
+ field = static_cast<AddressField>(field + 1);
+ }
+
+ return result;
+}
+
} // namespace addressinput
} // namespace i18n
« no previous file with comments | « third_party/libaddressinput/chromium/cpp/src/ruleset.h ('k') | third_party/libaddressinput/chromium/cpp/test/rule_test.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698