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

Side by Side Diff: chrome/browser/autofill/address_field.cc

Issue 7063031: Heuristics for grabber-continental.com.out (select-one) (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: nits Created 9 years, 7 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
« no previous file with comments | « no previous file | chrome/browser/autofill/autofill_resources.grd » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved.
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 "chrome/browser/autofill/address_field.h" 5 #include "chrome/browser/autofill/address_field.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 8
9 #include "base/logging.h" 9 #include "base/logging.h"
10 #include "base/memory/scoped_ptr.h" 10 #include "base/memory/scoped_ptr.h"
(...skipping 177 matching lines...) Expand 10 before | Expand all | Expand 10 after
188 if (is_ecml) { 188 if (is_ecml) {
189 pattern = GetEcmlPattern(kEcmlShipToAddress1, kEcmlBillToAddress1, '|'); 189 pattern = GetEcmlPattern(kEcmlShipToAddress1, kEcmlBillToAddress1, '|');
190 if (!ParseField(scanner, pattern, &address_field->address1_)) 190 if (!ParseField(scanner, pattern, &address_field->address1_))
191 return false; 191 return false;
192 } else { 192 } else {
193 pattern = l10n_util::GetStringUTF16(IDS_AUTOFILL_ADDRESS_LINE_1_RE); 193 pattern = l10n_util::GetStringUTF16(IDS_AUTOFILL_ADDRESS_LINE_1_RE);
194 string16 label_pattern = 194 string16 label_pattern =
195 l10n_util::GetStringUTF16(IDS_AUTOFILL_ADDRESS_LINE_1_LABEL_RE); 195 l10n_util::GetStringUTF16(IDS_AUTOFILL_ADDRESS_LINE_1_LABEL_RE);
196 196
197 if (!ParseField(scanner, pattern, &address_field->address1_) && 197 if (!ParseField(scanner, pattern, &address_field->address1_) &&
198 !ParseFieldSpecifics(scanner, label_pattern, MATCH_LABEL, 198 !ParseFieldSpecifics(scanner, label_pattern, MATCH_LABEL | MATCH_TEXT,
199 &address_field->address1_)) { 199 &address_field->address1_)) {
200 return false; 200 return false;
201 } 201 }
202 } 202 }
203 203
204 // Optionally parse more address lines, which may have empty labels. 204 // Optionally parse more address lines, which may have empty labels.
205 // Some pages have 3 address lines (eg SharperImageModifyAccount.html) 205 // Some pages have 3 address lines (eg SharperImageModifyAccount.html)
206 // Some pages even have 4 address lines (e.g. uk/ShoesDirect2.html)! 206 // Some pages even have 4 address lines (e.g. uk/ShoesDirect2.html)!
207 if (is_ecml) { 207 if (is_ecml) {
208 pattern = GetEcmlPattern(kEcmlShipToAddress2, kEcmlBillToAddress2, '|'); 208 pattern = GetEcmlPattern(kEcmlShipToAddress2, kEcmlBillToAddress2, '|');
209 if (!ParseEmptyLabel(scanner, &address_field->address2_)) 209 if (!ParseEmptyLabel(scanner, &address_field->address2_))
210 ParseField(scanner, pattern, &address_field->address2_); 210 ParseField(scanner, pattern, &address_field->address2_);
211 } else { 211 } else {
212 pattern = l10n_util::GetStringUTF16(IDS_AUTOFILL_ADDRESS_LINE_2_RE); 212 pattern = l10n_util::GetStringUTF16(IDS_AUTOFILL_ADDRESS_LINE_2_RE);
213 string16 label_pattern = 213 string16 label_pattern =
214 l10n_util::GetStringUTF16(IDS_AUTOFILL_ADDRESS_LINE_1_LABEL_RE); 214 l10n_util::GetStringUTF16(IDS_AUTOFILL_ADDRESS_LINE_1_LABEL_RE);
215 if (!ParseEmptyLabel(scanner, &address_field->address2_) && 215 if (!ParseEmptyLabel(scanner, &address_field->address2_) &&
216 !ParseField(scanner, pattern, &address_field->address2_)) { 216 !ParseField(scanner, pattern, &address_field->address2_)) {
217 ParseFieldSpecifics(scanner, label_pattern, MATCH_LABEL, 217 ParseFieldSpecifics(scanner, label_pattern, MATCH_LABEL | MATCH_TEXT,
218 &address_field->address2_); 218 &address_field->address2_);
219 } 219 }
220 } 220 }
221 221
222 // Try for a third line, which we will promptly discard. 222 // Try for a third line, which we will promptly discard.
223 if (address_field->address2_ != NULL) { 223 if (address_field->address2_ != NULL) {
224 if (is_ecml) { 224 if (is_ecml) {
225 pattern = GetEcmlPattern(kEcmlShipToAddress3, kEcmlBillToAddress3, '|'); 225 pattern = GetEcmlPattern(kEcmlShipToAddress3, kEcmlBillToAddress3, '|');
226 ParseField(scanner, pattern, NULL); 226 ParseField(scanner, pattern, NULL);
227 } else { 227 } else {
(...skipping 15 matching lines...) Expand all
243 // Note: ECML standard uses 2 letter country code (ISO 3166) 243 // Note: ECML standard uses 2 letter country code (ISO 3166)
244 if (address_field->country_ && !address_field->country_->IsEmpty()) 244 if (address_field->country_ && !address_field->country_->IsEmpty())
245 return false; 245 return false;
246 246
247 string16 pattern; 247 string16 pattern;
248 if (is_ecml) 248 if (is_ecml)
249 pattern = GetEcmlPattern(kEcmlShipToCountry, kEcmlBillToCountry, '|'); 249 pattern = GetEcmlPattern(kEcmlShipToCountry, kEcmlBillToCountry, '|');
250 else 250 else
251 pattern = l10n_util::GetStringUTF16(IDS_AUTOFILL_COUNTRY_RE); 251 pattern = l10n_util::GetStringUTF16(IDS_AUTOFILL_COUNTRY_RE);
252 252
253 return ParseField(scanner, pattern, &address_field->country_); 253 return ParseFieldSpecifics(scanner, pattern, MATCH_DEFAULT | MATCH_SELECT,
254 &address_field->country_);
254 } 255 }
255 256
256 // static 257 // static
257 bool AddressField::ParseZipCode(AutofillScanner* scanner, 258 bool AddressField::ParseZipCode(AutofillScanner* scanner,
258 bool is_ecml, 259 bool is_ecml,
259 AddressField* address_field) { 260 AddressField* address_field) {
260 // Parse a zip code. On some UK pages (e.g. The China Shop2.html) this 261 // Parse a zip code. On some UK pages (e.g. The China Shop2.html) this
261 // is called a "post code". 262 // is called a "post code".
262 // 263 //
263 // HACK: Just for the MapQuest driving directions page we match the 264 // HACK: Just for the MapQuest driving directions page we match the
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
327 AddressField* address_field) { 328 AddressField* address_field) {
328 if (address_field->state_) 329 if (address_field->state_)
329 return false; 330 return false;
330 331
331 string16 pattern; 332 string16 pattern;
332 if (is_ecml) 333 if (is_ecml)
333 pattern = GetEcmlPattern(kEcmlShipToStateProv, kEcmlBillToStateProv, '|'); 334 pattern = GetEcmlPattern(kEcmlShipToStateProv, kEcmlBillToStateProv, '|');
334 else 335 else
335 pattern = l10n_util::GetStringUTF16(IDS_AUTOFILL_STATE_RE); 336 pattern = l10n_util::GetStringUTF16(IDS_AUTOFILL_STATE_RE);
336 337
337 return ParseField(scanner, pattern, &address_field->state_); 338 return ParseFieldSpecifics(scanner, pattern, MATCH_DEFAULT | MATCH_SELECT,
339 &address_field->state_);
338 } 340 }
339 341
340 AddressType AddressField::AddressTypeFromText(const string16 &text) { 342 AddressType AddressField::AddressTypeFromText(const string16 &text) {
341 if (text.find(l10n_util::GetStringUTF16(IDS_AUTOFILL_ADDRESS_TYPE_SAME_AS_RE)) 343 if (text.find(l10n_util::GetStringUTF16(IDS_AUTOFILL_ADDRESS_TYPE_SAME_AS_RE))
342 != string16::npos || 344 != string16::npos ||
343 text.find(l10n_util::GetStringUTF16(IDS_AUTOFILL_ADDRESS_TYPE_USE_MY_RE)) 345 text.find(l10n_util::GetStringUTF16(IDS_AUTOFILL_ADDRESS_TYPE_USE_MY_RE))
344 != string16::npos) 346 != string16::npos)
345 // This text could be a checkbox label such as "same as my billing 347 // This text could be a checkbox label such as "same as my billing
346 // address" or "use my shipping address". 348 // address" or "use my shipping address".
347 // ++ It would help if we generally skipped all text that appears 349 // ++ It would help if we generally skipped all text that appears
(...skipping 15 matching lines...) Expand all
363 return kBillingAddress; 365 return kBillingAddress;
364 366
365 if (bill == string16::npos && ship != string16::npos) 367 if (bill == string16::npos && ship != string16::npos)
366 return kShippingAddress; 368 return kShippingAddress;
367 369
368 if (bill > ship) 370 if (bill > ship)
369 return kBillingAddress; 371 return kBillingAddress;
370 372
371 return kShippingAddress; 373 return kShippingAddress;
372 } 374 }
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/autofill/autofill_resources.grd » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698