From dce7c0afa22ca6568bbf6cca6a9cd669ef8b4b28 Mon Sep 17 00:00:00 2001 From: Tomi Valkeinen Date: Fri, 3 Jun 2016 21:41:41 +0300 Subject: util: add helpers --- libkms++util/strhelpers.h | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 libkms++util/strhelpers.h (limited to 'libkms++util/strhelpers.h') diff --git a/libkms++util/strhelpers.h b/libkms++util/strhelpers.h new file mode 100644 index 0000000..2c540f3 --- /dev/null +++ b/libkms++util/strhelpers.h @@ -0,0 +1,33 @@ +#include +#include +#include +#include + +std::string to_lower(const std::string& str); + +template +std::string join(const T& values, const std::string& delim) +{ + std::ostringstream ss; + for (const auto& v : values) { + if (&v != &values[0]) + ss << delim; + ss << v; + } + return ss.str(); +} + +template +std::string join(const std::vector& values, const std::string& delim, std::function func) +{ + std::ostringstream ss; + for (const auto& v : values) { + if (&v != &values[0]) + ss << delim; + ss << func(v); + } + return ss.str(); +} + +std::string sformat(const char *fmt, ...) + __attribute__ ((format (printf, 1, 2))); -- cgit v1.2.3