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

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

Issue 102843002: Move RemoveChars, ReplaceChars, TrimString, and TruncateUTF8ToByteSize to base namespace. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years 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 | Annotate | Revision Log
OLDNEW
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/autofill_field.h" 5 #include "components/autofill/core/browser/autofill_field.h"
6 6
7 #include "base/logging.h" 7 #include "base/logging.h"
8 #include "base/sha1.h" 8 #include "base/sha1.h"
9 #include "base/strings/string_number_conversions.h" 9 #include "base/strings/string_number_conversions.h"
10 #include "base/strings/string_split.h" 10 #include "base/strings/string_split.h"
(...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after
162 162
163 return false; 163 return false;
164 } 164 }
165 165
166 // Try to fill a credit card type |value| (Visa, MasterCard, etc.) into the 166 // Try to fill a credit card type |value| (Visa, MasterCard, etc.) into the
167 // given |field|. 167 // given |field|.
168 bool FillCreditCardTypeSelectControl(const base::string16& value, 168 bool FillCreditCardTypeSelectControl(const base::string16& value,
169 FormFieldData* field) { 169 FormFieldData* field) {
170 // Try stripping off spaces. 170 // Try stripping off spaces.
171 base::string16 value_stripped; 171 base::string16 value_stripped;
172 RemoveChars(StringToLowerASCII(value), base::kWhitespaceUTF16, 172 base::RemoveChars(StringToLowerASCII(value), base::kWhitespaceUTF16,
173 &value_stripped); 173 &value_stripped);
174 174
175 for (size_t i = 0; i < field->option_values.size(); ++i) { 175 for (size_t i = 0; i < field->option_values.size(); ++i) {
176 base::string16 option_value_lowercase; 176 base::string16 option_value_lowercase;
177 RemoveChars(StringToLowerASCII(field->option_values[i]), 177 base::RemoveChars(StringToLowerASCII(field->option_values[i]),
178 base::kWhitespaceUTF16, &option_value_lowercase); 178 base::kWhitespaceUTF16, &option_value_lowercase);
179 base::string16 option_contents_lowercase; 179 base::string16 option_contents_lowercase;
180 RemoveChars(StringToLowerASCII(field->option_contents[i]), 180 base::RemoveChars(StringToLowerASCII(field->option_contents[i]),
181 base::kWhitespaceUTF16, &option_contents_lowercase); 181 base::kWhitespaceUTF16, &option_contents_lowercase);
182 182
183 // Perform a case-insensitive comparison; but fill the form with the 183 // Perform a case-insensitive comparison; but fill the form with the
184 // original text, not the lowercased version. 184 // original text, not the lowercased version.
185 if (value_stripped == option_value_lowercase || 185 if (value_stripped == option_value_lowercase ||
186 value_stripped == option_contents_lowercase) { 186 value_stripped == option_contents_lowercase) {
187 field->value = field->option_values[i]; 187 field->value = field->option_values[i];
188 return true; 188 return true;
189 } 189 }
190 } 190 }
191 191
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after
285 FormFieldData* field) { 285 FormFieldData* field) {
286 if (field->form_control_type == "textarea") { 286 if (field->form_control_type == "textarea") {
287 field->value = value; 287 field->value = value;
288 return; 288 return;
289 } 289 }
290 290
291 base::string16 one_line_value; 291 base::string16 one_line_value;
292 const char16 kNewline[] = { '\n', 0 }; 292 const char16 kNewline[] = { '\n', 0 };
293 const base::string16 separator = 293 const base::string16 separator =
294 l10n_util::GetStringUTF16(IDS_AUTOFILL_ADDRESS_LINE_SEPARATOR); 294 l10n_util::GetStringUTF16(IDS_AUTOFILL_ADDRESS_LINE_SEPARATOR);
295 ReplaceChars(value, kNewline, separator, &one_line_value); 295 base::ReplaceChars(value, kNewline, separator, &one_line_value);
296 field->value = one_line_value; 296 field->value = one_line_value;
297 } 297 }
298 298
299 std::string Hash32Bit(const std::string& str) { 299 std::string Hash32Bit(const std::string& str) {
300 std::string hash_bin = base::SHA1HashString(str); 300 std::string hash_bin = base::SHA1HashString(str);
301 DCHECK_EQ(20U, hash_bin.length()); 301 DCHECK_EQ(20U, hash_bin.length());
302 302
303 uint32 hash32 = ((hash_bin[0] & 0xFF) << 24) | 303 uint32 hash32 = ((hash_bin[0] & 0xFF) << 24) |
304 ((hash_bin[1] & 0xFF) << 16) | 304 ((hash_bin[1] & 0xFF) << 16) |
305 ((hash_bin[2] & 0xFF) << 8) | 305 ((hash_bin[2] & 0xFF) << 8) |
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after
400 FillSelectControl(type, value, app_locale, field_data); 400 FillSelectControl(type, value, app_locale, field_data);
401 else if (field_data->form_control_type == "month") 401 else if (field_data->form_control_type == "month")
402 FillMonthControl(value, field_data); 402 FillMonthControl(value, field_data);
403 else if (type.GetStorableType() == ADDRESS_HOME_STREET_ADDRESS) 403 else if (type.GetStorableType() == ADDRESS_HOME_STREET_ADDRESS)
404 FillStreetAddress(value, field_data); 404 FillStreetAddress(value, field_data);
405 else 405 else
406 field_data->value = value; 406 field_data->value = value;
407 } 407 }
408 408
409 } // namespace autofill 409 } // namespace autofill
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698