Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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/address_field.h" | 5 #include "chrome/browser/autofill/address_field.h" |
| 6 | 6 |
| 7 #include "base/logging.h" | 7 #include "base/logging.h" |
| 8 #include "base/scoped_ptr.h" | 8 #include "base/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" |
| (...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 84 // The ECML standard uses 2 letter country codes. So we will | 84 // The ECML standard uses 2 letter country codes. So we will |
| 85 // have to remember that this is an ECML form, for when we fill | 85 // have to remember that this is an ECML form, for when we fill |
| 86 // it out. | 86 // it out. |
| 87 address_field->is_ecml_ = is_ecml; | 87 address_field->is_ecml_ = is_ecml; |
| 88 | 88 |
| 89 // Allow address fields to appear in any order. | 89 // Allow address fields to appear in any order. |
| 90 while (true) { | 90 while (true) { |
| 91 if (ParseCompany(&q, is_ecml, address_field.get()) || | 91 if (ParseCompany(&q, is_ecml, address_field.get()) || |
| 92 ParseAddressLines(&q, is_ecml, address_field.get()) || | 92 ParseAddressLines(&q, is_ecml, address_field.get()) || |
| 93 ParseCity(&q, is_ecml, address_field.get()) || | 93 ParseCity(&q, is_ecml, address_field.get()) || |
| 94 ParseState(&q, is_ecml, address_field.get()) || | |
| 94 ParseZipCode(&q, is_ecml, address_field.get()) || | 95 ParseZipCode(&q, is_ecml, address_field.get()) || |
| 95 ParseCountry(&q, is_ecml, address_field.get())) { | 96 ParseCountry(&q, is_ecml, address_field.get())) { |
| 96 continue; | 97 continue; |
| 97 } else if ((!address_field->state_ || address_field->state_->IsEmpty()) && | |
| 98 address_field->ParseState(&q, is_ecml, address_field.get())) { | |
| 99 continue; | |
| 100 } else if (ParseText(&q, ASCIIToUTF16("attention|attn.")) || | 98 } else if (ParseText(&q, ASCIIToUTF16("attention|attn.")) || |
| 101 ParseText(&q, ASCIIToUTF16("province|region|other"))) { | 99 ParseText(&q, ASCIIToUTF16("province|region|other"))) { |
| 102 // We ignore the following: | 100 // We ignore the following: |
| 103 // * Attention. | 101 // * Attention. |
| 104 // * Province/Region/Other. | 102 // * Province/Region/Other. |
| 105 continue; | 103 continue; |
| 106 } else if (*q != **iter && ParseEmpty(&q)) { | 104 } else if (*q != **iter && ParseEmpty(&q)) { |
| 107 // Ignore non-labeled fields within an address; the page | 105 // Ignore non-labeled fields within an address; the page |
| 108 // MapQuest Driving Directions North America.html contains such a field. | 106 // MapQuest Driving Directions North America.html contains such a field. |
| 109 // We only ignore such fields after we've parsed at least one other field; | 107 // We only ignore such fields after we've parsed at least one other field; |
| (...skipping 222 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 332 pattern = GetEcmlPattern(kEcmlShipToCity, kEcmlBillToCity, '|'); | 330 pattern = GetEcmlPattern(kEcmlShipToCity, kEcmlBillToCity, '|'); |
| 333 else | 331 else |
| 334 pattern = ASCIIToUTF16("city|town"); | 332 pattern = ASCIIToUTF16("city|town"); |
| 335 | 333 |
| 336 if (!ParseText(iter, pattern, &address_field->city_)) | 334 if (!ParseText(iter, pattern, &address_field->city_)) |
| 337 return false; | 335 return false; |
| 338 | 336 |
| 339 return true; | 337 return true; |
| 340 } | 338 } |
| 341 | 339 |
| 340 // static | |
| 342 bool AddressField::ParseState( | 341 bool AddressField::ParseState( |
| 343 std::vector<AutoFillField*>::const_iterator* iter, | 342 std::vector<AutoFillField*>::const_iterator* iter, |
| 344 bool is_ecml, AddressField* address_field) { | 343 bool is_ecml, AddressField* address_field) { |
| 344 if (address_field->state_) | |
|
Ilya Sherman
2010/11/02 15:35:08
nit: Do we not want "&& !address_field->state_->Is
James Hawkins
2010/11/02 17:32:14
No. I don't know why it was written in the first p
| |
| 345 return false; | |
| 346 | |
| 345 string16 pattern; | 347 string16 pattern; |
| 346 if (is_ecml) | 348 if (is_ecml) |
| 347 pattern = GetEcmlPattern(kEcmlShipToStateProv, kEcmlBillToStateProv, '|'); | 349 pattern = GetEcmlPattern(kEcmlShipToStateProv, kEcmlBillToStateProv, '|'); |
| 348 else | 350 else |
| 349 pattern = ASCIIToUTF16("state|county"); | 351 pattern = ASCIIToUTF16("state|county"); |
| 350 | 352 |
| 351 if (!ParseText(iter, pattern, &address_field->state_)) | 353 if (!ParseText(iter, pattern, &address_field->state_)) |
| 352 return false; | 354 return false; |
| 353 | 355 |
| 354 return true; | 356 return true; |
| (...skipping 21 matching lines...) Expand all Loading... | |
| 376 return kBillingAddress; | 378 return kBillingAddress; |
| 377 | 379 |
| 378 if (bill == string16::npos && ship != string16::npos) | 380 if (bill == string16::npos && ship != string16::npos) |
| 379 return kShippingAddress; | 381 return kShippingAddress; |
| 380 | 382 |
| 381 if (bill > ship) | 383 if (bill > ship) |
| 382 return kBillingAddress; | 384 return kBillingAddress; |
| 383 | 385 |
| 384 return kShippingAddress; | 386 return kShippingAddress; |
| 385 } | 387 } |
| OLD | NEW |