Chromium Code Reviews| Index: components/autofill/core/browser/autofill_data_util.cc |
| diff --git a/components/autofill/core/browser/autofill_data_util.cc b/components/autofill/core/browser/autofill_data_util.cc |
| index 63dc48213a01f9e4e7d1b95df2df7717d69696f7..c7b1a6fee79a327dcc8481fef849f2262e2cd3c4 100644 |
| --- a/components/autofill/core/browser/autofill_data_util.cc |
| +++ b/components/autofill/core/browser/autofill_data_util.cc |
| @@ -9,6 +9,7 @@ |
| #include "base/strings/string_split.h" |
| #include "base/strings/string_util.h" |
| #include "base/strings/utf_string_conversions.h" |
| +#include "components/autofill/core/browser/field_types.h" |
| namespace autofill { |
| namespace data_util { |
| @@ -73,6 +74,15 @@ void StripSuffixes(std::vector<base::string16>* name_tokens) { |
| } |
| } |
| +// Concatenates two strings, adding a space and, optionally, a period. |
| +base::string16 StringConcatenationHelper(base::string16 first, |
| + base::string16 second, |
| + bool period) { |
| + base::string16 delimiter = |
| + period ? base::UTF8ToUTF16(". ") : base::UTF8ToUTF16(" "); |
| + return first + delimiter + second; |
| +} |
| + |
| } // namespace |
| NameParts SplitName(const base::string16& name) { |
| @@ -128,5 +138,48 @@ NameParts SplitName(const base::string16& name) { |
| return parts; |
| } |
| +bool ProfileMatchesFullName(const base::string16 full_name, |
| + const autofill::AutofillProfile& profile) { |
| + // First Last |
| + base::string16 candidate = |
| + StringConcatenationHelper(profile.GetRawInfo(autofill::NAME_FIRST), |
|
Mathieu
2016/04/13 18:12:24
Not sure this StringConcatenationHelper is helping
tmartino
2016/04/13 19:43:25
Agreed.
|
| + profile.GetRawInfo(autofill::NAME_LAST), false); |
| + if (!full_name.compare(candidate)) { |
| + return true; |
| + } |
| + |
| + // First Middle Last |
| + candidate = StringConcatenationHelper( |
| + StringConcatenationHelper(profile.GetRawInfo(autofill::NAME_FIRST), |
| + profile.GetRawInfo(autofill::NAME_MIDDLE), |
| + false), |
| + profile.GetRawInfo(autofill::NAME_LAST), false); |
| + if (!full_name.compare(candidate)) { |
| + return true; |
| + } |
| + |
| + // First M Last |
| + candidate = StringConcatenationHelper( |
| + StringConcatenationHelper( |
| + profile.GetRawInfo(autofill::NAME_FIRST), |
| + profile.GetRawInfo(autofill::NAME_MIDDLE_INITIAL), false), |
| + profile.GetRawInfo(autofill::NAME_LAST), false); |
| + if (!full_name.compare(candidate)) { |
| + return true; |
| + } |
| + |
| + // First M. Last |
| + candidate = StringConcatenationHelper( |
| + StringConcatenationHelper( |
| + profile.GetRawInfo(autofill::NAME_FIRST), |
| + profile.GetRawInfo(autofill::NAME_MIDDLE_INITIAL), false), |
| + profile.GetRawInfo(autofill::NAME_LAST), true); |
| + if (!full_name.compare(candidate)) { |
| + return true; |
| + } |
| + |
| + return false; |
| +} |
| + |
| } // namespace data_util |
| } // namespace autofill |