diff options
Diffstat (limited to 'src/libutil/util.hh')
-rw-r--r-- | src/libutil/util.hh | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/src/libutil/util.hh b/src/libutil/util.hh index 94d8cc555..9b149de80 100644 --- a/src/libutil/util.hh +++ b/src/libutil/util.hh @@ -510,6 +510,18 @@ std::optional<N> string2Float(const std::string_view s) } +/* Convert a little-endian integer to host order. */ +template<typename T> +T readLittleEndian(unsigned char * p) +{ + T x = 0; + for (size_t i = 0; i < sizeof(x); ++i, ++p) { + x |= ((T) *p) << (i * 8); + } + return x; +} + + /* Return true iff `s' starts with `prefix'. */ bool hasPrefix(std::string_view s, std::string_view prefix); @@ -563,6 +575,12 @@ std::string base64Decode(std::string_view s); std::string stripIndentation(std::string_view s); +/* Get the prefix of 's' up to and excluding the next line break (LF + optionally preceded by CR), and the remainder following the line + break. */ +std::pair<std::string_view, std::string_view> getLine(std::string_view s); + + /* Get a value for the specified key from an associate container. */ template <class T> const typename T::mapped_type * get(const T & map, const typename T::key_type & key) @@ -737,4 +755,13 @@ inline std::string operator + (std::string && s, std::string_view s2) return std::move(s); } +inline std::string operator + (std::string_view s1, const char * s2) +{ + std::string s; + s.reserve(s1.size() + strlen(s2)); + s.append(s1); + s.append(s2); + return s; +} + } |