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 184 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
195 return false; | 195 return false; |
196 | 196 |
197 string16 pattern; | 197 string16 pattern; |
198 if (is_ecml) { | 198 if (is_ecml) { |
199 pattern = GetEcmlPattern(kEcmlShipToAddress1, | 199 pattern = GetEcmlPattern(kEcmlShipToAddress1, |
200 kEcmlBillToAddress1, '|'); | 200 kEcmlBillToAddress1, '|'); |
201 if (!ParseText(iter, pattern, &address_field->address1_)) | 201 if (!ParseText(iter, pattern, &address_field->address1_)) |
202 return false; | 202 return false; |
203 } else { | 203 } else { |
204 pattern = | 204 pattern = |
205 ASCIIToUTF16("street|address line|address1|street_line1|addr1"); | 205 ASCIIToUTF16("address.?line|address1|addr1|street"); |
206 string16 label_pattern = ASCIIToUTF16("address"); | 206 string16 label_pattern = ASCIIToUTF16("address"); |
207 | 207 |
208 if (!ParseText(iter, pattern, &address_field->address1_)) | 208 if (!ParseText(iter, pattern, &address_field->address1_)) |
209 if (!ParseLabelText(iter, label_pattern, &address_field->address1_)) | 209 if (!ParseLabelText(iter, label_pattern, &address_field->address1_)) |
210 return false; | 210 return false; |
211 } | 211 } |
212 | 212 |
213 // Optionally parse more address lines, which may have empty labels. | 213 // Optionally parse more address lines, which may have empty labels. |
214 // Some pages have 3 address lines (eg SharperImageModifyAccount.html) | 214 // Some pages have 3 address lines (eg SharperImageModifyAccount.html) |
215 // Some pages even have 4 address lines (e.g. uk/ShoesDirect2.html)! | 215 // Some pages even have 4 address lines (e.g. uk/ShoesDirect2.html)! |
216 if (is_ecml) { | 216 if (is_ecml) { |
217 pattern = GetEcmlPattern(kEcmlShipToAddress2, | 217 pattern = GetEcmlPattern(kEcmlShipToAddress2, |
218 kEcmlBillToAddress2, '|'); | 218 kEcmlBillToAddress2, '|'); |
219 if (!ParseEmptyText(iter, &address_field->address2_)) | 219 if (!ParseEmptyText(iter, &address_field->address2_)) |
220 ParseText(iter, pattern, &address_field->address2_); | 220 ParseText(iter, pattern, &address_field->address2_); |
221 } else { | 221 } else { |
222 pattern = ASCIIToUTF16("address2|street|street_line2|addr2|suite|unit"); | 222 pattern = ASCIIToUTF16("address.?line2|address2|addr2|street|suite|unit"); |
223 string16 label_pattern = ASCIIToUTF16("address"); | 223 string16 label_pattern = ASCIIToUTF16("address"); |
224 if (!ParseEmptyText(iter, &address_field->address2_)) | 224 if (!ParseEmptyText(iter, &address_field->address2_)) |
225 if (!ParseText(iter, pattern, &address_field->address2_)) | 225 if (!ParseText(iter, pattern, &address_field->address2_)) |
226 ParseLabelText(iter, label_pattern, &address_field->address2_); | 226 ParseLabelText(iter, label_pattern, &address_field->address2_); |
227 } | 227 } |
228 | 228 |
229 // Try for a third line, which we will promptly discard. | 229 // Try for a third line, which we will promptly discard. |
230 if (address_field->address2_ != NULL) { | 230 if (address_field->address2_ != NULL) { |
231 if (is_ecml) { | 231 if (is_ecml) { |
232 pattern = GetEcmlPattern(kEcmlShipToAddress3, | 232 pattern = GetEcmlPattern(kEcmlShipToAddress3, |
233 kEcmlBillToAddress3, '|'); | 233 kEcmlBillToAddress3, '|'); |
234 ParseText(iter, pattern); | 234 ParseText(iter, pattern); |
235 } else { | 235 } else { |
236 pattern = ASCIIToUTF16("address3|street|street_line3|addr3|line3"); | 236 pattern = ASCIIToUTF16("address.?line3|address3|addr3|street|line3"); |
237 string16 label_pattern = ASCIIToUTF16("address"); | |
238 if (!ParseEmptyText(iter, NULL)) | 237 if (!ParseEmptyText(iter, NULL)) |
239 if (!ParseText(iter, pattern, NULL)) | 238 ParseText(iter, pattern, NULL); |
240 ParseLabelText(iter, label_pattern, NULL); | |
241 } | 239 } |
242 } | 240 } |
243 | 241 |
244 return true; | 242 return true; |
245 } | 243 } |
246 | 244 |
247 // static | 245 // static |
248 bool AddressField::ParseCountry( | 246 bool AddressField::ParseCountry( |
249 std::vector<AutoFillField*>::const_iterator* iter, | 247 std::vector<AutoFillField*>::const_iterator* iter, |
250 bool is_ecml, AddressField* address_field) { | 248 bool is_ecml, AddressField* address_field) { |
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
378 return kBillingAddress; | 376 return kBillingAddress; |
379 | 377 |
380 if (bill == string16::npos && ship != string16::npos) | 378 if (bill == string16::npos && ship != string16::npos) |
381 return kShippingAddress; | 379 return kShippingAddress; |
382 | 380 |
383 if (bill > ship) | 381 if (bill > ship) |
384 return kBillingAddress; | 382 return kBillingAddress; |
385 | 383 |
386 return kShippingAddress; | 384 return kShippingAddress; |
387 } | 385 } |
OLD | NEW |