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 a single address: country code, administrative area, 16 // locality, etc. The field names correspond to OASIS xAL standard: 17 // https://www.oasis-open.org/committees/ciq/Downloads/ciq_html_docs.zip 18 19 #ifndef I18N_ADDRESSINPUT_ADDRESS_DATA_H_ 20 #define I18N_ADDRESSINPUT_ADDRESS_DATA_H_ 21 22 #include <libaddressinput/address_field.h> 23 24 #include <string> 25 #include <vector> 26 27 namespace i18n { 28 namespace addressinput { 29 30 // Stores an address. Sample usage: 31 // AddressData address; 32 // address.recipient = "Chen-Kang Yang"; 33 // address.organization = "Google"; 34 // address.address_lines.push_back("1098 Alta Ave"); 35 // address.administrative_area = "CA"; 36 // address.locality = "Mountain View"; 37 // address.postal_code = "94043"; 38 // address.country_code = "US"; 39 // address.language_code = "en"; 40 // Process(address); 41 struct AddressData { 42 // Clears |lines| and populates it with the lines of the address as they 43 // should appear on an envelope for |country_code|. The |lines| parameter 44 // should not be NULL. 45 // 46 // If there're no address formatting rules for |country_code|, then the 47 // default rules are used: 48 // https://i18napis.appspot.com/ssl-address/data/ZZ 49 void FormatForDisplay(std::vector<std::string>* lines) const; 50 51 // Returns the value of the |field|. The parameter should not be 52 // STREET_ADDRESS, which comprises multiple fields. 53 const std::string& GetFieldValue(AddressField field) const; 54 55 // Sets the |field| to |value|. The parameter should not be STREET_ADDRESS, 56 // which comprises multiple fields. 57 void SetFieldValue(AddressField field, const std::string& value); 58 59 // Returns true if all required fields are present (non-empty). 60 bool HasAllRequiredFields() const; 61 62 // The BCP 47 language code used to guide how the address is formatted for 63 // display. The same address may have different representations in different 64 // languages. 65 // For example, the French name of "New Mexico" is "Nouveau-Mexique". 66 std::string language_code; 67 68 // The uppercase CLDR country/region code. 69 // For example, "US" for United States. 70 // (Note: Use "GB", not "UK", for Great Britain.) 71 std::string country_code; 72 73 // Top-level administrative subdivision of this country. 74 // Examples: US state, IT region, UK constituent nation, JP prefecture. 75 std::string administrative_area; 76 77 // Generally refers to the city/town portion of an address. 78 // Examples: US city, IT comune, UK post town. 79 std::string locality; 80 81 // Dependent locality or sublocality. Used for UK dependent localities, or 82 // neighborhoods or boroughs in other locations. 83 std::string dependent_locality; 84 85 // Identifies recipients of large volumes of mail. Used in only a few 86 // countries. 87 // Examples: FR CEDEX. 88 std::string sorting_code; 89 90 // The alphanumeric value generally assigned to geographical areas, but 91 // sometimes also assigned to individual addresses. 92 // Examples: "94043", "94043-1351", "SW1W", "SW1W 9TQ". 93 std::string postal_code; 94 95 // The free format street address lines. 96 std::vector<std::string> address_lines; 97 98 // The firm, company, or organization. 99 std::string organization; 100 101 // The name of the recipient or contact person. Not present in xAL. 102 std::string recipient; 103 }; 104 105 } // namespace addressinput 106 } // namespace i18n 107 108 #endif // I18N_ADDRESSINPUT_ADDRESS_DATA_H_ 109