OLD | NEW |
| (Empty) |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | |
2 // Use of this source code is governed by a BSD-style license that can be | |
3 // found in the LICENSE file. | |
4 | |
5 #ifndef COMPONENTS_AUTOFILL_BROWSER_PHONE_FIELD_H_ | |
6 #define COMPONENTS_AUTOFILL_BROWSER_PHONE_FIELD_H_ | |
7 | |
8 #include <vector> | |
9 | |
10 #include "base/compiler_specific.h" | |
11 #include "components/autofill/browser/autofill_type.h" | |
12 #include "components/autofill/browser/form_field.h" | |
13 #include "components/autofill/browser/phone_number.h" | |
14 | |
15 namespace autofill { | |
16 | |
17 class AutofillField; | |
18 class AutofillScanner; | |
19 | |
20 // A phone number in one of the following formats: | |
21 // - area code, prefix, suffix | |
22 // - area code, number | |
23 // - number | |
24 class PhoneField : public FormField { | |
25 public: | |
26 virtual ~PhoneField(); | |
27 | |
28 static FormField* Parse(AutofillScanner* scanner); | |
29 | |
30 protected: | |
31 // FormField: | |
32 virtual bool ClassifyField(FieldTypeMap* map) const OVERRIDE; | |
33 | |
34 private: | |
35 FRIEND_TEST_ALL_PREFIXES(PhoneFieldTest, ParseOneLinePhone); | |
36 FRIEND_TEST_ALL_PREFIXES(PhoneFieldTest, ParseTwoLinePhone); | |
37 FRIEND_TEST_ALL_PREFIXES(PhoneFieldTest, ThreePartPhoneNumber); | |
38 FRIEND_TEST_ALL_PREFIXES(PhoneFieldTest, ThreePartPhoneNumberPrefixSuffix); | |
39 FRIEND_TEST_ALL_PREFIXES(PhoneFieldTest, ThreePartPhoneNumberPrefixSuffix2); | |
40 FRIEND_TEST_ALL_PREFIXES(PhoneFieldTest, CountryAndCityAndPhoneNumber); | |
41 | |
42 // This is for easy description of the possible parsing paths of the phone | |
43 // fields. | |
44 enum RegexType { | |
45 REGEX_COUNTRY, | |
46 REGEX_AREA, | |
47 REGEX_AREA_NOTEXT, | |
48 REGEX_PHONE, | |
49 REGEX_PREFIX_SEPARATOR, | |
50 REGEX_PREFIX, | |
51 REGEX_SUFFIX_SEPARATOR, | |
52 REGEX_SUFFIX, | |
53 REGEX_EXTENSION, | |
54 | |
55 // Separates regexps in grammar. | |
56 REGEX_SEPARATOR, | |
57 }; | |
58 | |
59 // Parsed fields. | |
60 enum PhonePart { | |
61 FIELD_NONE = -1, | |
62 FIELD_COUNTRY_CODE, | |
63 FIELD_AREA_CODE, | |
64 FIELD_PHONE, | |
65 FIELD_SUFFIX, | |
66 FIELD_EXTENSION, | |
67 | |
68 FIELD_MAX, | |
69 }; | |
70 | |
71 struct Parser { | |
72 RegexType regex; // Field matching reg-ex. | |
73 PhonePart phone_part; // Index of the field. | |
74 size_t max_size; // Max size of the field to match. 0 means any. | |
75 }; | |
76 | |
77 static const Parser kPhoneFieldGrammars[]; | |
78 | |
79 PhoneField(); | |
80 | |
81 // Returns the regular expression string correspoding to |regex_id| | |
82 static base::string16 GetRegExp(RegexType regex_id); | |
83 | |
84 // FIELD_PHONE is always present; holds suffix if prefix is present. | |
85 // The rest could be NULL. | |
86 const AutofillField* parsed_phone_fields_[FIELD_MAX]; | |
87 | |
88 DISALLOW_COPY_AND_ASSIGN(PhoneField); | |
89 }; | |
90 | |
91 } // namespace autofill | |
92 | |
93 #endif // COMPONENTS_AUTOFILL_BROWSER_PHONE_FIELD_H_ | |
OLD | NEW |