29 #include <boost/lexical_cast.hpp>
35 inline std::vector<T>
Split(
const std::string&
source,
const std::string& splitBy,
bool trimElements =
false,
bool removeEmptyElements =
false)
39 return std::vector<T>();
42 std::vector<std::string> components =
Split(
source, splitBy, trimElements, removeEmptyElements);
45 std::vector<T> result(components.size());
46 std::transform(components.begin(), components.end(), result.begin(), boost::lexical_cast<T, std::string>);
54 template<std::size_t...Is>
58 static std::string
Format(
const std::string& form,
const std::tuple<Ts...>& tuple)
61 #pragma GCC diagnostic push
62 #pragma GCC diagnostic ignored "-Wformat-security"
64 int sz = std::snprintf(buff,
sizeof(buff), form.c_str(), std::get<Is>(tuple)...);
65 if (0 < sz &&
static_cast<std::size_t
>(sz) <
sizeof(buff))
69 std::vector<char> buffd(sz + 1);
70 if (std::snprintf(buff,
sizeof(buff), form.c_str(), std::get<Is>(tuple)...) != sz)
72 throw std::logic_error
75 " std::snprintf behaved unexpectedly"
78 #pragma GCC diagnostic pop
81 static std::string
Format(
const std::string& form, std::tuple<>)
89 template<std::size_t From, std::size_t To,
class...Ts>
90 std::string
TupleToStringF(
const std::string& form,
const std::tuple<Ts...>& tuple)
95 template<std::size_t From,
class...Ts>
96 std::string
TupleToStringF(
const std::string& form,
const std::tuple<Ts...>& tuple)
102 std::string
TupleToStringF(
const std::string& form,
const std::tuple<Ts...>& tuple)
104 return TupleToStringF<0>(form, tuple);