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 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
43 case DEPENDENT_LOCALITY: | 43 case DEPENDENT_LOCALITY: |
44 return &address.dependent_locality; | 44 return &address.dependent_locality; |
45 case SORTING_CODE: | 45 case SORTING_CODE: |
46 return &address.sorting_code; | 46 return &address.sorting_code; |
47 case POSTAL_CODE: | 47 case POSTAL_CODE: |
48 return &address.postal_code; | 48 return &address.postal_code; |
49 case ORGANIZATION: | 49 case ORGANIZATION: |
50 return &address.organization; | 50 return &address.organization; |
51 case RECIPIENT: | 51 case RECIPIENT: |
52 return &address.recipient; | 52 return &address.recipient; |
53 default: | 53 case STREET_ADDRESS: |
54 assert(false); | 54 break; |
55 return NULL; | |
56 } | 55 } |
56 | |
57 assert(false); | |
58 return NULL; | |
57 } | 59 } |
58 | 60 |
59 } // namespace | 61 } // namespace |
60 | 62 |
61 void AddressData::FormatForDisplay(std::vector<std::string>* lines) const { | 63 void AddressData::FormatForDisplay(std::vector<std::string>* lines) const { |
62 assert(lines != NULL); | 64 assert(lines != NULL); |
63 lines->clear(); | 65 lines->clear(); |
64 | 66 |
65 Rule rule; | 67 Rule rule; |
66 rule.CopyFrom(Rule::GetDefault()); | 68 rule.CopyFrom(Rule::GetDefault()); |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
110 } | 112 } |
111 | 113 |
112 void AddressData::SetFieldValue(AddressField field, const std::string& value) { | 114 void AddressData::SetFieldValue(AddressField field, const std::string& value) { |
113 std::string* field_value = | 115 std::string* field_value = |
114 const_cast<std::string*>(GetMemberForField(*this, field)); | 116 const_cast<std::string*>(GetMemberForField(*this, field)); |
115 if (field_value != NULL) { | 117 if (field_value != NULL) { |
116 *field_value = value; | 118 *field_value = value; |
117 } | 119 } |
118 } | 120 } |
119 | 121 |
122 bool AddressData::HasAllRequiredFields() const { | |
123 if (country_code.empty()) | |
124 return false; | |
125 | |
126 Rule rule; | |
127 rule.CopyFrom(Rule::GetDefault()); | |
128 if (!rule.ParseSerializedRule( | |
129 RegionDataConstants::GetRegionData(country_code))) { | |
130 return false; | |
131 } | |
132 | |
133 std::vector< ::i18n::addressinput::AddressField> required_fields = | |
134 rule.GetRequired(); | |
135 for (size_t i = 0; i < required_fields.size(); ++i) { | |
136 if (required_fields[i] == STREET_ADDRESS && | |
137 (address_lines.empty() || address_lines[0].empty())) { | |
please use gerrit instead
2014/05/09 23:38:55
Please avoid hitting GetFieldValue(STREET_ADDRESS)
| |
138 return false; | |
139 } | |
140 | |
141 if (GetFieldValue(required_fields[i]).empty()) { | |
142 return false; | |
143 } | |
144 } | |
145 | |
146 return true; | |
147 } | |
148 | |
120 } // namespace addressinput | 149 } // namespace addressinput |
121 } // namespace i18n | 150 } // namespace i18n |
OLD | NEW |