@@ -67,7 +67,7 @@ bool IsHexNumber(std::string_view str);
6767std::optional<std::vector<unsigned char >> DecodeBase64 (std::string_view str);
6868std::string EncodeBase64 (Span<const unsigned char > input);
6969inline 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)); }
7171std::optional<std::vector<unsigned char >> DecodeBase32 (std::string_view str);
7272
7373/* *
@@ -82,9 +82,9 @@ std::string EncodeBase32(Span<const unsigned char> input, bool pad = true);
8282 * If `pad` is true, then the output will be padded with '=' so that its length
8383 * is a multiple of 8.
8484 */
85- std::string EncodeBase32 (const std::string& str, bool pad = true );
85+ std::string EncodeBase32 (std::string_view str, bool pad = true );
8686
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);
8888
8989// LocaleIndependentAtoi is provided for backwards compatibility reasons.
9090//
@@ -98,12 +98,12 @@ void SplitHostPort(std::string in, uint16_t& portOut, std::string& hostOut);
9898// undefined behavior, while this function returns the maximum or minimum
9999// values, respectively.
100100template <typename T>
101- T LocaleIndependentAtoi (const std::string& str)
101+ T LocaleIndependentAtoi (std::string_view str)
102102{
103103 static_assert (std::is_integral<T>::value);
104104 T result;
105105 // Emulate atoi(...) handling of white space and leading +/-.
106- std::string s = TrimString (str);
106+ std::string_view s = TrimStringView (str);
107107 if (!s.empty () && s[0 ] == ' +' ) {
108108 if (s.length () >= 2 && s[1 ] == ' -' ) {
109109 return 0 ;
@@ -159,7 +159,7 @@ constexpr inline bool IsSpace(char c) noexcept {
159159 * parsed value is not in the range representable by the type T.
160160 */
161161template <typename T>
162- std::optional<T> ToIntegral (const std::string& str)
162+ std::optional<T> ToIntegral (std::string_view str)
163163{
164164 static_assert (std::is_integral<T>::value);
165165 T result;
@@ -175,42 +175,42 @@ std::optional<T> ToIntegral(const std::string& str)
175175 * @returns true if the entire string could be parsed as valid integer,
176176 * false if not the entire string could be parsed or when overflow or underflow occurred.
177177 */
178- [[nodiscard]] bool ParseInt32 (const std::string& str, int32_t *out);
178+ [[nodiscard]] bool ParseInt32 (std::string_view str, int32_t *out);
179179
180180/* *
181181 * Convert string to signed 64-bit integer with strict parse error feedback.
182182 * @returns true if the entire string could be parsed as valid integer,
183183 * false if not the entire string could be parsed or when overflow or underflow occurred.
184184 */
185- [[nodiscard]] bool ParseInt64 (const std::string& str, int64_t *out);
185+ [[nodiscard]] bool ParseInt64 (std::string_view str, int64_t *out);
186186
187187/* *
188188 * Convert decimal string to unsigned 8-bit integer with strict parse error feedback.
189189 * @returns true if the entire string could be parsed as valid integer,
190190 * false if not the entire string could be parsed or when overflow or underflow occurred.
191191 */
192- [[nodiscard]] bool ParseUInt8 (const std::string& str, uint8_t *out);
192+ [[nodiscard]] bool ParseUInt8 (std::string_view str, uint8_t *out);
193193
194194/* *
195195 * Convert decimal string to unsigned 16-bit integer with strict parse error feedback.
196196 * @returns true if the entire string could be parsed as valid integer,
197197 * false if the entire string could not be parsed or if overflow or underflow occurred.
198198 */
199- [[nodiscard]] bool ParseUInt16 (const std::string& str, uint16_t * out);
199+ [[nodiscard]] bool ParseUInt16 (std::string_view str, uint16_t * out);
200200
201201/* *
202202 * Convert decimal string to unsigned 32-bit integer with strict parse error feedback.
203203 * @returns true if the entire string could be parsed as valid integer,
204204 * false if not the entire string could be parsed or when overflow or underflow occurred.
205205 */
206- [[nodiscard]] bool ParseUInt32 (const std::string& str, uint32_t *out);
206+ [[nodiscard]] bool ParseUInt32 (std::string_view str, uint32_t *out);
207207
208208/* *
209209 * Convert decimal string to unsigned 64-bit integer with strict parse error feedback.
210210 * @returns true if the entire string could be parsed as valid integer,
211211 * false if not the entire string could be parsed or when overflow or underflow occurred.
212212 */
213- [[nodiscard]] bool ParseUInt64 (const std::string& str, uint64_t *out);
213+ [[nodiscard]] bool ParseUInt64 (std::string_view str, uint64_t *out);
214214
215215/* *
216216 * 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
223223 * Format a paragraph of text to a fixed width, adding spaces for
224224 * indentation to any added line.
225225 */
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 );
227227
228228/* *
229229 * Timing-attack-resistant comparison.
@@ -245,7 +245,7 @@ bool TimingResistantEqual(const T& a, const T& b)
245245 * @returns true on success, false on error.
246246 * @note The result must be in the range (-10^18,10^18), otherwise an overflow error will trigger.
247247 */
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);
249249
250250namespace {
251251/* * Helper class for the default infn argument to ConvertBits (just returns the input). */
@@ -306,7 +306,7 @@ constexpr char ToLower(char c)
306306 * @param[in] str the string to convert to lowercase.
307307 * @returns lowercased equivalent of str
308308 */
309- std::string ToLower (const std::string& str);
309+ std::string ToLower (std::string_view str);
310310
311311/* *
312312 * Converts the given character to its uppercase equivalent.
@@ -332,7 +332,7 @@ constexpr char ToUpper(char c)
332332 * @param[in] str the string to convert to uppercase.
333333 * @returns UPPERCASED EQUIVALENT OF str
334334 */
335- std::string ToUpper (const std::string& str);
335+ std::string ToUpper (std::string_view str);
336336
337337/* *
338338 * Capitalizes the first character of the given string.
@@ -356,6 +356,6 @@ std::string Capitalize(std::string str);
356356 * @returns optional uint64_t bytes from str or nullopt
357357 * if ToIntegral is false, str is empty, trailing whitespace or overflow
358358 */
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);
360360
361361#endif // BITCOIN_UTIL_STRENCODINGS_H
0 commit comments