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

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

Issue 211443003: Revert of Determine language code and type of format for address. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 8 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 "grit/libaddressinput_strings.h" 26 #include "grit/libaddressinput_strings.h"
27 #include "region_data_constants.h" 27 #include "region_data_constants.h"
28 #include "util/json.h" 28 #include "util/json.h"
29 #include "util/string_util.h" 29 #include "util/string_compare.h"
30 #include "util/string_split.h"
30 31
31 namespace i18n { 32 namespace i18n {
32 namespace addressinput { 33 namespace addressinput {
33 34
34 namespace { 35 namespace {
35 36
36 bool ParseToken(char c, AddressField* field) { 37 bool ParseToken(char c, AddressField* field) {
37 assert(field != NULL); 38 assert(field != NULL);
38 switch (c) { 39 switch (c) {
39 case 'R': 40 case 'R':
(...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after
211 212
212 bool FormatElement::operator==(const FormatElement& other) const { 213 bool FormatElement::operator==(const FormatElement& other) const {
213 return field == other.field && literal == other.literal; 214 return field == other.field && literal == other.literal;
214 } 215 }
215 216
216 Rule::Rule() 217 Rule::Rule()
217 : key_(), 218 : key_(),
218 name_(), 219 name_(),
219 latin_name_(), 220 latin_name_(),
220 format_(), 221 format_(),
221 latin_format_(),
222 required_(), 222 required_(),
223 sub_keys_(), 223 sub_keys_(),
224 sub_names_(), 224 sub_names_(),
225 sub_lnames_(), 225 sub_lnames_(),
226 languages_(), 226 languages_(),
227 input_languages_(),
228 language_(), 227 language_(),
229 postal_code_format_(), 228 postal_code_format_(),
230 admin_area_name_message_id_(INVALID_MESSAGE_ID), 229 admin_area_name_message_id_(INVALID_MESSAGE_ID),
231 invalid_admin_area_message_id_(INVALID_MESSAGE_ID), 230 invalid_admin_area_message_id_(INVALID_MESSAGE_ID),
232 postal_code_name_message_id_(INVALID_MESSAGE_ID), 231 postal_code_name_message_id_(INVALID_MESSAGE_ID),
233 invalid_postal_code_message_id_(INVALID_MESSAGE_ID) {} 232 invalid_postal_code_message_id_(INVALID_MESSAGE_ID) {}
234 233
235 Rule::~Rule() {} 234 Rule::~Rule() {}
236 235
237 // static 236 // static
238 const Rule& Rule::GetDefault() { 237 const Rule& Rule::GetDefault() {
239 // Allocated once and leaked on shutdown. 238 // Allocated once and leaked on shutdown.
240 static Rule* default_rule = NULL; 239 static Rule* default_rule = NULL;
241 if (default_rule == NULL) { 240 if (default_rule == NULL) {
242 default_rule = new Rule; 241 default_rule = new Rule;
243 default_rule->ParseSerializedRule( 242 default_rule->ParseSerializedRule(
244 RegionDataConstants::GetDefaultRegionData()); 243 RegionDataConstants::GetDefaultRegionData());
245 } 244 }
246 return *default_rule; 245 return *default_rule;
247 } 246 }
248 247
249 void Rule::CopyFrom(const Rule& rule) { 248 void Rule::CopyFrom(const Rule& rule) {
250 key_ = rule.key_; 249 key_ = rule.key_;
251 name_ = rule.name_; 250 name_ = rule.name_;
252 latin_name_ = rule.latin_name_; 251 latin_name_ = rule.latin_name_;
253 format_ = rule.format_; 252 format_ = rule.format_;
254 latin_format_ = rule.latin_format_;
255 required_ = rule.required_; 253 required_ = rule.required_;
256 sub_keys_ = rule.sub_keys_; 254 sub_keys_ = rule.sub_keys_;
257 languages_ = rule.languages_; 255 languages_ = rule.languages_;
258 input_languages_ = rule.input_languages_;
259 language_ = rule.language_; 256 language_ = rule.language_;
260 sub_keys_ = rule.sub_keys_; 257 sub_keys_ = rule.sub_keys_;
261 sub_names_ = rule.sub_names_; 258 sub_names_ = rule.sub_names_;
262 sub_lnames_ = rule.sub_lnames_; 259 sub_lnames_ = rule.sub_lnames_;
263 postal_code_format_ = rule.postal_code_format_; 260 postal_code_format_ = rule.postal_code_format_;
264 admin_area_name_message_id_ = rule.admin_area_name_message_id_; 261 admin_area_name_message_id_ = rule.admin_area_name_message_id_;
265 invalid_admin_area_message_id_ = rule.invalid_admin_area_message_id_; 262 invalid_admin_area_message_id_ = rule.invalid_admin_area_message_id_;
266 postal_code_name_message_id_ = rule.postal_code_name_message_id_; 263 postal_code_name_message_id_ = rule.postal_code_name_message_id_;
267 invalid_postal_code_message_id_ = rule.invalid_postal_code_message_id_; 264 invalid_postal_code_message_id_ = rule.invalid_postal_code_message_id_;
268 } 265 }
(...skipping 18 matching lines...) Expand all
287 } 284 }
288 285
289 if (json_rule.GetStringValueForKey("lname", &value)) { 286 if (json_rule.GetStringValueForKey("lname", &value)) {
290 latin_name_.swap(value); 287 latin_name_.swap(value);
291 } 288 }
292 289
293 if (json_rule.GetStringValueForKey("fmt", &value)) { 290 if (json_rule.GetStringValueForKey("fmt", &value)) {
294 ParseAddressFieldsFormat(value, &format_); 291 ParseAddressFieldsFormat(value, &format_);
295 } 292 }
296 293
297 if (json_rule.GetStringValueForKey("lfmt", &value)) {
298 ParseAddressFieldsFormat(value, &latin_format_);
299 }
300
301 if (json_rule.GetStringValueForKey("require", &value)) { 294 if (json_rule.GetStringValueForKey("require", &value)) {
302 ParseAddressFieldsRequired(value, &required_); 295 ParseAddressFieldsRequired(value, &required_);
303 } 296 }
304 297
305 // Used as a separator in a list of items. For example, the list of supported 298 // Used as a separator in a list of items. For example, the list of supported
306 // languages can be "de~fr~it". 299 // languages can be "de~fr~it".
307 static const char kSeparator = '~'; 300 static const char kSeparator = '~';
308 if (json_rule.GetStringValueForKey("sub_keys", &value)) { 301 if (json_rule.GetStringValueForKey("sub_keys", &value)) {
309 SplitString(value, kSeparator, &sub_keys_); 302 SplitString(value, kSeparator, &sub_keys_);
310 } 303 }
311 304
312 if (json_rule.GetStringValueForKey("sub_names", &value)) { 305 if (json_rule.GetStringValueForKey("sub_names", &value)) {
313 SplitString(value, kSeparator, &sub_names_); 306 SplitString(value, kSeparator, &sub_names_);
314 assert(sub_names_.size() == sub_keys_.size()); 307 assert(sub_names_.size() == sub_keys_.size());
315 } 308 }
316 309
317 if (json_rule.GetStringValueForKey("sub_lnames", &value)) { 310 if (json_rule.GetStringValueForKey("sub_lnames", &value)) {
318 SplitString(value, kSeparator, &sub_lnames_); 311 SplitString(value, kSeparator, &sub_lnames_);
319 assert(sub_lnames_.size() == sub_keys_.size()); 312 assert(sub_lnames_.size() == sub_keys_.size());
320 } 313 }
321 314
322 if (json_rule.GetStringValueForKey("languages", &value)) { 315 if (json_rule.GetStringValueForKey("languages", &value)) {
323 SplitString(value, kSeparator, &languages_); 316 SplitString(value, kSeparator, &languages_);
324 } 317 }
325 318
326 if (json_rule.GetStringValueForKey("input_languages", &value)) {
327 SplitString(value, kSeparator, &input_languages_);
328 }
329
330 if (json_rule.GetStringValueForKey("lang", &value)) { 319 if (json_rule.GetStringValueForKey("lang", &value)) {
331 language_.swap(value); 320 language_.swap(value);
332 } 321 }
333 322
334 if (json_rule.GetStringValueForKey("zip", &value)) { 323 if (json_rule.GetStringValueForKey("zip", &value)) {
335 postal_code_format_.swap(value); 324 postal_code_format_.swap(value);
336 } 325 }
337 326
338 if (json_rule.GetStringValueForKey("state_name_type", &value)) { 327 if (json_rule.GetStringValueForKey("state_name_type", &value)) {
339 admin_area_name_message_id_ = GetAdminAreaMessageId(value, false); 328 admin_area_name_message_id_ = GetAdminAreaMessageId(value, false);
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
394 if (LooseStringCompare(values[i], target)) { 383 if (LooseStringCompare(values[i], target)) {
395 *sub_key = sub_keys_[i]; 384 *sub_key = sub_keys_[i];
396 return true; 385 return true;
397 } 386 }
398 } 387 }
399 return false; 388 return false;
400 } 389 }
401 390
402 } // namespace addressinput 391 } // namespace addressinput
403 } // namespace i18n 392 } // namespace i18n
OLDNEW
« no previous file with comments | « third_party/libaddressinput/chromium/cpp/src/rule.h ('k') | third_party/libaddressinput/chromium/cpp/src/time_to_string.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698