libzypp  13.10.6
String.h
Go to the documentation of this file.
1 /*---------------------------------------------------------------------\
2 | ____ _ __ __ ___ |
3 | |__ / \ / / . \ . \ |
4 | / / \ V /| _/ _/ |
5 | / /__ | | | | | | |
6 | /_____||_| |_| |_| |
7 | |
8 \---------------------------------------------------------------------*/
12 #ifndef ZYPP_BASE_STRING_H
13 #define ZYPP_BASE_STRING_H
14 
15 #include <cstring>
16 
17 #include <iosfwd>
18 #include <vector>
19 #include <string>
20 #include <sstream>
21 
22 #include "zypp/base/Easy.h"
23 #include "zypp/base/PtrTypes.h"
24 #include "zypp/base/Function.h"
25 
27 namespace zypp
28 {
32  template <class _Tp>
33  std::string asUserString( const _Tp & val_r )
34  { return val_r.asUserString(); }
35 
36 }// namespace zypp
38 
40 namespace zypp
41 {
42 
81  class C_Str
82  {
83  public:
85 
86  public:
87  C_Str() : _val( 0 ), _sze( 0 ) {}
88  C_Str( char * c_str_r ) : _val( c_str_r ), _sze( std::string::npos ) {}
89  C_Str( const char * c_str_r ) : _val( c_str_r ), _sze( std::string::npos ) {}
90  C_Str( const std::string & str_r ) : _val( str_r.c_str() ), _sze( str_r.size() ) {}
91 
92  public:
93  bool isNull() const { return !_val; }
94  bool empty() const { return !(_val && *_val); }
95  size_type size() const
96  {
97  if ( _sze == std::string::npos )
98  { _sze = _val ? ::strlen( _val ) : 0; }
99  return _sze;
100  };
101 
102  operator const char *() const { return c_str(); }
103  const char * c_str() const { return _val ? _val : ""; }
104 
105  private:
106  const char *const _val;
107  mutable size_type _sze;
108  };
109 
111  inline std::ostream & operator<<( std::ostream & str, const C_Str & obj )
112  { return str << obj.c_str(); }
113 
115 
118  namespace str
119  {
120 
122 
125  inline std::string asString( const std::string &t )
126  { return t; }
127 
128  inline std::string asString( const char * t )
129  { return t; }
130 
131  inline std::string asString( char * t )
132  { return t; }
133 
134  template<class _T>
135  inline std::string asString( const _T &t )
136  { return t.asString(); }
137 
138  template<class _T>
139  inline std::string asString( const intrusive_ptr<_T> &p )
140  { return p->asString(); }
141 
142  template<class _T>
143  inline std::string asString( const weak_ptr<_T> &p )
144  { return p->asString(); }
145 
146  template<>
147  inline std::string asString( const bool &t )
148  { return t ? "+" : "-"; }
149 
151 
152  std::string form( const char * format, ... )
153  __attribute__ ((format (printf, 1, 2)));
154 
156 
160  std::string strerror( int errno_r );
161 
163 
173  struct SafeBuf
174  {
175  char * _buf;
176  SafeBuf() : _buf( 0 ) {}
177  ~SafeBuf() { if ( _buf ) free( _buf ); }
178  std::string asString() const
179  { return _buf ? std::string(_buf) : std::string(); }
180  };
181 
183 
193  struct Str
194  {
195  template<class _Tp>
196  Str & operator<<( const _Tp & val )
197  { _str << val; return *this; }
198 
199  operator std::string() const
200  { return _str.str(); }
201 
202  std::ostringstream _str;
203  };
204 
206 
219  inline std::string numstring( char n, int w = 0 ) { return form( "%*hhd", w, n ); }
220  inline std::string numstring( unsigned char n, int w = 0 ) { return form( "%*hhu", w, n ); }
221  inline std::string numstring( short n, int w = 0 ) { return form( "%*hd", w, n ); }
222  inline std::string numstring( unsigned short n, int w = 0 ) { return form( "%*hu", w, n ); }
223  inline std::string numstring( int n, int w = 0 ) { return form( "%*d", w, n ); }
224  inline std::string numstring( unsigned n, int w = 0 ) { return form( "%*u", w, n ); }
225  inline std::string numstring( long n, int w = 0 ) { return form( "%*ld", w, n ); }
226  inline std::string numstring( unsigned long n, int w = 0 ) { return form( "%*lu", w, n ); }
227  inline std::string numstring( long long n, int w = 0 ) { return form( "%*lld", w, n ); }
228  inline std::string numstring( unsigned long long n, int w = 0 ) { return form( "%*llu", w, n ); }
229 
230  template<> inline std::string asString( const char & t ) { return numstring( t ); }
231  template<> inline std::string asString( const unsigned char & t ) { return numstring( t ); }
232  template<> inline std::string asString( const short & t ) { return numstring( t ); }
233  template<> inline std::string asString( const unsigned short & t ) { return numstring( t ); }
234  template<> inline std::string asString( const int & t ) { return numstring( t ); }
235  template<> inline std::string asString( const unsigned & t ) { return numstring( t ); }
236  template<> inline std::string asString( const long & t ) { return numstring( t ); }
237  template<> inline std::string asString( const unsigned long & t ) { return numstring( t ); }
238  template<> inline std::string asString( const long long & t ) { return numstring( t ); }
239  template<> inline std::string asString( const unsigned long long & t ) { return numstring( t ); }
241 
243 
254  inline std::string hexstring( char n, int w = 4 ) { return form( "%#0*hhx", w, n ); }
255  inline std::string hexstring( unsigned char n, int w = 4 ) { return form( "%#0*hhx", w, n ); }
256  inline std::string hexstring( short n, int w = 10 ){ return form( "%#0*hx", w, n ); }
257  inline std::string hexstring( unsigned short n, int w = 10 ){ return form( "%#0*hx", w, n ); }
258  inline std::string hexstring( int n, int w = 10 ){ return form( "%#0*x", w, n ); }
259  inline std::string hexstring( unsigned n, int w = 10 ){ return form( "%#0*x", w, n ); }
260  inline std::string hexstring( long n, int w = 10 ){ return form( "%#0*lx", w, n ); }
261  inline std::string hexstring( unsigned long n, int w = 10 ){ return form( "%#0*lx", w, n ); }
262  inline std::string hexstring( long long n, int w = 0 ) { return form( "%#0*llx", w, n ); }
263  inline std::string hexstring( unsigned long long n, int w = 0 ) { return form( "%#0*llx", w, n ); }
265 
267 
278  inline std::string octstring( char n, int w = 4 ) { return form( "%#0*hho", w, n ); }
279  inline std::string octstring( unsigned char n, int w = 4 ) { return form( "%#0*hho", w, n ); }
280  inline std::string octstring( short n, int w = 5 ) { return form( "%#0*ho", w, n ); }
281  inline std::string octstring( unsigned short n, int w = 5 ) { return form( "%#0*ho", w, n ); }
282  inline std::string octstring( int n, int w = 5 ) { return form( "%#0*o", w, n ); }
283  inline std::string octstring( unsigned n, int w = 5 ) { return form( "%#0*o", w, n ); }
284  inline std::string octstring( long n, int w = 5 ) { return form( "%#0*lo", w, n ); }
285  inline std::string octstring( unsigned long n, int w = 5 ) { return form( "%#0*lo", w, n ); }
286  inline std::string octstring( long long n, int w = 0 ) { return form( "%#0*llo", w, n ); }
287  inline std::string octstring( unsigned long long n, int w = 0 ) { return form( "%#0*llo", w, n ); }
289 
291 
300  template<typename _It>
301  _It strtonum( const C_Str & str );
302 
303  template<>
304  inline short strtonum( const C_Str & str ) { return ::strtol ( str, NULL, 0 ); }
305  template<>
306  inline int strtonum( const C_Str & str ) { return ::strtol ( str, NULL, 0 ); }
307  template<>
308  inline long strtonum( const C_Str & str ) { return ::strtol ( str, NULL, 0 ); }
309  template<>
310  inline long long strtonum( const C_Str & str ) { return ::strtoll ( str, NULL, 0 ); }
311 
312  template<>
313  inline unsigned short strtonum( const C_Str & str ) { return ::strtoul ( str, NULL, 0 ); }
314  template<>
315  inline unsigned strtonum( const C_Str & str ) { return ::strtoul ( str, NULL, 0 ); }
316  template<>
317  inline unsigned long strtonum( const C_Str & str ) { return ::strtoul ( str, NULL, 0 ); }
318  template<>
319  inline unsigned long long strtonum( const C_Str & str ) { return ::strtoull( str, NULL, 0 ); }
320 
326  template<typename _It>
327  inline _It strtonum( const C_Str & str, _It & i )
328  { return i = strtonum<_It>( str ); }
330 
332 
336  bool strToTrue( const C_Str & str );
337 
339  bool strToFalse( const C_Str & str );
340 
345  inline bool strToBool( const C_Str & str, bool default_r )
346  { return( default_r ? strToFalse( str ) : strToTrue( str ) ); }
347 
352  inline bool strToBoolNodefault( const C_Str & str, bool & return_r )
353  {
354  if ( strToTrue( str ) ) return (return_r = true);
355  if ( !strToFalse( str ) ) return (return_r = false);
356  return return_r;
357  }
358 
360 
364  std::string gsub( const std::string & str_r, const std::string & from_r, const std::string & to_r );
365 
368  std::string gsubFun( const std::string & str_r, const std::string & from_r, function<std::string()> to_r );
369 
374  std::string & replaceAll( std::string & str_r, const std::string & from_r, const std::string & to_r );
375 
378  std::string & replaceAllFun( std::string & str_r, const std::string & from_r, function<std::string()> to_r );
379 
380 
382 
393  template<class _OutputIterator>
394  unsigned split( const C_Str & line_r,
395  _OutputIterator result_r,
396  const C_Str & sepchars_r = " \t" )
397  {
398  const char * beg = line_r;
399  const char * cur = beg;
400  // skip leading sepchars
401  while ( *cur && ::strchr( sepchars_r, *cur ) )
402  ++cur;
403  unsigned ret = 0;
404  for ( beg = cur; *beg; beg = cur, ++result_r, ++ret )
405  {
406  // skip non sepchars
407  while( *cur && !::strchr( sepchars_r, *cur ) )
408  ++cur;
409  // build string
410  *result_r = std::string( beg, cur-beg );
411  // skip sepchars
412  while ( *cur && ::strchr( sepchars_r, *cur ) )
413  ++cur;
414  }
415  return ret;
416  }
417 
445  template<class _OutputIterator>
446  unsigned splitEscaped( const C_Str & line_r,
447  _OutputIterator result_r,
448  const C_Str & sepchars_r = " \t",
449  bool withEmpty = false)
450  {
451  const char * beg = line_r;
452  const char * cur = beg;
453  unsigned ret = 0;
454 
455  // skip leading sepchars
456  while ( *cur && ::strchr( sepchars_r, *cur ) )
457  {
458  ++cur;
459  if (withEmpty)
460  {
461  *result_r = "";
462  ++ret;
463  }
464  }
465 
466  // there were only sepchars in the string
467  if (!*cur && withEmpty)
468  {
469  *result_r = "";
470  return ++ret;
471  }
472 
473  // after the leading sepchars
474  for ( beg = cur; *beg; beg = cur, ++result_r, ++ret )
475  {
476  if ( *cur == '"' || *cur == '\'' )
477  {
478  char closeChar = *cur;
479  ++cur;
480  bool cont = true;
481  while (cont)
482  {
483  while ( *cur && *cur != closeChar)
484  ++cur;
485  if ( *cur == '\0' )
486  {
487  return ret; //TODO parsing exception no closing quote
488  }
489  int escCount = 0;
490  const char * esc = cur-1;
491  while ( esc != beg && *esc == '\\' )
492  {
493  escCount++;
494  --esc;
495  }
496  cont = (escCount % 2 == 1); // find some non escaped escape char
497  cur++; //skip quote
498  }
499 
500  std::string s( beg+1, cur-beg-2 ); //without quotes
501  //transform escaped escape
502  replaceAll( s, "\\\\", "\\" );
503  //transform escaped quotes (only same as open
504  char tmpn[2] = { closeChar, 0 };
505  char tmpo[3] = { '\\', closeChar, 0 };
506  replaceAll( s, tmpo, tmpn );
507 
508  *result_r = s;
509  }
510  else
511  {
512  // skip non sepchars
513  while( *cur && !::strchr( sepchars_r, *cur ) )
514  {
515  //ignore char after backslash
516  if ( *cur == '\\' )
517  {
518  ++cur;
519  }
520  ++cur;
521  }
522  // build string
523  std::string s( beg, cur-beg );
524  //transform escaped escape
525  replaceAll( s, "\\\\", "\\" );
526 
527  const char *delimeter = sepchars_r;
528  while ( *delimeter )
529  {
530  std::string ds("\\");
531  const char tmp[2] = { *delimeter, '\0' };
532  std::string del(tmp);
533  ds+= del;
534  replaceAll( s, ds, del );
535  ++delimeter;
536  }
537 
538  *result_r = s;
539  }
540  // skip sepchars
541  if ( *cur && ::strchr( sepchars_r, *cur ) )
542  ++cur;
543  while ( *cur && ::strchr( sepchars_r, *cur ) )
544  {
545  ++cur;
546  if (withEmpty)
547  {
548  *result_r = "";
549  ++ret;
550  }
551  }
552  // the last was a separator => one more field
553  if ( !*cur && withEmpty && ::strchr( sepchars_r, *(cur-1) ) )
554  {
555  *result_r = "";
556  ++ret;
557  }
558  }
559  return ret;
560  }
561 
582  template<class _OutputIterator>
583  unsigned splitFields( const C_Str & line_r,
584  _OutputIterator result_r,
585  const C_Str & sepchars_r = ":" )
586  {
587  const char * beg = line_r;
588  const char * cur = beg;
589  unsigned ret = 0;
590  for ( beg = cur; *beg; beg = cur, ++result_r )
591  {
592  // skip non sepchars
593  while( *cur && !::strchr( sepchars_r, *cur ) )
594  ++cur;
595  // build string
596  *result_r = std::string( beg, cur-beg );
597  ++ret;
598  // skip sepchar
599  if ( *cur )
600  {
601  ++cur;
602  if ( ! *cur ) // ending with sepchar
603  {
604  *result_r = std::string(); // add final empty field
605  ++ret;
606  break;
607  }
608  }
609  }
610  return ret;
611  }
612 
619  template<class _OutputIterator>
620  unsigned splitFieldsEscaped( const C_Str & line_r,
621  _OutputIterator result_r,
622  const C_Str & sepchars_r = ":" )
623  {
624  return
625  splitEscaped( line_r, result_r, sepchars_r, true /* withEmpty */ );
626  }
627 
629 
631 
634  template <class _Iterator>
635  std::string join( _Iterator begin, _Iterator end,
636  const C_Str & sep_r = " " )
637  {
638  std::string res;
639  for ( _Iterator iter = begin; iter != end; ++ iter )
640  {
641  if ( iter != begin )
642  res += sep_r;
643  res += asString(*iter);
644  }
645  return res;
646  }
647 
649  template <class _Container>
650  std::string join( const _Container & cont_r,
651  const C_Str & sep_r = " " )
652  { return join( cont_r.begin(), cont_r.end(), sep_r ); }
653 
658  template <class _Iterator>
659  std::string joinEscaped( _Iterator begin, _Iterator end,
660  const char sep_r = ' ' )
661  {
662  std::vector<char> buf;
663  for ( _Iterator iter = begin; iter != end; ++ iter )
664  {
665  if ( iter != begin )
666  buf.push_back( sep_r );
667 
668  if ( iter->empty() )
669  {
670  // empty string goes ""
671  buf.push_back( '"' );
672  buf.push_back( '"' );
673  }
674  else
675  {
676  std::string toadd( asString(*iter) );
677  for_( ch, toadd.begin(), toadd.end() )
678  {
679  switch ( *ch )
680  {
681  case '"':
682  case '\'':
683  case '\\':
684  buf.push_back( '\\' );
685  buf.push_back( *ch );
686  break;
687  default:
688  if ( *ch == sep_r )
689  buf.push_back( '\\' );
690  buf.push_back( *ch );
691  }
692  }
693  }
694  }
695  return std::string( buf.begin(), buf.end() );
696  }
698 
699 
701 
709  std::string escape( const C_Str & str_r, const char c = ' ' );
710 
712  inline void appendEscaped( std::string & str_r, const C_Str & next_r, const char sep_r = ' ' )
713  {
714  if ( ! str_r.empty() )
715  str_r += sep_r;
716  if ( next_r.empty() )
717  str_r += "\"\"";
718  else
719  str_r += escape( next_r, sep_r );
720  }
721 
723 
725 
735  std::string hexencode( const C_Str & str_r );
737  std::string hexdecode( const C_Str & str_r );
739 
746  std::string toLower( const std::string & s );
748  inline std::string toLower( const char * s )
749  { return( s ? toLower( std::string(s) ) : std::string() ); }
750 
754  std::string toUpper( const std::string & s );
756  inline std::string toUpper( const char * s )
757  { return( s ? toUpper( std::string(s) ) : std::string() ); }
759 
760 
763  inline int compareCI( const C_Str & lhs, const C_Str & rhs )
764  { return ::strcasecmp( lhs, rhs ); }
766 
770  inline bool contains( const C_Str & str_r, const C_Str & val_r )
771  { return ::strstr( str_r, val_r ); }
773  inline bool containsCI( const C_Str & str_r, const C_Str & val_r )
774  { return ::strcasestr( str_r, val_r ); }
776 
778 
783  enum Trim {
784  NO_TRIM = 0x00,
785  L_TRIM = 0x01,
786  R_TRIM = 0x02,
788  };
789 
790  std::string trim( const std::string & s, const Trim trim_r = TRIM );
791 
792  inline std::string ltrim( const std::string & s )
793  { return trim( s, L_TRIM ); }
794 
795  inline std::string rtrim( const std::string & s )
796  { return trim( s, R_TRIM ); }
798 
799  std::string stripFirstWord( std::string & line, const bool ltrim_first );
800 
801  std::string stripLastWord( std::string & line, const bool rtrim_first );
802 
806  std::string getline( std::istream & str, bool trim = false );
807 
811  std::string getline( std::istream & str, const Trim trim_r );
812 
820  std::string receiveUpTo( std::istream & str, const char delim_r, bool returnDelim_r = false );
821 
823 
828  inline bool hasPrefix( const C_Str & str_r, const C_Str & prefix_r )
829  { return( ::strncmp( str_r, prefix_r, prefix_r.size() ) == 0 ); }
830 
832  inline std::string stripPrefix( const C_Str & str_r, const C_Str & prefix_r )
833  { return( hasPrefix( str_r, prefix_r ) ? str_r + prefix_r.size() : str_r.c_str() ); }
834 
836  inline bool hasSuffix( const C_Str & str_r, const C_Str & suffix_r )
837  { return( str_r.size() >= suffix_r.size() && ::strncmp( str_r + str_r.size() - suffix_r.size() , suffix_r, suffix_r.size() ) == 0 ); }
838 
840  inline std::string stripSuffix( const C_Str & str_r, const C_Str & suffix_r )
841  {
842  if ( hasSuffix( str_r, suffix_r ) )
843  return std::string( str_r, str_r.size() - suffix_r.size() );
844  return str_r.c_str();
845  }
847  inline std::string::size_type commonPrefix( const C_Str & lhs, const C_Str & rhs )
848  {
849  const char * lp = lhs.c_str();
850  const char * rp = rhs.c_str();
851  std::string::size_type ret = 0;
852  while ( *lp == *rp && *lp != '\0' )
853  { ++lp, ++rp, ++ret; }
854  return ret;
855  }
856 
858  inline bool startsWith( const C_Str & str_r, const C_Str & prefix_r )
859  { return hasPrefix( str_r, prefix_r ); }
861  inline bool endsWith( const C_Str & str_r, const C_Str & prefix_r )
862  { return hasSuffix( str_r, prefix_r ); }
864  } // namespace str
868 } // namespace zypp
870 #endif // ZYPP_BASE_STRING_H
void appendEscaped(std::string &str_r, const C_Str &next_r, const char sep_r= ' ')
Escape next_r and append it to str_r using separator sep_r.
Definition: String.h:712
bool contains(const C_Str &str_r, const C_Str &val_r)
Locate substring case sensitive.
Definition: String.h:770
std::string octstring(char n, int w=4)
Definition: String.h:278
bool strToBoolNodefault(const C_Str &str, bool &return_r)
Parse str into a bool if it&#39;s a legal true or false string.
Definition: String.h:352
std::string stripPrefix(const C_Str &str_r, const C_Str &prefix_r)
Strip a prefix_r from str_r and return the resulting string.
Definition: String.h:832
unsigned split(const C_Str &line_r, _OutputIterator result_r, const C_Str &sepchars_r=" \t")
Split line_r into words.
Definition: String.h:394
std::string asUserString(const _Tp &val_r)
Request a human readable (translated) string representation of _Tp [_Tp.asUserString()] Classes may i...
Definition: String.h:33
std::string::size_type size_type
Definition: String.h:84
std::string::size_type commonPrefix(const C_Str &lhs, const C_Str &rhs)
Return size of the common prefix of lhs and rhs.
Definition: String.h:847
std::string escape(const C_Str &str_r, const char sep_r)
Escape desired character c using a backslash.
Definition: String.cc:339
std::string stripSuffix(const C_Str &str_r, const C_Str &suffix_r)
Strip a suffix_r from str_r and return the resulting string.
Definition: String.h:840
std::string asString() const
Definition: String.h:178
C_Str(const std::string &str_r)
Definition: String.h:90
#define for_(IT, BEG, END)
Convenient for-loops using iterator.
Definition: Easy.h:27
unsigned splitFieldsEscaped(const C_Str &line_r, _OutputIterator result_r, const C_Str &sepchars_r=":")
Split line_r into fields handling also escaped separators.
Definition: String.h:620
bool empty() const
Definition: String.h:94
Trim
To define how to trim.
Definition: String.h:783
std::string joinEscaped(_Iterator begin, _Iterator end, const char sep_r= ' ')
Join strings using separator sep_r, quoting or escaping the values.
Definition: String.h:659
unsigned splitEscaped(const C_Str &line_r, _OutputIterator result_r, const C_Str &sepchars_r=" \t", bool withEmpty=false)
Split line_r into words with respect to escape delimeters.
Definition: String.h:446
std::string ltrim(const std::string &s)
Definition: String.h:792
std::string & replaceAll(std::string &str_r, const std::string &from_r, const std::string &to_r)
Replace all occurrences of from_r with to_r in str_r (inplace).
Definition: String.cc:304
std::string stripFirstWord(std::string &line, const bool ltrim_first)
Definition: String.cc:237
Convenient building of std::string via std::ostream::operator&lt;&lt;.
Definition: String.h:193
std::string trim(const std::string &s, const Trim trim_r)
Definition: String.cc:204
std::string join(_Iterator begin, _Iterator end, const C_Str &sep_r=" ")
Join strings using separator sep_r (defaults to BLANK).
Definition: String.h:635
Convenience char* constructible from std::string and char*, it maps (char*)0 to an empty string...
Definition: String.h:81
bool startsWith(const C_Str &str_r, const C_Str &prefix_r)
alias for hasPrefix
Definition: String.h:858
const char *const _val
Definition: String.h:106
std::string getline(std::istream &str, const Trim trim_r)
Return stream content up to (but not returning) the next newline.
Definition: String.cc:361
std::string stripLastWord(std::string &line, const bool rtrim_first)
Definition: String.cc:270
bool strToFalse(const C_Str &str)
Return false if str is 0, false, no, off.
Definition: String.cc:78
bool containsCI(const C_Str &str_r, const C_Str &val_r)
Locate substring case insensitive.
Definition: String.h:773
_It strtonum(const C_Str &str)
Parsing numbers from string.
Definition: String.h:304
std::string gsubFun(const std::string &str_r, const std::string &from_r, function< std::string()> to_r)
Definition: String.cc:318
bool endsWith(const C_Str &str_r, const C_Str &prefix_r)
alias for hasSuffix
Definition: String.h:861
std::string numstring(char n, int w=0)
Definition: String.h:219
size_type _sze
Definition: String.h:107
std::string toLower(const std::string &s)
Return lowercase version of s.
Definition: String.cc:166
int compareCI(const C_Str &lhs, const C_Str &rhs)
Definition: String.h:763
SolvableIdType size_type
Definition: PoolMember.h:99
std::string rtrim(const std::string &s)
Definition: String.h:795
Str & operator<<(const _Tp &val)
Definition: String.h:196
bool strToTrue(const C_Str &str)
Parsing boolean from string.
Definition: String.cc:61
std::string form(const char *format,...)
Printf style construction of std::string.
Definition: String.cc:34
std::string & replaceAllFun(std::string &str_r, const std::string &from_r, function< std::string()> to_r)
Definition: String.cc:324
bool hasSuffix(const C_Str &str_r, const C_Str &suffix_r)
Return whether str_r has suffix suffix_r.
Definition: String.h:836
std::string gsub(const std::string &str_r, const std::string &from_r, const std::string &to_r)
Return a string with all occurrences of from_r replaced with to_r.
Definition: String.cc:298
bool isNull() const
Definition: String.h:93
C_Str(const char *c_str_r)
Definition: String.h:89
std::string receiveUpTo(std::istream &str, const char delim_r, bool returnDelim_r)
Return stream content up to the next ocurrence of delim_r or EOF delim_r, if found, is always read from the stream.
Definition: String.cc:371
bool strToBool(const C_Str &str, bool default_r)
Parse str into a bool depending on the default value.
Definition: String.h:345
const char * c_str() const
Definition: String.h:103
std::string hexencode(const C_Str &str_r)
Encode all characters other than [a-zA-Z0-9] as XX.
Definition: String.cc:113
std::ostream & operator<<(std::ostream &str, const C_Str &obj)
Definition: String.h:111
size_type size() const
Definition: String.h:95
std::string strerror(int errno_r)
Return string describing the error_r code.
Definition: String.cc:51
C_Str(char *c_str_r)
Definition: String.h:88
std::string asString(const std::string &t)
Global asString() that works with std::string too.
Definition: String.h:125
std::string toUpper(const std::string &s)
Return uppercase version of s.
Definition: String.cc:185
Assert free called for allocated char *.
Definition: String.h:173
bool hasPrefix(const C_Str &str_r, const C_Str &prefix_r)
Return whether str_r has prefix prefix_r.
Definition: String.h:828
std::string hexstring(char n, int w=4)
Definition: String.h:254
unsigned splitFields(const C_Str &line_r, _OutputIterator result_r, const C_Str &sepchars_r=":")
Split line_r into fields.
Definition: String.h:583
std::ostringstream _str
Definition: String.h:202
std::string hexdecode(const C_Str &str_r)
Decode hexencoded XX sequences.
Definition: String.cc:134