50std::string
fmtf(
const char* f, ... );
51template<
typename T >
inline std::string
fmt(
const T& val);
57 std::ostream &
o,
X list )
63 while( !list.empty() ) {
64 o <<
fmt( list.head() );
65 if ( !list.tail().empty() )
74inline std::string
fmt(
const T& val)
76 std::stringstream str;
84template<>
inline std::string
fmt<char*>(
char *
const & val) {
return val; }
95 for (
typename C::const_iterator i =
c.begin(); i !=
c.end(); ++i ) {
97 if ( i !=
c.end() && i + 1 !=
c.end() )
106template<
typename X >
107inline std::string
fmt(
const std::set< X >& val) {
112template<
typename X >
113inline std::string
fmt(
const std::vector< X > &val) {
118template<
typename X >
119inline std::string
fmt(
const std::deque< X > &val) {
124inline std::string
basename(
const std::string& pathname)
126 size_t pos = pathname.rfind(
"/");
127 if (pos == std::string::npos)
130 return pathname.substr(pos+1);
134inline std::string
dirname(
const std::string& pathname)
136 size_t pos = pathname.rfind(
"/");
137 if (pos == std::string::npos)
138 return std::string();
141 return std::string(
"/");
143 return pathname.substr(0, pos);
151std::string
normpath(
const std::string& pathname);
156 if (str.size() <
part.size())
158 return str.substr(0,
part.size()) ==
part;
164 if (str.size() <
part.size())
166 return str.substr(str.size() -
part.size()) ==
part;
172 res.reserve(str.size());
173 for (std::string::const_iterator i = str.begin(); i != str.end(); ++i)
181#if !__xlC__ && (! __GNUC__ || __GNUC__ >= 4)
186template<
typename FUN>
193 size_t end = str.size() - 1;
199 return str.substr(beg, end-beg+1);
205inline std::string
trim(
const std::string& str)
207 return trim(str, ::isspace);
211inline std::string
trim(
const std::string& str)
217 size_t end = str.size() - 1;
218 while (beg < end && ::isspace(str[beg]))
220 while (end >= beg && ::isspace(str[end]))
223 return str.substr(beg, end-beg+1);
228inline std::string
toupper(
const std::string& str)
231 res.reserve(str.size());
232 for (std::string::const_iterator i = str.begin(); i != str.end(); ++i)
238inline std::string
tolower(
const std::string& str)
241 res.reserve(str.size());
242 for (std::string::const_iterator i = str.begin(); i != str.end(); ++i)
248inline std::string
ucfirst(
const std::string& str)
250 if (str.empty())
return str;
253 return res +
tolower(str.substr(1));
291std::string
urlencode(
const std::string& str);
294std::string
urldecode(
const std::string& str);
323 const std::string& sep;
324 const std::string& str;
329 const_iterator(
const std::string& sep,
const std::string& str) : sep(sep), str(str), pos(0)
333 const_iterator(
const std::string& sep,
const std::string& str,
bool) : sep(sep), str(str), pos(std::string::
npos) {}
337 if (pos == str.size())
338 pos = std::string::npos;
343 if (pos + 1 == str.size())
344 end = std::string::npos;
348 end = str.find(sep, pos);
349 if (
end == std::string::npos)
351 cur = str.substr(pos);
356 cur = str.substr(pos,
end-pos);
357 pos =
end + sep.size();
365 if (pos == std::string::npos)
366 return std::string();
368 return str.substr(pos);
383 return pos ==
ti.pos;
389 return pos !=
ti.pos;
396 Split(
const std::string& sep,
const std::string& str) : sep(sep), str(str) {}
405template<
typename ITER>
406std::string
join(
const ITER& begin,
const ITER& end,
const std::string& sep =
", ")
408 std::stringstream res;
410 for (
ITER i = begin; i != end; ++i)
442 std::pair<std::string, std::string> value;
451 const std::pair<std::string, std::string>&
operator*()
const
455 const std::pair<std::string, std::string>*
operator->()
const
476std::string
c_escape(
const std::string& str);
bool operator!=(const const_iterator &ti) const
Definition string.h:385
const_iterator(const std::string &sep, const std::string &str)
Definition string.h:329
const std::string & operator*() const
Definition string.h:371
const_iterator(const std::string &sep, const std::string &str, bool)
Definition string.h:333
bool operator==(const const_iterator &ti) const
Definition string.h:379
std::string remainder() const
Definition string.h:363
const std::string * operator->() const
Definition string.h:375
const_iterator & operator++()
Definition string.h:335
Split a string where a given substring is found.
Definition string.h:315
Split(const std::string &sep, const std::string &str)
Create a splitter that uses the given regular expression to find tokens.
Definition string.h:396
const_iterator begin() const
Split the string and iterate the resulting tokens.
Definition string.h:401
const_iterator end() const
Definition string.h:402
const_iterator()
Definition string.h:447
const_iterator & operator++()
Definition string.cpp:318
bool operator==(const const_iterator &ti) const
Definition string.h:459
const std::pair< std::string, std::string > & operator*() const
Definition string.h:451
const std::pair< std::string, std::string > * operator->() const
Definition string.h:455
bool operator!=(const const_iterator &ti) const
Definition string.h:463
Parse a record of Yaml-style field: value couples.
Definition string.h:436
const_iterator end()
Definition string.h:470
const_iterator begin(std::istream &in)
Definition string.h:469
Definition operators.h:12
std::string fmt< char * >(char *const &val)
Definition string.h:84
std::string fmt_container(const C &c, char f, char l)
Definition string.h:87
std::string join(const ITER &begin, const ITER &end, const std::string &sep=", ")
Definition string.h:406
TPair< std::ostream, typenameX::Type >::First & operator<<(std::ostream &o, X list)
Definition string.h:56
std::string trim(const std::string &str, const FUN &classifier)
Return the substring of 'str' without all leading and trailing characters for which 'classifier' retu...
Definition string.h:187
std::string normpath(const std::string &pathname)
Normalise a pathname.
Definition string.cpp:133
std::string urlencode(const std::string &str)
Urlencode a string.
Definition string.cpp:160
std::string c_unescape(const std::string &str, size_t &lenParsed)
Unescape a C string, stopping at the first double quotes or at the end of the string.
Definition string.cpp:424
std::string dirname(const std::string &pathname)
Given a pathname, return the directory name without the file name.
Definition string.h:134
std::string toupper(const std::string &str)
Convert a string to uppercase.
Definition string.h:228
std::string urldecode(const std::string &str)
Decode an urlencoded string.
Definition string.cpp:178
bool endsWith(const std::string &str, const std::string &part)
Check if a string ends with the given substring.
Definition string.h:162
std::string encodeBase64(const std::string &str)
Encode a string in Base64.
Definition string.cpp:208
std::string replace(const std::string &str, char from, char to)
Definition string.h:169
std::string appendpath(const std::string &path1, const std::string &path2)
Definition string.h:277
std::string decodeBase64(const std::string &str)
Decode a string encoded in Base64.
Definition string.cpp:241
std::string fmt< std::string >(const std::string &val)
Definition string.h:81
bool startsWith(const std::string &str, const std::string &part)
Check if a string starts with the given substring.
Definition string.h:154
std::string c_escape(const std::string &str)
Escape the string so it can safely used as a C string inside double quotes.
Definition string.cpp:400
std::string ucfirst(const std::string &str)
Return the same string, with the first character uppercased.
Definition string.h:248
std::string joinpath(const std::string &path1, const std::string &path2)
Join two paths, adding slashes when appropriate.
Definition string.h:257
std::string fmtf(const char *f,...)
Definition string.cpp:113
std::string tolower(const std::string &str)
Convert a string to lowercase.
Definition string.h:238
std::string basename(const std::string &pathname)
Given a pathname, return the file name without its path.
Definition string.h:124
std::string fmt(const char *f,...)
Definition string.cpp:123
A First
Definition sfinae.h:97