libzypp  15.28.6
zypp::str Namespace Reference

String related utilities and Regular expression matching. More...

Classes

class  regex
 Regular expression. More...
 
class  smatch
 Regular expression match result. More...
 
struct  SafeBuf
 Assert free called for allocated char *. More...
 
class  Str
 Convenient building of std::string via std::ostringstream Basically a std::ostringstream autoconvertible to std::string for building string arguments. More...
 
class  Format
 Convenient building of std::string with boost::format. More...
 
class  FormatNAC
 Format with (N)o (A)rgument (C)heck. More...
 

Typedefs

typedef Exception regex_error
 

Functions

std::string form (const char *format,...) __attribute__((format(printf
 Printf style construction of std::string. More...
 
bool regex_match (const std::string &s, smatch &matches, const regex &regex)
 regex ZYPP_STR_REGEX regex ZYPP_STR_REGEX More...
 
bool regex_match (const char *s, const regex &regex)
 regex ZYPP_STR_REGEX regex ZYPP_STR_REGEX More...
 
bool regex_match (const std::string &s, const regex &regex)
 regex ZYPP_STR_REGEX regex ZYPP_STR_REGEX More...
 
std::string strerror (int errno_r)
 Return string describing the error_r code. More...
 
std::string stripFirstWord (std::string &line, const bool ltrim_first)
 
std::string stripLastWord (std::string &line, const bool rtrim_first)
 
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. More...
 
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). More...
 
std::string gsubFun (const std::string &str_r, const std::string &from_r, function< std::string()> to_r)
 
std::string & replaceAllFun (std::string &str_r, const std::string &from_r, function< std::string()> to_r)
 
std::string getline (std::istream &str, const Trim trim_r)
 Return stream content up to (but not returning) the next newline. More...
 
std::string getline (std::istream &str, bool trim=false)
 Return stream content up to (but not returning) the next newline. More...
 
std::string receiveUpTo (std::istream &str, const char delim_r, bool returnDelim_r=false)
 Return stream content up to the next ocurrence of delim_r or EOF delim_r, if found, is always read from the stream. More...
 
const std::string & asString (const std::string &t)
 Global asString() that works with std::string too. More...
 
std::string && asString (std::string &&t)
 
std::string asString (const char *t)
 
std::string asString (char *t)
 
template<class Tp >
std::string asString (const Tp &t)
 
template<class Tp >
std::string asString (const intrusive_ptr< Tp > &p)
 
template<class Tp >
std::string asString (const weak_ptr< Tp > &p)
 
template<>
std::string asString (const bool &t)
 
template<typename TInt >
std::string binstring (TInt val_r)
 String representation of number as bit-string with leading '0's. More...
 
std::string gapify (std::string inp_r, std::string::size_type gap_r=1, char gapchar= ' ')
 Enhance readability: insert gaps at regular distance. More...
 
bool strToTrue (const C_Str &str)
 Parsing boolean from string. More...
 
bool strToFalse (const C_Str &str)
 Return false if str is 0, false, no, off. More...
 
TriBool strToTriBool (const C_Str &str)
 Parse str into a bool if it's a legal true or false string; else indterminate. More...
 
bool strToBool (const C_Str &str, bool default_r)
 Parse str into a bool depending on the default value. More...
 
bool strToBoolNodefault (const C_Str &str, bool &return_r)
 Parse str into a bool if it's a legal true or false string. More...
 
Hexencode.

Encode all characters other than [a-zA-Z0-9] as XX.

Todo:
unsecape()

This includes the % character itself, which becomes %25.

std::string hexencode (const C_Str &str_r)
 Encode all characters other than [a-zA-Z0-9] as XX. More...
 
std::string hexdecode (const C_Str &str_r)
 Decode hexencoded XX sequences. More...
 
Case conversion.
std::string toLower (const std::string &s)
 Return lowercase version of s. More...
 
std::string toLower (std::string &&s)
 
std::string toUpper (const std::string &s)
 Return uppercase version of s. More...
 
std::string toUpper (std::string &&s)
 
std::string toLower (const char *s)
 
std::string toUpper (const char *s)
 
Escape.
std::string escape (const C_Str &str_r, const char c= ' ')
 Escape desired character c using a backslash. More...
 
std::string bEscape (std::string str_r, const C_Str &special_r)
 Return str_r with '\'-escaped chars occurring in special_r (and '\'). More...
 
std::string rxEscapeStr (std::string str_r)
 Escape plain STRING str_r for use in a regex (not anchored by "^" or "$"). More...
 
std::string rxEscapeGlob (std::string str_r)
 Escape GLOB str_r for use in a regex (not anchored by "^" or "$"). More...
 
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. More...
 
String representation of number.

Optional second argument sets the minimal string width (' ' padded).

Negative values will cause the number to be left adjusted within the string.

Default width is 0.

numstring(42) -> "42"
numstring(42, 4) -> " 42"
numstring(42,-4) -> "42 "
std::string numstring (char n, int w=0)
 
std::string numstring (unsigned char n, int w=0)
 
std::string numstring (short n, int w=0)
 
std::string numstring (unsigned short n, int w=0)
 
std::string numstring (int n, int w=0)
 
std::string numstring (unsigned n, int w=0)
 
std::string numstring (long n, int w=0)
 
std::string numstring (unsigned long n, int w=0)
 
std::string numstring (long long n, int w=0)
 
std::string numstring (unsigned long long n, int w=0)
 
template<>
std::string asString (const char &t)
 
template<>
std::string asString (const unsigned char &t)
 
template<>
std::string asString (const short &t)
 
template<>
std::string asString (const unsigned short &t)
 
template<>
std::string asString (const int &t)
 
template<>
std::string asString (const unsigned &t)
 
template<>
std::string asString (const long &t)
 
template<>
std::string asString (const unsigned long &t)
 
template<>
std::string asString (const long long &t)
 
template<>
std::string asString (const unsigned long long &t)
 
String representation of number as hex value with leading '0x'.

Optional second argument sets the minimal string width (0 padded).

Negative values will cause the number to be left adjusted within the string. Default width is 10 (4 for char).

hexstring(42)           -> "0x0000002a"
hexstring(42, 4)        -> "0x2a"
hexstring(42,-4)        -> "0x2a"
std::string hexstring (char n, int w=4)
 
std::string hexstring (unsigned char n, int w=4)
 
std::string hexstring (short n, int w=10)
 
std::string hexstring (unsigned short n, int w=10)
 
std::string hexstring (int n, int w=10)
 
std::string hexstring (unsigned n, int w=10)
 
std::string hexstring (long n, int w=10)
 
std::string hexstring (unsigned long n, int w=10)
 
std::string hexstring (long long n, int w=0)
 
std::string hexstring (unsigned long long n, int w=0)
 
String representation of number as octal value with leading '0'.

Optional second argument sets the minimal string width (0 padded).

Negative values will cause the number to be left adjusted within the string. Default width is 5 (4 for char).

octstring(42)           -> "00052"
octstring(42, 4)        -> "0052"
octstring(42,-4)        -> "052 "
std::string octstring (char n, int w=4)
 
std::string octstring (unsigned char n, int w=4)
 
std::string octstring (short n, int w=5)
 
std::string octstring (unsigned short n, int w=5)
 
std::string octstring (int n, int w=5)
 
std::string octstring (unsigned n, int w=5)
 
std::string octstring (long n, int w=5)
 
std::string octstring (unsigned long n, int w=5)
 
std::string octstring (long long n, int w=0)
 
std::string octstring (unsigned long long n, int w=0)
 
template<typename TInt >
TInt strtonum (const C_Str &str)
 Parsing numbers from string. More...
 
template<>
short strtonum (const C_Str &str)
 Parsing numbers from string. More...
 
template<>
int strtonum (const C_Str &str)
 Parsing numbers from string. More...
 
template<>
long strtonum (const C_Str &str)
 Parsing numbers from string. More...
 
template<>
long long strtonum (const C_Str &str)
 Parsing numbers from string. More...
 
template<>
unsigned short strtonum (const C_Str &str)
 Parsing numbers from string. More...
 
template<>
unsigned strtonum (const C_Str &str)
 Parsing numbers from string. More...
 
template<>
unsigned long strtonum (const C_Str &str)
 Parsing numbers from string. More...
 
template<>
unsigned long long strtonum (const C_Str &str)
 Parsing numbers from string. More...
 
template<typename TInt >
TInt strtonum (const C_Str &str, TInt &i)
 String to integer type detemined 2nd function arg i. More...
 
Split.
template<class TOutputIterator >
unsigned split (const C_Str &line_r, TOutputIterator result_r, const C_Str &sepchars_r=" \t")
 Split line_r into words. More...
 
template<class TOutputIterator >
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. More...
 
template<class TOutputIterator >
unsigned splitFields (const C_Str &line_r, TOutputIterator result_r, const C_Str &sepchars_r=":")
 Split line_r into fields. More...
 
template<class TOutputIterator >
unsigned splitFieldsEscaped (const C_Str &line_r, TOutputIterator result_r, const C_Str &sepchars_r=":")
 Split line_r into fields handling also escaped separators. More...
 
Join.
template<class TIterator >
std::string join (TIterator begin, TIterator end, const C_Str &sep_r=" ")
 Join strings using separator sep_r (defaults to BLANK). More...
 
template<class TContainer >
std::string join (const TContainer &cont_r, const C_Str &sep_r=" ")
 Join strings using separator sep_r (defaults to BLANK). More...
 
template<class TIterator >
std::string joinEscaped (TIterator begin, TIterator end, const char sep_r= ' ')
 Join strings using separator sep_r, quoting or escaping the values. More...
 
Indent.
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. More...
 
std::ostream & printIndented (std::ostream &str, const std::string &text_r, unsigned indent_r, char indentch_r= ' ', unsigned maxWitdh_r=0)
 
std::ostream & printIndented (std::ostream &str, const std::string &text_r, unsigned indent_r, unsigned maxWitdh_r, char indentch_r= ' ')
 
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*, const char*)] Prints nothing for an empty string. More...
 
