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

Side by Side Diff: base/string_number_conversions.cc

Issue 7584031: base::HexStringToInt conversion function treats the string "0x" as a valid hex number (Closed) Base URL: http://src.chromium.org/svn/trunk/src/
Patch Set: '' Created 9 years, 4 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « AUTHORS ('k') | base/string_number_conversions_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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 "base/string_number_conversions.h" 5 #include "base/string_number_conversions.h"
6 6
7 #include <ctype.h> 7 #include <ctype.h>
8 #include <errno.h> 8 #include <errno.h>
9 #include <stdlib.h> 9 #include <stdlib.h>
10 #include <wctype.h> 10 #include <wctype.h>
(...skipping 202 matching lines...) Expand 10 before | Expand all | Expand 10 after
213 static bool Invoke(const_iterator begin, const_iterator end, 213 static bool Invoke(const_iterator begin, const_iterator end,
214 typename traits::value_type* output) { 214 typename traits::value_type* output) {
215 *output = 0; 215 *output = 0;
216 216
217 if (begin == end) { 217 if (begin == end) {
218 return false; 218 return false;
219 } 219 }
220 220
221 // Note: no performance difference was found when using template 221 // Note: no performance difference was found when using template
222 // specialization to remove this check in bases other than 16 222 // specialization to remove this check in bases other than 16
223 if (traits::kBase == 16 && end - begin >= 2 && *begin == '0' && 223 if (traits::kBase == 16 && end - begin > 2 && *begin == '0' &&
224 (*(begin + 1) == 'x' || *(begin + 1) == 'X')) { 224 (*(begin + 1) == 'x' || *(begin + 1) == 'X')) {
225 begin += 2; 225 begin += 2;
226 } 226 }
227 227
228 for (const_iterator current = begin; current != end; ++current) { 228 for (const_iterator current = begin; current != end; ++current) {
229 uint8 new_digit = 0; 229 uint8 new_digit = 0;
230 230
231 if (!CharToDigit<traits::kBase>(*current, &new_digit)) { 231 if (!CharToDigit<traits::kBase>(*current, &new_digit)) {
232 return false; 232 return false;
233 } 233 }
(...skipping 302 matching lines...) Expand 10 before | Expand all | Expand 10 after
536 end, 536 end,
537 output); 537 output);
538 } 538 }
539 #endif 539 #endif
540 540
541 bool HexStringToBytes(const std::string& input, std::vector<uint8>* output) { 541 bool HexStringToBytes(const std::string& input, std::vector<uint8>* output) {
542 return HexStringToBytesT(input, output); 542 return HexStringToBytesT(input, output);
543 } 543 }
544 544
545 } // namespace base 545 } // namespace base
OLDNEW
« no previous file with comments | « AUTHORS ('k') | base/string_number_conversions_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698