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

Unified Diff: components/autofill/core/browser/contact_info.cc

Issue 261993006: Modified to allow to preserve two-word string in first-name and last-name in autofill profile. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 7 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 side-by-side diff with in-line comments
Download patch
Index: components/autofill/core/browser/contact_info.cc
diff --git a/components/autofill/core/browser/contact_info.cc b/components/autofill/core/browser/contact_info.cc
index 0793bb5ff310c507941a7edd69bca4dfe57345b3..e0c8a1d60ea370bdc3f96b511e957f847c000b84 100644
--- a/components/autofill/core/browser/contact_info.cc
+++ b/components/autofill/core/browser/contact_info.cc
@@ -115,27 +115,73 @@ base::string16 NameInfo::MiddleInitial() const {
}
void NameInfo::SetFullName(const base::string16& full) {
Ilya Sherman 2014/05/15 22:21:27 You shouldn't need to make any changes to this met
Pritam Nikam 2014/05/19 12:09:15 Done.
- // Clear the names.
- first_ = base::string16();
- middle_ = base::string16();
- last_ = base::string16();
+ // search whether full_name_ holds first_, middle_ or last_ names
+ // parsing the full_name_ gives values for first_, middle_, and last_ fields.
+ base::string16 str = (base::string16)full;
+ std::size_t foundFirst = base::string16::npos;
+ if (!first_.empty())
+ foundFirst = str.find(first_);
+
+ std::size_t foundMiddle = base::string16::npos;
+ if (!middle_.empty())
+ foundMiddle = str.find(middle_);
+ std::size_t foundLast = base::string16::npos;
+ if (!last_.empty())
+ foundLast = str.find(last_);
+ // tokenize full name
std::vector<base::string16> full_name_tokens;
- Tokenize(full, base::ASCIIToUTF16(" "), &full_name_tokens);
-
- // There are four possibilities: empty; first name; first and last names;
- // first, middle (possibly multiple strings) and then the last name.
- if (full_name_tokens.size() > 0) {
- first_ = full_name_tokens[0];
- if (full_name_tokens.size() > 1) {
- last_ = full_name_tokens.back();
- if (full_name_tokens.size() > 2) {
- full_name_tokens.erase(full_name_tokens.begin());
- full_name_tokens.pop_back();
- middle_ = JoinString(full_name_tokens, ' ');
+ Tokenize(str, base::ASCIIToUTF16(" "), &full_name_tokens);
+
+ // first name
+ if (first_.empty()) {
+ if (foundMiddle != base::string16::npos) {
+ if (foundMiddle != 0) {
+ base::string16 name = str.substr(0, foundMiddle);
+ TrimWhitespace(name, base::TRIM_ALL, &first_);
}
+ } else {
+ if (foundLast != base::string16::npos) {
+ if (foundLast != 0)
+ first_ = full_name_tokens[0];
+ } else
+ first_ = full_name_tokens[0];
}
}
+
+ // last name
+ if (last_.empty()) {
+ if (foundMiddle != base::string16::npos) {
+ if (middle_ != str) {
+ base::string16 name =
+ str.substr(foundMiddle + middle_.length(),
+ str.length() - (foundMiddle + middle_.length()));
+ TrimWhitespace(name, base::TRIM_ALL, &last_);
+ }
+ } else {
+ foundFirst = str.find(first_);
+ if (foundFirst != base::string16::npos) {
+ str.erase(foundFirst, first_.length());
+ if (!str.empty())
+ last_ = full_name_tokens[full_name_tokens.size() - 1];
+ } else
+ last_ = full_name_tokens[full_name_tokens.size() - 1];
+ }
+ }
+
+ // middle name
+ if (middle_.empty()) {
+ foundFirst = str.find(first_);
+
+ if (foundFirst != base::string16::npos)
+ str.erase(foundFirst, first_.length());
+
+ foundLast = str.find(last_);
+ if (foundLast != base::string16::npos)
+ str.erase(foundLast, str.length());
+
+ TrimWhitespace(str, base::TRIM_ALL, &middle_);
+ }
}
EmailInfo::EmailInfo() {}

Powered by Google App Engine
This is Rietveld 408576698