mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-11-12 15:09:59 +01:00
Make SanitizeString use string_view
This commit is contained in:
@@ -24,15 +24,15 @@ static const std::string SAFE_CHARS[] =
|
|||||||
CHARS_ALPHA_NUM + "!*'();:@&=+$,/?#[]-_.~%", // SAFE_CHARS_URI
|
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;
|
std::string result;
|
||||||
for (std::string::size_type i = 0; i < str.size(); i++)
|
for (char c : str) {
|
||||||
{
|
if (SAFE_CHARS[rule].find(c) != std::string::npos) {
|
||||||
if (SAFE_CHARS[rule].find(str[i]) != std::string::npos)
|
result.push_back(c);
|
||||||
strResult.push_back(str[i]);
|
}
|
||||||
}
|
}
|
||||||
return strResult;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
const signed char p_util_hexdigit[256] =
|
const signed char p_util_hexdigit[256] =
|
||||||
|
|||||||
@@ -54,7 +54,7 @@ enum class ByteUnit : uint64_t {
|
|||||||
* @param[in] rule The set of safe chars to choose (default: least restrictive)
|
* @param[in] rule The set of safe chars to choose (default: least restrictive)
|
||||||
* @return A new string without unsafe chars
|
* @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<unsigned char> ParseHex(std::string_view str);
|
std::vector<unsigned char> ParseHex(std::string_view str);
|
||||||
signed char HexDigit(char c);
|
signed char HexDigit(char c);
|
||||||
/* Returns true if each character in str is a hex character, and has an even
|
/* Returns true if each character in str is a hex character, and has an even
|
||||||
|
|||||||
Reference in New Issue
Block a user