std::ostream & autoPrefix0 (std::ostream &str, const std::string &text_r, function< std::string()> fnc_r)
 
Case insensitive comparison.
int compareCI (const C_Str &lhs, const C_Str &rhs)
 
Locate substring.
bool contains (const C_Str &str_r, const C_Str &val_r)
 Locate substring case sensitive. More...
 
bool containsCI (const C_Str &str_r, const C_Str &val_r)
 Locate substring case insensitive. More...
 
String prefix/suffix handling.
bool hasPrefix (const C_Str &str_r, const C_Str &prefix_r)
 Return whether str_r has prefix prefix_r. More...
 
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. More...
 
bool hasSuffix (const C_Str &str_r, const C_Str &suffix_r)
 Return whether str_r has suffix suffix_r. More...
 
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. More...
 
std::string::size_type commonPrefix (const C_Str &lhs, const C_Str &rhs)
 Return size of the common prefix of lhs and rhs. More...
 
bool startsWith (const C_Str &str_r, const C_Str &prefix_r)
 alias for hasPrefix More...
 
bool endsWith (const C_Str &str_r, const C_Str &prefix_r)
 alias for hasSuffix More...
 

Trimming whitepace.

Todo:
optimize l/r trim.
enum  Trim { NO_TRIM = 0x00, L_TRIM = 0x01, R_TRIM = 0x02, TRIM = (L_TRIM|R_TRIM) }
 To define how to trim. More...
 
