aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/util/strencodings.cpp11
-rw-r--r--src/util/strencodings.h2
2 files changed, 5 insertions, 8 deletions
diff --git a/src/util/strencodings.cpp b/src/util/strencodings.cpp
index 7e7e7e2003..9a6883228f 100644
--- a/src/util/strencodings.cpp
+++ b/src/util/strencodings.cpp
@@ -66,17 +66,14 @@ bool IsHex(std::string_view str)
return (str.size() > 0) && (str.size()%2 == 0);
}
-bool IsHexNumber(const std::string& str)
+bool IsHexNumber(std::string_view str)
{
- size_t starting_location = 0;
- if (str.size() > 2 && *str.begin() == '0' && *(str.begin()+1) == 'x') {
- starting_location = 2;
- }
- for (const char c : str.substr(starting_location)) {
+ if (str.substr(0, 2) == "0x") str.remove_prefix(2);
+ for (char c : str) {
if (HexDigit(c) < 0) return false;
}
// Return false for empty string or "0x".
- return (str.size() > starting_location);
+ return str.size() > 0;
}
std::vector<unsigned char> ParseHex(std::string_view str)
diff --git a/src/util/strencodings.h b/src/util/strencodings.h
index 67baaaeca0..678f42cb06 100644
--- a/src/util/strencodings.h
+++ b/src/util/strencodings.h
@@ -63,7 +63,7 @@ bool IsHex(std::string_view str);
/**
* Return true if the string is a hex number, optionally prefixed with "0x"
*/
-bool IsHexNumber(const std::string& str);
+bool IsHexNumber(std::string_view str);
std::vector<unsigned char> DecodeBase64(const char* p, bool* pf_invalid = nullptr);
std::string DecodeBase64(const std::string& str, bool* pf_invalid = nullptr);
std::string EncodeBase64(Span<const unsigned char> input);