libzypp: zypp-core/base/String.h File Reference

libzypp 17.38.15

String.h File Reference
`#include <cstring>`
`#include <iosfwd>`
`#include <vector>`
`#include <string>`
`#include <sstream>`
`#include <optional>`
`#include <boost/format.hpp>`
`#include <boost/utility/string_ref.hpp>`
`#include <zypp-core/base/Easy.h>`
`#include <zypp-core/base/PtrTypes.h>`
`#include <zypp-core/base/Function.h>`

Go to the source code of this file.

## Classes
class | zypp::C_Str
| Convenience `char*` constructible from `std::string` and `char*`, it maps ``(char*)0 to an empty string. More...
struct | zypp::str::SafeBuf
| Assert `free` called for allocated char *. More...
class | zypp::str::Str
| Convenient building of std::string via std::ostringstream Basically a std::ostringstream autoconvertible to std::string for building string arguments. More...
class | zypp::str::Format
| Convenient building of std::string with boost::format. More...

## Namespaces
namespace | boost
| Boost libraries.
namespace | boost::logic
namespace | zypp
| Easy-to use interface to the ZYPP dependency resolver.
namespace | zypp::str
| Provide print[f] and sprint[f] functions based on JoinFormat.

## Typedefs
using | zypp::TriBool = boost::logic::tribool
| 3-state boolean logic (`true`, `false` and `indeterminate`).