std::string trim (const std::string &s, const Trim trim_r)
 
std::string trim (std::string &&s, const Trim trim_r)
 
std::string ltrim (const std::string &s)
 
std::string ltrim (std::string &&s)
 
std::string rtrim (const std::string &s)
 
std::string rtrim (std::string &&s)
 

Detailed Description

String related utilities and Regular expression matching.

See Also
Regular expression matching

Typedef Documentation

Definition at line 54 of file Regex.h.

Enumeration Type Documentation

To define how to trim.

Enumerator
NO_TRIM 
L_TRIM 
R_TRIM 
TRIM 

Definition at line 986 of file String.h.

Function Documentation

bool zypp::str::regex_match ( const std::string &  s,
smatch &  matches,
const regex &  regex 
)
inline

regex ZYPP_STR_REGEX regex ZYPP_STR_REGEX

regex ZYPP_STR_REGEX regex ZYPP_STR_REGEX

Definition at line 70 of file Regex.h.

bool zypp::str::regex_match ( const char *  s,
const regex regex 
)

regex ZYPP_STR_REGEX regex ZYPP_STR_REGEX

regex ZYPP_STR_REGEX regex ZYPP_STR_REGEX

Definition at line 68 of file Regex.cc.

bool zypp::str::regex_match ( const std::string &  s,
const regex &  regex 
)
inline

regex ZYPP_STR_REGEX regex ZYPP_STR_REGEX

