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 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
55 // - Trailing characters in the string after parsing the number. |*output| | 55 // - Trailing characters in the string after parsing the number. |*output| |
56 // will be set to the value of the number that was parsed. | 56 // will be set to the value of the number that was parsed. |
57 // - Leading whitespace in the string before parsing the number. |*output| will | 57 // - Leading whitespace in the string before parsing the number. |*output| will |
58 // be set to the value of the number that was parsed. | 58 // be set to the value of the number that was parsed. |
59 // - No characters parseable as a number at the beginning of the string. | 59 // - No characters parseable as a number at the beginning of the string. |
60 // |*output| will be set to 0. | 60 // |*output| will be set to 0. |
61 // - Empty string. |*output| will be set to 0. | 61 // - Empty string. |*output| will be set to 0. |
62 BASE_EXPORT bool StringToInt(const StringPiece& input, int* output); | 62 BASE_EXPORT bool StringToInt(const StringPiece& input, int* output); |
63 BASE_EXPORT bool StringToInt(const StringPiece16& input, int* output); | 63 BASE_EXPORT bool StringToInt(const StringPiece16& input, int* output); |
64 | 64 |
| 65 BASE_EXPORT bool StringToUint(const StringPiece& input, unsigned* output); |
| 66 BASE_EXPORT bool StringToUint(const StringPiece16& input, unsigned* output); |
| 67 |
65 BASE_EXPORT bool StringToInt64(const StringPiece& input, int64* output); | 68 BASE_EXPORT bool StringToInt64(const StringPiece& input, int64* output); |
66 BASE_EXPORT bool StringToInt64(const StringPiece16& input, int64* output); | 69 BASE_EXPORT bool StringToInt64(const StringPiece16& input, int64* output); |
67 | 70 |
68 BASE_EXPORT bool StringToSizeT(const StringPiece& input, size_t* output); | 71 BASE_EXPORT bool StringToUint64(const StringPiece& input, uint64* output); |
69 BASE_EXPORT bool StringToSizeT(const StringPiece16& input, size_t* output); | 72 BASE_EXPORT bool StringToUint64(const StringPiece16& input, uint64* output); |
70 | 73 |
71 // For floating-point conversions, only conversions of input strings in decimal | 74 // For floating-point conversions, only conversions of input strings in decimal |
72 // form are defined to work. Behavior with strings representing floating-point | 75 // form are defined to work. Behavior with strings representing floating-point |
73 // numbers in hexadecimal, and strings representing non-fininte values (such as | 76 // numbers in hexadecimal, and strings representing non-fininte values (such as |
74 // NaN and inf) is undefined. Otherwise, these behave the same as the integral | 77 // NaN and inf) is undefined. Otherwise, these behave the same as the integral |
75 // variants. This expects the input string to NOT be specific to the locale. | 78 // variants. This expects the input string to NOT be specific to the locale. |
76 // If your input is locale specific, use ICU to read the number. | 79 // If your input is locale specific, use ICU to read the number. |
77 BASE_EXPORT bool StringToDouble(const std::string& input, double* output); | 80 BASE_EXPORT bool StringToDouble(const std::string& input, double* output); |
78 | 81 |
79 // Hex encoding ---------------------------------------------------------------- | 82 // Hex encoding ---------------------------------------------------------------- |
(...skipping 13 matching lines...) Expand all Loading... |
93 // |*output| will contain as many bytes as were successfully parsed prior to the | 96 // |*output| will contain as many bytes as were successfully parsed prior to the |
94 // error. There is no overflow, but input.size() must be evenly divisible by 2. | 97 // error. There is no overflow, but input.size() must be evenly divisible by 2. |
95 // Leading 0x or +/- are not allowed. | 98 // Leading 0x or +/- are not allowed. |
96 BASE_EXPORT bool HexStringToBytes(const std::string& input, | 99 BASE_EXPORT bool HexStringToBytes(const std::string& input, |
97 std::vector<uint8>* output); | 100 std::vector<uint8>* output); |
98 | 101 |
99 } // namespace base | 102 } // namespace base |
100 | 103 |
101 #endif // BASE_STRING_NUMBER_CONVERSIONS_H_ | 104 #endif // BASE_STRING_NUMBER_CONVERSIONS_H_ |
102 | 105 |
OLD | NEW |