| 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 "base/logging.h" | 7 #include "base/logging.h" |
| 8 #include "base/memory/scoped_ptr.h" | 8 #include "base/memory/scoped_ptr.h" |
| 9 #include "base/strings/string16.h" | 9 #include "base/strings/string16.h" |
| 10 #include "base/strings/string_util.h" | 10 #include "base/strings/string_util.h" |
| 11 #include "base/strings/utf_string_conversions.h" | 11 #include "base/strings/utf_string_conversions.h" |
| 12 #include "components/autofill/core/browser/autofill_field.h" | 12 #include "components/autofill/core/browser/autofill_field.h" |
| 13 #include "components/autofill/core/browser/autofill_regex_constants.h" | 13 #include "components/autofill/core/browser/autofill_regex_constants.h" |
| 14 #include "components/autofill/core/browser/autofill_scanner.h" | 14 #include "components/autofill/core/browser/autofill_scanner.h" |
| 15 #include "ui/base/l10n/l10n_util.h" | 15 #include "ui/base/l10n/l10n_util.h" |
| 16 | 16 |
| 17 namespace autofill { | 17 namespace autofill { |
| 18 namespace { | 18 namespace { |
| 19 | 19 |
| 20 // This string includes all area code separators, including NoText. | 20 // This string includes all area code separators, including NoText. |
| 21 base::string16 GetAreaRegex() { | 21 base::string16 GetAreaRegex() { |
| 22 base::string16 area_code = UTF8ToUTF16(autofill::kAreaCodeRe); | 22 base::string16 area_code = base::UTF8ToUTF16(autofill::kAreaCodeRe); |
| 23 area_code.append(ASCIIToUTF16("|")); // Regexp separator. | 23 area_code.append(base::ASCIIToUTF16("|")); // Regexp separator. |
| 24 area_code.append(UTF8ToUTF16(autofill::kAreaCodeNotextRe)); | 24 area_code.append(base::UTF8ToUTF16(autofill::kAreaCodeNotextRe)); |
| 25 return area_code; | 25 return area_code; |
| 26 } | 26 } |
| 27 | 27 |
| 28 } // namespace | 28 } // namespace |
| 29 | 29 |
| 30 PhoneField::~PhoneField() {} | 30 PhoneField::~PhoneField() {} |
| 31 | 31 |
| 32 // Phone field grammars - first matched grammar will be parsed. Grammars are | 32 // Phone field grammars - first matched grammar will be parsed. Grammars are |
| 33 // separated by { REGEX_SEPARATOR, FIELD_NONE, 0 }. Suffix and extension are | 33 // separated by { REGEX_SEPARATOR, FIELD_NONE, 0 }. Suffix and extension are |
| 34 // parsed separately unless they are necessary parts of the match. | 34 // parsed separately unless they are necessary parts of the match. |
| (...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 175 } | 175 } |
| 176 | 176 |
| 177 scoped_ptr<PhoneField> phone_field(new PhoneField); | 177 scoped_ptr<PhoneField> phone_field(new PhoneField); |
| 178 for (int i = 0; i < FIELD_MAX; ++i) | 178 for (int i = 0; i < FIELD_MAX; ++i) |
| 179 phone_field->parsed_phone_fields_[i] = parsed_fields[i]; | 179 phone_field->parsed_phone_fields_[i] = parsed_fields[i]; |
| 180 | 180 |
| 181 // Look for optional fields. | 181 // Look for optional fields. |
| 182 | 182 |
| 183 // Look for a third text box. | 183 // Look for a third text box. |
| 184 if (!phone_field->parsed_phone_fields_[FIELD_SUFFIX]) { | 184 if (!phone_field->parsed_phone_fields_[FIELD_SUFFIX]) { |
| 185 if (!ParseField(scanner, UTF8ToUTF16(autofill::kPhoneSuffixRe), | 185 if (!ParseField(scanner, base::UTF8ToUTF16(autofill::kPhoneSuffixRe), |
| 186 &phone_field->parsed_phone_fields_[FIELD_SUFFIX])) { | 186 &phone_field->parsed_phone_fields_[FIELD_SUFFIX])) { |
| 187 ParseField(scanner, UTF8ToUTF16(autofill::kPhoneSuffixSeparatorRe), | 187 ParseField(scanner, base::UTF8ToUTF16(autofill::kPhoneSuffixSeparatorRe), |
| 188 &phone_field->parsed_phone_fields_[FIELD_SUFFIX]); | 188 &phone_field->parsed_phone_fields_[FIELD_SUFFIX]); |
| 189 } | 189 } |
| 190 } | 190 } |
| 191 | 191 |
| 192 // Now look for an extension. | 192 // Now look for an extension. |
| 193 ParseField(scanner, UTF8ToUTF16(autofill::kPhoneExtensionRe), | 193 ParseField(scanner, base::UTF8ToUTF16(autofill::kPhoneExtensionRe), |
| 194 &phone_field->parsed_phone_fields_[FIELD_EXTENSION]); | 194 &phone_field->parsed_phone_fields_[FIELD_EXTENSION]); |
| 195 | 195 |
| 196 return phone_field.release(); | 196 return phone_field.release(); |
| 197 } | 197 } |
| 198 | 198 |
| 199 bool PhoneField::ClassifyField(ServerFieldTypeMap* map) const { | 199 bool PhoneField::ClassifyField(ServerFieldTypeMap* map) const { |
| 200 bool ok = true; | 200 bool ok = true; |
| 201 | 201 |
| 202 DCHECK(parsed_phone_fields_[FIELD_PHONE]); // Phone was correctly parsed. | 202 DCHECK(parsed_phone_fields_[FIELD_PHONE]); // Phone was correctly parsed. |
| 203 | 203 |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 242 } | 242 } |
| 243 | 243 |
| 244 PhoneField::PhoneField() { | 244 PhoneField::PhoneField() { |
| 245 memset(parsed_phone_fields_, 0, sizeof(parsed_phone_fields_)); | 245 memset(parsed_phone_fields_, 0, sizeof(parsed_phone_fields_)); |
| 246 } | 246 } |
| 247 | 247 |
| 248 // static | 248 // static |
| 249 base::string16 PhoneField::GetRegExp(RegexType regex_id) { | 249 base::string16 PhoneField::GetRegExp(RegexType regex_id) { |
| 250 switch (regex_id) { | 250 switch (regex_id) { |
| 251 case REGEX_COUNTRY: | 251 case REGEX_COUNTRY: |
| 252 return UTF8ToUTF16(autofill::kCountryCodeRe); | 252 return base::UTF8ToUTF16(autofill::kCountryCodeRe); |
| 253 case REGEX_AREA: | 253 case REGEX_AREA: |
| 254 return GetAreaRegex(); | 254 return GetAreaRegex(); |
| 255 case REGEX_AREA_NOTEXT: | 255 case REGEX_AREA_NOTEXT: |
| 256 return UTF8ToUTF16(autofill::kAreaCodeNotextRe); | 256 return base::UTF8ToUTF16(autofill::kAreaCodeNotextRe); |
| 257 case REGEX_PHONE: | 257 case REGEX_PHONE: |
| 258 return UTF8ToUTF16(autofill::kPhoneRe); | 258 return base::UTF8ToUTF16(autofill::kPhoneRe); |
| 259 case REGEX_PREFIX_SEPARATOR: | 259 case REGEX_PREFIX_SEPARATOR: |
| 260 return UTF8ToUTF16(autofill::kPhonePrefixSeparatorRe); | 260 return base::UTF8ToUTF16(autofill::kPhonePrefixSeparatorRe); |
| 261 case REGEX_PREFIX: | 261 case REGEX_PREFIX: |
| 262 return UTF8ToUTF16(autofill::kPhonePrefixRe); | 262 return base::UTF8ToUTF16(autofill::kPhonePrefixRe); |
| 263 case REGEX_SUFFIX_SEPARATOR: | 263 case REGEX_SUFFIX_SEPARATOR: |
| 264 return UTF8ToUTF16(autofill::kPhoneSuffixSeparatorRe); | 264 return base::UTF8ToUTF16(autofill::kPhoneSuffixSeparatorRe); |
| 265 case REGEX_SUFFIX: | 265 case REGEX_SUFFIX: |
| 266 return UTF8ToUTF16(autofill::kPhoneSuffixRe); | 266 return base::UTF8ToUTF16(autofill::kPhoneSuffixRe); |
| 267 case REGEX_EXTENSION: | 267 case REGEX_EXTENSION: |
| 268 return UTF8ToUTF16(autofill::kPhoneExtensionRe); | 268 return base::UTF8ToUTF16(autofill::kPhoneExtensionRe); |
| 269 default: | 269 default: |
| 270 NOTREACHED(); | 270 NOTREACHED(); |
| 271 break; | 271 break; |
| 272 } | 272 } |
| 273 return base::string16(); | 273 return base::string16(); |
| 274 } | 274 } |
| 275 | 275 |
| 276 } // namespace autofill | 276 } // namespace autofill |
| OLD | NEW |