regex ZYPP_STR_REGEX regex ZYPP_STR_REGEX

Definition at line 77 of file Regex.h.

std::string std::string zypp::str::strerror ( int  errno_r)

Return string describing the error_r code.

Like strerror, but the numerical value is included in the string as well.

Definition at line 53 of file String.cc.

bool zypp::str::strToTrue ( const C_Str &  str)

Parsing boolean from string.

Return true if str is 1, true, yes, on (or a nonzero number).

Definition at line 63 of file String.cc.

bool zypp::str::strToFalse ( const C_Str &  str)

Return false if str is 0, false, no, off.

Definition at line 80 of file String.cc.

TriBool zypp::str::strToTriBool ( const C_Str &  str)

Parse str into a bool if it's a legal true or false string; else indterminate.

Definition at line 91 of file String.cc.

std::string zypp::str::hexencode ( const C_Str &  str_r)

Encode all characters other than [a-zA-Z0-9] as XX.

This includes the % character itself, which becomes %25.

Definition at line 122 of file String.cc.

std::string zypp::str::hexdecode ( const C_Str &  str_r)

Decode hexencoded XX sequences.

Definition at line 143 of file String.cc.

std::string zypp::str::toLower ( const std::string &  s)

Return lowercase version of s.

Todo:
improve

Definition at line 175 of file String.cc.

std::string zypp::str::toLower ( std::string &&  s)

Definition at line 178 of file String.cc.

std::string zypp::str::toUpper ( const std::string &  s)

Return uppercase version of s.

Todo:
improve

Definition at line 198 of file String.cc.

std::string zypp::str::toUpper ( std::string &&  s)

Definition at line 201 of file String.cc.

std::string zypp::str::trim ( const std::string &  s,
const Trim  trim_r 
)

Definition at line 221 of file String.cc.

std::string zypp::str::trim ( std::string &&  s,
const Trim  trim_r 
)

Definition at line 224 of file String.cc.

std::string zypp::str::stripFirstWord ( std::string &  line,
const bool  ltrim_first 
)

Definition at line 261 of file String.cc.

std::string zypp::str::stripLastWord ( std::string &  line,
const bool  rtrim_first 
)

Definition at line 294 of file String.cc.

std::string zypp::str::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 at line 322 of file String.cc.

std::string & zypp::str::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).

A reference to str_r is also returned for convenience.

Definition at line 328 of file String.cc.

std::string zypp::str::gsubFun ( const std::string &  str_r,
const std::string &  from_r,
function< std::string()>  to_r 
)

Definition at line 345 of file String.cc.

std::string & zypp::str::replaceAllFun ( std::string &  str_r,
const std::string &  from_r,
function< std::string()>  to_r 
)

Definition at line 351 of file String.cc.

std::string zypp::str::escape ( const C_Str &  str_r,
const char  c = ' ' 
)

Escape desired character c using a backslash.

For use when printing c separated values, and where joinEscaped() is too heavy.

Definition at line 369 of file String.cc.

std::string zypp::str::bEscape ( std::string  str_r,
const C_Str &  special_r 
)

Return str_r with '\'-escaped chars occurring in special_r (and '\').

Definition at line 392 of file String.cc.

std::string zypp::str::rxEscapeStr ( std::string  str_r)

Escape plain STRING str_r for use in a regex (not anchored by "^" or "$").

Definition at line 413 of file String.cc.

std::string zypp::str::rxEscapeGlob ( std::string  str_r)

Escape GLOB str_r for use in a regex (not anchored by "^" or "$").

Definition at line 418 of file String.cc.

std::string zypp::str::getline ( std::istream &  str,
const Trim  trim_r 
)

Return stream content up to (but not returning) the next newline.

See Also
receiveUpTo

Definition at line 476 of file String.cc.

std::string zypp::str::getline ( std::istream &  str,
bool  trim = false 
)

Return stream content up to (but not returning) the next newline.

See Also
receiveUpTo

Definition at line 481 of file String.cc.

std::string zypp::str::receiveUpTo ( std::istream &  str,
const char  delim_r,
bool  returnDelim_r = false 
)

Return stream content up to the next ocurrence of delim_r or EOF delim_r, if found, is always read from the stream.

Whether it is also returned in the string depends on returnDelim_r. If the stream status is good, delim_r was found in the stream. If we reached EOF while looking for delim_r, eof is set; and also fail, if we did not read any data before.

