@@ -67,7 +67,7 @@ bool IsHexNumber(std::string_view str);
67
67
std::optional<std::vector<unsigned char >> DecodeBase64 (std::string_view str);
68
68
std::string EncodeBase64 (Span<const unsigned char > input);
69
69
inline std::string EncodeBase64 (Span<const std::byte> input) { return EncodeBase64 (MakeUCharSpan (input)); }
70
- inline std::string EncodeBase64 (const std::string& str) { return EncodeBase64 (MakeUCharSpan (str)); }
70
+ inline std::string EncodeBase64 (std::string_view str) { return EncodeBase64 (MakeUCharSpan (str)); }
71
71
std::optional<std::vector<unsigned char >> DecodeBase32 (std::string_view str);
72
72
73
73
/* *
@@ -82,9 +82,9 @@ std::string EncodeBase32(Span<const unsigned char> input, bool pad = true);
82
82
* If `pad` is true, then the output will be padded with '=' so that its length
83
83
* is a multiple of 8.
84
84
*/
85
- std::string EncodeBase32 (const std::string& str, bool pad = true );
85
+ std::string EncodeBase32 (std::string_view str, bool pad = true );
86
86
87
- void SplitHostPort (std::string in, uint16_t & portOut, std::string& hostOut);
87
+ void SplitHostPort (std::string_view in, uint16_t & portOut, std::string& hostOut);
88
88
89
89
// LocaleIndependentAtoi is provided for backwards compatibility reasons.
90
90
//
@@ -98,12 +98,12 @@ void SplitHostPort(std::string in, uint16_t& portOut, std::string& hostOut);
98
98
// undefined behavior, while this function returns the maximum or minimum
99
99
// values, respectively.
100
100
template <typename T>
101
- T LocaleIndependentAtoi (const std::string& str)
101
+ T LocaleIndependentAtoi (std::string_view str)
102
102
{
103
103
static_assert (std::is_integral<T>::value);
104
104
T result;
105
105
// Emulate atoi(...) handling of white space and leading +/-.
106
- std::string s = TrimString (str);
106
+ std::string_view s = TrimStringView (str);
107
107
if (!s.empty () && s[0 ] == ' +' ) {
108
108
if (s.length () >= 2 && s[1 ] == ' -' ) {
109
109
return 0 ;
@@ -159,7 +159,7 @@ constexpr inline bool IsSpace(char c) noexcept {
159
159
* parsed value is not in the range representable by the type T.
160
160
*/
161
161
template <typename T>
162
- std::optional<T> ToIntegral (const std::string& str)
162
+ std::optional<T> ToIntegral (std::string_view str)
163
163
{
164
164
static_assert (std::is_integral<T>::value);
165
165
T result;
@@ -175,42 +175,42 @@ std::optional<T> ToIntegral(const std::string& str)
175
175
* @returns true if the entire string could be parsed as valid integer,
176
176
* false if not the entire string could be parsed or when overflow or underflow occurred.
177
177
*/
178
- [[nodiscard]] bool ParseInt32 (const std::string& str, int32_t *out);
178
+ [[nodiscard]] bool ParseInt32 (std::string_view str, int32_t *out);
179
179
180
180
/* *
181
181
* Convert string to signed 64-bit integer with strict parse error feedback.
182
182
* @returns true if the entire string could be parsed as valid integer,
183
183
* false if not the entire string could be parsed or when overflow or underflow occurred.
184
184
*/
185
- [[nodiscard]] bool ParseInt64 (const std::string& str, int64_t *out);
185
+ [[nodiscard]] bool ParseInt64 (std::string_view str, int64_t *out);
186
186
187
187
/* *
188
188
* Convert decimal string to unsigned 8-bit integer with strict parse error feedback.
189
189
* @returns true if the entire string could be parsed as valid integer,
190
190
* false if not the entire string could be parsed or when overflow or underflow occurred.
191
191
*/
192
- [[nodiscard]] bool ParseUInt8 (const std::string& str, uint8_t *out);
192
+ [[nodiscard]] bool ParseUInt8 (std::string_view str, uint8_t *out);
193
193
194
194
/* *
195
195
* Convert decimal string to unsigned 16-bit integer with strict parse error feedback.
196
196
* @returns true if the entire string could be parsed as valid integer,
197
197
* false if the entire string could not be parsed or if overflow or underflow occurred.
198
198
*/
199
- [[nodiscard]] bool ParseUInt16 (const std::string& str, uint16_t * out);
199
+ [[nodiscard]] bool ParseUInt16 (std::string_view str, uint16_t * out);
200
200
201
201
/* *
202
202
* Convert decimal string to unsigned 32-bit integer with strict parse error feedback.
203
203
* @returns true if the entire string could be parsed as valid integer,
204
204
* false if not the entire string could be parsed or when overflow or underflow occurred.
205
205
*/
206
- [[nodiscard]] bool ParseUInt32 (const std::string& str, uint32_t *out);
206
+ [[nodiscard]] bool ParseUInt32 (std::string_view str, uint32_t *out);
207
207
208
208
/* *
209
209
* Convert decimal string to unsigned 64-bit integer with strict parse error feedback.
210
210
* @returns true if the entire string could be parsed as valid integer,
211
211
* false if not the entire string could be parsed or when overflow or underflow occurred.
212
212
*/
213
- [[nodiscard]] bool ParseUInt64 (const std::string& str, uint64_t *out);
213
+ [[nodiscard]] bool ParseUInt64 (std::string_view str, uint64_t *out);
214
214
215
215
/* *
216
216
* Convert a span of bytes to a lower-case hexadecimal string.
@@ -223,7 +223,7 @@ inline std::string HexStr(const Span<const std::byte> s) { return HexStr(MakeUCh
223
223
* Format a paragraph of text to a fixed width, adding spaces for
224
224
* indentation to any added line.
225
225
*/
226
- std::string FormatParagraph (const std::string& in, size_t width = 79 , size_t indent = 0 );
226
+ std::string FormatParagraph (std::string_view in, size_t width = 79 , size_t indent = 0 );
227
227
228
228
/* *
229
229
* Timing-attack-resistant comparison.
@@ -245,7 +245,7 @@ bool TimingResistantEqual(const T& a, const T& b)
245
245
* @returns true on success, false on error.
246
246
* @note The result must be in the range (-10^18,10^18), otherwise an overflow error will trigger.
247
247
*/
248
- [[nodiscard]] bool ParseFixedPoint (const std::string &val , int decimals, int64_t *amount_out);
248
+ [[nodiscard]] bool ParseFixedPoint (std::string_view , int decimals, int64_t *amount_out);
249
249
250
250
namespace {
251
251
/* * Helper class for the default infn argument to ConvertBits (just returns the input). */
@@ -306,7 +306,7 @@ constexpr char ToLower(char c)
306
306
* @param[in] str the string to convert to lowercase.
307
307
* @returns lowercased equivalent of str
308
308
*/
309
- std::string ToLower (const std::string& str);
309
+ std::string ToLower (std::string_view str);
310
310
311
311
/* *
312
312
* Converts the given character to its uppercase equivalent.
@@ -332,7 +332,7 @@ constexpr char ToUpper(char c)
332
332
* @param[in] str the string to convert to uppercase.
333
333
* @returns UPPERCASED EQUIVALENT OF str
334
334
*/
335
- std::string ToUpper (const std::string& str);
335
+ std::string ToUpper (std::string_view str);
336
336
337
337
/* *
338
338
* Capitalizes the first character of the given string.
@@ -356,6 +356,6 @@ std::string Capitalize(std::string str);
356
356
* @returns optional uint64_t bytes from str or nullopt
357
357
* if ToIntegral is false, str is empty, trailing whitespace or overflow
358
358
*/
359
- std::optional<uint64_t > ParseByteUnits (const std::string& str, ByteUnit default_multiplier);
359
+ std::optional<uint64_t > ParseByteUnits (std::string_view str, ByteUnit default_multiplier);
360
360
361
361
#endif // BITCOIN_UTIL_STRENCODINGS_H
0 commit comments