| 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 #ifndef BASE_STRING_NUMBER_CONVERSIONS_H_ | 5 #ifndef BASE_STRING_NUMBER_CONVERSIONS_H_ |
| 6 #define BASE_STRING_NUMBER_CONVERSIONS_H_ | 6 #define BASE_STRING_NUMBER_CONVERSIONS_H_ |
| 7 | 7 |
| 8 #include <string> | 8 #include <string> |
| 9 #include <vector> | 9 #include <vector> |
| 10 | 10 |
| (...skipping 23 matching lines...) Expand all Loading... |
| 34 | 34 |
| 35 BASE_EXPORT std::string UintToString(unsigned value); | 35 BASE_EXPORT std::string UintToString(unsigned value); |
| 36 BASE_EXPORT string16 UintToString16(unsigned value); | 36 BASE_EXPORT string16 UintToString16(unsigned value); |
| 37 | 37 |
| 38 BASE_EXPORT std::string Int64ToString(int64 value); | 38 BASE_EXPORT std::string Int64ToString(int64 value); |
| 39 BASE_EXPORT string16 Int64ToString16(int64 value); | 39 BASE_EXPORT string16 Int64ToString16(int64 value); |
| 40 | 40 |
| 41 BASE_EXPORT std::string Uint64ToString(uint64 value); | 41 BASE_EXPORT std::string Uint64ToString(uint64 value); |
| 42 BASE_EXPORT string16 Uint64ToString16(uint64 value); | 42 BASE_EXPORT string16 Uint64ToString16(uint64 value); |
| 43 | 43 |
| 44 BASE_EXPORT std::string PointerToString(void* value); |
| 45 BASE_EXPORT string16 PointerToString16(void* value); |
| 46 |
| 44 // DoubleToString converts the double to a string format that ignores the | 47 // DoubleToString converts the double to a string format that ignores the |
| 45 // locale. If you want to use locale specific formatting, use ICU. | 48 // locale. If you want to use locale specific formatting, use ICU. |
| 46 BASE_EXPORT std::string DoubleToString(double value); | 49 BASE_EXPORT std::string DoubleToString(double value); |
| 47 | 50 |
| 48 // String -> number conversions ------------------------------------------------ | 51 // String -> number conversions ------------------------------------------------ |
| 49 | 52 |
| 50 // Perform a best-effort conversion of the input string to a numeric type, | 53 // Perform a best-effort conversion of the input string to a numeric type, |
| 51 // setting |*output| to the result of the conversion. Returns true for | 54 // setting |*output| to the result of the conversion. Returns true for |
| 52 // "perfect" conversions; returns false in the following cases: | 55 // "perfect" conversions; returns false in the following cases: |
| 53 // - Overflow/underflow. |*output| will be set to the maximum value supported | 56 // - Overflow/underflow. |*output| will be set to the maximum value supported |
| (...skipping 10 matching lines...) Expand all Loading... |
| 64 | 67 |
| 65 BASE_EXPORT bool StringToUint(const StringPiece& input, unsigned* output); | 68 BASE_EXPORT bool StringToUint(const StringPiece& input, unsigned* output); |
| 66 BASE_EXPORT bool StringToUint(const StringPiece16& input, unsigned* output); | 69 BASE_EXPORT bool StringToUint(const StringPiece16& input, unsigned* output); |
| 67 | 70 |
| 68 BASE_EXPORT bool StringToInt64(const StringPiece& input, int64* output); | 71 BASE_EXPORT bool StringToInt64(const StringPiece& input, int64* output); |
| 69 BASE_EXPORT bool StringToInt64(const StringPiece16& input, int64* output); | 72 BASE_EXPORT bool StringToInt64(const StringPiece16& input, int64* output); |
| 70 | 73 |
| 71 BASE_EXPORT bool StringToUint64(const StringPiece& input, uint64* output); | 74 BASE_EXPORT bool StringToUint64(const StringPiece& input, uint64* output); |
| 72 BASE_EXPORT bool StringToUint64(const StringPiece16& input, uint64* output); | 75 BASE_EXPORT bool StringToUint64(const StringPiece16& input, uint64* output); |
| 73 | 76 |
| 77 BASE_EXPORT bool StringToPointer(const StringPiece& input, void** output); |
| 78 BASE_EXPORT bool StringToPointer(const StringPiece16& input, void** output); |
| 79 |
| 74 BASE_EXPORT bool StringToSizeT(const StringPiece& input, size_t* output); | 80 BASE_EXPORT bool StringToSizeT(const StringPiece& input, size_t* output); |
| 75 BASE_EXPORT bool StringToSizeT(const StringPiece16& input, size_t* output); | 81 BASE_EXPORT bool StringToSizeT(const StringPiece16& input, size_t* output); |
| 76 | 82 |
| 77 // For floating-point conversions, only conversions of input strings in decimal | 83 // For floating-point conversions, only conversions of input strings in decimal |
| 78 // form are defined to work. Behavior with strings representing floating-point | 84 // form are defined to work. Behavior with strings representing floating-point |
| 79 // numbers in hexadecimal, and strings representing non-fininte values (such as | 85 // numbers in hexadecimal, and strings representing non-fininte values (such as |
| 80 // NaN and inf) is undefined. Otherwise, these behave the same as the integral | 86 // NaN and inf) is undefined. Otherwise, these behave the same as the integral |
| 81 // variants. This expects the input string to NOT be specific to the locale. | 87 // variants. This expects the input string to NOT be specific to the locale. |
| 82 // If your input is locale specific, use ICU to read the number. | 88 // If your input is locale specific, use ICU to read the number. |
| 83 BASE_EXPORT bool StringToDouble(const std::string& input, double* output); | 89 BASE_EXPORT bool StringToDouble(const std::string& input, double* output); |
| (...skipping 15 matching lines...) Expand all Loading... |
| 99 // |*output| will contain as many bytes as were successfully parsed prior to the | 105 // |*output| will contain as many bytes as were successfully parsed prior to the |
| 100 // error. There is no overflow, but input.size() must be evenly divisible by 2. | 106 // error. There is no overflow, but input.size() must be evenly divisible by 2. |
| 101 // Leading 0x or +/- are not allowed. | 107 // Leading 0x or +/- are not allowed. |
| 102 BASE_EXPORT bool HexStringToBytes(const std::string& input, | 108 BASE_EXPORT bool HexStringToBytes(const std::string& input, |
| 103 std::vector<uint8>* output); | 109 std::vector<uint8>* output); |
| 104 | 110 |
| 105 } // namespace base | 111 } // namespace base |
| 106 | 112 |
| 107 #endif // BASE_STRING_NUMBER_CONVERSIONS_H_ | 113 #endif // BASE_STRING_NUMBER_CONVERSIONS_H_ |
| 108 | 114 |
| OLD | NEW |