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, |
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 "rule.h" | 15 #include "rule.h" |
16 | 16 |
17 #include <libaddressinput/address_field.h> | 17 #include <libaddressinput/address_field.h> |
18 #include <libaddressinput/util/scoped_ptr.h> | 18 #include <libaddressinput/util/scoped_ptr.h> |
19 | 19 |
20 #include <cassert> | 20 #include <cassert> |
21 #include <cstddef> | 21 #include <cstddef> |
22 #include <string> | 22 #include <string> |
23 #include <vector> | 23 #include <vector> |
24 | 24 |
25 #include "grit.h" | 25 #include "grit.h" |
26 #include "messages.h" | 26 #include "messages.h" |
| 27 #include "region_data_constants.h" |
27 #include "util/json.h" | 28 #include "util/json.h" |
28 #include "util/string_split.h" | 29 #include "util/string_split.h" |
29 | 30 |
30 namespace i18n { | 31 namespace i18n { |
31 namespace addressinput { | 32 namespace addressinput { |
32 | 33 |
33 namespace { | 34 namespace { |
34 | 35 |
35 bool ParseToken(char c, AddressField* field) { | 36 bool ParseToken(char c, AddressField* field) { |
36 assert(field != NULL); | 37 assert(field != NULL); |
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
164 required_(), | 165 required_(), |
165 sub_keys_(), | 166 sub_keys_(), |
166 languages_(), | 167 languages_(), |
167 language_(), | 168 language_(), |
168 postal_code_format_(), | 169 postal_code_format_(), |
169 admin_area_name_message_id_(INVALID_MESSAGE_ID), | 170 admin_area_name_message_id_(INVALID_MESSAGE_ID), |
170 postal_code_name_message_id_(INVALID_MESSAGE_ID) {} | 171 postal_code_name_message_id_(INVALID_MESSAGE_ID) {} |
171 | 172 |
172 Rule::~Rule() {} | 173 Rule::~Rule() {} |
173 | 174 |
| 175 // static |
| 176 const Rule& Rule::GetDefault() { |
| 177 // Allocated once and leaked on shutdown. |
| 178 static Rule* default_rule = NULL; |
| 179 if (default_rule == NULL) { |
| 180 default_rule = new Rule; |
| 181 default_rule->ParseSerializedRule( |
| 182 RegionDataConstants::GetDefaultRegionData()); |
| 183 } |
| 184 return *default_rule; |
| 185 } |
| 186 |
174 void Rule::CopyFrom(const Rule& rule) { | 187 void Rule::CopyFrom(const Rule& rule) { |
175 format_ = rule.format_; | 188 format_ = rule.format_; |
176 required_ = rule.required_; | 189 required_ = rule.required_; |
177 sub_keys_ = rule.sub_keys_; | 190 sub_keys_ = rule.sub_keys_; |
178 languages_ = rule.languages_; | 191 languages_ = rule.languages_; |
179 language_ = rule.language_; | 192 language_ = rule.language_; |
180 postal_code_format_ = rule.postal_code_format_; | 193 postal_code_format_ = rule.postal_code_format_; |
181 admin_area_name_message_id_ = rule.admin_area_name_message_id_; | 194 admin_area_name_message_id_ = rule.admin_area_name_message_id_; |
182 postal_code_name_message_id_ = rule.postal_code_name_message_id_; | 195 postal_code_name_message_id_ = rule.postal_code_name_message_id_; |
183 } | 196 } |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
222 | 235 |
223 if (json->GetStringValueForKey("zip_name_type", &value)) { | 236 if (json->GetStringValueForKey("zip_name_type", &value)) { |
224 postal_code_name_message_id_ = GetPostalCodeMessageId(value); | 237 postal_code_name_message_id_ = GetPostalCodeMessageId(value); |
225 } | 238 } |
226 | 239 |
227 return true; | 240 return true; |
228 } | 241 } |
229 | 242 |
230 } // namespace addressinput | 243 } // namespace addressinput |
231 } // namespace i18n | 244 } // namespace i18n |
OLD | NEW |