Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 Loading... | |
| 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 PHONE_TYPE { |
|
dhollowa
2011/02/16 00:25:37
Types should be mixed case, not all-caps. So: s/P
GeorgeY
2011/02/16 20:53:34
Done.
| |
| 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, Preffix, Suffix) | |
|
Ilya Sherman
2011/02/16 09:33:22
nit: "Prefix" (one 'f')
GeorgeY
2011/02/16 20:53:34
Done.
| |
| 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 REGEX_MATCH { | |
|
dhollowa
2011/02/16 00:25:37
Types should be mixed case, not all-caps. So: s/R
GeorgeY
2011/02/16 20:53:34
Done. (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(REGEX_MATCH 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(PHONE_TYPE 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 PHONE_TYPE 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 { |
|
dhollowa
2011/02/16 00:25:37
Let's add a type to this enum, "PhonePart" say (?)
GeorgeY
2011/02/16 20:53:34
Done.
| |
| 72 AutoFillField* extension_; // optional | 97 FIELD_COUNTRY_CODE, |
|
dhollowa
2011/02/16 00:25:37
I notice the |phone_field_grammars_| member is ini
GeorgeY
2011/02/16 20:53:34
Done.
| |
| 98 FIELD_AREA_CODE, | |
| 99 FIELD_PHONE, | |
| 100 FIELD_SUFFIX, | |
| 101 FIELD_EXTENSION, | |
| 102 | |
| 103 FIELD_MAX, | |
| 104 }; | |
| 105 | |
| 106 // FIELD_PHONE is always present; holds suffix if prefix is present. | |
| 107 // The rest could be NULL. | |
| 108 AutoFillField* parsed_phone_fields_[FIELD_MAX]; | |
| 109 | |
| 110 static struct Parser { | |
| 111 REGEX_MATCH regex; // Field matching reg-ex. | |
| 112 size_t field_id; // Index of the field. | |
|
dhollowa
2011/02/16 00:25:37
As mentioned above, size_t -> PhonePart, and field
GeorgeY
2011/02/16 20:53:34
Done.
| |
| 113 int max_size; // Max size of the field to match. 0 means any. | |
| 114 } phone_field_grammars_[]; | |
| 73 | 115 |
| 74 DISALLOW_COPY_AND_ASSIGN(PhoneField); | 116 DISALLOW_COPY_AND_ASSIGN(PhoneField); |
| 75 }; | 117 }; |
| 76 | 118 |
| 77 #endif // CHROME_BROWSER_AUTOFILL_PHONE_FIELD_H_ | 119 #endif // CHROME_BROWSER_AUTOFILL_PHONE_FIELD_H_ |
| OLD | NEW |