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

Side by Side 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: Rebase on top of https://codereview.chromium.org/359213002/ Created 6 years, 5 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 The Chromium Authors. All rights reserved.
Evan Stade 2014/06/30 18:51:06 this file should probably be called libaddressinpu
please use gerrit instead 2014/07/01 04:53:50 Renamed to required_fields.h because it contains H
Evan Stade 2014/07/01 19:03:31 That's not generic enough.
please use gerrit instead 2014/07/01 20:43:45 libaddressinput_util it is.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "third_party/libaddressinput/chromium/has_all_required_fields.h" 5 #include "third_party/libaddressinput/chromium/has_all_required_fields.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 8
9 #include "base/logging.h" 9 #include "base/logging.h"
10 #include "base/macros.h" 10 #include "base/macros.h"
11 #include "third_party/libaddressinput/chromium/cpp/include/libaddressinput/addre ss_data.h" 11 #include "third_party/libaddressinput/src/cpp/include/libaddressinput/address_da ta.h"
12 #include "third_party/libaddressinput/chromium/cpp/include/libaddressinput/addre ss_metadata.h" 12 #include "third_party/libaddressinput/src/cpp/include/libaddressinput/address_me tadata.h"
13 13
14 namespace autofill { 14 namespace autofill {
15 namespace addressinput { 15 namespace addressinput {
16 16
17 namespace { 17 namespace {
18 18
19 using ::i18n::addressinput::AddressData; 19 using ::i18n::addressinput::AddressData;
20 using ::i18n::addressinput::AddressField; 20 using ::i18n::addressinput::AddressField;
21 using ::i18n::addressinput::AddressProblem; 21 using ::i18n::addressinput::AddressProblem;
22 using ::i18n::addressinput::IsFieldRequired; 22 using ::i18n::addressinput::IsFieldRequired;
23 23
24 using ::i18n::addressinput::MISSING_REQUIRED_FIELD;
25
24 // Based on ::i18n::addressinput::ValidationTask::ShouldReport(). 26 // Based on ::i18n::addressinput::ValidationTask::ShouldReport().
25 bool ShouldReport( 27 bool ShouldReport(const std::multimap<AddressField, AddressProblem>* filter,
26 const std::multimap<AddressField, AddressProblem::Type>* filter, 28 AddressField field,
27 AddressField field, 29 AddressProblem problem) {
28 AddressProblem::Type problem) {
29 return filter == NULL || filter->empty() || 30 return filter == NULL || filter->empty() ||
30 std::find( 31 std::find(filter->begin(),
31 filter->begin(), 32 filter->end(),
32 filter->end(), 33 std::multimap<AddressField, AddressProblem>::value_type(
33 std::multimap<AddressField, AddressProblem::Type>::value_type( 34 field, problem)) != filter->end();
34 field, problem)) != filter->end();
35 } 35 }
36 36
37 } // namespace 37 } // namespace
38 38
39 bool HasAllRequiredFields(const AddressData& address_to_check) { 39 bool HasAllRequiredFields(const AddressData& address_to_check) {
40 std::multimap<AddressField, AddressProblem::Type> problems; 40 std::multimap<AddressField, AddressProblem> problems;
41 ValidateRequiredFields(address_to_check, NULL, &problems); 41 ValidateRequiredFields(address_to_check, NULL, &problems);
42 return problems.empty(); 42 return problems.empty();
43 } 43 }
44 44
45 void ValidateRequiredFields( 45 void ValidateRequiredFields(
46 const AddressData& address_to_check, 46 const AddressData& address_to_check,
47 const std::multimap<AddressField, AddressProblem::Type>* filter, 47 const std::multimap<AddressField, AddressProblem>* filter,
48 std::multimap<AddressField, AddressProblem::Type>* problems) { 48 std::multimap<AddressField, AddressProblem>* problems) {
49 DCHECK(problems); 49 DCHECK(problems);
50 50
51 static const AddressField kFields[] = { 51 static const AddressField kFields[] = {
52 ::i18n::addressinput::COUNTRY, 52 ::i18n::addressinput::COUNTRY,
53 ::i18n::addressinput::ADMIN_AREA, 53 ::i18n::addressinput::ADMIN_AREA,
54 ::i18n::addressinput::LOCALITY, 54 ::i18n::addressinput::LOCALITY,
55 ::i18n::addressinput::DEPENDENT_LOCALITY, 55 ::i18n::addressinput::DEPENDENT_LOCALITY,
56 ::i18n::addressinput::SORTING_CODE, 56 ::i18n::addressinput::SORTING_CODE,
57 ::i18n::addressinput::POSTAL_CODE, 57 ::i18n::addressinput::POSTAL_CODE,
58 ::i18n::addressinput::STREET_ADDRESS, 58 ::i18n::addressinput::STREET_ADDRESS,
59 ::i18n::addressinput::RECIPIENT}; 59 ::i18n::addressinput::RECIPIENT};
60 60
61 for (size_t i = 0; i < arraysize(kFields); ++i) { 61 for (size_t i = 0; i < arraysize(kFields); ++i) {
62 AddressField field = kFields[i]; 62 AddressField field = kFields[i];
63 if (address_to_check.IsFieldEmpty(field) && 63 if (address_to_check.IsFieldEmpty(field) &&
64 IsFieldRequired(field, address_to_check.region_code) && 64 IsFieldRequired(field, address_to_check.region_code) &&
65 ShouldReport(filter, field, AddressProblem::MISSING_REQUIRED_FIELD)) { 65 ShouldReport(filter, field, MISSING_REQUIRED_FIELD)) {
66 problems->insert( 66 problems->insert(std::make_pair(field, MISSING_REQUIRED_FIELD));
67 std::make_pair(field, AddressProblem::MISSING_REQUIRED_FIELD));
68 } 67 }
69 } 68 }
70 } 69 }
71 70
72 } // namespace addressinput 71 } // namespace addressinput
73 } // namespace autofill 72 } // namespace autofill
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698