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

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 stevenjb 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",
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after
121 parts.middle = name_tokens.back(); 122 parts.middle = name_tokens.back();
122 name_tokens.pop_back(); 123 name_tokens.pop_back();
123 } 124 }
124 125
125 // Remainder is given name. 126 // Remainder is given name.
126 parts.given = base::JoinString(name_tokens, base::ASCIIToUTF16(" ")); 127 parts.given = base::JoinString(name_tokens, base::ASCIIToUTF16(" "));
127 128
128 return parts; 129 return parts;
129 } 130 }
130 131
132 bool ProfileMatchesFullName(const base::string16 full_name,
133 const autofill::AutofillProfile& profile) {
134 const base::string16 kSpace = base::ASCIIToUTF16(" ");
135 const base::string16 kPeriodSpace = base::ASCIIToUTF16(". ");
136
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