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

Side by Side Diff: chrome/browser/autocomplete_history_manager.cc

Issue 3968001: Update code that previously constructed strings from string iterators only to... (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: '' Created 10 years, 1 month 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 (c) 2010 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2010 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 "chrome/browser/autocomplete_history_manager.h" 5 #include "chrome/browser/autocomplete_history_manager.h"
6 6
7 #include <vector> 7 #include <vector>
8 8
9 #include "base/string16.h" 9 #include "base/string16.h"
10 #include "base/string_number_conversions.h" 10 #include "base/string_number_conversions.h"
(...skipping 13 matching lines...) Expand all
24 // Limit on the number of suggestions to appear in the pop-up menu under an 24 // Limit on the number of suggestions to appear in the pop-up menu under an
25 // text input element in a form. 25 // text input element in a form.
26 const int kMaxAutocompleteMenuItems = 6; 26 const int kMaxAutocompleteMenuItems = 6;
27 27
28 // The separator characters for SSNs. 28 // The separator characters for SSNs.
29 const string16 kSSNSeparators = ASCIIToUTF16(" -"); 29 const string16 kSSNSeparators = ASCIIToUTF16(" -");
30 30
31 bool IsSSN(const string16& text) { 31 bool IsSSN(const string16& text) {
32 string16 number_string; 32 string16 number_string;
33 RemoveChars(text, kSSNSeparators.c_str(), &number_string); 33 RemoveChars(text, kSSNSeparators.c_str(), &number_string);
34 if (number_string.length() != 9 || !IsStringASCII(number_string))
35 return false;
36 34
37 // A SSN is of the form AAA-GG-SSSS (A = area number, G = group number, S = 35 // A SSN is of the form AAA-GG-SSSS (A = area number, G = group number, S =
38 // serial number). The validation we do here is simply checking if the area, 36 // serial number). The validation we do here is simply checking if the area,
39 // group, and serial numbers are valid. It is possible to check if the group 37 // group, and serial numbers are valid. It is possible to check if the group
40 // number is valid for the given area, but that data changes all the time. 38 // number is valid for the given area, but that data changes all the time.
41 // 39 //
42 // See: http://www.socialsecurity.gov/history/ssn/geocard.html 40 // See: http://www.socialsecurity.gov/history/ssn/geocard.html
43 // http://www.socialsecurity.gov/employer/stateweb.htm 41 // http://www.socialsecurity.gov/employer/stateweb.htm
44 // http://www.socialsecurity.gov/employer/ssnvhighgroup.htm 42 // http://www.socialsecurity.gov/employer/ssnvhighgroup.htm
45 43 if (number_string.length() != 9 || !IsStringASCII(number_string))
46 string16 area_string = number_string.substr(0, 3); 44 return false;
47 string16 group_string = number_string.substr(3, 2);
48 string16 serial_string = number_string.substr(5, 4);
49 45
50 int area; 46 int area;
51 if (!base::StringToInt(area_string, &area)) 47 if (!base::StringToInt(number_string.begin(),
48 number_string.begin() + 3,
49 &area))
52 return false; 50 return false;
53 if (area < 1 || 51 if (area < 1 ||
54 area == 666 || 52 area == 666 ||
55 (area > 733 && area < 750) || 53 (area > 733 && area < 750) ||
56 area > 772) 54 area > 772)
57 return false; 55 return false;
58 56
59 int group; 57 int group;
60 if (!base::StringToInt(group_string, &group) || group == 0) 58 if (!base::StringToInt(number_string.begin() + 3,
59 number_string.begin() + 5,
60 &group) || group == 0)
61 return false; 61 return false;
62 62
63 int serial; 63 int serial;
64 if (!base::StringToInt(serial_string, &serial) || serial == 0) 64 if (!base::StringToInt(number_string.begin() + 5,
65 number_string.begin() + 9,
66 &serial) || serial == 0)
65 return false; 67 return false;
66 68
67 return true; 69 return true;
68 } 70 }
69 71
70 } // namespace 72 } // namespace
71 73
72 AutocompleteHistoryManager::AutocompleteHistoryManager( 74 AutocompleteHistoryManager::AutocompleteHistoryManager(
73 TabContents* tab_contents) : tab_contents_(tab_contents), 75 TabContents* tab_contents) : tab_contents_(tab_contents),
74 pending_query_handle_(0), 76 pending_query_handle_(0),
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after
185 DCHECK(result->GetType() == AUTOFILL_VALUE_RESULT); 187 DCHECK(result->GetType() == AUTOFILL_VALUE_RESULT);
186 const WDResult<std::vector<string16> >* autofill_result = 188 const WDResult<std::vector<string16> >* autofill_result =
187 static_cast<const WDResult<std::vector<string16> >*>(result); 189 static_cast<const WDResult<std::vector<string16> >*>(result);
188 host->AutocompleteSuggestionsReturned( 190 host->AutocompleteSuggestionsReturned(
189 query_id_, autofill_result->GetValue()); 191 query_id_, autofill_result->GetValue());
190 } else { 192 } else {
191 host->AutocompleteSuggestionsReturned( 193 host->AutocompleteSuggestionsReturned(
192 query_id_, std::vector<string16>()); 194 query_id_, std::vector<string16>());
193 } 195 }
194 } 196 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698