38 #ifndef SFL_STRUTIL_HPP
39 #define SFL_STRUTIL_HPP
54 template<
typename displayable_t,
typename prefix_t>
55 std::string displayString(displayable_t
const & displayable, prefix_t
const & prefix)
57 std::ostringstream result;
58 displayable.display(result, prefix);
68 template<
typename Foo>
69 std::string to_string(
const Foo & foo) {
70 std::ostringstream os;
77 std::string to_string<bool>(
const bool & flag);
80 template<
typename Foo>
81 bool string_to(
const std::string & str, Foo & foo) {
83 std::istringstream is(str);
96 bool string_to<bool>(
const std::string & str,
bool & foo);
102 template<
typename Foo>
103 bool string_to_bool(
const std::string & str, Foo & foo) {
105 if( ! string_to(str, bar))
136 bool splitstring(std::string
const & input,
char separator,
137 std::string & head, std::string & tail);
144 template<
typename tokenlist_t>
145 size_t tokenize(std::string
const & input,
char separator, tokenlist_t & output) {
147 std::string tail(input);
148 while (splitstring(tail, separator, head, tail))
149 output.push_back(head);
150 output.push_back(head);
151 return output.size();
159 template<
typename tokenlist_t,
typename value_t>
160 bool token_to(tokenlist_t
const & tokenlist,
size_t index, value_t & value) {
161 if (index >= tokenlist.size())
163 return string_to(tokenlist[index], value);
168 #endif // SFL_STRUTIL_HPP