Definition at line 486 of file String.cc.

const std::string& zypp::str::asString ( const std::string &  t)
inline

Global asString() that works with std::string too.

Definition at line 136 of file String.h.

std::string&& zypp::str::asString ( std::string &&  t)
inline

Definition at line 140 of file String.h.

std::string zypp::str::asString ( const char *  t)
inline

Definition at line 144 of file String.h.

std::string zypp::str::asString ( char *  t)
inline

Definition at line 147 of file String.h.

template<class Tp >
std::string zypp::str::asString ( const Tp &  t)
inline

Definition at line 151 of file String.h.

template<class Tp >
std::string zypp::str::asString ( const intrusive_ptr< Tp > &  p)
inline

Definition at line 155 of file String.h.

template<class Tp >
std::string zypp::str::asString ( const weak_ptr< Tp > &  p)
inline

Definition at line 159 of file String.h.

template<>
std::string zypp::str::asString ( const bool t)
inline

Definition at line 163 of file String.h.

std::string zypp::str::numstring ( char  n,
int  w = 0 
)
inline

Definition at line 304 of file String.h.

std::string zypp::str::numstring ( unsigned char  n,
int  w = 0 
)
inline

Definition at line 305 of file String.h.

std::string zypp::str::numstring ( short  n,
int  w = 0 
)
inline

Definition at line 306 of file String.h.

std::string zypp::str::numstring ( unsigned short  n,
int  w = 0 
)
inline

Definition at line 307 of file String.h.

std::string zypp::str::numstring ( int  n,
int  w = 0 
)
inline

Definition at line 308 of file String.h.

std::string zypp::str::numstring ( unsigned  n,
int  w = 0 
)
inline

Definition at line 309 of file String.h.

std::string zypp::str::numstring ( long  n,
int  w = 0 
)
inline

Definition at line 310 of file String.h.

std::string zypp::str::numstring ( unsigned long  n,
int  w = 0 
)
inline

Definition at line 311 of file String.h.

std::string zypp::str::numstring ( long long  n,
int  w = 0 
)
inline

Definition at line 312 of file String.h.

std::string zypp::str::numstring ( unsigned long long  n,
int  w = 0 
)
inline

Definition at line 313 of file String.h.

template<>
std::string zypp::str::asString ( const char &  t)
inline

Definition at line 315 of file String.h.

template<>
std::string zypp::str::asString ( const unsigned char &  t)
inline

Definition at line 316 of file String.h.

template<>
std::string zypp::str::asString ( const short &  t)
inline

Definition at line 317 of file String.h.

template<>
std::string zypp::str::asString ( const unsigned short &  t)
inline

Definition at line 318 of file String.h.

template<>
std::string zypp::str::asString ( const int &  t)
inline

Definition at line 319 of file String.h.

template<>
std::string zypp::str::asString ( const unsigned &  t)
inline

Definition at line 320 of file String.h.

template<>
std::string zypp::str::asString ( const long &  t)
inline

Definition at line 321 of file String.h.

template<>
std::string zypp::str::asString ( const unsigned long &  t)
inline

Definition at line 322 of file String.h.

template<>
std::string zypp::str::asString ( const long long &  t)
inline

Definition at line 323 of file String.h.

template<>
std::string zypp::str::asString ( const unsigned long long &  t)
inline

Definition at line 324 of file String.h.

std::string zypp::str::hexstring ( char  n,
int  w = 4 
)
inline

Definition at line 339 of file String.h.

std::string zypp::str::hexstring ( unsigned char  n,
int  w = 4 
)
inline

Definition at line 340 of file String.h.

std::string zypp::str::hexstring ( short  n,
int  w = 10 
)
inline

Definition at line 341 of file String.h.

std::string zypp::str::hexstring ( unsigned short  n,
int  w = 10 
)
inline

Definition at line 342 of file String.h.

std::string zypp::str::hexstring ( int  n,
int  w = 10 
)
inline

Definition at line 343 of file String.h.

std::string zypp::str::hexstring ( unsigned  n,
int  w = 10 
)
inline

Definition at line 344 of file String.h.

std::string zypp::str::hexstring ( long  n,
int  w = 10 
)
inline

Definition at line 345 of file String.h.

std::string zypp::str::hexstring ( unsigned long  n,
int  w = 10 
)
inline

Definition at line 346 of file String.h.

