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 "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"
19 class AutofillScanner
;
21 // A phone number in one of the following formats:
22 // - area code, prefix, suffix
23 // - area code, number
25 class PhoneField
: public FormField
{
27 ~PhoneField() override
;
29 static scoped_ptr
<FormField
> Parse(AutofillScanner
* scanner
);
33 bool ClassifyField(ServerFieldTypeMap
* map
) const override
;
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
50 REGEX_PREFIX_SEPARATOR
,
52 REGEX_SUFFIX_SEPARATOR
,
56 // Separates regexps in grammar.
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
[];
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_