12#ifndef ZYPP_BASE_STRING_H
13#define ZYPP_BASE_STRING_H
21#include <boost/format.hpp>
22#include <boost/utility/string_ref.hpp>
24#include <zypp-core/base/Easy.h>
25#include <zypp-core/base/PtrTypes.h>
26#include <zypp-core/base/Function.h>
29namespace boost {
namespace logic {
class tribool; } }
30namespace zypp {
typedef boost::logic::tribool
TriBool; }
41 {
return val_r.asUserString(); }
98 C_Str(
const char * c_str_r ) :
_val( c_str_r ),
_sze(
std::string::npos ) {}
100 C_Str(
const boost::string_ref & str_r ) :
_val( str_r.data() ),
_sze( str_r.
size() ) {}
101#ifdef __cpp_lib_string_view
102 C_Str(
const std::string_view & str_r ) :
_val( str_r.data() ),
_sze( str_r.
size() ) {}
110 if (
_sze == std::string::npos )
115 operator const char *()
const {
return c_str(); }
119 const char *
const _val;
124 inline std::ostream &
operator<<( std::ostream &
str,
const C_Str & obj )
125 {
return str << obj.c_str(); }
139 inline const std::string &
asString(
const std::string & t )
142 inline std::string &&
asString( std::string && t )
143 {
return std::move(t); }
145 inline std::string
asString(
const char * t )
146 {
return t ==
nullptr ? std::string() : t; }
148 inline std::string
asString(
char * t )
149 {
return t ==
nullptr ? std::string() : t; }
152 inline std::string
asString(
const Tp &t )
153 {
return t.asString(); }
157 {
return p->asString(); }
161 {
return p->asString(); }
164 inline std::string
asString(
const bool &t )
165 {
return t ?
"true" :
"false"; }
169 std::string
form(
const char * format, ... )
170 __attribute__ ((format (printf, 1, 2)));
193 SafeBuf() :
_buf( 0 ) {}
194 ~SafeBuf() {
if (
_buf ) free(
_buf ); }
196 {
return _buf ? std::string(
_buf) :
std::string(); }
215 { _str << std::forward<Tp>(val);
return *
this; }
217 Str &
operator<<( std::ostream& (*iomanip)( std::ostream& ) )
218 {
_str << iomanip;
return *
this; }
220 operator std::string()
const {
return _str.str(); }
222 std::string
str()
const {
return _str.str(); }
224 const std::ostream &
stream()
const {
return _str; }
227 void clear() {
_str.str( std::string() ); }
230 std::ostringstream
_str;
234 inline std::ostream &
operator<<( std::ostream &
str,
const Str & obj )
235 {
return str << obj.str(); }
254 Format() {
_fmter.exceptions( boost::io::no_error_bits ); }
259 {
_fmter % std::forward<Tp>(arg);
return *
this; }
261 operator std::string()
const {
return _fmter.str(); }
263 std::string
str()
const {
return _fmter.str(); }
265 const boost::format &
fmter()
const {
return _fmter; }
273 inline std::ostream &
operator<<( std::ostream &
str,
const Format & obj )
274 {
return str << obj.fmter(); }
289 inline std::string
numstring(
char n,
int w = 0 ) {
return form(
"%*hhd", w, n ); }
290 inline std::string
numstring(
unsigned char n,
int w = 0 ) {
return form(
"%*hhu", w, n ); }
291 inline std::string
numstring(
short n,
int w = 0 ) {
return form(
"%*hd", w, n ); }
292 inline std::string
numstring(
unsigned short n,
int w = 0 ) {
return form(
"%*hu", w, n ); }
293 inline std::string
numstring(
int n,
int w = 0 ) {
return form(
"%*d", w, n ); }
294 inline std::string
numstring(
unsigned n,
int w = 0 ) {
return form(
"%*u", w, n ); }
295 inline std::string
numstring(
long n,
int w = 0 ) {
return form(
"%*ld", w, n ); }
296 inline std::string
numstring(
unsigned long n,
int w = 0 ) {
return form(
"%*lu", w, n ); }
297 inline std::string
numstring(
long long n,
int w = 0 ) {
return form(
"%*lld", w, n ); }
298 inline std::string
numstring(
unsigned long long n,
int w = 0 ) {
return form(
"%*llu", w, n ); }
300 template<>
inline std::string
asString(
const char & t ) {
return numstring( t ); }
301 template<>
inline std::string
asString(
const unsigned char & t ) {
return numstring( t ); }
302 template<>
inline std::string
asString(
const short & t ) {
return numstring( t ); }
303 template<>
inline std::string
asString(
const unsigned short & t ) {
return numstring( t ); }
304 template<>
inline std::string
asString(
const int & t ) {
return numstring( t ); }
305 template<>
inline std::string
asString(
const unsigned & t ) {
return numstring( t ); }
306 template<>
inline std::string
asString(
const long & t ) {
return numstring( t ); }
307 template<>
inline std::string
asString(
const unsigned long & t ) {
return numstring( t ); }
308 template<>
inline std::string
asString(
const long long & t ) {
return numstring( t ); }
309 template<>
inline std::string
asString(
const unsigned long long & t ) {
return numstring( t ); }
324 inline std::string
hexstring(
char n,
int w = 4 ) {
return form(
"%#0*hhx", w, n ); }
325 inline std::string
hexstring(
unsigned char n,
int w = 4 ) {
return form(
"%#0*hhx", w, n ); }
326 inline std::string
hexstring(
short n,
int w = 10 ){
return form(
"%#0*hx", w, n ); }
327 inline std::string
hexstring(
unsigned short n,
int w = 10 ){
return form(
"%#0*hx", w, n ); }
328 inline std::string
hexstring(
int n,
int w = 10 ){
return form(
"%#0*x", w, n ); }
329 inline std::string
hexstring(
unsigned n,
int w = 10 ){
return form(
"%#0*x", w, n ); }
330 inline std::string
hexstring(
long n,
int w = 10 ){
return form(
"%#0*lx", w, n ); }
331 inline std::string
hexstring(
unsigned long n,
int w = 10 ){
return form(
"%#0*lx", w, n ); }
332 inline std::string
hexstring(
long long n,
int w = 0 ) {
return form(
"%#0*llx", w, n ); }
333 inline std::string
hexstring(
unsigned long long n,
int w = 0 ) {
return form(
"%#0*llx", w, n ); }
348 inline std::string
octstring(
char n,
int w = 4 ) {
return form(
"%#0*hho", w, n ); }
349 inline std::string
octstring(
unsigned char n,
int w = 4 ) {
return form(
"%#0*hho", w, n ); }
350 inline std::string
octstring(
short n,
int w = 5 ) {
return form(
"%#0*ho", w, n ); }
351 inline std::string
octstring(
unsigned short n,
int w = 5 ) {
return form(
"%#0*ho", w, n ); }
352 inline std::string
octstring(
int n,
int w = 5 ) {
return form(
"%#0*o", w, n ); }
353 inline std::string
octstring(
unsigned n,
int w = 5 ) {
return form(
"%#0*o", w, n ); }
354 inline std::string
octstring(
long n,
int w = 5 ) {
return form(
"%#0*lo", w, n ); }
355 inline std::string
octstring(
unsigned long n,
int w = 5 ) {
return form(
"%#0*lo", w, n ); }
356 inline std::string
octstring(
long long n,
int w = 0 ) {
return form(
"%#0*llo", w, n ); }
357 inline std::string
octstring(
unsigned long long n,
int w = 0 ) {
return form(
"%#0*llo", w, n ); }
363 template <
typename TInt>
366 constexpr unsigned bits =
sizeof(TInt)*8;
367 std::string ret( bits,
' ' );
369 for (
unsigned pos = bits; pos > 0; )
370 { --pos; ret[pos] = ((val_r & bit)?
'1':
'0'); bit = bit<<1; }
384 template<
typename TInt>
388 inline short strtonum(
const C_Str &
str ) { return ::strtol (
str, NULL, 0 ); }
390 inline int strtonum(
const C_Str &
str ) { return ::strtol (
str, NULL, 0 ); }
392 inline long strtonum(
const C_Str &
str ) { return ::strtol (
str, NULL, 0 ); }
394 inline long long strtonum(
const C_Str &
str ) { return ::strtoll (
str, NULL, 0 ); }
397 inline unsigned short strtonum(
const C_Str &
str ) { return ::strtoul (
str, NULL, 0 ); }
399 inline unsigned strtonum(
const C_Str &
str ) { return ::strtoul (
str, NULL, 0 ); }
401 inline unsigned long strtonum(
const C_Str &
str ) { return ::strtoul (
str, NULL, 0 ); }
403 inline unsigned long long strtonum(
const C_Str &
str ) { return ::strtoull(
str, NULL, 0 ); }
410 template<
typename TInt>
411 inline TInt
strtonum(
const C_Str &
str, TInt & i )
412 {
return i = strtonum<TInt>(
str ); }
429 inline bool strToBool(
const C_Str &
str,
bool default_r )
451 std::string
gsub(
const std::string & str_r,
const std::string & from_r,
const std::string & to_r );
455 std::string
gsubFun(
const std::string & str_r,
const std::string & from_r, function<std::string()> to_r );
461 std::string &
replaceAll( std::string & str_r,
const std::string & from_r,
const std::string & to_r );
465 std::string &
replaceAllFun( std::string & str_r,
const std::string & from_r, function<std::string()> to_r );
479 inline std::string
gapify( std::string inp_r, std::string::size_type gap_r = 1,
char gapchar =
' ' )
481 if ( gap_r && inp_r.size() > gap_r )
483 inp_r.reserve( inp_r.size() + (inp_r.size()-1)/gap_r );
484 for ( std::string::size_type pos = gap_r; pos < inp_r.size(); pos += gap_r+1 )
485 inp_r.insert( pos, 1, gapchar );
503 std::string
trim(
const std::string & s,
const Trim trim_r =
TRIM );
504 std::string
trim( std::string && s,
const Trim trim_r =
TRIM );
506 inline std::string
ltrim(
const std::string & s )
508 inline std::string
ltrim( std::string && s )
511 inline std::string
rtrim(
const std::string & s )
513 inline std::string
rtrim( std::string && s )
530 template<
class TOutputIterator>
531 unsigned split(
const C_Str & line_r, TOutputIterator result_r,
const C_Str & sepchars_r =
" \t",
const Trim trim_r =
NO_TRIM )
533 const char * beg = line_r;
534 const char * cur = beg;
536 while ( *cur && ::strchr( sepchars_r, *cur ) )
539 for ( beg = cur; *beg; beg = cur, ++result_r, ++ret )
542 while( *cur && !::strchr( sepchars_r, *cur ) )
545 *result_r =
trim( std::string( beg, cur-beg ), trim_r );
547 while ( *cur && ::strchr( sepchars_r, *cur ) )
553 template<
class TOutputIterator>
554 unsigned split(
const C_Str & line_r, TOutputIterator result_r,
const Trim trim_r )
555 {
return split( line_r, result_r,
" \t", trim_r ); }
594 template<
class TOutputIterator>
595 unsigned splitEscaped(
const C_Str & line_r, TOutputIterator result_r,
const C_Str & sepchars_r =
" \t",
bool withEmpty =
false)
597 const char * beg = line_r;
598 const char * cur = beg;
602 while ( *cur && ::strchr( sepchars_r, *cur ) )
613 if (!*cur && withEmpty)
620 enum class Quote {
None, Slash, Single, Double, DoubleSlash };
621 std::vector<char> buf;
622 Quote quoting = Quote::None;
623 for ( beg = cur; *beg; beg = cur, ++result_r, ++ret )
627 quoting = Quote::None;
634 case '\\': quoting = Quote::Slash;
break;
635 case '\'': quoting = Quote::Single;
break;
636 case '"': quoting = Quote::Double;
break;
637 default: buf.push_back( *cur );
break;
642 buf.push_back( *cur );
643 quoting = Quote::None;
649 case '\'': quoting = Quote::None;
break;
650 default: buf.push_back( *cur );
break;
657 case '\"': quoting = Quote::None;
break;
658 case '\\': quoting = Quote::DoubleSlash;
break;
659 default: buf.push_back( *cur );
break;
663 case Quote::DoubleSlash:
667 case '\\': buf.push_back( *cur );
break;
669 buf.push_back(
'\\' );
670 buf.push_back( *cur );
673 quoting = Quote::Double;
677 }
while ( *cur && ( quoting != Quote::None || !::strchr( sepchars_r, *cur ) ) );
678 *result_r = std::string( buf.begin(), buf.end() );
682 if ( *cur && ::strchr( sepchars_r, *cur ) )
684 while ( *cur && ::strchr( sepchars_r, *cur ) )
694 if ( !*cur && withEmpty && ::strchr( sepchars_r, *(cur-1) ) )
724 template<
class TOutputIterator>
725 unsigned splitFields(
const C_Str & line_r, TOutputIterator result_r,
const C_Str & sepchars_r =
":" )
727 const char * beg = line_r;
728 const char * cur = beg;
730 for ( beg = cur; *beg; beg = cur, ++result_r )
733 while( *cur && !::strchr( sepchars_r, *cur ) )
735 if ( *cur ==
'\\' && *(cur+1) )
740 *result_r = std::string( beg, cur-beg );
748 *result_r = std::string();
763 template<
class TOutputIterator>
764 unsigned splitFieldsEscaped(
const C_Str & line_r, TOutputIterator result_r,
const C_Str & sepchars_r =
":" )
766 return splitEscaped( line_r, result_r, sepchars_r,
true );
775 template <
class TIterator>
776 std::string
join( TIterator begin, TIterator end,
const C_Str & sep_r =
" " )
779 for ( TIterator iter = begin; iter != end; ++ iter )
789 template <
class TContainer>
790 std::string
join(
const TContainer & cont_r,
const C_Str & sep_r =
" " )
791 {
return join( cont_r.begin(), cont_r.end(), sep_r ); }
797 template <
class TIterator>
798 std::string
joinEscaped( TIterator begin, TIterator end,
const char sep_r =
' ' )
800 std::vector<char> buf;
801 for ( TIterator iter = begin; iter != end; ++ iter )
804 buf.push_back( sep_r );
809 buf.push_back(
'"' );
810 buf.push_back(
'"' );
814 std::string toadd(
asString(*iter) );
815 for_( ch, toadd.begin(), toadd.end() )
822 buf.push_back(
'\\' );
823 buf.push_back( *ch );
827 buf.push_back(
'\\' );
828 buf.push_back( *ch );
833 return std::string( buf.begin(), buf.end() );
845 inline std::ostream &
printIndented( std::ostream &
str,
const std::string & text_r,
const std::string & indent_r =
" ",
unsigned maxWitdh_r = 0 )
849 if ( indent_r.size() >= maxWitdh_r )
852 maxWitdh_r -= indent_r.size();
855 for (
const char * e = text_r.c_str(), * s = e; *e; s = ++e )
857 for ( ; *e && *e !=
'\n'; ++e ) ;
859 if ( maxWitdh_r && width > maxWitdh_r )
863 for ( e = s+width; e > s && *e !=
' '; --e ) ;
870 str.write( s, width );
878 inline std::ostream &
printIndented( std::ostream &
str,
const std::string & text_r,
unsigned indent_r,
char indentch_r =
' ',
unsigned maxWitdh_r = 0 )
879 {
return printIndented(
str, text_r, std::string( indent_r, indentch_r ), maxWitdh_r ); }
881 inline std::ostream &
printIndented( std::ostream &
str,
const std::string & text_r,
unsigned indent_r,
unsigned maxWitdh_r,
char indentch_r =
' ' )
882 {
return printIndented(
str, text_r, std::string( indent_r, indentch_r ), maxWitdh_r ); }
887 inline std::ostream &
autoPrefix( std::ostream &
str,
const std::string & text_r, function<std::string(
const char*,
const char*)> fnc_r )
889 for (
const char * e = text_r.c_str(); *e; ++e )
892 for ( ; *e && *e !=
'\n'; ++e ) ;
893 str << fnc_r( s, e );
902 inline std::ostream &
autoPrefix0( std::ostream &
str,
const std::string & text_r, function<std::string()> fnc_r )
904 auto wrap = [&fnc_r](
const char*,
const char* )-> std::string {
919 std::string
escape(
const C_Str & str_r,
const char c =
' ' );
922 inline void appendEscaped( std::string & str_r,
const C_Str & next_r,
const char sep_r =
' ' )
924 if ( ! str_r.empty() )
926 if ( next_r.empty() )
929 str_r +=
escape( next_r, sep_r );
933 std::string
bEscape( std::string str_r,
const C_Str & special_r );
954 std::string
hexencode(
const C_Str & str_r );
956 std::string
hexdecode(
const C_Str & str_r );
965 std::string
toLower(
const std::string & s );
966 std::string
toLower( std::string && s );
968 inline std::string
toLower(
const char * s )
969 {
return( s ?
toLower( std::string(s) ) : std::string() ); }
974 std::string
toUpper(
const std::string & s );
975 std::string
toUpper( std::string && s );
977 inline std::string
toUpper(
const char * s )
978 {
return( s ?
toUpper( std::string(s) ) : std::string() ); }
984 inline int compareCI(
const C_Str & lhs,
const C_Str & rhs )
985 { return ::strcasecmp( lhs, rhs ); }
991 inline bool contains(
const C_Str & str_r,
const C_Str & val_r )
992 { return ::strstr( str_r, val_r ); }
994 inline bool containsCI(
const C_Str & str_r,
const C_Str & val_r )
995 { return ::strcasestr( str_r, val_r ); }
998 std::string
stripFirstWord( std::string & line,
const bool ltrim_first =
true );
1000 std::string
stripLastWord( std::string & line,
const bool rtrim_first =
true );
1019 std::string
receiveUpTo( std::istream &
str,
const char delim_r,
bool returnDelim_r =
false );
1027 inline bool hasPrefix(
const C_Str & str_r,
const C_Str & prefix_r )
1028 {
return( ::strncmp( str_r, prefix_r, prefix_r.size() ) == 0 ); }
1030 inline bool hasPrefixCI(
const C_Str & str_r,
const C_Str & prefix_r )
1031 {
return( ::strncasecmp( str_r, prefix_r, prefix_r.size() ) == 0 ); }
1034 inline std::string
stripPrefix(
const C_Str & str_r,
const C_Str & prefix_r )
1035 {
return(
hasPrefix( str_r, prefix_r ) ? str_r + prefix_r.size() : str_r.c_str() ); }
1037 inline std::string
stripPrefixCI(
const C_Str & str_r,
const C_Str & prefix_r )
1038 {
return(
hasPrefixCI( str_r, prefix_r ) ? str_r + prefix_r.size() : str_r.c_str() ); }
1041 inline bool hasSuffix(
const C_Str & str_r,
const C_Str & suffix_r )
1042 {
return( str_r.size() >= suffix_r.size() && ::strncmp( str_r + str_r.size() - suffix_r.size() , suffix_r, suffix_r.size() ) == 0 ); }
1044 inline bool hasSuffixCI(
const C_Str & str_r,
const C_Str & suffix_r )
1045 {
return( str_r.size() >= suffix_r.size() && ::strncasecmp( str_r + str_r.size() - suffix_r.size() , suffix_r, suffix_r.size() ) == 0 ); }
1048 inline std::string
stripSuffix(
const C_Str & str_r,
const C_Str & suffix_r )
1051 return std::string( str_r, str_r.size() - suffix_r.size() );
1052 return str_r.c_str();
1055 inline std::string
stripSuffixCI(
const C_Str & str_r,
const C_Str & suffix_r )
1058 return std::string( str_r, str_r.size() - suffix_r.size() );
1059 return str_r.c_str();
1063 inline std::string::size_type
commonPrefix(
const C_Str & lhs,
const C_Str & rhs )
1065 const char * lp = lhs.c_str();
1066 const char * rp = rhs.c_str();
1067 std::string::size_type ret = 0;
1068 while ( *lp == *rp && *lp !=
'\0' )
1069 { ++lp, ++rp, ++ret; }
1073 inline std::string::size_type
commonPrefixCI(
const C_Str & lhs,
const C_Str & rhs )
1075 const char * lp = lhs.c_str();
1076 const char * rp = rhs.c_str();
1077 std::string::size_type ret = 0;
1078 while ( tolower(*lp) == tolower(*rp) && *lp !=
'\0' )
1079 { ++lp, ++rp, ++ret; }
1085 inline bool startsWith(
const C_Str & str_r,
const C_Str & prefix_r )
1086 {
return hasPrefix( str_r, prefix_r ); }
1088 inline bool startsWithCI(
const C_Str & str_r,
const C_Str & prefix_r )
1092 inline bool endsWith(
const C_Str & str_r,
const C_Str & prefix_r )
1093 {
return hasSuffix( str_r, prefix_r ); }
1095 inline bool endsWithCI(
const C_Str & str_r,
const C_Str & prefix_r )
const char * c_str() const
std::string::size_type size_type
boost::logic::tribool TriBool
3-state boolean logic (true, false and indeterminate).
String related utilities and Regular expression matching.
std::string asString(TInt val, char zero='0', char one='1')
For printing bits.
std::string octstring(char n, int w=4)
std::string stripLastWord(std::string &line, const bool rtrim_first)
std::string hexdecode(const C_Str &str_r)
Decode hexencoded XX sequences.
std::string::size_type commonPrefix(const C_Str &lhs, const C_Str &rhs)
Return size of the common prefix of lhs and rhs.
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).
Trim
To define how to trim.
std::string hexencode(const C_Str &str_r)
Encode all characters other than [a-zA-Z0-9] as XX.
std::string joinEscaped(TIterator begin, TIterator end, const char sep_r=' ')
Join strings using separator sep_r, quoting or escaping the values.
std::string stripPrefixCI(const C_Str &str_r, const C_Str &prefix_r)
bool hasSuffix(const C_Str &str_r, const C_Str &suffix_r)
Return whether str_r has suffix suffix_r.
std::ostream & autoPrefix0(std::ostream &str, const std::string &text_r, function< std::string()> fnc_r)
unsigned splitFields(const C_Str &line_r, TOutputIterator result_r, const C_Str &sepchars_r=":")
Split line_r into fields.
std::string numstring(char n, int w=0)
std::string & replaceAllFun(std::string &str_r, const std::string &from_r, function< std::string()> to_r)
std::string gsubFun(const std::string &str_r, const std::string &from_r, function< std::string()> to_r)
std::string binstring(TInt val_r)
String representation of number as bit-string with leading '0's.
bool strToFalse(const C_Str &str)
Return false if str is 0, false, no, off, never.
std::string::size_type commonPrefixCI(const C_Str &lhs, const C_Str &rhs)
const std::string & asString(const std::string &t)
Global asString() that works with std::string too.
std::string stripFirstWord(std::string &line, const bool ltrim_first)
std::string stripSuffixCI(const C_Str &str_r, const C_Str &suffix_r)
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.
bool hasPrefix(const C_Str &str_r, const C_Str &prefix_r)
Return whether str_r has prefix prefix_r.
std::string getline(std::istream &str, const Trim trim_r)
Return stream content up to (but not returning) the next newline.
TriBool strToTriBool(const C_Str &str)
Parse str into a bool if it's a legal true or false string; else indeterminate.
unsigned splitFieldsEscaped(const C_Str &line_r, TOutputIterator result_r, const C_Str &sepchars_r=":")
Split line_r into fields handling also escaped separators.
bool startsWith(const C_Str &str_r, const C_Str &prefix_r)
alias for hasPrefix
bool endsWith(const C_Str &str_r, const C_Str &prefix_r)
alias for hasSuffix
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.
std::string bEscape(std::string str_r, const C_Str &special_r)
Return str_r with '\'-escaped chars occurring in special_r (and '\').
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,...
std::string rtrim(const std::string &s)
std::string strerror(int errno_r)
Return string describing the error_r code.
std::string join(TIterator begin, TIterator end, const C_Str &sep_r=" ")
Join strings using separator sep_r (defaults to BLANK).
std::string escape(const C_Str &str_r, const char sep_r)
Escape desired character c using a backslash.
std::string toUpper(const std::string &s)
Return uppercase version of s.
std::string ltrim(const std::string &s)
std::string form(const char *format,...) __attribute__((format(printf
Printf style construction of std::string.
std::ostream & printIndented(std::ostream &str, const std::string &text_r, const std::string &indent_r=" ", unsigned maxWitdh_r=0)
Indent by string [" "] optionally wrap.
std::string rxEscapeStr(std::string str_r)
Escape plain STRING str_r for use in a regex (not anchored by "^" or "$").
bool strToBool(const C_Str &str, bool default_r)
Parse str into a bool depending on the default value.
bool hasPrefixCI(const C_Str &str_r, const C_Str &prefix_r)
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.
std::string hexstring(char n, int w=4)
unsigned split(const C_Str &line_r, TOutputIterator result_r, const C_Str &sepchars_r=" \t", const Trim trim_r=NO_TRIM)
Split line_r into words.
TInt strtonum(const C_Str &str)
Parsing numbers from string.
std::string rxEscapeGlob(std::string str_r)
Escape GLOB str_r for use in a regex (not anchored by "^" or "$").
bool containsCI(const C_Str &str_r, const C_Str &val_r)
Locate substring case insensitive.
bool contains(const C_Str &str_r, const C_Str &val_r)
Locate substring case sensitive.
std::ostream & autoPrefix(std::ostream &str, const std::string &text_r, function< std::string(const char *, const char *)> fnc_r)
Prefix lines by string computed by function taking line begin/end [std::string(const char*,...
std::string toLower(const std::string &s)
Return lowercase version of s.
bool strToTrue(const C_Str &str)
Parsing boolean from string.
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.
unsigned splitEscaped(const C_Str &line_r, TOutputIterator result_r, const C_Str &sepchars_r=" \t", bool withEmpty=false)
Split line_r into words with respect to escape delimeters.
bool endsWithCI(const C_Str &str_r, const C_Str &prefix_r)
bool hasSuffixCI(const C_Str &str_r, const C_Str &suffix_r)
std::string trim(const std::string &s, const Trim trim_r)
bool strToBoolNodefault(const C_Str &str, bool &return_r)
Parse str into a bool if it's a legal true or false string.
int compareCI(const C_Str &lhs, const C_Str &rhs)
std::string gapify(std::string inp_r, std::string::size_type gap_r=1, char gapchar=' ')
Enhance readability: insert gaps at regular distance.
bool startsWithCI(const C_Str &str_r, const C_Str &prefix_r)
Easy-to use interface to the ZYPP dependency resolver.
std::string asUserString(VendorSupportOption opt)
converts the support option to a name intended to be printed to the user.
std::ostream & operator<<(std::ostream &str, const SerialNumber &obj)
Str & operator<<(Tp &&val)
std::string asString() const
const std::ostream & stream() const
#define for_(IT, BEG, END)
Convenient for-loops using iterator.