std::string zypp::str::hexstring ( long long  n,
int  w = 0 
)
inline

Definition at line 347 of file String.h.

std::string zypp::str::hexstring ( unsigned long long  n,
int  w = 0 
)
inline

Definition at line 348 of file String.h.

std::string zypp::str::octstring ( char  n,
int  w = 4 
)
inline

Definition at line 363 of file String.h.

std::string zypp::str::octstring ( unsigned char  n,
int  w = 4 
)
inline

Definition at line 364 of file String.h.

std::string zypp::str::octstring ( short  n,
int  w = 5 
)
inline

Definition at line 365 of file String.h.

std::string zypp::str::octstring ( unsigned short  n,
int  w = 5 
)
inline

Definition at line 366 of file String.h.

std::string zypp::str::octstring ( int  n,
int  w = 5 
)
inline

Definition at line 367 of file String.h.

std::string zypp::str::octstring ( unsigned  n,
int  w = 5 
)
inline

Definition at line 368 of file String.h.

std::string zypp::str::octstring ( long  n,
int  w = 5 
)
inline

Definition at line 369 of file String.h.

std::string zypp::str::octstring ( unsigned long  n,
int  w = 5 
)
inline

Definition at line 370 of file String.h.

std::string zypp::str::octstring ( long long  n,
int  w = 0 
)
inline

Definition at line 371 of file String.h.

std::string zypp::str::octstring ( unsigned long long  n,
int  w = 0 
)
inline

Definition at line 372 of file String.h.

template<typename TInt >
std::string zypp::str::binstring ( TInt  val_r)

String representation of number as bit-string with leading '0's.

Definition at line 379 of file String.h.

template<typename TInt >
TInt zypp::str::strtonum ( const C_Str &  str)
inline

Parsing numbers from string.

String to integer type determined by template arg.

Note
Only specializations are defined.
time_t t = strtonum<time_t>( "42" );

Definition at line 403 of file String.h.

template<>
short zypp::str::strtonum ( const C_Str &  str)
inline

Parsing numbers from string.

String to integer type determined by template arg.

Note
Only specializations are defined.
time_t t = strtonum<time_t>( "42" );

Definition at line 403 of file String.h.

template<>
int zypp::str::strtonum ( const C_Str &  str)
inline

Parsing numbers from string.

String to integer type determined by template arg.

Note
Only specializations are defined.
time_t t = strtonum<time_t>( "42" );

Definition at line 405 of file String.h.

template<>
long zypp::str::strtonum ( const C_Str &  str)
inline

Parsing numbers from string.

String to integer type determined by template arg.

Note
Only specializations are defined.
time_t t = strtonum<time_t>( "42" );

Definition at line 407 of file String.h.

template<>
long long zypp::str::strtonum ( const C_Str &  str)
inline

Parsing numbers from string.

String to integer type determined by template arg.

Note
Only specializations are defined.
time_t t = strtonum<time_t>( "42" );

Definition at line 409 of file String.h.

template<>
unsigned short zypp::str::strtonum ( const C_Str &  str)
inline

Parsing numbers from string.

String to integer type determined by template arg.

Note
Only specializations are defined.
time_t t = strtonum<time_t>( "42" );

Definition at line 412 of file String.h.

template<>
unsigned zypp::str::strtonum ( const C_Str &  str)
inline

Parsing numbers from string.

String to integer type determined by template arg.

Note
Only specializations are defined.
time_t t = strtonum<time_t>( "42" );

Definition at line 414 of file String.h.

template<>
unsigned long zypp::str::strtonum ( const C_Str &  str)
inline

Parsing numbers from string.

String to integer type determined by template arg.

Note
Only specializations are defined.
time_t t = strtonum<time_t>( "42" );

Definition at line 416 of file String.h.

template<>
unsigned long long zypp::str::strtonum ( const C_Str &  str)
inline

Parsing numbers from string.

String to integer type determined by template arg.

Note
Only specializations are defined.
time_t t = strtonum<time_t>( "42" );

Definition at line 418 of file String.h.

template<typename TInt >
TInt zypp::str::strtonum ( const C_Str &  str,
TInt &  i 
)
inline

String to integer type detemined 2nd function arg i.

time_t t; strtonum( "42", t );

Definition at line 426 of file String.h.

bool zypp::str::strToBool ( const C_Str &  str,
bool  default_r 
)
inline

