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 #include "components/autofill/core/browser/phone_field.h" | 5 #include "components/autofill/core/browser/phone_field.h" |
6 | 6 |
7 #include <string.h> | 7 #include <string.h> |
| 8 |
| 9 #include <memory> |
8 #include <utility> | 10 #include <utility> |
9 | 11 |
10 #include "base/logging.h" | 12 #include "base/logging.h" |
11 #include "base/macros.h" | 13 #include "base/macros.h" |
12 #include "base/memory/scoped_ptr.h" | |
13 #include "base/strings/string16.h" | 14 #include "base/strings/string16.h" |
14 #include "base/strings/string_util.h" | 15 #include "base/strings/string_util.h" |
15 #include "base/strings/utf_string_conversions.h" | 16 #include "base/strings/utf_string_conversions.h" |
16 #include "components/autofill/core/browser/autofill_field.h" | 17 #include "components/autofill/core/browser/autofill_field.h" |
17 #include "components/autofill/core/browser/autofill_regex_constants.h" | 18 #include "components/autofill/core/browser/autofill_regex_constants.h" |
18 #include "components/autofill/core/browser/autofill_scanner.h" | 19 #include "components/autofill/core/browser/autofill_scanner.h" |
19 | 20 |
20 namespace autofill { | 21 namespace autofill { |
21 namespace { | 22 namespace { |
22 | 23 |
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
122 {REGEX_SEPARATOR, FIELD_NONE, 0}, | 123 {REGEX_SEPARATOR, FIELD_NONE, 0}, |
123 // Ext: <ext> | 124 // Ext: <ext> |
124 {REGEX_EXTENSION, FIELD_EXTENSION, 0}, | 125 {REGEX_EXTENSION, FIELD_EXTENSION, 0}, |
125 {REGEX_SEPARATOR, FIELD_NONE, 0}, | 126 {REGEX_SEPARATOR, FIELD_NONE, 0}, |
126 // Phone: <phone> (Ext: <ext>)? | 127 // Phone: <phone> (Ext: <ext>)? |
127 {REGEX_PHONE, FIELD_PHONE, 0}, | 128 {REGEX_PHONE, FIELD_PHONE, 0}, |
128 {REGEX_SEPARATOR, FIELD_NONE, 0}, | 129 {REGEX_SEPARATOR, FIELD_NONE, 0}, |
129 }; | 130 }; |
130 | 131 |
131 // static | 132 // static |
132 scoped_ptr<FormField> PhoneField::Parse(AutofillScanner* scanner) { | 133 std::unique_ptr<FormField> PhoneField::Parse(AutofillScanner* scanner) { |
133 if (scanner->IsEnd()) | 134 if (scanner->IsEnd()) |
134 return nullptr; | 135 return nullptr; |
135 | 136 |
136 size_t start_cursor = scanner->SaveCursor(); | 137 size_t start_cursor = scanner->SaveCursor(); |
137 | 138 |
138 // The form owns the following variables, so they should not be deleted. | 139 // The form owns the following variables, so they should not be deleted. |
139 AutofillField* parsed_fields[FIELD_MAX]; | 140 AutofillField* parsed_fields[FIELD_MAX]; |
140 | 141 |
141 for (size_t i = 0; i < arraysize(kPhoneFieldGrammars); ++i) { | 142 for (size_t i = 0; i < arraysize(kPhoneFieldGrammars); ++i) { |
142 memset(parsed_fields, 0, sizeof(parsed_fields)); | 143 memset(parsed_fields, 0, sizeof(parsed_fields)); |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
175 if (i + 1 == arraysize(kPhoneFieldGrammars)) { | 176 if (i + 1 == arraysize(kPhoneFieldGrammars)) { |
176 return nullptr; // Tried through all the possibilities - did not match. | 177 return nullptr; // Tried through all the possibilities - did not match. |
177 } | 178 } |
178 } | 179 } |
179 | 180 |
180 if (!parsed_fields[FIELD_PHONE]) { | 181 if (!parsed_fields[FIELD_PHONE]) { |
181 scanner->RewindTo(start_cursor); | 182 scanner->RewindTo(start_cursor); |
182 return nullptr; | 183 return nullptr; |
183 } | 184 } |
184 | 185 |
185 scoped_ptr<PhoneField> phone_field(new PhoneField); | 186 std::unique_ptr<PhoneField> phone_field(new PhoneField); |
186 for (int i = 0; i < FIELD_MAX; ++i) | 187 for (int i = 0; i < FIELD_MAX; ++i) |
187 phone_field->parsed_phone_fields_[i] = parsed_fields[i]; | 188 phone_field->parsed_phone_fields_[i] = parsed_fields[i]; |
188 | 189 |
189 // Look for optional fields. | 190 // Look for optional fields. |
190 | 191 |
191 // Look for a third text box. | 192 // Look for a third text box. |
192 if (!phone_field->parsed_phone_fields_[FIELD_SUFFIX]) { | 193 if (!phone_field->parsed_phone_fields_[FIELD_SUFFIX]) { |
193 if (!ParsePhoneField(scanner, kPhoneSuffixRe, | 194 if (!ParsePhoneField(scanner, kPhoneSuffixRe, |
194 &phone_field->parsed_phone_fields_[FIELD_SUFFIX])) { | 195 &phone_field->parsed_phone_fields_[FIELD_SUFFIX])) { |
195 ParsePhoneField(scanner, kPhoneSuffixSeparatorRe, | 196 ParsePhoneField(scanner, kPhoneSuffixSeparatorRe, |
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
289 bool PhoneField::ParsePhoneField(AutofillScanner* scanner, | 290 bool PhoneField::ParsePhoneField(AutofillScanner* scanner, |
290 const std::string& regex, | 291 const std::string& regex, |
291 AutofillField** field) { | 292 AutofillField** field) { |
292 return ParseFieldSpecifics(scanner, | 293 return ParseFieldSpecifics(scanner, |
293 base::UTF8ToUTF16(regex), | 294 base::UTF8ToUTF16(regex), |
294 MATCH_DEFAULT | MATCH_TELEPHONE | MATCH_NUMBER, | 295 MATCH_DEFAULT | MATCH_TELEPHONE | MATCH_NUMBER, |
295 field); | 296 field); |
296 } | 297 } |
297 | 298 |
298 } // namespace autofill | 299 } // namespace autofill |
OLD | NEW |