@@ -50,26 +50,35 @@ BASE_EXPORT std::string NumberToString(long long value);
50
50
BASE_EXPORT std::u16string NumberToString16 (long long value);
51
51
BASE_EXPORT std::string NumberToString (unsigned long long value);
52
52
BASE_EXPORT std::u16string NumberToString16 (unsigned long long value);
53
+
54
+ // Returns a string that contains a full representation of `value`.
53
55
BASE_EXPORT std::string NumberToString (double value);
54
56
BASE_EXPORT std::u16string NumberToString16 (double value);
55
57
58
+ // Returns a string that contains a representation of `value` expressed with
59
+ // exactly `digits` digits after the decimal point.
60
+ BASE_EXPORT std::string NumberToStringWithFixedPrecision (double value,
61
+ int digits);
62
+ BASE_EXPORT std::u16string NumberToString16WithFixedPrecision (double value,
63
+ int digits);
64
+
56
65
// String -> number conversions ------------------------------------------------
57
66
58
67
// Perform a best-effort conversion of the input string to a numeric type,
59
- // setting | *output| to the result of the conversion. Returns true for
68
+ // setting ` *output` to the result of the conversion. Returns true for
60
69
// "perfect" conversions; returns false in the following cases:
61
- // - Overflow. | *output| will be set to the maximum value supported
70
+ // - Overflow. ` *output` will be set to the maximum value supported
62
71
// by the data type.
63
- // - Underflow. | *output| will be set to the minimum value supported
72
+ // - Underflow. ` *output` will be set to the minimum value supported
64
73
// by the data type.
65
- // - Trailing characters in the string after parsing the number. | *output|
74
+ // - Trailing characters in the string after parsing the number. ` *output`
66
75
// will be set to the value of the number that was parsed.
67
- // - Leading whitespace in the string before parsing the number. | *output| will
76
+ // - Leading whitespace in the string before parsing the number. ` *output` will
68
77
// be set to the value of the number that was parsed.
69
78
// - No characters parseable as a number at the beginning of the string.
70
- // | *output| will be set to 0.
71
- // - Empty string. | *output| will be set to 0.
72
- // WARNING: Will write to | output| even when returning false.
79
+ // ` *output` will be set to 0.
80
+ // - Empty string. ` *output` will be set to 0.
81
+ // WARNING: Will write to ` output` even when returning false.
73
82
// Read the comments above carefully.
74
83
BASE_EXPORT bool StringToInt (std::string_view input, int * output);
75
84
BASE_EXPORT bool StringToInt (std::u16string_view input, int * output);
@@ -92,18 +101,18 @@ BASE_EXPORT bool StringToSizeT(std::u16string_view input, size_t* output);
92
101
// NaN and inf) is undefined. Otherwise, these behave the same as the integral
93
102
// variants. This expects the input string to NOT be specific to the locale.
94
103
// If your input is locale specific, use ICU to read the number.
95
- // WARNING: Will write to | output| even when returning false.
104
+ // WARNING: Will write to ` output` even when returning false.
96
105
// Read the comments here and above StringToInt() carefully.
97
106
BASE_EXPORT bool StringToDouble (std::string_view input, double * output);
98
107
BASE_EXPORT bool StringToDouble (std::u16string_view input, double * output);
99
108
100
109
// Hex encoding ----------------------------------------------------------------
101
110
102
111
// Returns a hex string representation of a binary buffer. The returned hex
103
- // string will be in upper case. This function does not check if | size| is
112
+ // string will be in upper case. This function does not check if ` size` is
104
113
// within reasonable limits since it's written with trusted data in mind. If
105
114
// you suspect that the data you want to format might be large, the absolute
106
- // max size for | size| should be is
115
+ // max size for ` size` should be is
107
116
// std::numeric_limits<size_t>::max() / 2
108
117
BASE_EXPORT std::string HexEncode (base::span<const uint8_t > bytes);
109
118
BASE_EXPORT std::string HexEncode (std::string_view chars);
@@ -128,42 +137,42 @@ inline void AppendHexEncodedByte(uint8_t byte,
128
137
}
129
138
130
139
// Best effort conversion, see StringToInt above for restrictions.
131
- // Will only successful parse hex values that will fit into | output| , i.e.
132
- // -0x80000000 < | input| < 0x7FFFFFFF .
140
+ // Will only successful parse hex values that will fit into ` output` , i.e.
141
+ // -0x8000'0000 < ` input` < 0x7FFF'FFFF .
133
142
BASE_EXPORT bool HexStringToInt (std::string_view input, int * output);
134
143
135
144
// Best effort conversion, see StringToInt above for restrictions.
136
- // Will only successful parse hex values that will fit into | output| , i.e.
137
- // 0x00000000 < | input| < 0xFFFFFFFF .
138
- // The string is not required to start with 0x .
145
+ // Will only successful parse hex values that will fit into ` output` , i.e.
146
+ // 0x0000'0000 < ` input` < 0xFFFF'FFFF .
147
+ // The string is not required to start with "0x" .
139
148
BASE_EXPORT bool HexStringToUInt (std::string_view input, uint32_t * output);
140
149
141
150
// Best effort conversion, see StringToInt above for restrictions.
142
- // Will only successful parse hex values that will fit into | output| , i.e.
143
- // -0x8000000000000000 < | input| < 0x7FFFFFFFFFFFFFFF .
151
+ // Will only successful parse hex values that will fit into ` output` , i.e.
152
+ // -0x8000'0000'0000'0000 < ` input` < 0x7FFF'FFFF'FFFF'FFFF .
144
153
BASE_EXPORT bool HexStringToInt64 (std::string_view input, int64_t * output);
145
154
146
155
// Best effort conversion, see StringToInt above for restrictions.
147
- // Will only successful parse hex values that will fit into | output| , i.e.
148
- // 0x0000000000000000 < | input| < 0xFFFFFFFFFFFFFFFF .
149
- // The string is not required to start with 0x .
156
+ // Will only successful parse hex values that will fit into ` output` , i.e.
157
+ // 0x0000'0000'0000'0000 < ` input` < 0xFFFF'FFFF'FFFF'FFFF .
158
+ // The string is not required to start with "0x" .
150
159
BASE_EXPORT bool HexStringToUInt64 (std::string_view input, uint64_t * output);
151
160
152
161
// Similar to the previous functions, except that output is a vector of bytes.
153
- // | *output| will contain as many bytes as were successfully parsed prior to the
162
+ // ` *output` will contain as many bytes as were successfully parsed prior to the
154
163
// error. There is no overflow, but input.size() must be evenly divisible by 2.
155
- // Leading 0x or +/- are not allowed.
164
+ // Leading "0x" or +/- are not allowed.
156
165
BASE_EXPORT bool HexStringToBytes (std::string_view input,
157
166
std::vector<uint8_t >* output);
158
167
159
168
// Same as HexStringToBytes, but for an std::string.
160
169
BASE_EXPORT bool HexStringToString (std::string_view input, std::string* output);
161
170
162
- // Decodes the hex string | input| into a presized | output| . The output buffer
163
- // must be sized exactly to | input.size() / 2| or decoding will fail and no
164
- // bytes will be written to | output| . Decoding an empty input is also
171
+ // Decodes the hex string ` input` into a presized ` output` . The output buffer
172
+ // must be sized exactly to ` input.size() / 2` or decoding will fail and no
173
+ // bytes will be written to ` output` . Decoding an empty input is also
165
174
// considered a failure. When decoding fails due to encountering invalid input
166
- // characters, | output| will have been filled with the decoded bytes up until
175
+ // characters, ` output` will have been filled with the decoded bytes up until
167
176
// the failure.
168
177
BASE_EXPORT bool HexStringToSpan (std::string_view input,
169
178
base::span<uint8_t > output);
0 commit comments