Parse str into a bool depending on the default value.

If the default is true, look for a legal false string. If the default is false, look for a legal true string.

Definition at line 444 of file String.h.

bool zypp::str::strToBoolNodefault ( const C_Str &  str,
bool return_r 
)
inline

Parse str into a bool if it's a legal true or false string.

If str is not a recognized true or false string, return_r is left unchanged.

Definition at line 451 of file String.h.

std::string zypp::str::gapify ( std::string  inp_r,
std::string::size_type  gap_r = 1,
char  gapchar = ' ' 
)
inline

Enhance readability: insert gaps at regular distance.

// no gaps
Key Fingerprint: 22C07BA534178CD02EFE22AAB88B2FD43DBDC284
// gapify 8
Key Fingerprint: 22C07BA5 34178CD0 2EFE22AA B88B2FD4 3DBDC284
// gapify 4
Key Fingerprint: 22C0 7BA5 3417 8CD0 2EFE 22AA B88B 2FD4 3DBD C284
// gapify 4, '-'
Key Fingerprint: 22C0-7BA5-3417-8CD0-2EFE-22AA-B88B-2FD4-3DBD-C284

Definition at line 494 of file String.h.

template<class TOutputIterator >
unsigned zypp::str::split ( const C_Str &  line_r,
TOutputIterator  result_r,
const C_Str &  sepchars_r = " \t" 
)

Split line_r into words.

Any sequence of characters in sepchars_r is treated as delimiter. The words are passed to OutputIterator result_r.

std::vector<std::string> words;
str::split( "some line", std::back_inserter(words) )

Definition at line 518 of file String.h.

template<class TOutputIterator >
unsigned zypp::str::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.

Any sequence of characters in sepchars_r is treated as delimiter if not inside "" or '' or escaped by .

  • A non-quoted backslash () preserves the literal value of the next character.
  • Enclosing characters in single quotes preserves the literal value of each character within the quotes. A single quote may not occur between single quotes, even when preceded by a backslash.
  • Enclosing characters in double quotes preserves the literal value of all characters within the quotes, with the exception of . The backslash retains its special meaning only when followed by " or .

The words are passed to OutputIterator result_r.

