aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPieter Wuille <pieter@wuille.net>2022-04-04 11:12:04 -0400
committerMacroFake <falke.marco@gmail.com>2022-04-27 14:12:55 +0200
commit40062997f223d88d4f92aaae4622a31476686163 (patch)
treefbe4db177806a7ef0deb210a59cb74e7de29e1eb
parentc1d165a8c2678c31aced5e1d46231d9996b0774a (diff)
Make IsHex use string_view
-rw-r--r--src/util/strencodings.cpp8
-rw-r--r--src/util/strencodings.h2
2 files changed, 4 insertions, 6 deletions
diff --git a/src/util/strencodings.cpp b/src/util/strencodings.cpp
index f5288eca17..7e7e7e2003 100644
--- a/src/util/strencodings.cpp
+++ b/src/util/strencodings.cpp
@@ -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);
}
diff --git a/src/util/strencodings.h b/src/util/strencodings.h
index 0e72466fc3..67baaaeca0 100644
--- a/src/util/strencodings.h
+++ b/src/util/strencodings.h
@@ -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"
*/