| 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 if (address_lines.empty() || address_lines[0].empty()) { |
| 138 return false; |
| 139 } |
| 140 } else if (GetFieldValue(required_fields[i]).empty()) { |
| 141 return false; |
| 142 } |
| 143 } |
| 144 |
| 145 return true; |
| 146 } |
| 147 |
| 120 } // namespace addressinput | 148 } // namespace addressinput |
| 121 } // namespace i18n | 149 } // namespace i18n |
| OLD | NEW |