OLD | NEW |
---|---|
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 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 | 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 COMPONENTS_AUTOFILL_CORE_BROWSER_FORM_FIELD_H_ | 5 #ifndef COMPONENTS_AUTOFILL_CORE_BROWSER_FORM_FIELD_H_ |
6 #define COMPONENTS_AUTOFILL_CORE_BROWSER_FORM_FIELD_H_ | 6 #define COMPONENTS_AUTOFILL_CORE_BROWSER_FORM_FIELD_H_ |
7 | 7 |
8 #include <vector> | 8 #include <vector> |
9 | 9 |
10 #include "base/basictypes.h" | 10 #include "base/basictypes.h" |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
62 RESULT_MATCH_NAME, // Only the name matches the pattern. | 62 RESULT_MATCH_NAME, // Only the name matches the pattern. |
63 RESULT_MATCH_NAME_LABEL // Name and label both match the pattern. | 63 RESULT_MATCH_NAME_LABEL // Name and label both match the pattern. |
64 }; | 64 }; |
65 | 65 |
66 // Only derived classes may instantiate. | 66 // Only derived classes may instantiate. |
67 FormField() {} | 67 FormField() {} |
68 | 68 |
69 // Attempts to parse a form field with the given pattern. Returns true on | 69 // Attempts to parse a form field with the given pattern. Returns true on |
70 // success and fills |match| with a pointer to the field. | 70 // success and fills |match| with a pointer to the field. |
71 static bool ParseField(AutofillScanner* scanner, | 71 static bool ParseField(AutofillScanner* scanner, |
72 const base::string16& pattern, | 72 const std::string& pattern, |
vabr (Chromium)
2015/11/26 14:47:42
Please
#include <string>
for std::string.
| |
73 AutofillField** match); | 73 AutofillField** match); |
74 | 74 |
75 // Parses the stream of fields in |scanner| with regular expression |pattern| | 75 // Parses the stream of fields in |scanner| with regular expression |pattern| |
76 // as specified in the |match_type| bit field (see |MatchType|). If |match| | 76 // as specified in the |match_type| bit field (see |MatchType|). If |match| |
77 // is non-NULL and the pattern matches, the matched field is returned. | 77 // is non-NULL and the pattern matches, the matched field is returned. |
78 // A |true| result is returned in the case of a successful match, false | 78 // A |true| result is returned in the case of a successful match, false |
79 // otherwise. | 79 // otherwise. |
80 static bool ParseFieldSpecifics(AutofillScanner* scanner, | 80 static bool ParseFieldSpecifics(AutofillScanner* scanner, |
81 const base::string16& pattern, | 81 const std::string& pattern, |
82 int match_type, | 82 int match_type, |
83 AutofillField** match); | 83 AutofillField** match); |
84 | 84 |
85 // Like ParseFieldSpecifics(), but applies |pattern| against the name and | 85 // Like ParseFieldSpecifics(), but applies |pattern| against the name and |
86 // label of the current field separately. If the return value is | 86 // label of the current field separately. If the return value is |
87 // RESULT_MATCH_NAME_LABEL, then |scanner| advances and |match| is filled if | 87 // RESULT_MATCH_NAME_LABEL, then |scanner| advances and |match| is filled if |
88 // it is non-NULL. Otherwise |scanner| does not advance and |match| does not | 88 // it is non-NULL. Otherwise |scanner| does not advance and |match| does not |
89 // change. | 89 // change. |
90 static ParseNameLabelResult ParseNameAndLabelSeparately( | 90 static ParseNameLabelResult ParseNameAndLabelSeparately( |
91 AutofillScanner* scanner, | 91 AutofillScanner* scanner, |
92 const base::string16& pattern, | 92 const std::string& pattern, |
93 int match_type, | 93 int match_type, |
94 AutofillField** match); | 94 AutofillField** match); |
95 | 95 |
96 // Attempts to parse a field with an empty label. Returns true | 96 // Attempts to parse a field with an empty label. Returns true |
97 // on success and fills |match| with a pointer to the field. | 97 // on success and fills |match| with a pointer to the field. |
98 static bool ParseEmptyLabel(AutofillScanner* scanner, AutofillField** match); | 98 static bool ParseEmptyLabel(AutofillScanner* scanner, AutofillField** match); |
99 | 99 |
100 // Adds an association between a field and a type to |map|. | 100 // Adds an association between a field and a type to |map|. |
101 static bool AddClassification(const AutofillField* field, | 101 static bool AddClassification(const AutofillField* field, |
102 ServerFieldType type, | 102 ServerFieldType type, |
(...skipping 13 matching lines...) Expand all Loading... | |
116 | 116 |
117 // Function pointer type for the parsing function that should be passed to the | 117 // Function pointer type for the parsing function that should be passed to the |
118 // ParseFormFieldsPass() helper function. | 118 // ParseFormFieldsPass() helper function. |
119 typedef scoped_ptr<FormField> ParseFunction(AutofillScanner* scanner); | 119 typedef scoped_ptr<FormField> ParseFunction(AutofillScanner* scanner); |
120 | 120 |
121 // Matches |pattern| to the contents of the field at the head of the | 121 // Matches |pattern| to the contents of the field at the head of the |
122 // |scanner|. | 122 // |scanner|. |
123 // Returns |true| if a match is found according to |match_type|, and |false| | 123 // Returns |true| if a match is found according to |match_type|, and |false| |
124 // otherwise. | 124 // otherwise. |
125 static bool MatchAndAdvance(AutofillScanner* scanner, | 125 static bool MatchAndAdvance(AutofillScanner* scanner, |
126 const base::string16& pattern, | 126 const std::string& pattern, |
127 int match_type, | 127 int match_type, |
128 AutofillField** match); | 128 AutofillField** match); |
129 | 129 |
130 // Matches the regular expression |pattern| against the components of |field| | 130 // Matches the regular expression |pattern| against the components of |field| |
131 // as specified in the |match_type| bit field (see |MatchType|). | 131 // as specified in the |match_type| bit field (see |MatchType|). |
132 static bool Match(const AutofillField* field, | 132 static bool Match(const AutofillField* field, |
133 const base::string16& pattern, | 133 const std::string& pattern, |
134 int match_type); | 134 int match_type); |
135 | 135 |
136 // Perform a "pass" over the |fields| where each pass uses the supplied | 136 // Perform a "pass" over the |fields| where each pass uses the supplied |
137 // |parse| method to match content to a given field type. | 137 // |parse| method to match content to a given field type. |
138 // |fields| is both an input and an output parameter. Upon exit |fields| | 138 // |fields| is both an input and an output parameter. Upon exit |fields| |
139 // holds any remaining unclassified fields for further processing. | 139 // holds any remaining unclassified fields for further processing. |
140 // Classification results of the processed fields are stored in |map|. | 140 // Classification results of the processed fields are stored in |map|. |
141 static void ParseFormFieldsPass(ParseFunction parse, | 141 static void ParseFormFieldsPass(ParseFunction parse, |
142 std::vector<AutofillField*>* fields, | 142 std::vector<AutofillField*>* fields, |
143 ServerFieldTypeMap* map); | 143 ServerFieldTypeMap* map); |
144 | 144 |
145 DISALLOW_COPY_AND_ASSIGN(FormField); | 145 DISALLOW_COPY_AND_ASSIGN(FormField); |
146 }; | 146 }; |
147 | 147 |
148 } // namespace autofill | 148 } // namespace autofill |
149 | 149 |
150 #endif // COMPONENTS_AUTOFILL_CORE_BROWSER_FORM_FIELD_H_ | 150 #endif // COMPONENTS_AUTOFILL_CORE_BROWSER_FORM_FIELD_H_ |
OLD | NEW |