OLD | NEW |
(Empty) | |
| 1 // Copyright (C) 2013 Google Inc. |
| 2 // |
| 3 // Licensed under the Apache License, Version 2.0 (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 |
| 6 // |
| 7 // http://www.apache.org/licenses/LICENSE-2.0 |
| 8 // |
| 9 // Unless required by applicable law or agreed to in writing, software |
| 10 // distributed under the License is distributed on an "AS IS" BASIS, |
| 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 // See the License for the specific language governing permissions and |
| 13 // limitations under the License. |
| 14 // |
| 15 // An object to store validation rules. |
| 16 |
| 17 #ifndef I18N_ADDRESSINPUT_RULE_H_ |
| 18 #define I18N_ADDRESSINPUT_RULE_H_ |
| 19 |
| 20 #include <libaddressinput/address_field.h> |
| 21 #include <libaddressinput/util/basictypes.h> |
| 22 |
| 23 #include <string> |
| 24 #include <vector> |
| 25 |
| 26 namespace i18n { |
| 27 namespace addressinput { |
| 28 |
| 29 // Stores the validation rules. Sample usage: |
| 30 // Rule rule; |
| 31 // if (rule.ParseSerializedRule("{\"fmt\": \"%A%n%C%S %Z\"}")) { |
| 32 // Process(rule.GetFormat()); |
| 33 // } |
| 34 class Rule { |
| 35 public: |
| 36 Rule(); |
| 37 ~Rule(); |
| 38 |
| 39 // Copies all data from |rule|. |
| 40 void CopyFrom(const Rule& rule); |
| 41 |
| 42 // Parses |serialized_rule|. Returns |true| if the |serialized_rule| has valid |
| 43 // format (JSON dictionary). |
| 44 bool ParseSerializedRule(const std::string& serialized_rule); |
| 45 |
| 46 // Returns the address format for this rule. The format can include the |
| 47 // NEWLINE extension for AddressField enum. |
| 48 const std::vector<AddressField>& GetFormat() const { return format_; } |
| 49 |
| 50 // The message string identifier for admin area name. If not set, then |
| 51 // INVALID_MESSAGE_ID. |
| 52 int GetAdminAreaNameMessageId() const { return admin_area_name_message_id_; } |
| 53 |
| 54 // The message string identifier for postal code name. If not set, then |
| 55 // INVALID_MESSAGE_ID. |
| 56 int GetPostalCodeNameMessageId() const { |
| 57 return postal_code_name_message_id_; |
| 58 } |
| 59 |
| 60 private: |
| 61 std::vector<AddressField> format_; |
| 62 int admin_area_name_message_id_; |
| 63 int postal_code_name_message_id_; |
| 64 |
| 65 DISALLOW_COPY_AND_ASSIGN(Rule); |
| 66 }; |
| 67 |
| 68 } // namespace addressinput |
| 69 } // namespace i18n |
| 70 |
| 71 #endif // I18N_ADDRESSINPUT_RULE_H_ |
OLD | NEW |