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

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

Issue 7120005: Simplify Autofill Scanner semantics (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 9 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « chrome/browser/autofill/credit_card_field.cc ('k') | no next file » | 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/phone_field.h" 5 #include "chrome/browser/autofill/phone_field.h"
6 6
7 #include "base/logging.h" 7 #include "base/logging.h"
8 #include "base/memory/scoped_ptr.h" 8 #include "base/memory/scoped_ptr.h"
9 #include "base/string16.h" 9 #include "base/string16.h"
10 #include "base/string_util.h" 10 #include "base/string_util.h"
(...skipping 245 matching lines...) Expand 10 before | Expand all | Expand 10 after
256 AutofillScanner* scanner, 256 AutofillScanner* scanner,
257 bool regular_phone) { 257 bool regular_phone) {
258 DCHECK(phone_field); 258 DCHECK(phone_field);
259 scanner->SaveCursor(); 259 scanner->SaveCursor();
260 260
261 // The form owns the following variables, so they should not be deleted. 261 // The form owns the following variables, so they should not be deleted.
262 const AutofillField* parsed_fields[FIELD_MAX]; 262 const AutofillField* parsed_fields[FIELD_MAX];
263 263
264 for (size_t i = 0; i < arraysize(phone_field_grammars_); ++i) { 264 for (size_t i = 0; i < arraysize(phone_field_grammars_); ++i) {
265 memset(parsed_fields, 0, sizeof(parsed_fields)); 265 memset(parsed_fields, 0, sizeof(parsed_fields));
266 scanner->Rewind();
267 scanner->SaveCursor(); 266 scanner->SaveCursor();
268 267
269 // Attempt to parse according to the next grammar. 268 // Attempt to parse according to the next grammar.
270 for (; i < arraysize(phone_field_grammars_) && 269 for (; i < arraysize(phone_field_grammars_) &&
271 phone_field_grammars_[i].regex != REGEX_SEPARATOR; ++i) { 270 phone_field_grammars_[i].regex != REGEX_SEPARATOR; ++i) {
272 if (!ParseFieldSpecifics( 271 if (!ParseFieldSpecifics(
273 scanner, 272 scanner,
274 phone_field->GetRegExp(phone_field_grammars_[i].regex), 273 phone_field->GetRegExp(phone_field_grammars_[i].regex),
275 MATCH_DEFAULT | MATCH_TELEPHONE, 274 MATCH_DEFAULT | MATCH_TELEPHONE,
276 &parsed_fields[phone_field_grammars_[i].phone_part])) 275 &parsed_fields[phone_field_grammars_[i].phone_part]))
(...skipping 16 matching lines...) Expand all
293 // Proceed to the next grammar. 292 // Proceed to the next grammar.
294 do { 293 do {
295 ++i; 294 ++i;
296 } while (i < arraysize(phone_field_grammars_) && 295 } while (i < arraysize(phone_field_grammars_) &&
297 phone_field_grammars_[i].regex != REGEX_SEPARATOR); 296 phone_field_grammars_[i].regex != REGEX_SEPARATOR);
298 297
299 if (i + 1 == arraysize(phone_field_grammars_)) { 298 if (i + 1 == arraysize(phone_field_grammars_)) {
300 scanner->Rewind(); 299 scanner->Rewind();
301 return false; // Tried through all the possibilities - did not match. 300 return false; // Tried through all the possibilities - did not match.
302 } 301 }
302
303 scanner->Rewind();
303 } 304 }
304 305
305 if (!parsed_fields[FIELD_PHONE]) { 306 if (!parsed_fields[FIELD_PHONE]) {
306 scanner->Rewind(); 307 scanner->Rewind();
307 return false; 308 return false;
308 } 309 }
309 310
310 for (int i = 0; i < FIELD_MAX; ++i) 311 for (int i = 0; i < FIELD_MAX; ++i)
311 phone_field->parsed_phone_fields_[i] = parsed_fields[i]; 312 phone_field->parsed_phone_fields_[i] = parsed_fields[i];
312 313
(...skipping 18 matching lines...) Expand all
331 void PhoneField::SetPhoneType(PhoneType phone_type) { 332 void PhoneField::SetPhoneType(PhoneType phone_type) {
332 // Field types are different as well, so we create a temporary phone number, 333 // Field types are different as well, so we create a temporary phone number,
333 // to get relevant field types. 334 // to get relevant field types.
334 if (phone_type == HOME_PHONE) 335 if (phone_type == HOME_PHONE)
335 number_.reset(new PhoneNumber(AutofillType::PHONE_HOME)); 336 number_.reset(new PhoneNumber(AutofillType::PHONE_HOME));
336 else 337 else
337 number_.reset(new PhoneNumber(AutofillType::PHONE_FAX)); 338 number_.reset(new PhoneNumber(AutofillType::PHONE_FAX));
338 phone_type_ = phone_type; 339 phone_type_ = phone_type;
339 } 340 }
340 341
OLDNEW
« no previous file with comments | « chrome/browser/autofill/credit_card_field.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698