Make IsHex use string_view

This commit is contained in:
Pieter Wuille authored and MacroFake committed 2022-04-27 14:12:55 +02:00
1 parent c1d165a8c2
commit 40062997f2
2 files changed
+4 -6

No files matched your search

+3 -5
View File
@@ -58,12 +58,10 @@ signed char HexDigit(char c)
return p_util_hexdigit[(unsigned char)c];
}
bool IsHex(const std::string& str)
bool IsHex(std::string_view str)
{
for(std::string::const_iterator it(str.begin()); it != str.end(); ++it)
{
if (HexDigit(*it) < 0)
return false;
for (char c : str) {
if (HexDigit(c) < 0) return false;
}
return (str.size() > 0) && (str.size()%2 == 0);
}
+1 -1
View File
@@ -59,7 +59,7 @@ std::vector<unsigned char> 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
* number of hex digits.*/
bool IsHex(const std::string& str);
bool IsHex(std::string_view str);
/**
* Return true if the string is a hex number, optionally prefixed with "0x"
*/