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){
103 void replace(std::string &src,
char from,
char to){
108 void replace(
const std::string &src,
char from,
char to, std::string &dst);
111 typedef std::map<std::string,std::string> conv_map_t;
119 void replace(
const conv_map_t & m, std::string &s, std::size_t pos = 0);
124 void replace(
const std::string &src,
const std::string &from,
const std::string & to, std::string & dst);
129 std::string
trim(
const std::string &s,
const std::string &trimChars=
" \t\n\r");
140 std::string
trimSymmetric(
const std::string &s,
const std::string &leading=
"'\"",
const std::string & trailing=
"");
156 bool trimScan(
const std::string &s,
size_t & pos1,
size_t & pos2,
const std::string &trimChars=
" \t\n");
172 template <
class T,
class C>
174 void split(
const std::string & s, T & sequence,
const C &separators,
const std::string & trimChars=
" \t\n");
201 template <
class T1,
class T2,
class C>
203 bool split2(
const std::string & s, T1 & first, T2 & second,
const C &separators,
const std::string & trimChars=
" \t\n");
211 std::ostream &
join(
const T & container, std::ostream & ostr,
char separator = 0){
213 for (
typename T::const_iterator it = container.begin(); it != container.end(); ++it){
228 std::string
join(T & container,
char separator = 0){
229 std::stringstream sstr;
235 template <
unsigned int S>
237 void read(std::istream &istr, std::string & s){
239 while (istr.read(buffer, S)){
242 s.append(buffer, istr.gcount());
257 void convert(
const std::string &s, T & dst);
268 T
convert(
const std::string &s);
272 std::string &
import(
const T & src, std::string & target);
290 const T &
lazyConvert(
const std::string &s, T & tmp);
296 void appendString(T & sequence,
const std::string & str){
297 typename T::value_type tmp;
303 void appendSubstring(T & sequence,
const std::string & str, std::string::size_type pos, std::string::size_type n){
306 appendString(sequence, str.substr(pos, n));
309 appendString(sequence,
"");
317 template <
class T,
class C>
318 void StringTools::split(
const std::string & str, T & sequence,
const C & separators,
const std::string & trimChars){
322 const bool TRIM = !trimChars.empty();
323 const std::string::size_type n = str.size();
325 std::string::size_type pos1 = 0;
326 std::string::size_type pos2 = n;
332 appendSubstring(sequence, str, pos1, pos2-pos1);
335 appendString(sequence, str);
342 std::string::size_type pos = pos1;
347 pos = str.find_first_of(separators, pos);
348 if (pos == std::string::npos){
352 appendSubstring(sequence, str, pos1, pos2-pos1);
359 appendSubstring(sequence, str, pos1, pos2-pos1);
360 pos = str.find_first_not_of(trimChars, pos+1);
374 template <
class T1,
class T2,
class S>
375 bool StringTools::split2(
const std::string & s, T1 & first, T2 & second,
const S & separators,
const std::string & trimChars){
377 std::size_t i = s.find_first_of(separators);
379 if (i != std::string::npos){
381 std::string srcFirst(s, 0, i);
383 std::string srcSecond(s, std::min(s.size(), i));
385 if (!trimChars.empty()){
392 if (!srcSecond.empty()){
393 if (!trimChars.empty()){
421 if (trimChars.empty()){
453 std::stringstream sstr(str);
478 std::string & StringTools::import(
const std::string & src, std::string & dst){
484 std::string & StringTools::import(
const T & x, std::string & dst){
485 std::stringstream sstr;
487 dst.assign(sstr.str());
Definition: DataSelector.cpp:1277