## Functions
template<class Tp>
std::string | zypp::asUserString (const Tp &val_r)
| Request a human readable (translated) string representation of Tp [Tp.asUserString()] Classes may implement a default as member function.
std::ostream & | zypp::operator<< (std::ostream &str, const C_Str &obj)
| relates: C_Str Stream output
const std::string & | zypp::str::asString (const std::string &t)
| Global asString() that works with std::string too.
std::string && | zypp::str::asString (std::string &&t)
std::string | zypp::str::asString (const char *t)
std::string | zypp::str::asString (char *t)
template<class Tp>
std::string | zypp::str::asString (const Tp &t)
template<class Tp>
std::string | zypp::str::asString (const intrusive_ptr< Tp > &p)
template<class Tp>
std::string | zypp::str::asString (const weak_ptr< Tp > &p)
template<>
std::string | zypp::str::asString (const bool &t)
std::string | zypp::str::form (const char *format,...) __attribute__((format(printf
| Printf style construction of std::string.
std::string | zypp::str::strerror (int errno_r) ZYPP_API
| Return string describing the error_r code.
std::ostream & | zypp::str::operator<< (std::ostream &str, const Str &obj)
| relates: Str Stream output
std::ostream & | zypp::str::operator<< (std::ostream &str, const Format &obj)
| relates: Format Stream output
const std::string & | zypp::asString (const std::string &t)
| Global asString() that works with std::string too.
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 " zypp::str::numstring std::string numstring(char n, int w=0) Definition String.h:290
std::string | zypp::str::numstring (char n, int w=0)
std::string | zypp::str::numstring (unsigned char n, int w=0)
std::string | zypp::str::numstring (short n, int w=0)
std::string | zypp::str::numstring (unsigned short n, int w=0)
std::string | zypp::str::numstring (int n, int w=0)
std::string | zypp::str::numstring (unsigned n, int w=0)
std::string | zypp::str::numstring (long n, int w=0)
std::string | zypp::str::numstring (unsigned long n, int w=0)
std::string | zypp::str::numstring (long long n, int w=0)
std::string | zypp::str::numstring (unsigned long long n, int w=0)
template<>
std::string | zypp::str::asString (const char &t)
template<>
std::string | zypp::str::asString (const unsigned char &t)
template<>
std::string | zypp::str::asString (const short &t)
template<>
std::string | zypp::str::asString (const unsigned short &t)
template<>
std::string | zypp::str::asString (const int &t)
template<>
std::string | zypp::str::asString (const unsigned &t)
template<>
std::string | zypp::str::asString (const long &t)
template<>
std::string | zypp::str::asString (const unsigned long &t)
template<>
std::string | zypp::str::asString (const long long &t)
template<>
std::string | zypp::str::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 | zypp::str::hexstring (char n, int w=4)
std::string | zypp::str::hexstring (unsigned char n, int w=4)
std::string | zypp::str::hexstring (short n, int w=10)
std::string | zypp::str::hexstring (unsigned short n, int w=10)
std::string | zypp::str::hexstring (int n, int w=10)
std::string | zypp::str::hexstring (unsigned n, int w=10)
std::string | zypp::str::hexstring (long n, int w=10)
std::string | zypp::str::hexstring (unsigned long n, int w=10)
std::string | zypp::str::hexstring (long long n, int w=0)
std::string | zypp::str::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 | zypp::str::octstring (char n, int w=4)
std::string | zypp::str::octstring (unsigned char n, int w=4)
std::string | zypp::str::octstring (short n, int w=5)
std::string | zypp::str::octstring (unsigned short n, int w=5)
std::string | zypp::str::octstring (int n, int w=5)
std::string | zypp::str::octstring (unsigned n, int w=5)
std::string | zypp::str::octstring (long n, int w=5)
std::string | zypp::str::octstring (unsigned long n, int w=5)
std::string | zypp::str::octstring (long long n, int w=0)
std::string | zypp::str::octstring (unsigned long long n, int w=0)
template<typename TInt>
std::string | zypp::str::binstring (TInt val_r)
| String representation of number as bit-string with leading '0's.
template<typename TInt>
TInt | zypp::str::strtonum (const C_Str &str)
| Parsing numbers from string.
template<>
short | zypp::str::strtonum (const C_Str &str)
template<>
int | zypp::str::strtonum (const C_Str &str)
template<>
long | zypp::str::strtonum (const C_Str &str)
template<>
long long | zypp::str::strtonum (const C_Str &str)
template<>
unsigned short | zypp::str::strtonum (const C_Str &str)
template<>
unsigned | zypp::str::strtonum (const C_Str &str)
template<>
unsigned long | zypp::str::strtonum (const C_Str &str)
template<>
unsigned long long | zypp::str::strtonum (const C_Str &str)
template<typename TInt>
TInt | zypp::str::strtonum (const C_Str &str, TInt &i)
| String to integer type detemined 2nd function arg i.
bool | zypp::str::strToTrue (const C_Str &str) ZYPP_API
| Parsing boolean from string.
bool | zypp::str::strToFalse (const C_Str &str) ZYPP_API
| Return `false` if str is 0, false, no, off, never.
bool | zypp::str::strToBool (const C_Str &str, bool default_r)
| Parse `str` into a bool depending on the default value.
bool | zypp::str::strToBoolNodefault (const C_Str &str, bool &return_r)
| Parse `str` into a bool if it's a legal `true` or `false` string.
TriBool | zypp::str::strToTriBool (const C_Str &str) ZYPP_API
| Parse `str` into a bool if it's a legal `true` or `false` string; else `indeterminate`.
std::string | zypp::str::gsub (const std::string &str_r, const std::string &from_r, const std::string &to_r) ZYPP_API
| Return a string with all occurrences of `from_r` replaced with `to_r`.
std::string | zypp::str::gsubFun (const std::string &str_r, const std::string &from_r, function< std::string()> to_r)
std::string & | zypp::str::replaceAll (std::string &str_r, const std::string &from_r, const std::string &to_r) ZYPP_API
| Replace all occurrences of `from_r` with `to_r` in `str_r` (inplace).
std::string & | zypp::str::replaceAllFun (std::string &str_r, const std::string &from_r, const function< std::string()> &to_r)
std::string | zypp::str::gapify (std::string inp_r, std::string::size_type gap_r=1, char gapchar=' ')
| Enhance readability: insert gaps at regular distance.
Split.
template<class TOutputIterator>
unsigned | zypp::str::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.
template<class TOutputIterator>
unsigned | zypp::str::split (const C_Str &line_r, TOutputIterator result_r, const Trim trim_r)
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.
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.
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.
Join.
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).
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).
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.
Indent.
std::ostream & | zypp::str::printIndented (std::ostream &str, const std::string &text_r, const std::string &indent_r=" ", unsigned maxWitdh_r=0)
| Indent by string [" "] optionally wrap.
std::ostream & | zypp::str::printIndented (std::ostream &str, const std::string &text_r, unsigned indent_r, char indentch_r=' ', unsigned maxWitdh_r=0)
std::ostream & | zypp::str::printIndented (std::ostream &str, const std::string &text_r, unsigned indent_r, unsigned maxWitdh_r, char indentch_r=' ')
std::ostream & | zypp::str::autoPrefix (std::ostream &str, const std::string &text_r, const 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.
std::ostream & | zypp::str::autoPrefix0 (std::ostream &str, const std::string &text_r, function< std::string()> fnc_r)
Escape.
std::string | zypp::str::escape (const C_Str &str_r, const char c=' ') ZYPP_API
| Escape desired character c using a backslash.
void | zypp::str::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.
std::string | zypp::str::bEscape (std::string str_r, const C_Str &special_r) ZYPP_API
| Return str_r with '\'-escaped chars occurring in special_r (and '\').
std::string | zypp::str::rxEscapeStr (std::string str_r) ZYPP_API
| Escape plain STRING str_r for use in a regex (not anchored by "^" or "$").
std::string | zypp::str::rxEscapeGlob (std::string str_r) ZYPP_API
| Escape GLOB str_r for use in a regex (not anchored by "^" or "$").
Hexencode.
Encode all characters other than [a-zA-Z0-9] as XX. Todo unsecape() This includes the % character itself, which becomes %25.
std::string | zypp::str::hexencode (const C_Str &str_r)
| Encode all characters other than [a-zA-Z0-9] as XX.
std::string | zypp::str::hexdecode (const C_Str &str_r)
| Decode hexencoded XX sequences.
Case conversion.
std::string | zypp::str::toLower (const std::string &s) ZYPP_API
| Return lowercase version of s.
std::string | zypp::str::toLower (std::string &&s)
std::string | zypp::str::toLower (const char *s)
| This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
std::string | zypp::str::toUpper (const std::string &s) ZYPP_API
| Return uppercase version of s.
std::string | zypp::str::toUpper (std::string &&s)
std::string | zypp::str::toUpper (const char *s)
| This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
Case insensitive comparison.
int | zypp::str::compareCI (const C_Str &lhs, const C_Str &rhs)
Locate substring.
bool | zypp::str::contains (const C_Str &str_r, const C_Str &val_r)
| Locate substring case sensitive.
bool | zypp::str::containsCI (const C_Str &str_r, const C_Str &val_r)
| Locate substring case insensitive.
std::string | zypp::str::stripFirstWord (std::string &line, const bool ltrim_first)
std::string | zypp::str::stripLastWord (std::string &line, const bool rtrim_first)
std::string | zypp::str::getline (std::istream &str, bool trim=false) ZYPP_API
| Return stream content up to (but not returning) the next newline.
std::string | zypp::str::getline (std::istream &str, const Trim trim_r) ZYPP_API
| Return stream content up to (but not returning) the next newline.
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.
String prefix/suffix handling.
bool | zypp::str::hasPrefix (const C_Str &str_r, const C_Str &prefix_r)
| Return whether str_r has prefix prefix_r.
bool | zypp::str::hasPrefixCI (const C_Str &str_r, const C_Str &prefix_r)
std::string | zypp::str::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 | zypp::str::stripPrefixCI (const C_Str &str_r, const C_Str &prefix_r)
bool | zypp::str::hasSuffix (const C_Str &str_r, const C_Str &suffix_r)
| Return whether str_r has suffix suffix_r.
bool | zypp::str::hasSuffixCI (const C_Str &str_r, const C_Str &suffix_r)
std::string | zypp::str::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 | zypp::str::stripSuffixCI (const C_Str &str_r, const C_Str &suffix_r)
std::string::size_type | zypp::str::commonPrefix (const C_Str &lhs, const C_Str &rhs)
| Return size of the common prefix of lhs and rhs.
std::string::size_type | zypp::str::commonPrefixCI (const C_Str &lhs, const C_Str &rhs)
bool | zypp::str::startsWith (const C_Str &str_r, const C_Str &prefix_r)
| alias for hasPrefix
bool | zypp::str::startsWithCI (const C_Str &str_r, const C_Str &prefix_r)
bool | zypp::str::endsWith (const C_Str &str_r, const C_Str &prefix_r)
| alias for hasSuffix
bool | zypp::str::endsWithCI (const C_Str &str_r, const C_Str &prefix_r)

## Variables
std::string | zypp::str::ZYPP_API

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