Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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/contact_info.h" | 5 #include "components/autofill/core/browser/contact_info.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 #include <ostream> | 8 #include <ostream> |
| 9 #include <string> | 9 #include <string> |
| 10 | 10 |
| (...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 107 base::string16 NameInfo::MiddleInitial() const { | 107 base::string16 NameInfo::MiddleInitial() const { |
| 108 if (middle_.empty()) | 108 if (middle_.empty()) |
| 109 return base::string16(); | 109 return base::string16(); |
| 110 | 110 |
| 111 base::string16 middle_name(middle()); | 111 base::string16 middle_name(middle()); |
| 112 base::string16 initial; | 112 base::string16 initial; |
| 113 initial.push_back(middle_name[0]); | 113 initial.push_back(middle_name[0]); |
| 114 return initial; | 114 return initial; |
| 115 } | 115 } |
| 116 | 116 |
| 117 void NameInfo::SetFullName(const base::string16& full) { | 117 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.
| |
| 118 // Clear the names. | 118 // search whether full_name_ holds first_, middle_ or last_ names |
| 119 first_ = base::string16(); | 119 // parsing the full_name_ gives values for first_, middle_, and last_ fields. |
| 120 middle_ = base::string16(); | 120 base::string16 str = (base::string16)full; |
| 121 last_ = base::string16(); | 121 std::size_t foundFirst = base::string16::npos; |
| 122 if (!first_.empty()) | |
| 123 foundFirst = str.find(first_); | |
| 122 | 124 |
| 125 std::size_t foundMiddle = base::string16::npos; | |
| 126 if (!middle_.empty()) | |
| 127 foundMiddle = str.find(middle_); | |
| 128 std::size_t foundLast = base::string16::npos; | |
| 129 if (!last_.empty()) | |
| 130 foundLast = str.find(last_); | |
| 131 | |
| 132 // tokenize full name | |
| 123 std::vector<base::string16> full_name_tokens; | 133 std::vector<base::string16> full_name_tokens; |
| 124 Tokenize(full, base::ASCIIToUTF16(" "), &full_name_tokens); | 134 Tokenize(str, base::ASCIIToUTF16(" "), &full_name_tokens); |
| 125 | 135 |
| 126 // There are four possibilities: empty; first name; first and last names; | 136 // first name |
| 127 // first, middle (possibly multiple strings) and then the last name. | 137 if (first_.empty()) { |
| 128 if (full_name_tokens.size() > 0) { | 138 if (foundMiddle != base::string16::npos) { |
| 129 first_ = full_name_tokens[0]; | 139 if (foundMiddle != 0) { |
| 130 if (full_name_tokens.size() > 1) { | 140 base::string16 name = str.substr(0, foundMiddle); |
| 131 last_ = full_name_tokens.back(); | 141 TrimWhitespace(name, base::TRIM_ALL, &first_); |
| 132 if (full_name_tokens.size() > 2) { | |
| 133 full_name_tokens.erase(full_name_tokens.begin()); | |
| 134 full_name_tokens.pop_back(); | |
| 135 middle_ = JoinString(full_name_tokens, ' '); | |
| 136 } | 142 } |
| 143 } else { | |
| 144 if (foundLast != base::string16::npos) { | |
| 145 if (foundLast != 0) | |
| 146 first_ = full_name_tokens[0]; | |
| 147 } else | |
| 148 first_ = full_name_tokens[0]; | |
| 137 } | 149 } |
| 138 } | 150 } |
| 151 | |
| 152 // last name | |
| 153 if (last_.empty()) { | |
| 154 if (foundMiddle != base::string16::npos) { | |
| 155 if (middle_ != str) { | |
| 156 base::string16 name = | |
| 157 str.substr(foundMiddle + middle_.length(), | |
| 158 str.length() - (foundMiddle + middle_.length())); | |
| 159 TrimWhitespace(name, base::TRIM_ALL, &last_); | |
| 160 } | |
| 161 } else { | |
| 162 foundFirst = str.find(first_); | |
| 163 if (foundFirst != base::string16::npos) { | |
| 164 str.erase(foundFirst, first_.length()); | |
| 165 if (!str.empty()) | |
| 166 last_ = full_name_tokens[full_name_tokens.size() - 1]; | |
| 167 } else | |
| 168 last_ = full_name_tokens[full_name_tokens.size() - 1]; | |
| 169 } | |
| 170 } | |
| 171 | |
| 172 // middle name | |
| 173 if (middle_.empty()) { | |
| 174 foundFirst = str.find(first_); | |
| 175 | |
| 176 if (foundFirst != base::string16::npos) | |
| 177 str.erase(foundFirst, first_.length()); | |
| 178 | |
| 179 foundLast = str.find(last_); | |
| 180 if (foundLast != base::string16::npos) | |
| 181 str.erase(foundLast, str.length()); | |
| 182 | |
| 183 TrimWhitespace(str, base::TRIM_ALL, &middle_); | |
| 184 } | |
| 139 } | 185 } |
| 140 | 186 |
| 141 EmailInfo::EmailInfo() {} | 187 EmailInfo::EmailInfo() {} |
| 142 | 188 |
| 143 EmailInfo::EmailInfo(const EmailInfo& info) : FormGroup() { | 189 EmailInfo::EmailInfo(const EmailInfo& info) : FormGroup() { |
| 144 *this = info; | 190 *this = info; |
| 145 } | 191 } |
| 146 | 192 |
| 147 EmailInfo::~EmailInfo() {} | 193 EmailInfo::~EmailInfo() {} |
| 148 | 194 |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 197 return base::string16(); | 243 return base::string16(); |
| 198 } | 244 } |
| 199 | 245 |
| 200 void CompanyInfo::SetRawInfo(ServerFieldType type, | 246 void CompanyInfo::SetRawInfo(ServerFieldType type, |
| 201 const base::string16& value) { | 247 const base::string16& value) { |
| 202 DCHECK_EQ(COMPANY_NAME, type); | 248 DCHECK_EQ(COMPANY_NAME, type); |
| 203 company_name_ = value; | 249 company_name_ = value; |
| 204 } | 250 } |
| 205 | 251 |
| 206 } // namespace autofill | 252 } // namespace autofill |
| OLD | NEW |