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

Side by Side Diff: third_party/libaddressinput/chromium/cpp/src/rule.cc

Issue 109323011: [rac] Download all rules for a country code in libaddressinput. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix windows build. 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) 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
36 // Allocated once and leaked on shutdown.
37 static Rule* default_rule = NULL;
38
35 bool ParseToken(char c, AddressField* field) { 39 bool ParseToken(char c, AddressField* field) {
36 assert(field != NULL); 40 assert(field != NULL);
37 switch (c) { 41 switch (c) {
38 case 'R': 42 case 'R':
39 *field = COUNTRY; 43 *field = COUNTRY;
40 return true; 44 return true;
41 case 'S': 45 case 'S':
42 *field = ADMIN_AREA; 46 *field = ADMIN_AREA;
43 return true; 47 return true;
44 case 'C': 48 case 'C':
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after
164 required_(), 168 required_(),
165 sub_keys_(), 169 sub_keys_(),
166 languages_(), 170 languages_(),
167 language_(), 171 language_(),
168 postal_code_format_(), 172 postal_code_format_(),
169 admin_area_name_message_id_(INVALID_MESSAGE_ID), 173 admin_area_name_message_id_(INVALID_MESSAGE_ID),
170 postal_code_name_message_id_(INVALID_MESSAGE_ID) {} 174 postal_code_name_message_id_(INVALID_MESSAGE_ID) {}
171 175
172 Rule::~Rule() {} 176 Rule::~Rule() {}
173 177
178 // static
179 const Rule& Rule::GetDefault() {
180 if (default_rule == NULL) {
181 default_rule = new Rule;
182 default_rule->ParseSerializedRule(
183 RegionDataConstants::GetDefaultRegionData());
184 }
185 return *default_rule;
186 }
187
174 void Rule::CopyFrom(const Rule& rule) { 188 void Rule::CopyFrom(const Rule& rule) {
175 format_ = rule.format_; 189 format_ = rule.format_;
176 required_ = rule.required_; 190 required_ = rule.required_;
177 sub_keys_ = rule.sub_keys_; 191 sub_keys_ = rule.sub_keys_;
178 languages_ = rule.languages_; 192 languages_ = rule.languages_;
179 language_ = rule.language_; 193 language_ = rule.language_;
180 postal_code_format_ = rule.postal_code_format_; 194 postal_code_format_ = rule.postal_code_format_;
181 admin_area_name_message_id_ = rule.admin_area_name_message_id_; 195 admin_area_name_message_id_ = rule.admin_area_name_message_id_;
182 postal_code_name_message_id_ = rule.postal_code_name_message_id_; 196 postal_code_name_message_id_ = rule.postal_code_name_message_id_;
183 } 197 }
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
222 236
223 if (json->GetStringValueForKey("zip_name_type", &value)) { 237 if (json->GetStringValueForKey("zip_name_type", &value)) {
224 postal_code_name_message_id_ = GetPostalCodeMessageId(value); 238 postal_code_name_message_id_ = GetPostalCodeMessageId(value);
225 } 239 }
226 240
227 return true; 241 return true;
228 } 242 }
229 243
230 } // namespace addressinput 244 } // namespace addressinput
231 } // namespace i18n 245 } // namespace i18n
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698