summaryrefslogtreecommitdiff
path: root/libkms++util/strhelpers.h
blob: 2c540f38bf8721a459e4f914fbfdef55e14fbadf (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
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)));