1 // Copyright 2013 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.
5 #ifndef COMPONENTS_AUTOFILL_CORE_BROWSER_PHONE_FIELD_H_
6 #define COMPONENTS_AUTOFILL_CORE_BROWSER_PHONE_FIELD_H_
10 #include "base/compiler_specific.h"
11 #include "components/autofill/core/browser/autofill_type.h"
12 #include "components/autofill/core/browser/form_field.h"
13 #include "components/autofill/core/browser/phone_number.h"
18 class AutofillScanner;
20 // A phone number in one of the following formats:
21 // - area code, prefix, suffix
22 // - area code, number
24 class PhoneField : public FormField {
26 virtual ~PhoneField();
28 static FormField* Parse(AutofillScanner* scanner);
32 virtual bool ClassifyField(ServerFieldTypeMap* map) const OVERRIDE;
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);
42 // This is for easy description of the possible parsing paths of the phone
49 REGEX_PREFIX_SEPARATOR,
51 REGEX_SUFFIX_SEPARATOR,
55 // Separates regexps in grammar.
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.
77 static const Parser kPhoneFieldGrammars[];
81 // Returns the regular expression string correspoding to |regex_id|
82 static base::string16 GetRegExp(RegexType regex_id);
84 // FIELD_PHONE is always present; holds suffix if prefix is present.
85 // The rest could be NULL.
86 AutofillField* parsed_phone_fields_[FIELD_MAX];
88 DISALLOW_COPY_AND_ASSIGN(PhoneField);
91 } // namespace autofill
93 #endif // COMPONENTS_AUTOFILL_CORE_BROWSER_PHONE_FIELD_H_