See Also
splitEscaped
std::vector<std::string> words;
str::splitEscaped( "some line", std::back_inserter(words) )
example splitted strings
normal line -> 2 elements ( "normal", "line" )
escaped\ line -> 1 element(escaped line)
"quoted line" -> 1 element same as above
'quoted line' -> 1 element same as above
"escaped quote\"" -> 1 element (escaped quote")
\param line_r The string to parse.
\param result_r
\param sepchars_r String of separator characters.
\param withEmpty Whether to include empty fields between separators in the result.

Definition at line 577 of file String.h.

template<class TOutputIterator >
unsigned zypp::str::splitFields ( const C_Str &  line_r,
TOutputIterator  result_r,
const C_Str &  sepchars_r = ":" 
)

Split line_r into fields.

Any single character in sepchars_r is treated as a field separator unless -escaped. The words are passed to OutputIterator. result_r.

"" -> words 0
":" -> words 2 |||
"a" -> words 1 |a|
":a" -> words 2 ||a|
"a:" -> words 2 |a||
":a:" -> words 3 ||a||
std::vector<std::string> words;
str::split( "some line", std::back_inserter(words) )

Definition at line 707 of file String.h.

template<class TOutputIterator >
unsigned zypp::str::splitFieldsEscaped ( const C_Str &  line_r,
TOutputIterator  result_r,
const C_Str &  sepchars_r = ":" 
)

Split line_r into fields handling also escaped separators.

See Also
splitFields()
splitEscaped()

Definition at line 746 of file String.h.

template<class TIterator >
std::string zypp::str::join ( TIterator  begin,
TIterator  end,
const C_Str &  sep_r = " " 
)

Join strings using separator sep_r (defaults to BLANK).

Definition at line 758 of file String.h.

template<class TContainer >
std::string zypp::str::join ( const TContainer &  cont_r,
const C_Str &  sep_r = " " 
)

Join strings using separator sep_r (defaults to BLANK).

Definition at line 772 of file String.h.

template<class TIterator >
std::string zypp::str::joinEscaped ( TIterator  begin,
TIterator  end,
const char  sep_r = ' ' 
)

Join strings using separator sep_r, quoting or escaping the values.

Separator defaults to BLANK. Use splitEscaped to restore the values.

Definition at line 780 of file String.h.

std::ostream& zypp::str::printIndented ( std::ostream &  str,
const std::string &  text_r,
const std::string &  indent_r = "  ",
unsigned  maxWitdh_r = 0 
)
inline

Indent by string [" "] optionally wrap.

Prints nothing for an empty string. Asserts a trainling '
' on the last line. Optionally wrap lines at ' ' at a given length.

Definition at line 827 of file String.h.

std::ostream& zypp::str::printIndented ( std::ostream &  str,
const std::string &  text_r,
unsigned  indent_r,
char  indentch_r = ' ',
unsigned  maxWitdh_r = 0 
)
inline

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

Definition at line 860 of file String.h.

std::ostream& zypp::str::printIndented ( std::ostream &  str,
const std::string &  text_r,
unsigned  indent_r,
unsigned  maxWitdh_r,
char  indentch_r = ' ' 
)
inline

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

Definition at line 863 of file String.h.

std::ostream& zypp::str::autoPrefix ( std::ostream &  str,
const std::string &  text_r,
function< std::string(const char *, const char *)>  fnc_r 
)
inline

Prefix lines by string computed by function taking line begin/end [std::string(const char*, const char*)] Prints nothing for an empty string.

Asserts a trainling '
' on the last line.

Definition at line 869 of file String.h.

std::ostream& zypp::str::autoPrefix0 ( std::ostream &  str,
const std::string &  text_r,
function< std::string()>  fnc_r 
)
inline

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

Definition at line 884 of file String.h.

void zypp::str::appendEscaped ( std::string &  str_r,
const C_Str &  next_r,
const char  sep_r = ' ' 
)
inline

Escape next_r and append it to str_r using separator sep_r.

Definition at line 904 of file String.h.

std::string zypp::str::toLower ( const char *  s)
inline

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

Definition at line 950 of file String.h.

std::string zypp::str::toUpper ( const char *  s)
inline

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

Definition at line 959 of file String.h.

int zypp::str::compareCI ( const C_Str &  lhs,
const C_Str &  rhs 
)
inline

Definition at line 966 of file String.h.

bool zypp::str::contains ( const C_Str &  str_r,
const C_Str &  val_r 
)
inline

Locate substring case sensitive.

Definition at line 973 of file String.h.

bool zypp::str::containsCI ( const C_Str &  str_r,
const C_Str &  val_r 
)
inline

Locate substring case insensitive.

Definition at line 976 of file String.h.

std::string zypp::str::ltrim ( const std::string &  s)
inline

Definition at line 996 of file String.h.

std::string zypp::str::ltrim ( std::string &&  s)
inline

Definition at line 998 of file String.h.

std::string zypp::str::rtrim ( const std::string &  s)
inline

Definition at line 1001 of file String.h.

std::string zypp::str::rtrim ( std::string &&  s)
inline

Definition at line 1003 of file String.h.

bool zypp::str::hasPrefix ( const C_Str &  str_r,
const C_Str &  prefix_r 
)
inline

Return whether str_r has prefix prefix_r.

Definition at line 1036 of file String.h.

std::string zypp::str::stripPrefix ( const C_Str &  str_r,
const C_Str &  prefix_r 
)
inline

Strip a prefix_r from str_r and return the resulting string.

Definition at line 1040 of file String.h.

bool zypp::str::hasSuffix ( const C_Str &  str_r,
const C_Str &  suffix_r 
)
inline

Return whether str_r has suffix suffix_r.

Definition at line 1044 of file String.h.

std::string zypp::str::stripSuffix ( const C_Str &  str_r,
const C_Str &  suffix_r 
)
inline

Strip a suffix_r from str_r and return the resulting string.

Definition at line 1048 of file String.h.

std::string::size_type zypp::str::commonPrefix ( const C_Str &  lhs,
const C_Str &  rhs 
)
inline

Return size of the common prefix of lhs and rhs.

Definition at line 1055 of file String.h.

bool zypp::str::startsWith ( const C_Str &  str_r,
const C_Str &  prefix_r 
)
inline

alias for hasPrefix

Definition at line 1066 of file String.h.

bool zypp::str::endsWith ( const C_Str &  str_r,
const C_Str &  prefix_r 
)
inline

alias for hasSuffix

Definition at line 1069 of file String.h.