aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/netaddress.cpp10
-rw-r--r--src/util/string.h13
2 files changed, 15 insertions, 8 deletions
diff --git a/src/netaddress.cpp b/src/netaddress.cpp
index b50cf74069..86fca451f0 100644
--- a/src/netaddress.cpp
+++ b/src/netaddress.cpp
@@ -7,8 +7,9 @@
#include <hash.h>
#include <tinyformat.h>
-#include <util/strencodings.h>
#include <util/asmap.h>
+#include <util/strencodings.h>
+#include <util/string.h>
#include <algorithm>
#include <array>
@@ -50,13 +51,6 @@ void CNetAddr::SetIP(const CNetAddr& ipIn)
m_addr = ipIn.m_addr;
}
-template <typename T1, size_t PREFIX_LEN>
-inline bool HasPrefix(const T1& obj, const std::array<uint8_t, PREFIX_LEN>& prefix)
-{
- return obj.size() >= PREFIX_LEN &&
- std::equal(std::begin(prefix), std::end(prefix), std::begin(obj));
-}
-
void CNetAddr::SetLegacyIPv6(Span<const uint8_t> ipv6)
{
assert(ipv6.size() == ADDR_IPV6_SIZE);
diff --git a/src/util/string.h b/src/util/string.h
index cdb41630c6..a0c87bd00c 100644
--- a/src/util/string.h
+++ b/src/util/string.h
@@ -7,6 +7,8 @@
#include <attributes.h>
+#include <algorithm>
+#include <array>
#include <cstring>
#include <locale>
#include <sstream>
@@ -74,4 +76,15 @@ std::string ToString(const T& t)
return oss.str();
}
+/**
+ * Check whether a container begins with the given prefix.
+ */
+template <typename T1, size_t PREFIX_LEN>
+NODISCARD inline bool HasPrefix(const T1& obj,
+ const std::array<uint8_t, PREFIX_LEN>& prefix)
+{
+ return obj.size() >= PREFIX_LEN &&
+ std::equal(std::begin(prefix), std::end(prefix), std::begin(obj));
+}
+
#endif // BITCOIN_UTIL_STRENCODINGS_H