| 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 237 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|  248   invalid_admin_area_message_id_ = rule.invalid_admin_area_message_id_; |  248   invalid_admin_area_message_id_ = rule.invalid_admin_area_message_id_; | 
|  249   postal_code_name_message_id_ = rule.postal_code_name_message_id_; |  249   postal_code_name_message_id_ = rule.postal_code_name_message_id_; | 
|  250   invalid_postal_code_message_id_ = rule.invalid_postal_code_message_id_; |  250   invalid_postal_code_message_id_ = rule.invalid_postal_code_message_id_; | 
|  251 } |  251 } | 
|  252  |  252  | 
|  253 bool Rule::ParseSerializedRule(const std::string& serialized_rule) { |  253 bool Rule::ParseSerializedRule(const std::string& serialized_rule) { | 
|  254   scoped_ptr<Json> json(Json::Build()); |  254   scoped_ptr<Json> json(Json::Build()); | 
|  255   if (!json->ParseObject(serialized_rule)) { |  255   if (!json->ParseObject(serialized_rule)) { | 
|  256     return false; |  256     return false; | 
|  257   } |  257   } | 
 |  258   ParseJsonRule(*json); | 
 |  259   return true; | 
 |  260 } | 
|  258  |  261  | 
 |  262 void Rule::ParseJsonRule(const Json& json_rule) { | 
|  259   std::string value; |  263   std::string value; | 
|  260   if (json->GetStringValueForKey("fmt", &value)) { |  264   if (json_rule.GetStringValueForKey("fmt", &value)) { | 
|  261     ParseAddressFieldsFormat(value, &format_); |  265     ParseAddressFieldsFormat(value, &format_); | 
|  262   } |  266   } | 
|  263  |  267  | 
|  264   if (json->GetStringValueForKey("require", &value)) { |  268   if (json_rule.GetStringValueForKey("require", &value)) { | 
|  265     ParseAddressFieldsRequired(value, &required_); |  269     ParseAddressFieldsRequired(value, &required_); | 
|  266   } |  270   } | 
|  267  |  271  | 
|  268   // Used as a separator in a list of items. For example, the list of supported |  272   // Used as a separator in a list of items. For example, the list of supported | 
|  269   // languages can be "de~fr~it". |  273   // languages can be "de~fr~it". | 
|  270   static const char kSeparator = '~'; |  274   static const char kSeparator = '~'; | 
|  271   if (json->GetStringValueForKey("sub_keys", &value)) { |  275   if (json_rule.GetStringValueForKey("sub_keys", &value)) { | 
|  272     SplitString(value, kSeparator, &sub_keys_); |  276     SplitString(value, kSeparator, &sub_keys_); | 
|  273   } |  277   } | 
|  274  |  278  | 
|  275   if (json->GetStringValueForKey("languages", &value)) { |  279   if (json_rule.GetStringValueForKey("languages", &value)) { | 
|  276     SplitString(value, kSeparator, &languages_); |  280     SplitString(value, kSeparator, &languages_); | 
|  277   } |  281   } | 
|  278  |  282  | 
|  279   if (json->GetStringValueForKey("lang", &value)) { |  283   if (json_rule.GetStringValueForKey("lang", &value)) { | 
|  280     language_ = value; |  284     language_ = value; | 
|  281   } |  285   } | 
|  282  |  286  | 
|  283   if (json->GetStringValueForKey("zip", &value)) { |  287   if (json_rule.GetStringValueForKey("zip", &value)) { | 
|  284     postal_code_format_ = value; |  288     postal_code_format_ = value; | 
|  285   } |  289   } | 
|  286  |  290  | 
|  287   if (json->GetStringValueForKey("state_name_type", &value)) { |  291   if (json_rule.GetStringValueForKey("state_name_type", &value)) { | 
|  288     admin_area_name_message_id_ = GetAdminAreaMessageId(value, false); |  292     admin_area_name_message_id_ = GetAdminAreaMessageId(value, false); | 
|  289     invalid_admin_area_message_id_ = GetAdminAreaMessageId(value, true); |  293     invalid_admin_area_message_id_ = GetAdminAreaMessageId(value, true); | 
|  290   } |  294   } | 
|  291  |  295  | 
|  292   if (json->GetStringValueForKey("zip_name_type", &value)) { |  296   if (json_rule.GetStringValueForKey("zip_name_type", &value)) { | 
|  293     postal_code_name_message_id_ = GetPostalCodeMessageId(value, false); |  297     postal_code_name_message_id_ = GetPostalCodeMessageId(value, false); | 
|  294     invalid_postal_code_message_id_ = GetPostalCodeMessageId(value, true); |  298     invalid_postal_code_message_id_ = GetPostalCodeMessageId(value, true); | 
|  295   } |  299   } | 
|  296  |  | 
|  297   return true; |  | 
|  298 } |  300 } | 
|  299  |  301  | 
|  300 int Rule::GetInvalidFieldMessageId(AddressField field) const { |  302 int Rule::GetInvalidFieldMessageId(AddressField field) const { | 
|  301   switch (field) { |  303   switch (field) { | 
|  302     case ADMIN_AREA: |  304     case ADMIN_AREA: | 
|  303       return invalid_admin_area_message_id_; |  305       return invalid_admin_area_message_id_; | 
|  304     case LOCALITY: |  306     case LOCALITY: | 
|  305       return IDS_LIBADDRESSINPUT_I18N_INVALID_LOCALITY_LABEL; |  307       return IDS_LIBADDRESSINPUT_I18N_INVALID_LOCALITY_LABEL; | 
|  306     case DEPENDENT_LOCALITY: |  308     case DEPENDENT_LOCALITY: | 
|  307       return IDS_LIBADDRESSINPUT_I18N_INVALID_DEPENDENT_LOCALITY_LABEL; |  309       return IDS_LIBADDRESSINPUT_I18N_INVALID_DEPENDENT_LOCALITY_LABEL; | 
|  308     case POSTAL_CODE: |  310     case POSTAL_CODE: | 
|  309       return invalid_postal_code_message_id_; |  311       return invalid_postal_code_message_id_; | 
|  310     default: |  312     default: | 
|  311       return IDS_LIBADDRESSINPUT_I18N_INVALID_ENTRY; |  313       return IDS_LIBADDRESSINPUT_I18N_INVALID_ENTRY; | 
|  312   } |  314   } | 
|  313 } |  315 } | 
|  314  |  316  | 
|  315 }  // namespace addressinput |  317 }  // namespace addressinput | 
|  316 }  // namespace i18n |  318 }  // namespace i18n | 
| OLD | NEW |