aboutsummaryrefslogtreecommitdiff
path: root/src/util/strencodings.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/util/strencodings.h')
-rw-r--r--src/util/strencodings.h34
1 files changed, 17 insertions, 17 deletions
diff --git a/src/util/strencodings.h b/src/util/strencodings.h
index ba8132b08d..ebb6d88952 100644
--- a/src/util/strencodings.h
+++ b/src/util/strencodings.h
@@ -67,7 +67,7 @@ bool IsHexNumber(std::string_view str);
std::optional<std::vector<unsigned char>> DecodeBase64(std::string_view str);
std::string EncodeBase64(Span<const unsigned char> input);
inline std::string EncodeBase64(Span<const std::byte> input) { return EncodeBase64(MakeUCharSpan(input)); }
-inline std::string EncodeBase64(const std::string& str) { return EncodeBase64(MakeUCharSpan(str)); }
+inline std::string EncodeBase64(std::string_view str) { return EncodeBase64(MakeUCharSpan(str)); }
std::optional<std::vector<unsigned char>> DecodeBase32(std::string_view str);
/**
@@ -82,9 +82,9 @@ std::string EncodeBase32(Span<const unsigned char> input, bool pad = true);
* If `pad` is true, then the output will be padded with '=' so that its length
* is a multiple of 8.
*/
-std::string EncodeBase32(const std::string& str, bool pad = true);
+std::string EncodeBase32(std::string_view str, bool pad = true);
-void SplitHostPort(std::string in, uint16_t& portOut, std::string& hostOut);
+void SplitHostPort(std::string_view in, uint16_t& portOut, std::string& hostOut);
// LocaleIndependentAtoi is provided for backwards compatibility reasons.
//
@@ -98,12 +98,12 @@ void SplitHostPort(std::string in, uint16_t& portOut, std::string& hostOut);
// undefined behavior, while this function returns the maximum or minimum
// values, respectively.
template <typename T>
-T LocaleIndependentAtoi(const std::string& str)
+T LocaleIndependentAtoi(std::string_view str)
{
static_assert(std::is_integral<T>::value);
T result;
// Emulate atoi(...) handling of white space and leading +/-.
- std::string s = TrimString(str);
+ std::string_view s = TrimStringView(str);
if (!s.empty() && s[0] == '+') {
if (s.length() >= 2 && s[1] == '-') {
return 0;
@@ -159,7 +159,7 @@ constexpr inline bool IsSpace(char c) noexcept {
* parsed value is not in the range representable by the type T.
*/
template <typename T>
-std::optional<T> ToIntegral(const std::string& str)
+std::optional<T> ToIntegral(std::string_view str)
{
static_assert(std::is_integral<T>::value);
T result;
@@ -175,42 +175,42 @@ std::optional<T> ToIntegral(const std::string& str)
* @returns true if the entire string could be parsed as valid integer,
* false if not the entire string could be parsed or when overflow or underflow occurred.
*/
-[[nodiscard]] bool ParseInt32(const std::string& str, int32_t *out);
+[[nodiscard]] bool ParseInt32(std::string_view str, int32_t *out);
/**
* Convert string to signed 64-bit integer with strict parse error feedback.
* @returns true if the entire string could be parsed as valid integer,
* false if not the entire string could be parsed or when overflow or underflow occurred.
*/
-[[nodiscard]] bool ParseInt64(const std::string& str, int64_t *out);
+[[nodiscard]] bool ParseInt64(std::string_view str, int64_t *out);
/**
* Convert decimal string to unsigned 8-bit integer with strict parse error feedback.
* @returns true if the entire string could be parsed as valid integer,
* false if not the entire string could be parsed or when overflow or underflow occurred.
*/
-[[nodiscard]] bool ParseUInt8(const std::string& str, uint8_t *out);
+[[nodiscard]] bool ParseUInt8(std::string_view str, uint8_t *out);
/**
* Convert decimal string to unsigned 16-bit integer with strict parse error feedback.
* @returns true if the entire string could be parsed as valid integer,
* false if the entire string could not be parsed or if overflow or underflow occurred.
*/
-[[nodiscard]] bool ParseUInt16(const std::string& str, uint16_t* out);
+[[nodiscard]] bool ParseUInt16(std::string_view str, uint16_t* out);
/**
* Convert decimal string to unsigned 32-bit integer with strict parse error feedback.
* @returns true if the entire string could be parsed as valid integer,
* false if not the entire string could be parsed or when overflow or underflow occurred.
*/
-[[nodiscard]] bool ParseUInt32(const std::string& str, uint32_t *out);
+[[nodiscard]] bool ParseUInt32(std::string_view str, uint32_t *out);
/**
* Convert decimal string to unsigned 64-bit integer with strict parse error feedback.
* @returns true if the entire string could be parsed as valid integer,
* false if not the entire string could be parsed or when overflow or underflow occurred.
*/
-[[nodiscard]] bool ParseUInt64(const std::string& str, uint64_t *out);
+[[nodiscard]] bool ParseUInt64(std::string_view str, uint64_t *out);
/**
* 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
* Format a paragraph of text to a fixed width, adding spaces for
* indentation to any added line.
*/
-std::string FormatParagraph(const std::string& in, size_t width = 79, size_t indent = 0);
+std::string FormatParagraph(std::string_view in, size_t width = 79, size_t indent = 0);
/**
* Timing-attack-resistant comparison.
@@ -245,7 +245,7 @@ bool TimingResistantEqual(const T& a, const T& b)
* @returns true on success, false on error.
* @note The result must be in the range (-10^18,10^18), otherwise an overflow error will trigger.
*/
-[[nodiscard]] bool ParseFixedPoint(const std::string &val, int decimals, int64_t *amount_out);
+[[nodiscard]] bool ParseFixedPoint(std::string_view, int decimals, int64_t *amount_out);
namespace {
/** Helper class for the default infn argument to ConvertBits (just returns the input). */
@@ -306,7 +306,7 @@ constexpr char ToLower(char c)
* @param[in] str the string to convert to lowercase.
* @returns lowercased equivalent of str
*/
-std::string ToLower(const std::string& str);
+std::string ToLower(std::string_view str);
/**
* Converts the given character to its uppercase equivalent.
@@ -332,7 +332,7 @@ constexpr char ToUpper(char c)
* @param[in] str the string to convert to uppercase.
* @returns UPPERCASED EQUIVALENT OF str
*/
-std::string ToUpper(const std::string& str);
+std::string ToUpper(std::string_view str);
/**
* Capitalizes the first character of the given string.
@@ -356,6 +356,6 @@ std::string Capitalize(std::string str);
* @returns optional uint64_t bytes from str or nullopt
* if ToIntegral is false, str is empty, trailing whitespace or overflow
*/
-std::optional<uint64_t> ParseByteUnits(const std::string& str, ByteUnit default_multiplier);
+std::optional<uint64_t> ParseByteUnits(std::string_view str, ByteUnit default_multiplier);
#endif // BITCOIN_UTIL_STRENCODINGS_H