From d648b5120b2fefa9e599898bd26f05ecf4428fac Mon Sep 17 00:00:00 2001 From: Pieter Wuille Date: Mon, 4 Apr 2022 11:23:03 -0400 Subject: Make SanitizeString use string_view --- src/util/strencodings.cpp | 14 +++++++------- src/util/strencodings.h | 2 +- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/util/strencodings.cpp b/src/util/strencodings.cpp index 9a6883228f..6346bc0811 100644 --- a/src/util/strencodings.cpp +++ b/src/util/strencodings.cpp @@ -24,15 +24,15 @@ static const std::string SAFE_CHARS[] = CHARS_ALPHA_NUM + "!*'();:@&=+$,/?#[]-_.~%", // SAFE_CHARS_URI }; -std::string SanitizeString(const std::string& str, int rule) +std::string SanitizeString(std::string_view str, int rule) { - std::string strResult; - for (std::string::size_type i = 0; i < str.size(); i++) - { - if (SAFE_CHARS[rule].find(str[i]) != std::string::npos) - strResult.push_back(str[i]); + std::string result; + for (char c : str) { + if (SAFE_CHARS[rule].find(c) != std::string::npos) { + result.push_back(c); + } } - return strResult; + return result; } const signed char p_util_hexdigit[256] = diff --git a/src/util/strencodings.h b/src/util/strencodings.h index 678f42cb06..82645c6bf0 100644 --- a/src/util/strencodings.h +++ b/src/util/strencodings.h @@ -54,7 +54,7 @@ enum class ByteUnit : uint64_t { * @param[in] rule The set of safe chars to choose (default: least restrictive) * @return A new string without unsafe chars */ -std::string SanitizeString(const std::string& str, int rule = SAFE_CHARS_DEFAULT); +std::string SanitizeString(std::string_view str, int rule = SAFE_CHARS_DEFAULT); std::vector ParseHex(std::string_view str); signed char HexDigit(char c); /* Returns true if each character in str is a hex character, and has an even -- cgit v1.2.3