aboutsummaryrefslogtreecommitdiff
path: root/src/util/string.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/util/string.h')
-rw-r--r--src/util/string.h13
1 files changed, 13 insertions, 0 deletions
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