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

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

Issue 106763007: [rac] Parse postal code formats and required fields in libaddressinput. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Move AddressField parsing into Rule. Add more tests for parsing AddressFields. Created 7 years 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 // An object to store validation rules. 15 // An object to store validation rules.
16 16
17 #ifndef I18N_ADDRESSINPUT_RULE_H_ 17 #ifndef I18N_ADDRESSINPUT_RULE_H_
18 #define I18N_ADDRESSINPUT_RULE_H_ 18 #define I18N_ADDRESSINPUT_RULE_H_
19 19
20 #include <libaddressinput/address_field.h> 20 #include <libaddressinput/address_field.h>
21 #include <libaddressinput/util/basictypes.h> 21 #include <libaddressinput/util/basictypes.h>
22 22
23 #include <string> 23 #include <string>
24 #include <vector> 24 #include <vector>
25 25
26 namespace i18n { 26 namespace i18n {
27 namespace addressinput { 27 namespace addressinput {
28 28
29 // An extension of AddressField enum used only internally. The values are
Evan Stade 2013/12/18 23:18:17 "internally" sounds like "internal to Rule", but I
30 // negative to avoid clashing with the values in AddressField.
31 enum {
32 NEWLINE = -1
Evan Stade 2013/12/18 23:18:17 comment should explain what this actually means...
33 };
34
29 // Stores the validation rules. Sample usage: 35 // Stores the validation rules. Sample usage:
30 // Rule rule; 36 // Rule rule;
31 // if (rule.ParseSerializedRule("{\"fmt\": \"%A%n%C%S %Z\"}")) { 37 // if (rule.ParseSerializedRule("{\"fmt\": \"%A%n%C%S %Z\"}")) {
32 // Process(rule.GetFormat()); 38 // Process(rule.GetFormat());
33 // } 39 // }
34 class Rule { 40 class Rule {
35 public: 41 public:
36 Rule(); 42 Rule();
37 ~Rule(); 43 ~Rule();
38 44
39 // Copies all data from |rule|. 45 // Copies all data from |rule|.
40 void CopyFrom(const Rule& rule); 46 void CopyFrom(const Rule& rule);
41 47
42 // Parses |serialized_rule|. Returns |true| if the |serialized_rule| has valid 48 // Parses |serialized_rule|. Returns |true| if the |serialized_rule| has valid
43 // format (JSON dictionary). 49 // format (JSON dictionary).
44 bool ParseSerializedRule(const std::string& serialized_rule); 50 bool ParseSerializedRule(const std::string& serialized_rule);
45 51
46 // Returns the address format for this rule. The format can include the 52 // Returns the address format for this rule. The format can include the
47 // NEWLINE extension for AddressField enum. 53 // NEWLINE extension for AddressField enum.
48 const std::vector<AddressField>& GetFormat() const { return format_; } 54 const std::vector<AddressField>& GetFormat() const { return format_; }
49 55
56 // Returns the required fields for this rule.
57 const std::vector<AddressField>& GetRequired() const { return required_; }
58
50 // Returns the sub-keys for this rule, which are the administrative areas of a 59 // Returns the sub-keys for this rule, which are the administrative areas of a
51 // country, the localities of an administrative area, or the dependent 60 // country, the localities of an administrative area, or the dependent
52 // localities of a locality. For example, the rules for "US" have sub-keys of 61 // localities of a locality. For example, the rules for "US" have sub-keys of
53 // "CA", "NY", "TX", etc. 62 // "CA", "NY", "TX", etc.
54 const std::vector<std::string>& GetSubKeys() const { return sub_keys_; } 63 const std::vector<std::string>& GetSubKeys() const { return sub_keys_; }
55 64
56 // Returns all of the language codes for which this rule has custom rules, for 65 // Returns all of the language codes for which this rule has custom rules, for
57 // example ["de", "fr", "it"]. 66 // example ["de", "fr", "it"].
58 const std::vector<std::string>& GetLanguages() const { return languages_; } 67 const std::vector<std::string>& GetLanguages() const { return languages_; }
59 68
60 // Returns the language code of this rule, for example "de". 69 // Returns the language code of this rule, for example "de".
61 const std::string& GetLanguage() const { return language_; } 70 const std::string& GetLanguage() const { return language_; }
62 71
72 // Returns the postal code format, for example "\\d{5}([ \\-]\\d{4})?".
73 const std::string& GetPostalCodeFormat() const { return postal_code_format_; }
74
63 // The message string identifier for admin area name. If not set, then 75 // The message string identifier for admin area name. If not set, then
64 // INVALID_MESSAGE_ID. 76 // INVALID_MESSAGE_ID.
65 int GetAdminAreaNameMessageId() const { return admin_area_name_message_id_; } 77 int GetAdminAreaNameMessageId() const { return admin_area_name_message_id_; }
66 78
67 // The message string identifier for postal code name. If not set, then 79 // The message string identifier for postal code name. If not set, then
68 // INVALID_MESSAGE_ID. 80 // INVALID_MESSAGE_ID.
69 int GetPostalCodeNameMessageId() const { 81 int GetPostalCodeNameMessageId() const {
70 return postal_code_name_message_id_; 82 return postal_code_name_message_id_;
71 } 83 }
72 84
73 private: 85 private:
74 std::vector<AddressField> format_; 86 std::vector<AddressField> format_;
87 std::vector<AddressField> required_;
75 std::vector<std::string> sub_keys_; 88 std::vector<std::string> sub_keys_;
76 std::vector<std::string> languages_; 89 std::vector<std::string> languages_;
77 std::string language_; 90 std::string language_;
91 std::string postal_code_format_;
78 int admin_area_name_message_id_; 92 int admin_area_name_message_id_;
79 int postal_code_name_message_id_; 93 int postal_code_name_message_id_;
80 94
81 DISALLOW_COPY_AND_ASSIGN(Rule); 95 DISALLOW_COPY_AND_ASSIGN(Rule);
82 }; 96 };
83 97
84 } // namespace addressinput 98 } // namespace addressinput
85 } // namespace i18n 99 } // namespace i18n
86 100
87 #endif // I18N_ADDRESSINPUT_RULE_H_ 101 #endif // I18N_ADDRESSINPUT_RULE_H_
OLDNEW
« no previous file with comments | « third_party/libaddressinput/chromium/cpp/src/address_ui.cc ('k') | third_party/libaddressinput/chromium/cpp/src/rule.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698