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 27 matching lines...) Expand all Loading... | |
38 #include <libaddressinput/util/basictypes.h> | 38 #include <libaddressinput/util/basictypes.h> |
39 #include <libaddressinput/util/scoped_ptr.h> | 39 #include <libaddressinput/util/scoped_ptr.h> |
40 | 40 |
41 #include <map> | 41 #include <map> |
42 #include <string> | 42 #include <string> |
43 | 43 |
44 namespace i18n { | 44 namespace i18n { |
45 namespace addressinput { | 45 namespace addressinput { |
46 | 46 |
47 class Rule; | 47 class Rule; |
48 struct AddressData; | |
48 | 49 |
49 // Stores a parsed validation rule, its identifier, and its level. Sample usage: | 50 // Stores a parsed validation rule, its identifier, and its level. Sample usage: |
50 // LookupKey country_key("CA"); | 51 // LookupKey country_key("CA"); |
51 // Rule country_rule = RetrieveRule(country_key.GetKeyValue()); | 52 // Rule country_rule = RetrieveRule(country_key.GetKeyValue()); |
52 // country_key.SetRule(country_rule); | 53 // country_key.SetRule(country_rule); |
53 // | 54 // |
54 // LookupKey* administrative_area_key = country_key.AddSubKey("AB"); | 55 // LookupKey* administrative_area_key = country_key.AddSubKey("AB"); |
55 // administrative_area_key->SetRule( | 56 // administrative_area_key->SetRule( |
56 // RetrieveRule(administrative_area_key.GetKeyValue())); | 57 // RetrieveRule(administrative_area_key.GetKeyValue())); |
57 // | 58 // |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
89 const Rule* GetRule() const; | 90 const Rule* GetRule() const; |
90 | 91 |
91 // Adds a sub-LookupKey for |sub_region| and returns it. The caller does not | 92 // Adds a sub-LookupKey for |sub_region| and returns it. The caller does not |
92 // own the result. | 93 // own the result. |
93 LookupKey* AddSubKey(const std::string& sub_region); | 94 LookupKey* AddSubKey(const std::string& sub_region); |
94 | 95 |
95 // Adds a sub-LookupKey for |language_code| key and returns it. The caller | 96 // Adds a sub-LookupKey for |language_code| key and returns it. The caller |
96 // does not own the result. | 97 // does not own the result. |
97 LookupKey* AddLanguageCodeKey(const std::string& language_code); | 98 LookupKey* AddLanguageCodeKey(const std::string& language_code); |
98 | 99 |
99 // Returns the lookup key for |sub_region| or NULL. The caller does not own | 100 // Returns the lookup key for |sub_region| or NULL. The caller does not own |
Evan Stade
2013/12/19 02:12:38
explain when it may return NULL
please use gerrit instead
2014/01/08 00:55:52
Done.
| |
100 // the result. | 101 // the result. |
101 LookupKey* GetSubKey(const std::string& sub_key) const; | 102 const LookupKey* GetSubKey(const std::string& sub_region) const; |
102 | 103 |
103 // Returns the lookup key for |language_code| or NULL. The caller does not own | 104 // Returns the lookup key for |language_code| or NULL. The caller does not own |
Evan Stade
2013/12/19 02:12:38
explain when it may return NULL
please use gerrit instead
2014/01/08 00:55:52
Done.
| |
104 // the result. | 105 // the result. |
105 LookupKey* GetLanguageCodeKey(const std::string& language_code) const; | 106 const LookupKey* GetLanguageCodeKey(const std::string& language_code) const; |
107 | |
108 // Builds a mapping of address fields to corresponding parsed validation rules | |
109 // for |address|. The caller does not own the returned Rule objects. For | |
110 // example, if the address is "Calgary, Alberta, Canada" with "fr" language | |
111 // code, then returns the rules for "data/CA--fr" and "data/CA/AB--fr". | |
112 std::map<AddressField, const Rule*> BuildFieldRuleMap( | |
113 const AddressData& address) const; | |
106 | 114 |
107 private: | 115 private: |
108 // A mapping of string identifiers to LookupKey objects. A string identifier | 116 // A mapping of string identifiers to LookupKey objects. A string identifier |
109 // can be either a language code (e.g., "fr", "de", it") or a sub-region | 117 // can be either a language code (e.g., "fr", "de", it") or a sub-region |
110 // identifier (e.g., "NY", "TX", "CA"). | 118 // identifier (e.g., "NY", "TX", "CA"). |
111 typedef std::map<std::string, LookupKey*> LookupKeys; | 119 typedef std::map<std::string, LookupKey*> LookupKeys; |
112 | 120 |
113 // Builds a lookup key with identifier |key_value| at the given |level|. | 121 // Builds a lookup key with identifier |key_value| at the given |level|. |
114 LookupKey(const std::string& key_value, AddressField level); | 122 LookupKey(const std::string& key_value, AddressField level); |
115 | 123 |
(...skipping 13 matching lines...) Expand all Loading... | |
129 // language codes. | 137 // language codes. |
130 LookupKeys language_code_keys_; | 138 LookupKeys language_code_keys_; |
131 | 139 |
132 DISALLOW_COPY_AND_ASSIGN(LookupKey); | 140 DISALLOW_COPY_AND_ASSIGN(LookupKey); |
133 }; | 141 }; |
134 | 142 |
135 } // namespace addressinput | 143 } // namespace addressinput |
136 } // namespace i18n | 144 } // namespace i18n |
137 | 145 |
138 #endif // I18N_ADDRESSINPUT_LOOKUP_KEY_H_ | 146 #endif // I18N_ADDRESSINPUT_LOOKUP_KEY_H_ |
OLD | NEW |