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

Side by Side 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (C) 2014 Google Inc. 1 // Copyright (C) 2014 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,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and 12 // See the License for the specific language governing permissions and
13 // limitations under the License. 13 // limitations under the License.
14 14
15 #include "ruleset.h" 15 #include "ruleset.h"
16 16
17 #include <libaddressinput/address_data.h>
18 #include <libaddressinput/address_field.h>
17 #include <libaddressinput/util/scoped_ptr.h> 19 #include <libaddressinput/util/scoped_ptr.h>
18 20
19 #include <cassert> 21 #include <cassert>
20 #include <cstddef> 22 #include <cstddef>
21 #include <map> 23 #include <map>
22 #include <string> 24 #include <string>
23 #include <utility> 25 #include <utility>
24 26
25 #include "rule.h" 27 #include "rule.h"
26 #include "util/stl_util.h" 28 #include "util/stl_util.h"
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
61 sub_regions_.find(sub_region); 63 sub_regions_.find(sub_region);
62 return it == sub_regions_.end() ? NULL : it->second; 64 return it == sub_regions_.end() ? NULL : it->second;
63 } 65 }
64 66
65 const Rule* Ruleset::GetLanguageCode(const std::string& language_code) const { 67 const Rule* Ruleset::GetLanguageCode(const std::string& language_code) const {
66 std::map<std::string, const Rule*>::const_iterator it = 68 std::map<std::string, const Rule*>::const_iterator it =
67 language_codes_.find(language_code); 69 language_codes_.find(language_code);
68 return it == language_codes_.end() ? NULL : it->second; 70 return it == language_codes_.end() ? NULL : it->second;
69 } 71 }
70 72
73 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.
74 const AddressData& address) const {
75 std::map<AddressField, const Rule*> result;
76 if (address.country_code.empty()) {
77 result.insert(std::make_pair(COUNTRY, &Rule::GetDefault()));
78 return result;
79 }
80
81 AddressField field = COUNTRY;
82 for (const Ruleset* ruleset = this;
83 ruleset != NULL && field <= DEPENDENT_LOCALITY;
84 ruleset = ruleset->GetSubRegion(address.GetField(field))) {
85 const Rule* language_specific =
86 ruleset->GetLanguageCode(address.language_code);
87 result.insert(std::make_pair(
88 field,
89 language_specific != NULL ? language_specific : &ruleset->rule()));
90 field = static_cast<AddressField>(field + 1);
91 }
92
93 return result;
94 }
95
71 } // namespace addressinput 96 } // namespace addressinput
72 } // namespace i18n 97 } // namespace i18n
OLDNEW
« 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