| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 "chrome/browser/autofill/phone_field.h" | 5 #include "chrome/browser/autofill/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/string16.h" | 9 #include "base/string16.h" |
| 10 #include "base/string_util.h" | 10 #include "base/string_util.h" |
| 11 #include "base/utf_string_conversions.h" | 11 #include "base/utf_string_conversions.h" |
| 12 #include "chrome/browser/autofill/autofill_field.h" | 12 #include "chrome/browser/autofill/autofill_field.h" |
| 13 #include "chrome/browser/autofill/autofill_regex_constants.h" |
| 13 #include "chrome/browser/autofill/autofill_scanner.h" | 14 #include "chrome/browser/autofill/autofill_scanner.h" |
| 14 #include "chrome/browser/autofill/fax_number.h" | 15 #include "chrome/browser/autofill/fax_number.h" |
| 15 #include "chrome/browser/autofill/home_phone_number.h" | 16 #include "chrome/browser/autofill/home_phone_number.h" |
| 16 #include "ui/base/l10n/l10n_util.h" | 17 #include "ui/base/l10n/l10n_util.h" |
| 17 | 18 |
| 18 namespace { | |
| 19 | |
| 20 const char kPhoneRe[] = | |
| 21 "phone|mobile" | |
| 22 // de-DE | |
| 23 "|telefonnummer" | |
| 24 // es | |
| 25 "|telefono|tel\xc3\xa9""fono" | |
| 26 // fr-FR | |
| 27 "|telfixe" | |
| 28 // ja-JP | |
| 29 "|\xe9\x9b\xbb\xe8\xa9\xb1" | |
| 30 // pt-BR, pt-PT | |
| 31 "|telefone|telemovel" | |
| 32 // ru | |
| 33 "|\xd1\x82\xd0\xb5\xd0\xbb\xd0\xb5\xd1\x84\xd0\xbe\xd0\xbd" | |
| 34 // zh-CN | |
| 35 "|\xe7\x94\xb5\xe8\xaf\x9d" | |
| 36 // ko-KR | |
| 37 "|(\xec\xa0\x84\xed\x99\x94|\xed\x95\xb8\xeb\x93\x9c\xed\x8f\xb0|\xed\x9c" | |
| 38 "\xb4\xeb\x8c\x80\xed\x8f\xb0|\xed\x9c\xb4\xeb\x8c\x80\xec\xa0\x84\xed" | |
| 39 "\x99\x94)(.?\xeb\xb2\x88\xed\x98\xb8)?"; | |
| 40 const char kCountryCodeRe[] = | |
| 41 "country.*code|ccode|_cc"; | |
| 42 const char kAreaCodeNotextRe[] = | |
| 43 "^\\($"; | |
| 44 const char kAreaCodeRe[] = | |
| 45 "area.*code|acode|area" | |
| 46 // ko-KR | |
| 47 "|\xec\xa7\x80\xec\x97\xad.?\xeb\xb2\x88\xed\x98\xb8"; | |
| 48 const char kFaxRe[] = | |
| 49 "fax" | |
| 50 // fr-FR | |
| 51 "|t\xc3\xa9l\xc3\xa9""copie|telecopie" | |
| 52 // ja-JP | |
| 53 "|\xe3\x83\x95\xe3\x82\xa1\xe3\x83\x83\xe3\x82\xaf\xe3\x82\xb9" | |
| 54 // ru | |
| 55 "|\xd1\x84\xd0\xb0\xd0\xba\xd1\x81" | |
| 56 // zh-CN | |
| 57 "|\xe4\xbc\xa0\xe7\x9c\x9f" | |
| 58 // zh-TW | |
| 59 "|\xe5\x82\xb3\xe7\x9c\x9f" | |
| 60 // ko-KR | |
| 61 "|\xed\x8c\xa9\xec\x8a\xa4(.?\xeb\xb2\x88\xed\x98\xb8)?"; | |
| 62 const char kPhonePrefixSeparatorRe[] = | |
| 63 "^-$|^\\)$"; | |
| 64 const char kPhoneSuffixSeparatorRe[] = | |
| 65 "^-$"; | |
| 66 const char kPhonePrefixRe[] = | |
| 67 "prefix|exchange" | |
| 68 // fr-FR | |
| 69 "|preselection" | |
| 70 // pt-BR, pt-PT | |
| 71 "|ddd"; | |
| 72 const char kPhoneSuffixRe[] = | |
| 73 "suffix"; | |
| 74 const char kPhoneExtensionRe[] = | |
| 75 "\\bext|ext\\b|extension" | |
| 76 // pt-BR, pt-PT | |
| 77 "|ramal"; | |
| 78 | |
| 79 } // namespace | |
| 80 | |
| 81 // Phone field grammars - first matched grammar will be parsed. Grammars are | 19 // Phone field grammars - first matched grammar will be parsed. Grammars are |
| 82 // separated by { REGEX_SEPARATOR, FIELD_NONE, 0 }. Suffix and extension are | 20 // separated by { REGEX_SEPARATOR, FIELD_NONE, 0 }. Suffix and extension are |
| 83 // parsed separately unless they are necessary parts of the match. | 21 // parsed separately unless they are necessary parts of the match. |
| 84 // The following notation is used to describe the patterns: | 22 // The following notation is used to describe the patterns: |
| 85 // <cc> - country code field. | 23 // <cc> - country code field. |
| 86 // <ac> - area code field. | 24 // <ac> - area code field. |
| 87 // <phone> - phone or prefix. | 25 // <phone> - phone or prefix. |
| 88 // <suffix> - suffix. | 26 // <suffix> - suffix. |
| 89 // <ext> - extension. | 27 // <ext> - extension. |
| 90 // :N means field is limited to N characters, otherwise it is unlimited. | 28 // :N means field is limited to N characters, otherwise it is unlimited. |
| (...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 232 ok = AddClassification(parsed_phone_fields_[FIELD_PHONE], | 170 ok = AddClassification(parsed_phone_fields_[FIELD_PHONE], |
| 233 number_->GetWholeNumberType(), | 171 number_->GetWholeNumberType(), |
| 234 map); | 172 map); |
| 235 } | 173 } |
| 236 | 174 |
| 237 return ok; | 175 return ok; |
| 238 } | 176 } |
| 239 | 177 |
| 240 string16 PhoneField::GetCountryRegex() const { | 178 string16 PhoneField::GetCountryRegex() const { |
| 241 // This one is the same for Home and Fax numbers. | 179 // This one is the same for Home and Fax numbers. |
| 242 return UTF8ToUTF16(kCountryCodeRe); | 180 return UTF8ToUTF16(autofill::kCountryCodeRe); |
| 243 } | 181 } |
| 244 | 182 |
| 245 string16 PhoneField::GetAreaRegex() const { | 183 string16 PhoneField::GetAreaRegex() const { |
| 246 // This one is the same for Home and Fax numbers. | 184 // This one is the same for Home and Fax numbers. |
| 247 string16 area_code = UTF8ToUTF16(kAreaCodeRe); | 185 string16 area_code = UTF8ToUTF16(autofill::kAreaCodeRe); |
| 248 area_code.append(ASCIIToUTF16("|")); // Regexp separator. | 186 area_code.append(ASCIIToUTF16("|")); // Regexp separator. |
| 249 area_code.append(GetAreaNoTextRegex()); | 187 area_code.append(GetAreaNoTextRegex()); |
| 250 return area_code; | 188 return area_code; |
| 251 } | 189 } |
| 252 | 190 |
| 253 string16 PhoneField::GetAreaNoTextRegex() const { | 191 string16 PhoneField::GetAreaNoTextRegex() const { |
| 254 // This one is the same for Home and Fax numbers. | 192 // This one is the same for Home and Fax numbers. |
| 255 return UTF8ToUTF16(kAreaCodeNotextRe); | 193 return UTF8ToUTF16(autofill::kAreaCodeNotextRe); |
| 256 } | 194 } |
| 257 | 195 |
| 258 string16 PhoneField::GetPhoneRegex() const { | 196 string16 PhoneField::GetPhoneRegex() const { |
| 259 if (phone_type_ == HOME_PHONE) | 197 if (phone_type_ == HOME_PHONE) |
| 260 return UTF8ToUTF16(kPhoneRe); | 198 return UTF8ToUTF16(autofill::kPhoneRe); |
| 261 else if (phone_type_ == FAX_PHONE) | 199 else if (phone_type_ == FAX_PHONE) |
| 262 return UTF8ToUTF16(kFaxRe); | 200 return UTF8ToUTF16(autofill::kFaxRe); |
| 263 else | 201 else |
| 264 NOTREACHED(); | 202 NOTREACHED(); |
| 265 return string16(); | 203 return string16(); |
| 266 } | 204 } |
| 267 | 205 |
| 268 string16 PhoneField::GetPrefixSeparatorRegex() const { | 206 string16 PhoneField::GetPrefixSeparatorRegex() const { |
| 269 // This one is the same for Home and Fax numbers. | 207 // This one is the same for Home and Fax numbers. |
| 270 return UTF8ToUTF16(kPhonePrefixSeparatorRe); | 208 return UTF8ToUTF16(autofill::kPhonePrefixSeparatorRe); |
| 271 } | 209 } |
| 272 | 210 |
| 273 string16 PhoneField::GetPrefixRegex() const { | 211 string16 PhoneField::GetPrefixRegex() const { |
| 274 // This one is the same for Home and Fax numbers. | 212 // This one is the same for Home and Fax numbers. |
| 275 return UTF8ToUTF16(kPhonePrefixRe); | 213 return UTF8ToUTF16(autofill::kPhonePrefixRe); |
| 276 } | 214 } |
| 277 | 215 |
| 278 string16 PhoneField::GetSuffixSeparatorRegex() const { | 216 string16 PhoneField::GetSuffixSeparatorRegex() const { |
| 279 // This one is the same for Home and Fax numbers. | 217 // This one is the same for Home and Fax numbers. |
| 280 return UTF8ToUTF16(kPhoneSuffixSeparatorRe); | 218 return UTF8ToUTF16(autofill::kPhoneSuffixSeparatorRe); |
| 281 } | 219 } |
| 282 | 220 |
| 283 string16 PhoneField::GetSuffixRegex() const { | 221 string16 PhoneField::GetSuffixRegex() const { |
| 284 // This one is the same for Home and Fax numbers. | 222 // This one is the same for Home and Fax numbers. |
| 285 return UTF8ToUTF16(kPhoneSuffixRe); | 223 return UTF8ToUTF16(autofill::kPhoneSuffixRe); |
| 286 } | 224 } |
| 287 | 225 |
| 288 string16 PhoneField::GetExtensionRegex() const { | 226 string16 PhoneField::GetExtensionRegex() const { |
| 289 // This one is the same for Home and Fax numbers. | 227 // This one is the same for Home and Fax numbers. |
| 290 return UTF8ToUTF16(kPhoneExtensionRe); | 228 return UTF8ToUTF16(autofill::kPhoneExtensionRe); |
| 291 } | 229 } |
| 292 | 230 |
| 293 string16 PhoneField::GetRegExp(RegexType regex_id) const { | 231 string16 PhoneField::GetRegExp(RegexType regex_id) const { |
| 294 switch (regex_id) { | 232 switch (regex_id) { |
| 295 case REGEX_COUNTRY: return GetCountryRegex(); | 233 case REGEX_COUNTRY: return GetCountryRegex(); |
| 296 case REGEX_AREA: return GetAreaRegex(); | 234 case REGEX_AREA: return GetAreaRegex(); |
| 297 case REGEX_AREA_NOTEXT: return GetAreaNoTextRegex(); | 235 case REGEX_AREA_NOTEXT: return GetAreaNoTextRegex(); |
| 298 case REGEX_PHONE: return GetPhoneRegex(); | 236 case REGEX_PHONE: return GetPhoneRegex(); |
| 299 case REGEX_PREFIX_SEPARATOR: return GetPrefixSeparatorRegex(); | 237 case REGEX_PREFIX_SEPARATOR: return GetPrefixSeparatorRegex(); |
| 300 case REGEX_PREFIX: return GetPrefixRegex(); | 238 case REGEX_PREFIX: return GetPrefixRegex(); |
| (...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 389 void PhoneField::SetPhoneType(PhoneType phone_type) { | 327 void PhoneField::SetPhoneType(PhoneType phone_type) { |
| 390 // Field types are different as well, so we create a temporary phone number, | 328 // Field types are different as well, so we create a temporary phone number, |
| 391 // to get relevant field types. | 329 // to get relevant field types. |
| 392 if (phone_type == HOME_PHONE) | 330 if (phone_type == HOME_PHONE) |
| 393 number_.reset(new PhoneNumber(AutofillType::PHONE_HOME, NULL)); | 331 number_.reset(new PhoneNumber(AutofillType::PHONE_HOME, NULL)); |
| 394 else | 332 else |
| 395 number_.reset(new PhoneNumber(AutofillType::PHONE_FAX, NULL)); | 333 number_.reset(new PhoneNumber(AutofillType::PHONE_FAX, NULL)); |
| 396 phone_type_ = phone_type; | 334 phone_type_ = phone_type; |
| 397 } | 335 } |
| 398 | 336 |
| OLD | NEW |