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 #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 |
11 #include "base/base_export.h" | 11 #include "base/base_export.h" |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
54 // by the data type. | 54 // by the data type. |
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 |
| 65 BASE_EXPORT bool StringToUint(const StringPiece& input, unsigned* output); |
| 66 BASE_EXPORT bool StringToUint(const StringPiece16& input, unsigned* output); |
| 67 |
64 BASE_EXPORT bool StringToInt64(const StringPiece& input, int64* output); | 68 BASE_EXPORT bool StringToInt64(const StringPiece& input, int64* output); |
65 BASE_EXPORT bool StringToInt64(const StringPiece16& input, int64* output); | 69 BASE_EXPORT bool StringToInt64(const StringPiece16& input, int64* output); |
66 | 70 |
| 71 BASE_EXPORT bool StringToUint64(const StringPiece& input, uint64* output); |
| 72 BASE_EXPORT bool StringToUint64(const StringPiece16& input, uint64* output); |
| 73 |
67 // For floating-point conversions, only conversions of input strings in decimal | 74 // For floating-point conversions, only conversions of input strings in decimal |
68 // form are defined to work. Behavior with strings representing floating-point | 75 // form are defined to work. Behavior with strings representing floating-point |
69 // numbers in hexadecimal, and strings representing non-fininte values (such as | 76 // numbers in hexadecimal, and strings representing non-fininte values (such as |
70 // 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 |
71 // 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. |
72 // 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. |
73 BASE_EXPORT bool StringToDouble(const std::string& input, double* output); | 80 BASE_EXPORT bool StringToDouble(const std::string& input, double* output); |
74 | 81 |
75 // Hex encoding ---------------------------------------------------------------- | 82 // Hex encoding ---------------------------------------------------------------- |
76 | 83 |
(...skipping 12 matching lines...) Expand all Loading... |
89 // |*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 |
90 // 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. |
91 // Leading 0x or +/- are not allowed. | 98 // Leading 0x or +/- are not allowed. |
92 BASE_EXPORT bool HexStringToBytes(const std::string& input, | 99 BASE_EXPORT bool HexStringToBytes(const std::string& input, |
93 std::vector<uint8>* output); | 100 std::vector<uint8>* output); |
94 | 101 |
95 } // namespace base | 102 } // namespace base |
96 | 103 |
97 #endif // BASE_STRING_NUMBER_CONVERSIONS_H_ | 104 #endif // BASE_STRING_NUMBER_CONVERSIONS_H_ |
98 | 105 |
OLD | NEW |