summaryrefslogtreecommitdiff
path: root/kms++util/strhelpers.h
diff options
context:
space:
mode:
Diffstat (limited to 'kms++util/strhelpers.h')
-rw-r--r--kms++util/strhelpers.h33
1 files changed, 33 insertions, 0 deletions
diff --git a/kms++util/strhelpers.h b/kms++util/strhelpers.h
new file mode 100644
index 0000000..2c540f3
--- /dev/null
+++ b/kms++util/strhelpers.h
@@ -0,0 +1,33 @@
+#include <sstream>
+#include <string>
+#include <vector>
+#include <functional>
+
+std::string to_lower(const std::string& str);
+
+template <typename T>
+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 <typename T>
+std::string join(const std::vector<T>& values, const std::string& delim, std::function<std::string(T)> 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)));