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/name_field.h" | 5 #include "chrome/browser/autofill/name_field.h" |
6 | 6 |
7 #include "base/string_util.h" | 7 #include "base/string_util.h" |
8 #include "chrome/browser/autofill/autofill_type.h" | 8 #include "chrome/browser/autofill/autofill_type.h" |
9 | 9 |
10 NameField* NameField::Parse(std::vector<AutoFillField*>::const_iterator* iter, | 10 NameField* NameField::Parse(std::vector<AutoFillField*>::const_iterator* iter, |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
67 std::vector<AutoFillField*>::const_iterator q = *iter; | 67 std::vector<AutoFillField*>::const_iterator q = *iter; |
68 | 68 |
69 // A fair number of pages use the names "fname" and "lname" for naming | 69 // A fair number of pages use the names "fname" and "lname" for naming |
70 // first and last name fields (examples from the test suite: | 70 // first and last name fields (examples from the test suite: |
71 // BESTBUY_COM - Sign In2.html; Crate and Barrel Check Out.html; | 71 // BESTBUY_COM - Sign In2.html; Crate and Barrel Check Out.html; |
72 // dell_checkout1.html). At least one UK page (The China Shop2.html) | 72 // dell_checkout1.html). At least one UK page (The China Shop2.html) |
73 // asks, in stuffy English style, for just initials and a surname, | 73 // asks, in stuffy English style, for just initials and a surname, |
74 // so we match "initials" here (and just fill in a first name there, | 74 // so we match "initials" here (and just fill in a first name there, |
75 // American-style). | 75 // American-style). |
76 // The ".*first$" matches fields ending in "first" (example in sample8.html). | 76 // The ".*first$" matches fields ending in "first" (example in sample8.html). |
77 if (!ParseText(&q, | 77 string16 match = |
78 ASCIIToUTF16("first name|firstname|initials|fname|.*first$"), | 78 ASCIIToUTF16("first name|first_name|firstname|initials|fname|.*first$"); |
79 &v.first_name_)) | 79 if (!ParseText(&q, match, &v.first_name_)) |
80 return NULL; | 80 return NULL; |
81 | 81 |
82 // We check for a middle initial before checking for a middle name | 82 // We check for a middle initial before checking for a middle name |
83 // because at least one page (PC Connection.html) has a field marked | 83 // because at least one page (PC Connection.html) has a field marked |
84 // as both (the label text is "MI" and the element name is | 84 // as both (the label text is "MI" and the element name is |
85 // "txtmiddlename"); such a field probably actually represents a | 85 // "txtmiddlename"); such a field probably actually represents a |
86 // middle initial. | 86 // middle initial. |
87 if (ParseText(&q, | 87 match = ASCIIToUTF16("^mi$|middle initial|middleinitial|m.i."); |
88 ASCIIToUTF16("^mi$|middle initial|middleinitial|m.i."), | 88 if (ParseText(&q, match, &v.middle_name_)) { |
89 &v.middle_name_)) { | |
90 v.middle_initial_ = true; | 89 v.middle_initial_ = true; |
91 } else { | 90 } else { |
92 ParseText( | 91 match = ASCIIToUTF16("middle name|mname|middlename"); |
93 &q, ASCIIToUTF16("middle name|mname|middlename"), &v.middle_name_); | 92 ParseText(&q, match, &v.middle_name_); |
94 } | 93 } |
95 | 94 |
96 // The ".*last$" matches fields ending in "last" (example in sample8.html). | 95 // The ".*last$" matches fields ending in "last" (example in sample8.html). |
97 if (!ParseText(&q, | 96 match = ASCIIToUTF16("last name|last_name|lastname|lname|surname|.*last$"); |
98 ASCIIToUTF16("last name|lastname|lname|surname|.*last$"), | 97 if (!ParseText(&q, match, &v.last_name_)) |
99 &v.last_name_)) | |
100 return NULL; | 98 return NULL; |
101 | 99 |
102 *iter = q; | 100 *iter = q; |
103 return new FirstLastNameField(v); | 101 return new FirstLastNameField(v); |
104 } | 102 } |
105 | 103 |
106 FirstLastNameField* FirstLastNameField::ParseEcmlName( | 104 FirstLastNameField* FirstLastNameField::ParseEcmlName( |
107 std::vector<AutoFillField*>::const_iterator* iter) { | 105 std::vector<AutoFillField*>::const_iterator* iter) { |
108 FirstLastNameField field; | 106 FirstLastNameField field; |
109 std::vector<AutoFillField*>::const_iterator q = *iter; | 107 std::vector<AutoFillField*>::const_iterator q = *iter; |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
159 middle_initial_(false) { | 157 middle_initial_(false) { |
160 } | 158 } |
161 | 159 |
162 FirstLastNameField::FirstLastNameField(const FirstLastNameField& field) | 160 FirstLastNameField::FirstLastNameField(const FirstLastNameField& field) |
163 : NameField(), | 161 : NameField(), |
164 first_name_(field.first_name_), | 162 first_name_(field.first_name_), |
165 middle_name_(field.middle_name_), | 163 middle_name_(field.middle_name_), |
166 last_name_(field.last_name_), | 164 last_name_(field.last_name_), |
167 middle_initial_(field.middle_initial_) { | 165 middle_initial_(field.middle_initial_) { |
168 } | 166 } |
OLD | NEW |