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

Side by Side Diff: third_party/libaddressinput/chromium/cpp/src/address_validator.cc

Issue 145553009: rAc: use libaddressinput to validate international addresses. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: . Created 6 years, 11 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 (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 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
72 } 72 }
73 return true; 73 return true;
74 } 74 }
75 75
76 // Validates AddressData structure. 76 // Validates AddressData structure.
77 class AddressValidatorImpl : public AddressValidator { 77 class AddressValidatorImpl : public AddressValidator {
78 public: 78 public:
79 // Takes ownership of |downloader| and |storage|. Does not take ownership of 79 // Takes ownership of |downloader| and |storage|. Does not take ownership of
80 // |load_rules_delegate|. 80 // |load_rules_delegate|.
81 AddressValidatorImpl(scoped_ptr<Downloader> downloader, 81 AddressValidatorImpl(scoped_ptr<Downloader> downloader,
82 scoped_ptr<Storage> storage, 82 Storage* storage,
83 LoadRulesDelegate* load_rules_delegate) 83 LoadRulesDelegate* load_rules_delegate)
84 : aggregator_(scoped_ptr<Retriever>(new Retriever( 84 : aggregator_(scoped_ptr<Retriever>(
85 VALIDATION_DATA_URL, 85 new Retriever(VALIDATION_DATA_URL, downloader.Pass(), storage))),
86 downloader.Pass(),
87 storage.Pass()))),
88 load_rules_delegate_(load_rules_delegate), 86 load_rules_delegate_(load_rules_delegate),
89 loading_rules_(), 87 loading_rules_(),
90 rules_() {} 88 rules_() {}
91 89
92 virtual ~AddressValidatorImpl() { 90 virtual ~AddressValidatorImpl() {
93 STLDeleteValues(&rules_); 91 STLDeleteValues(&rules_);
94 } 92 }
95 93
96 // AddressValidator implementation. 94 // AddressValidator implementation.
97 virtual void LoadRules(const std::string& country_code) { 95 virtual void LoadRules(const std::string& country_code) {
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
176 174
177 // Validate sub-region specific postal code format. A sub-region specifies 175 // Validate sub-region specific postal code format. A sub-region specifies
178 // the regular expression for a prefix of the postal code. 176 // the regular expression for a prefix of the postal code.
179 int match_position = -1; 177 int match_position = -1;
180 if (ruleset->field() > COUNTRY && 178 if (ruleset->field() > COUNTRY &&
181 !address.postal_code.empty() && 179 !address.postal_code.empty() &&
182 !rule.GetPostalCodeFormat().empty() && 180 !rule.GetPostalCodeFormat().empty() &&
183 FilterAllows(filter, 181 FilterAllows(filter,
184 POSTAL_CODE, 182 POSTAL_CODE,
185 AddressProblem::MISMATCHING_VALUE) && 183 AddressProblem::MISMATCHING_VALUE) &&
186 (!RE2::PartialMatch(address.postal_code, 184 !RE2::FullMatch(address.postal_code,
187 rule.GetPostalCodeFormat(), 185 "^(" + rule.GetPostalCodeFormat() + ").*")) {
Evan Stade 2014/01/27 23:11:15 this should be a separate cl
Dan Beam 2014/01/28 02:22:36 Done.
188 &match_position) ||
189 match_position != 0)) {
190 problems->push_back(AddressProblem( 186 problems->push_back(AddressProblem(
191 POSTAL_CODE, 187 POSTAL_CODE,
192 AddressProblem::MISMATCHING_VALUE, 188 AddressProblem::MISMATCHING_VALUE,
193 country_rule.GetInvalidPostalCodeMessageId())); 189 country_rule.GetInvalidPostalCodeMessageId()));
194 } 190 }
195 191
196 ruleset = ruleset->GetSubRegionRuleset(sub_field); 192 ruleset = ruleset->GetSubRegionRuleset(sub_field);
197 } 193 }
198 194
199 return SUCCESS; 195 return SUCCESS;
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
233 DISALLOW_COPY_AND_ASSIGN(AddressValidatorImpl); 229 DISALLOW_COPY_AND_ASSIGN(AddressValidatorImpl);
234 }; 230 };
235 231
236 } // namespace 232 } // namespace
237 233
238 AddressValidator::~AddressValidator() {} 234 AddressValidator::~AddressValidator() {}
239 235
240 // static 236 // static
241 scoped_ptr<AddressValidator> AddressValidator::Build( 237 scoped_ptr<AddressValidator> AddressValidator::Build(
242 scoped_ptr<Downloader> downloader, 238 scoped_ptr<Downloader> downloader,
243 scoped_ptr<Storage> storage, 239 Storage* storage,
244 LoadRulesDelegate* load_rules_delegate) { 240 LoadRulesDelegate* load_rules_delegate) {
245 return scoped_ptr<AddressValidator>(new AddressValidatorImpl( 241 return scoped_ptr<AddressValidator>(new AddressValidatorImpl(
246 downloader.Pass(), storage.Pass(), load_rules_delegate)); 242 downloader.Pass(), storage, load_rules_delegate));
247 } 243 }
248 244
249 } // namespace addressinput 245 } // namespace addressinput
250 } // namespace i18n 246 } // namespace i18n
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698