Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(380)

Side by Side Diff: components/autofill/core/browser/autofill_data_util.cc

Issue 1868003003: Preserving first/middle/last names when an Autofill profile is submitted (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Addressing further mathp nits Created 4 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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/autofill_data_util.h" 5 #include "components/autofill/core/browser/autofill_data_util.h"
6 6
7 #include <vector> 7 #include <vector>
8 8
9 #include "base/strings/string_split.h" 9 #include "base/strings/string_split.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/field_types.h"
12 13
13 namespace autofill { 14 namespace autofill {
14 namespace data_util { 15 namespace data_util {
15 16
16 namespace { 17 namespace {
17 const char* const name_prefixes[] = { 18 const char* const name_prefixes[] = {
18 "1lt", "1st", "2lt", "2nd", "3rd", "admiral", "capt", 19 "1lt", "1st", "2lt", "2nd", "3rd", "admiral", "capt",
19 "captain", "col", "cpt", "dr", "gen", "general", "lcdr", 20 "captain", "col", "cpt", "dr", "gen", "general", "lcdr",
20 "lt", "ltc", "ltg", "ltjg", "maj", "major", "mg", 21 "lt", "ltc", "ltg", "ltjg", "maj", "major", "mg",
21 "mr", "mrs", "ms", "pastor", "prof", "rep", "reverend", 22 "mr", "mrs", "ms", "pastor", "prof", "rep", "reverend",
22 "rev", "sen", "st"}; 23 "rev", "sen", "st"};
23 24
24 const char* const name_suffixes[] = {"b.a", "ba", "d.d.s", "dds", "i", "ii", 25 const char* const name_suffixes[] = {"b.a", "ba", "d.d.s", "dds", "i", "ii",
25 "iii", "iv", "ix", "jr", "m.a", "m.d", 26 "iii", "iv", "ix", "jr", "m.a", "m.d",
26 "ma", "md", "ms", "ph.d", "phd", "sr", 27 "ma", "md", "ms", "ph.d", "phd", "sr",
27 "v", "vi", "vii", "viii", "x"}; 28 "v", "vi", "vii", "viii", "x"};
28 29
29 const char* const family_name_prefixes[] = {"d'", "de", "del", "der", "di", 30 const char* const family_name_prefixes[] = {"d'", "de", "del", "der", "di",
30 "la", "le", "mc", "san", "st", 31 "la", "le", "mc", "san", "st",
31 "ter", "van", "von"}; 32 "ter", "van", "von"};
32 33
34 const base::string16 kSpace = base::ASCIIToUTF16(" ");
Mathieu 2016/04/15 16:59:40 nit: can you move this into ProfileMatchesFullName
tmartino 2016/04/16 20:06:53 Done.
35 const base::string16 kPeriodSpace = base::ASCIIToUTF16(". ");
36
33 // Returns true if |set| contains |element|, modulo a final period. 37 // Returns true if |set| contains |element|, modulo a final period.
34 bool ContainsString(const char* const set[], 38 bool ContainsString(const char* const set[],
35 size_t set_size, 39 size_t set_size,
36 const base::string16& element) { 40 const base::string16& element) {
37 if (!base::IsStringASCII(element)) 41 if (!base::IsStringASCII(element))
38 return false; 42 return false;
39 43
40 base::string16 trimmed_element; 44 base::string16 trimmed_element;
41 base::TrimString(element, base::ASCIIToUTF16("."), &trimmed_element); 45 base::TrimString(element, base::ASCIIToUTF16("."), &trimmed_element);
42 46
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
121 parts.middle = name_tokens.back(); 125 parts.middle = name_tokens.back();
122 name_tokens.pop_back(); 126 name_tokens.pop_back();
123 } 127 }
124 128
125 // Remainder is given name. 129 // Remainder is given name.
126 parts.given = base::JoinString(name_tokens, base::ASCIIToUTF16(" ")); 130 parts.given = base::JoinString(name_tokens, base::ASCIIToUTF16(" "));
127 131
128 return parts; 132 return parts;
129 } 133 }
130 134
135 bool ProfileMatchesFullName(const base::string16 full_name,
136 const autofill::AutofillProfile& profile) {
137 // First Last
138 base::string16 candidate = profile.GetRawInfo(autofill::NAME_FIRST) + kSpace +
139 profile.GetRawInfo(autofill::NAME_LAST);
140 if (!full_name.compare(candidate)) {
141 return true;
142 }
143
144 // First Middle Last
145 candidate = profile.GetRawInfo(autofill::NAME_FIRST) + kSpace +
146 profile.GetRawInfo(autofill::NAME_MIDDLE) + kSpace +
147 profile.GetRawInfo(autofill::NAME_LAST);
148 if (!full_name.compare(candidate)) {
149 return true;
150 }
151
152 // First M Last
153 candidate = profile.GetRawInfo(autofill::NAME_FIRST) + kSpace +
154 profile.GetRawInfo(autofill::NAME_MIDDLE_INITIAL) + kSpace +
155 profile.GetRawInfo(autofill::NAME_LAST);
156 if (!full_name.compare(candidate)) {
157 return true;
158 }
159
160 // First M. Last
161 candidate = profile.GetRawInfo(autofill::NAME_FIRST) + kSpace +
162 profile.GetRawInfo(autofill::NAME_MIDDLE_INITIAL) + kPeriodSpace +
163 profile.GetRawInfo(autofill::NAME_LAST);
164 if (!full_name.compare(candidate)) {
165 return true;
166 }
167
168 return false;
169 }
170
131 } // namespace data_util 171 } // namespace data_util
132 } // namespace autofill 172 } // namespace autofill
OLDNEW
« no previous file with comments | « components/autofill/core/browser/autofill_data_util.h ('k') | components/autofill/core/browser/autofill_data_util_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698