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

Unified Diff: third_party/libaddressinput/chromium/has_all_required_fields.cc

Issue 298863012: Use upstream libaddressinput in Chrome. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Whitelist strings used on all platforms. Created 6 years, 6 months 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 side-by-side diff with in-line comments
Download patch
Index: third_party/libaddressinput/chromium/has_all_required_fields.cc
diff --git a/third_party/libaddressinput/chromium/has_all_required_fields.cc b/third_party/libaddressinput/chromium/has_all_required_fields.cc
new file mode 100644
index 0000000000000000000000000000000000000000..0719468ee03513676bb2ed5ec1d2cd550029b852
--- /dev/null
+++ b/third_party/libaddressinput/chromium/has_all_required_fields.cc
@@ -0,0 +1,72 @@
+// Copyright 2014 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "third_party/libaddressinput/chromium/has_all_required_fields.h"
+
+#include <algorithm>
+
+#include "base/logging.h"
+#include "base/macros.h"
+#include "third_party/libaddressinput/src/cpp/include/libaddressinput/address_data.h"
+#include "third_party/libaddressinput/src/cpp/include/libaddressinput/address_metadata.h"
+
+namespace autofill {
+namespace addressinput {
+
+namespace {
+
+using ::i18n::addressinput::AddressData;
+using ::i18n::addressinput::AddressField;
+using ::i18n::addressinput::AddressProblem;
+using ::i18n::addressinput::IsFieldRequired;
+
+using ::i18n::addressinput::MISSING_REQUIRED_FIELD;
+
+// Based on ::i18n::addressinput::ValidationTask::ShouldReport().
+bool ShouldReport(const std::multimap<AddressField, AddressProblem>* filter,
+ AddressField field,
+ AddressProblem problem) {
+ return filter == NULL || filter->empty() ||
+ std::find(filter->begin(),
+ filter->end(),
+ std::multimap<AddressField, AddressProblem>::value_type(
+ field, problem)) != filter->end();
+}
+
+} // namespace
+
+bool HasAllRequiredFields(const AddressData& address_to_check) {
+ std::multimap<AddressField, AddressProblem> problems;
+ ValidateRequiredFields(address_to_check, NULL, &problems);
+ return problems.empty();
+}
+
+void ValidateRequiredFields(
+ const AddressData& address_to_check,
+ const std::multimap<AddressField, AddressProblem>* filter,
+ std::multimap<AddressField, AddressProblem>* problems) {
+ DCHECK(problems);
+
+ static const AddressField kFields[] = {
+ ::i18n::addressinput::COUNTRY,
+ ::i18n::addressinput::ADMIN_AREA,
+ ::i18n::addressinput::LOCALITY,
+ ::i18n::addressinput::DEPENDENT_LOCALITY,
+ ::i18n::addressinput::SORTING_CODE,
+ ::i18n::addressinput::POSTAL_CODE,
+ ::i18n::addressinput::STREET_ADDRESS,
+ ::i18n::addressinput::RECIPIENT};
+
+ for (size_t i = 0; i < arraysize(kFields); ++i) {
+ AddressField field = kFields[i];
+ if (address_to_check.IsFieldEmpty(field) &&
+ IsFieldRequired(field, address_to_check.region_code) &&
+ ShouldReport(filter, field, MISSING_REQUIRED_FIELD)) {
+ problems->insert(std::make_pair(field, MISSING_REQUIRED_FIELD));
+ }
+ }
+}
+
+} // namespace addressinput
+} // namespace autofill

Powered by Google App Engine
This is Rietveld 408576698