Rename GetIconID to GetIconId
[chromium-blink-merge.git] / components / autofill / core / browser / phone_field.h
blob55341790480ab6d94e0006023565ec8cdfb8e3d7
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_
8 #include <vector>
10 #include "base/compiler_specific.h"
11 #include "base/memory/scoped_ptr.h"
12 #include "components/autofill/core/browser/autofill_type.h"
13 #include "components/autofill/core/browser/form_field.h"
14 #include "components/autofill/core/browser/phone_number.h"
16 namespace autofill {
18 class AutofillField;
19 class AutofillScanner;
21 // A phone number in one of the following formats:
22 // - area code, prefix, suffix
23 // - area code, number
24 // - number
25 class PhoneField : public FormField {
26 public:
27 ~PhoneField() override;
29 static scoped_ptr<FormField> Parse(AutofillScanner* scanner);
31 protected:
32 // FormField:
33 bool ClassifyField(ServerFieldTypeMap* map) const override;
35 private:
36 FRIEND_TEST_ALL_PREFIXES(PhoneFieldTest, ParseOneLinePhone);
37 FRIEND_TEST_ALL_PREFIXES(PhoneFieldTest, ParseTwoLinePhone);
38 FRIEND_TEST_ALL_PREFIXES(PhoneFieldTest, ThreePartPhoneNumber);
39 FRIEND_TEST_ALL_PREFIXES(PhoneFieldTest, ThreePartPhoneNumberPrefixSuffix);
40 FRIEND_TEST_ALL_PREFIXES(PhoneFieldTest, ThreePartPhoneNumberPrefixSuffix2);
41 FRIEND_TEST_ALL_PREFIXES(PhoneFieldTest, CountryAndCityAndPhoneNumber);
43 // This is for easy description of the possible parsing paths of the phone
44 // fields.
45 enum RegexType {
46 REGEX_COUNTRY,
47 REGEX_AREA,
48 REGEX_AREA_NOTEXT,
49 REGEX_PHONE,
50 REGEX_PREFIX_SEPARATOR,
51 REGEX_PREFIX,
52 REGEX_SUFFIX_SEPARATOR,
53 REGEX_SUFFIX,
54 REGEX_EXTENSION,
56 // Separates regexps in grammar.
57 REGEX_SEPARATOR,
60 // Parsed fields.
61 enum PhonePart {
62 FIELD_NONE = -1,
63 FIELD_COUNTRY_CODE,
64 FIELD_AREA_CODE,
65 FIELD_PHONE,
66 FIELD_SUFFIX,
67 FIELD_EXTENSION,
69 FIELD_MAX,
72 struct Parser {
73 RegexType regex; // Field matching reg-ex.
74 PhonePart phone_part; // Index of the field.
75 size_t max_size; // Max size of the field to match. 0 means any.
78 static const Parser kPhoneFieldGrammars[];
80 PhoneField();
82 // Returns the regular expression string corresponding to |regex_id|
83 static std::string GetRegExp(RegexType regex_id);
85 // Convenient wrapper for ParseFieldSpecifics().
86 static bool ParsePhoneField(AutofillScanner* scanner,
87 const std::string& regex,
88 AutofillField** field);
90 // FIELD_PHONE is always present; holds suffix if prefix is present.
91 // The rest could be NULL.
92 AutofillField* parsed_phone_fields_[FIELD_MAX];
94 DISALLOW_COPY_AND_ASSIGN(PhoneField);
97 } // namespace autofill
99 #endif // COMPONENTS_AUTOFILL_CORE_BROWSER_PHONE_FIELD_H_