diff options
author | rouslan@chromium.org <rouslan@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-12-11 02:16:26 +0000 |
---|---|---|
committer | rouslan@chromium.org <rouslan@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-12-11 02:16:26 +0000 |
commit | f77553e9aae2c1c57ebcf92bbbd606ef5f1c441e (patch) | |
tree | aad123eda32025ee78f4eeb5f51562bcd2c33be3 /third_party | |
parent | 08b6be83631442f356e64b465d864d3ea9a9b0e3 (diff) | |
download | chromium_src-f77553e9aae2c1c57ebcf92bbbd606ef5f1c441e.zip chromium_src-f77553e9aae2c1c57ebcf92bbbd606ef5f1c441e.tar.gz chromium_src-f77553e9aae2c1c57ebcf92bbbd606ef5f1c441e.tar.bz2 |
[rac] Add AddressProblem enum.
This patch adds the AddressProblem enum to libaddressinput. Chrome will
use this enum to filter address problems and process validation results.
BUG=327046
Review URL: https://codereview.chromium.org/108083006
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@239962 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'third_party')
3 files changed, 138 insertions, 0 deletions
diff --git a/third_party/libaddressinput/chromium/cpp/include/libaddressinput/address_problem.h b/third_party/libaddressinput/chromium/cpp/include/libaddressinput/address_problem.h new file mode 100644 index 0000000..559fcfd --- /dev/null +++ b/third_party/libaddressinput/chromium/cpp/include/libaddressinput/address_problem.h @@ -0,0 +1,85 @@ +// Copyright (C) 2013 Google Inc. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +#ifndef I18N_ADDRESSINPUT_ADDRESS_PROBLEM_H_ +#define I18N_ADDRESSINPUT_ADDRESS_PROBLEM_H_ + +#include <libaddressinput/address_field.h> + +#include <iosfwd> +#include <string> + +namespace i18n { +namespace addressinput { + +// A problem for address validation. +struct AddressProblem { + // Types of problems encountered in address validation. + enum Type { + // The field is empty or whitespace, but it is required for addresses in + // this country. + // + // For example, in the US, administrative area is a required field. + MISSING_REQUIRED_FIELD, + + // A list of values for the field is defined, but the value does not occur + // in the list. Applies to hierarchical elements like country code, + // administrative area, locality, and dependent locality. + // + // For example, in the US, the values for for administrative area include + // "CA", but not "XX". + UNKNOWN_VALUE, + + // A format for the field is defined, but the value does not match. This is + // used to match postal code against the general format pattern. Formats + // indicate how many digits/letters should be present and what punctuation + // is allowed. + // + // For example, in the US, postal codes are five digits with an optional + // hyphen followed by four digits. + UNRECOGNIZED_FORMAT, + + // A specific pattern for the field is defined based on a specific + // sub-region (an administrative area for example), but the value does not + // match. This is used to match postal code against a regular expression. + // + // For example, in the US, postal codes in the state of California start + // with a '9'. + MISMATCHING_VALUE + }; + + // The address field that has the problem. + AddressField field; + + // The type of problem. + Type type; + + // The human readable description of the problem. + std::string description; +}; + +// Produces human-readable output in logging, for example in unit tests. +// Produces what you would expect for valid values, e.g. +// "MISSING_REQUIRED_FIELD" for MISSING_REQUIRED_FIELD. For invalid values, +// produces "[INVALID]". +std::ostream& operator<<(std::ostream& o, AddressProblem::Type problem_type); + +// Produces human-readable output in logging, for example in unit tests. +// Example: [ADMIN_AREA, UNKNOWN_VALUE, "Invalid state"]. +std::ostream& operator<<(std::ostream& o, const AddressProblem& problem); + +} // namespace addressinput +} // namespace i18n + +#endif // I18N_ADDRESSINPUT_ADDRESS_PROBLEM_H_ diff --git a/third_party/libaddressinput/chromium/cpp/src/address_problem.cc b/third_party/libaddressinput/chromium/cpp/src/address_problem.cc new file mode 100644 index 0000000..14a0030 --- /dev/null +++ b/third_party/libaddressinput/chromium/cpp/src/address_problem.cc @@ -0,0 +1,51 @@ +// Copyright (C) 2013 Google Inc. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +#include <libaddressinput/address_problem.h> + +#include <ostream> + +namespace i18n { +namespace addressinput { + +std::ostream& operator<<(std::ostream& o, AddressProblem::Type problem_type) { + switch (problem_type) { + case AddressProblem::MISSING_REQUIRED_FIELD: + o << "MISSING_REQUIRED_FIELD"; + break; + case AddressProblem::UNKNOWN_VALUE: + o << "UNKNOWN_VALUE"; + break; + case AddressProblem::UNRECOGNIZED_FORMAT: + o << "UNRECOGNIZED_FORMAT"; + break; + case AddressProblem::MISMATCHING_VALUE: + o << "MISMATCHING_VALUE"; + break; + default : + o << "[INVALID]"; + break; + } + return o; +} + +std::ostream& operator<<(std::ostream& o, const AddressProblem& problem) { + o << "[" << problem.field << ", " + << problem.type << ", \"" + << problem.description << "\"]"; + return o; +} + +} // namespace addressinput +} // namespace i18n diff --git a/third_party/libaddressinput/libaddressinput.gyp b/third_party/libaddressinput/libaddressinput.gyp index 28f5e2c..84ef364e 100644 --- a/third_party/libaddressinput/libaddressinput.gyp +++ b/third_party/libaddressinput/libaddressinput.gyp @@ -48,12 +48,14 @@ 'chromium/json.cc', '<(libaddressinput_dir)/cpp/include/libaddressinput/address_data.h', '<(libaddressinput_dir)/cpp/include/libaddressinput/address_field.h', + '<(libaddressinput_dir)/cpp/include/libaddressinput/address_problem.h', '<(libaddressinput_dir)/cpp/include/libaddressinput/address_ui_component.h', '<(libaddressinput_dir)/cpp/include/libaddressinput/address_ui.h', '<(libaddressinput_dir)/cpp/include/libaddressinput/localization.h', '<(libaddressinput_dir)/cpp/src/address_field.cc', '<(libaddressinput_dir)/cpp/src/address_field_util.cc', '<(libaddressinput_dir)/cpp/src/address_field_util.h', + '<(libaddressinput_dir)/cpp/src/address_problem.cc', '<(libaddressinput_dir)/cpp/src/address_ui.cc', '<(libaddressinput_dir)/cpp/src/localization.cc', '<(libaddressinput_dir)/cpp/src/region_data_constants.cc', |