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

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

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

Powered by Google App Engine
This is Rietveld 408576698