1 #ifndef UTILMM_STRINGTOOLS_HH
2 #define UTILMM_STRINGTOOLS_HH
8 #include <boost/filesystem/path.hpp>
9 #include <boost/lexical_cast.hpp>
14 inline stringlist split(std::string
const& s, std::string
const& sep =
" ",
bool ignore_empty =
true)
19 string::size_type sep_length = sep.length();
21 string::size_type from = 0;
24 string::size_type to = s.find(sep, from);
25 if (to == string::npos)
27 if (from < s.length() || !ignore_empty)
28 l.push_back(
string(s, from));
32 if (to > from || !ignore_empty)
33 l.push_back(
string(s, from, to - from));
34 from = to + sep_length;
47 stringlist::const_iterator
const end = l.end();
48 stringlist::const_iterator it = l.begin();
49 for (++it; it != l.end(); ++it)
55 inline std::string
join(std::list<T>
const& l, std::string
const& sep =
" ")
58 for (
typename std::template list<T>::const_iterator it = l.begin(); it != l.end(); ++it)
59 strl.push_back(boost::lexical_cast<std::string>(*it));
60 return join(strl, sep);
63 inline std::string
upcase(std::string
const& s)
67 string::iterator it, end = ret.end();
68 for (it = ret.begin(); it != ret.end(); ++it)
74 inline bool starts_with(std::string
const& str, std::string
const& start)
75 {
return std::string(str, 0, start.length()) == start; }
77 inline boost::filesystem::path
clean_path(std::string str)
80 string::size_type i = str.find(
"//");
81 while (i < str.length())
83 str = str.erase(i, 1);
87 boost::filesystem::path p(str);
bool starts_with(std::string const &str, std::string const &start)
Definition: stringtools.hh:74
std::list< std::string > stringlist
Definition: stringtools.hh:12
boost::filesystem::path clean_path(std::string str)
Definition: stringtools.hh:77
std::string upcase(std::string const &s)
Definition: stringtools.hh:63
std::string join(stringlist const &l, std::string const &sep=" ")
Definition: stringtools.hh:38
stringlist split(std::string const &s, std::string const &sep=" ", bool ignore_empty=true)
Definition: stringtools.hh:14