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

Side by Side Diff: third_party/libaddressinput/chromium/cpp/src/ruleset.h

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 #ifndef I18N_ADDRESSINPUT_RULESET_H_ 15 #ifndef I18N_ADDRESSINPUT_RULESET_H_
16 #define I18N_ADDRESSINPUT_RULESET_H_ 16 #define I18N_ADDRESSINPUT_RULESET_H_
17 17
18 #include <libaddressinput/address_field.h>
18 #include <libaddressinput/util/basictypes.h> 19 #include <libaddressinput/util/basictypes.h>
19 #include <libaddressinput/util/scoped_ptr.h> 20 #include <libaddressinput/util/scoped_ptr.h>
20 21
21 #include <map> 22 #include <map>
22 #include <string> 23 #include <string>
23 24
24 namespace i18n { 25 namespace i18n {
25 namespace addressinput { 26 namespace addressinput {
26 27
28 class AddressData;
27 class Rule; 29 class Rule;
28 30
29 // A recursive data structure that stores a set of rules for a region. Can store 31 // A recursive data structure that stores a set of rules for a region. Can store
30 // the rules for a country, its administrative areas, localities, and dependent 32 // the rules for a country, its administrative areas, localities, and dependent
31 // localities, in addition to the language-specific rules. 33 // localities, in addition to the language-specific rules.
32 // 34 //
33 // Example for Canada and some of its provinces: 35 // Example for Canada and some of its provinces:
34 // CA-->fr 36 // CA-->fr
35 // | 37 // |
36 // ------------------------------------- 38 // -------------------------------------
(...skipping 14 matching lines...) Expand all
51 // Returns the region-wide rule in the default language of the country. 53 // Returns the region-wide rule in the default language of the country.
52 const Rule& rule() const { return *rule_.get(); } 54 const Rule& rule() const { return *rule_.get(); }
53 55
54 // Adds and returns a ruleset for |sub_region| with the subregion-wide |rule| 56 // Adds and returns a ruleset for |sub_region| with the subregion-wide |rule|
55 // in the default language of the country. The caller does not own the result. 57 // in the default language of the country. The caller does not own the result.
56 Ruleset* AddSubRegion(const std::string& sub_region, scoped_ptr<Rule> rule); 58 Ruleset* AddSubRegion(const std::string& sub_region, scoped_ptr<Rule> rule);
57 59
58 // Adds a language-specific |rule| for |language_code| for this region. 60 // Adds a language-specific |rule| for |language_code| for this region.
59 void AddLanguageCode(const std::string& language_code, scoped_ptr<Rule> rule); 61 void AddLanguageCode(const std::string& language_code, scoped_ptr<Rule> rule);
60 62
61 // Returns the set of rules for |sub_region|. The result can be NULL. The 63 // Returns the set of rules for |sub_region|. The result is NULL if there's no
62 // caller does not own the result. 64 // such |sub_region|. The caller does not own the result.
63 Ruleset* GetSubRegion(const std::string& sub_region) const; 65 Ruleset* GetSubRegion(const std::string& sub_region) const;
64 66
65 // Returns the language-specific rule for |language_code|. The result can be 67 // Returns the language-specific rule for |language_code|. The result is NULL
66 // NULL. The caller does not own the result. 68 // if there's no such |language_code|. The caller does not own the result.
67 const Rule* GetLanguageCode(const std::string& language_code) const; 69 const Rule* GetLanguageCode(const std::string& language_code) const;
68 70
71 // Returns a mapping of field types to validation rules based on the field
72 // values in |address|. Should be invoked only on a root ruleset (at country
73 // level).
74 std::map<AddressField, const Rule*> BuildRulesForAddress(
75 const AddressData& address) const;
76
69 private: 77 private:
70 // The region-wide rule in the default language of the country. 78 // The region-wide rule in the default language of the country.
71 scoped_ptr<const Rule> rule_; 79 scoped_ptr<const Rule> rule_;
72 80
73 // Owned rulesets for sub-regions. 81 // Owned rulesets for sub-regions.
74 std::map<std::string, Ruleset*> sub_regions_; 82 std::map<std::string, Ruleset*> sub_regions_;
75 83
76 // Owned language-specific rules for the region. 84 // Owned language-specific rules for the region.
77 std::map<std::string, const Rule*> language_codes_; 85 std::map<std::string, const Rule*> language_codes_;
78 86
79 DISALLOW_COPY_AND_ASSIGN(Ruleset); 87 DISALLOW_COPY_AND_ASSIGN(Ruleset);
80 }; 88 };
81 89
82 } // namespace addressinput 90 } // namespace addressinput
83 } // namespace i18n 91 } // namespace i18n
84 92
85 #endif // I18N_ADDRESSINPUT_RULESET_H_ 93 #endif // I18N_ADDRESSINPUT_RULESET_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698