OLD | NEW |
1 // Copyright (c) 2012 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/strings/string_number_conversions.h" | 5 #include "base/strings/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 354 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
365 }; | 365 }; |
366 | 366 |
367 template <typename VALUE> | 367 template <typename VALUE> |
368 bool String16ToIntImpl(const StringPiece16& input, VALUE* output) { | 368 bool String16ToIntImpl(const StringPiece16& input, VALUE* output) { |
369 return IteratorRangeToNumber<StringPiece16ToNumberTraits<VALUE, 10> >::Invoke( | 369 return IteratorRangeToNumber<StringPiece16ToNumberTraits<VALUE, 10> >::Invoke( |
370 input.begin(), input.end(), output); | 370 input.begin(), input.end(), output); |
371 } | 371 } |
372 | 372 |
373 } // namespace | 373 } // namespace |
374 | 374 |
| 375 #if defined(STRING_NUMBER_CONVERSIONS_DETECT_RISKY_CONVERSIONS) |
| 376 namespace internal { |
| 377 #endif |
| 378 |
375 std::string IntToString(int value) { | 379 std::string IntToString(int value) { |
376 return IntToStringT<std::string, int, unsigned int, true>:: | 380 return IntToStringT<std::string, int, unsigned int, true>:: |
377 IntToString(value); | 381 IntToString(value); |
378 } | 382 } |
379 | 383 |
380 string16 IntToString16(int value) { | 384 string16 IntToString16(int value) { |
381 return IntToStringT<string16, int, unsigned int, true>:: | 385 return IntToStringT<string16, int, unsigned int, true>:: |
382 IntToString(value); | 386 IntToString(value); |
383 } | 387 } |
384 | 388 |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
416 return IntToStringT<string16, size_t, size_t, false>::IntToString(value); | 420 return IntToStringT<string16, size_t, size_t, false>::IntToString(value); |
417 } | 421 } |
418 | 422 |
419 std::string DoubleToString(double value) { | 423 std::string DoubleToString(double value) { |
420 // According to g_fmt.cc, it is sufficient to declare a buffer of size 32. | 424 // According to g_fmt.cc, it is sufficient to declare a buffer of size 32. |
421 char buffer[32]; | 425 char buffer[32]; |
422 dmg_fp::g_fmt(buffer, value); | 426 dmg_fp::g_fmt(buffer, value); |
423 return std::string(buffer); | 427 return std::string(buffer); |
424 } | 428 } |
425 | 429 |
| 430 #if defined(STRING_NUMBER_CONVERSIONS_DETECT_RISKY_CONVERSIONS) |
| 431 } // namespace internal |
| 432 #endif |
| 433 |
426 bool StringToInt(const StringPiece& input, int* output) { | 434 bool StringToInt(const StringPiece& input, int* output) { |
427 return StringToIntImpl(input, output); | 435 return StringToIntImpl(input, output); |
428 } | 436 } |
429 | 437 |
430 bool StringToInt(const StringPiece16& input, int* output) { | 438 bool StringToInt(const StringPiece16& input, int* output) { |
431 return String16ToIntImpl(input, output); | 439 return String16ToIntImpl(input, output); |
432 } | 440 } |
433 | 441 |
434 bool StringToUint(const StringPiece& input, unsigned* output) { | 442 bool StringToUint(const StringPiece& input, unsigned* output) { |
435 return StringToIntImpl(input, output); | 443 return StringToIntImpl(input, output); |
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
525 bool HexStringToUInt64(const StringPiece& input, uint64* output) { | 533 bool HexStringToUInt64(const StringPiece& input, uint64* output) { |
526 return IteratorRangeToNumber<HexIteratorRangeToUInt64Traits>::Invoke( | 534 return IteratorRangeToNumber<HexIteratorRangeToUInt64Traits>::Invoke( |
527 input.begin(), input.end(), output); | 535 input.begin(), input.end(), output); |
528 } | 536 } |
529 | 537 |
530 bool HexStringToBytes(const std::string& input, std::vector<uint8>* output) { | 538 bool HexStringToBytes(const std::string& input, std::vector<uint8>* output) { |
531 return HexStringToBytesT(input, output); | 539 return HexStringToBytesT(input, output); |
532 } | 540 } |
533 | 541 |
534 } // namespace base | 542 } // namespace base |
OLD | NEW |