38 #ifndef DRAIN_STRING_H_
39 #define DRAIN_STRING_H_
58 bool startsWith(
const std::string &s,
const std::string & substring);
62 bool endsWith(
const std::string &s,
const std::string & substring);
69 std::string &
upperCase(std::string & s,
size_t n = std::numeric_limits<size_t>::max());
82 std::string &
lowerCase(std::string & s,
size_t n = std::numeric_limits<size_t>::max());
96 std::string
replace(
const std::string &src,
const std::string &from,
const std::string & to){
102 typedef std::map<std::string,std::string> conv_map_t;
110 void replace(
const conv_map_t & m, std::string &s, std::size_t pos = 0);
115 void replace(
const std::string &src,
const std::string &from,
const std::string & to, std::string & dst);
120 std::string
trim(
const std::string &s,
const std::string &trimChars=
" \t\n\r");
131 std::string
trimSymmetric(
const std::string &s,
const std::string &leading=
"'\"",
const std::string & trailing=
"");
147 bool trimScan(
const std::string &s,
size_t & pos1,
size_t & pos2,
const std::string &trimChars=
" \t\n");
163 template <
class T,
class C>
165 void split(
const std::string & s, T & sequence,
const C &separators,
const std::string & trimChars=
" \t\n");
192 template <
class T1,
class T2,
class C>
194 bool split2(
const std::string & s, T1 & first, T2 & second,
const C &separators,
const std::string & trimChars=
" \t\n");
202 std::ostream &
join(
const T & container, std::ostream & ostr,
char separator = 0){
204 for (
typename T::const_iterator it = container.begin(); it != container.end(); ++it){
219 std::string
join(T & container,
char separator = 0){
220 std::stringstream sstr;
226 template <
unsigned int S>
228 void read(std::istream &istr, std::string & s){
230 while (istr.read(buffer, S)){
233 s.append(buffer, istr.gcount());
248 void convert(
const std::string &s, T & dst);
259 T
convert(
const std::string &s);
263 std::string &
import(
const T & src, std::string & target);
281 const T &
lazyConvert(
const std::string &s, T & tmp);
287 void appendString(T & sequence,
const std::string & str){
288 typename T::value_type tmp;
294 void appendSubstring(T & sequence,
const std::string & str, std::string::size_type pos, std::string::size_type n){
297 appendString(sequence, str.substr(pos, n));
300 appendString(sequence,
"");
308 template <
class T,
class C>
309 void StringTools::split(
const std::string & str, T & sequence,
const C & separators,
const std::string & trimChars){
313 const bool TRIM = !trimChars.empty();
314 const std::string::size_type n = str.size();
316 std::string::size_type pos1 = 0;
317 std::string::size_type pos2 = n;
323 appendSubstring(sequence, str, pos1, pos2-pos1);
326 appendString(sequence, str);
333 std::string::size_type pos = pos1;
338 pos = str.find_first_of(separators, pos);
339 if (pos == std::string::npos){
343 appendSubstring(sequence, str, pos1, pos2-pos1);
350 appendSubstring(sequence, str, pos1, pos2-pos1);
351 pos = str.find_first_not_of(trimChars, pos+1);
365 template <
class T1,
class T2,
class S>
366 bool StringTools::split2(
const std::string & s, T1 & first, T2 & second,
const S & separators,
const std::string & trimChars){
368 std::size_t i = s.find_first_of(separators);
370 if (i != std::string::npos){
372 std::string srcFirst(s, 0, i);
374 std::string srcSecond(s, std::min(s.size(), i));
376 if (!trimChars.empty()){
383 if (!srcSecond.empty()){
384 if (!trimChars.empty()){
412 if (trimChars.empty()){
444 std::stringstream sstr(str);
469 std::string & StringTools::import(
const std::string & src, std::string & dst){
475 std::string & StringTools::import(
const T & x, std::string & dst){
476 std::stringstream sstr;
478 dst.assign(sstr.str());
Definition: DataSelector.cpp:1277