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

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

Issue 6480083: Changed parsing code for the phonenumbers fields to incorporate different com... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 9 years, 10 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) 2009 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2009 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 #ifndef CHROME_BROWSER_AUTOFILL_PHONE_FIELD_H_ 5 #ifndef CHROME_BROWSER_AUTOFILL_PHONE_FIELD_H_
6 #define CHROME_BROWSER_AUTOFILL_PHONE_FIELD_H_ 6 #define CHROME_BROWSER_AUTOFILL_PHONE_FIELD_H_
7 #pragma once 7 #pragma once
8 8
9 #include <vector> 9 #include <vector>
10 10
(...skipping 13 matching lines...) Expand all
24 static PhoneField* Parse(std::vector<AutoFillField*>::const_iterator* iter, 24 static PhoneField* Parse(std::vector<AutoFillField*>::const_iterator* iter,
25 bool is_ecml); 25 bool is_ecml);
26 static PhoneField* ParseECML( 26 static PhoneField* ParseECML(
27 std::vector<AutoFillField*>::const_iterator* iter); 27 std::vector<AutoFillField*>::const_iterator* iter);
28 28
29 virtual bool GetFieldInfo(FieldTypeMap* field_type_map) const; 29 virtual bool GetFieldInfo(FieldTypeMap* field_type_map) const;
30 30
31 private: 31 private:
32 PhoneField(); 32 PhoneField();
33 33
34 enum PHONE_TYPE { 34 enum PhoneType {
35 PHONE_TYPE_FIRST = 0, 35 PHONE_TYPE_FIRST = 0,
36 HOME_PHONE = PHONE_TYPE_FIRST, 36 HOME_PHONE = PHONE_TYPE_FIRST,
37 FAX_PHONE, 37 FAX_PHONE,
38 38
39 // Must be last. 39 // Must be last.
40 PHONE_TYPE_MAX, 40 PHONE_TYPE_MAX,
41 }; 41 };
42 42
43 // Some field names are different for phone and fax. 43 // Some field names are different for phone and fax.
44 string16 GetCountryRegex() const;
45 // This string includes all area code separators, including NoText.
44 string16 GetAreaRegex() const; 46 string16 GetAreaRegex() const;
47 // Separator of the area code in the case fields are formatted without
48 // any text indicating what fields are (e.g. field1 "(" field2 ")" field3 "-"
49 // field4 means Country Code, Area Code, Prefix, Suffix)
50 string16 GetAreaNoTextRegex() const;
45 string16 GetPhoneRegex() const; 51 string16 GetPhoneRegex() const;
52 string16 GetPrefixSeparatorRegex() const;
46 string16 GetPrefixRegex() const; 53 string16 GetPrefixRegex() const;
54 string16 GetSuffixSeparatorRegex() const;
47 string16 GetSuffixRegex() const; 55 string16 GetSuffixRegex() const;
48 string16 GetExtensionRegex() const; 56 string16 GetExtensionRegex() const;
49 57
58 // This is for easy description of the possible parsing paths of the phone
59 // fields.
60 enum RegexType {
61 REGEX_COUNTRY,
62 REGEX_AREA,
63 REGEX_AREA_NOTEXT,
64 REGEX_PHONE,
65 REGEX_PREFIX_SEPARATOR,
66 REGEX_PREFIX,
67 REGEX_SUFFIX_SEPARATOR,
68 REGEX_SUFFIX,
69 REGEX_EXTENSION,
70
71 // Separates regexps in grammar.
72 REGEX_SEPARATOR,
73 };
74
75 string16 GetRegExp(RegexType regex_id) const;
76
50 // |field| - field to fill up on successful parsing. 77 // |field| - field to fill up on successful parsing.
51 // |iter| - in/out. Form field iterator, points to the first field that is 78 // |iter| - in/out. Form field iterator, points to the first field that is
52 // attempted to be parsed. If parsing successful, points to the first field 79 // attempted to be parsed. If parsing successful, points to the first field
53 // after parsed fields. 80 // after parsed fields.
54 // |regular_phone| - true if the parsed phone is a HOME phone, false 81 // |regular_phone| - true if the parsed phone is a HOME phone, false
55 // otherwise. 82 // otherwise.
56 static bool ParseInternal(PhoneField* field, 83 static bool ParseInternal(PhoneField* field,
57 std::vector<AutoFillField*>::const_iterator* iter, 84 std::vector<AutoFillField*>::const_iterator* iter,
58 bool regular_phone); 85 bool regular_phone);
59 86
60 void SetPhoneType(PHONE_TYPE phone_type); 87 void SetPhoneType(PhoneType phone_type);
61 88
62 // Field types are different as well, so we create a temporary phone number, 89 // Field types are different as well, so we create a temporary phone number,
63 // to get relevant field types. 90 // to get relevant field types.
64 scoped_ptr<PhoneNumber> number_; 91 scoped_ptr<PhoneNumber> number_;
65 PHONE_TYPE phone_type_; 92 PhoneType phone_type_;
66 93
67 // Always present; holds suffix if prefix is present.
68 AutoFillField* phone_;
69 94
70 AutoFillField* area_code_; // optional 95 // Parsed fields.
71 AutoFillField* prefix_; // optional 96 enum PhonePart {
72 AutoFillField* extension_; // optional 97 FIELD_NONE = -1,
98 FIELD_COUNTRY_CODE,
99 FIELD_AREA_CODE,
100 FIELD_PHONE,
101 FIELD_SUFFIX,
102 FIELD_EXTENSION,
103
104 FIELD_MAX,
105 };
106
107 // FIELD_PHONE is always present; holds suffix if prefix is present.
108 // The rest could be NULL.
109 AutoFillField* parsed_phone_fields_[FIELD_MAX];
110
111 static struct Parser {
112 RegexType regex; // Field matching reg-ex.
113 PhonePart phone_part; // Index of the field.
114 int max_size; // Max size of the field to match. 0 means any.
115 } phone_field_grammars_[];
73 116
74 DISALLOW_COPY_AND_ASSIGN(PhoneField); 117 DISALLOW_COPY_AND_ASSIGN(PhoneField);
75 }; 118 };
76 119
77 #endif // CHROME_BROWSER_AUTOFILL_PHONE_FIELD_H_ 120 #endif // CHROME_BROWSER_AUTOFILL_PHONE_FIELD_H_
OLDNEW
« no previous file with comments | « chrome/browser/autofill/form_structure_unittest.cc ('k') | chrome/browser/autofill/phone_field.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698