OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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> |
11 | 11 |
(...skipping 383 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
395 } | 395 } |
396 | 396 |
397 bool StringToInt(const StringPiece& input, int* output) { | 397 bool StringToInt(const StringPiece& input, int* output) { |
398 return StringToIntImpl(input, output); | 398 return StringToIntImpl(input, output); |
399 } | 399 } |
400 | 400 |
401 bool StringToInt(const StringPiece16& input, int* output) { | 401 bool StringToInt(const StringPiece16& input, int* output) { |
402 return String16ToIntImpl(input, output); | 402 return String16ToIntImpl(input, output); |
403 } | 403 } |
404 | 404 |
| 405 bool StringToUint(const StringPiece& input, unsigned* output) { |
| 406 return StringToIntImpl(input, output); |
| 407 } |
| 408 |
| 409 bool StringToUint(const StringPiece16& input, unsigned* output) { |
| 410 return String16ToIntImpl(input, output); |
| 411 } |
| 412 |
405 bool StringToInt64(const StringPiece& input, int64* output) { | 413 bool StringToInt64(const StringPiece& input, int64* output) { |
406 return StringToIntImpl(input, output); | 414 return StringToIntImpl(input, output); |
407 } | 415 } |
408 | 416 |
409 bool StringToInt64(const StringPiece16& input, int64* output) { | 417 bool StringToInt64(const StringPiece16& input, int64* output) { |
410 return String16ToIntImpl(input, output); | 418 return String16ToIntImpl(input, output); |
411 } | 419 } |
412 | 420 |
| 421 bool StringToUint64(const StringPiece& input, uint64* output) { |
| 422 return StringToIntImpl(input, output); |
| 423 } |
| 424 |
| 425 bool StringToUint64(const StringPiece16& input, uint64* output) { |
| 426 return String16ToIntImpl(input, output); |
| 427 } |
| 428 |
413 bool StringToDouble(const std::string& input, double* output) { | 429 bool StringToDouble(const std::string& input, double* output) { |
414 errno = 0; // Thread-safe? It is on at least Mac, Linux, and Windows. | 430 errno = 0; // Thread-safe? It is on at least Mac, Linux, and Windows. |
415 char* endptr = NULL; | 431 char* endptr = NULL; |
416 *output = dmg_fp::strtod(input.c_str(), &endptr); | 432 *output = dmg_fp::strtod(input.c_str(), &endptr); |
417 | 433 |
418 // Cases to return false: | 434 // Cases to return false: |
419 // - If errno is ERANGE, there was an overflow or underflow. | 435 // - If errno is ERANGE, there was an overflow or underflow. |
420 // - If the input string is empty, there was nothing to parse. | 436 // - If the input string is empty, there was nothing to parse. |
421 // - If endptr does not point to the end of the string, there are either | 437 // - If endptr does not point to the end of the string, there are either |
422 // characters remaining in the string after a parsed number, or the string | 438 // characters remaining in the string after a parsed number, or the string |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
455 bool HexStringToInt(const StringPiece& input, int* output) { | 471 bool HexStringToInt(const StringPiece& input, int* output) { |
456 return IteratorRangeToNumber<HexIteratorRangeToIntTraits>::Invoke( | 472 return IteratorRangeToNumber<HexIteratorRangeToIntTraits>::Invoke( |
457 input.begin(), input.end(), output); | 473 input.begin(), input.end(), output); |
458 } | 474 } |
459 | 475 |
460 bool HexStringToBytes(const std::string& input, std::vector<uint8>* output) { | 476 bool HexStringToBytes(const std::string& input, std::vector<uint8>* output) { |
461 return HexStringToBytesT(input, output); | 477 return HexStringToBytesT(input, output); |
462 } | 478 } |
463 | 479 |
464 } // namespace base | 480 } // namespace base |
OLD | NEW |