zypp::str Namespace Reference

String related utilities and Regular expressions. More...


Classes

struct  SafeBuf
 Assert free called for allocated char *. 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 ltrim (const std::string &s)
std::string rtrim (const std::string &s)
bool strToTrue (const std::string &str)
 Return true if str is 1, true, yes, on.
bool strToFalse (const std::string &str)
 Return false if str is 0, false, no, off.
bool strToBool (const std::string &str, bool default_r)
 Parse str into a bool depending on the default value.

Hexencode.

Encode all characters other than [a-zA-Z0-9] as XX. This includes the % character itself, which becomes 25.

std::string hexencode (const std::string &str_r)
 Encode all characters other than [a-zA-Z0-9] as XX.
std::string hexdecode (const std::string &str_r)
 Decode hexencoded XX sequences.

Case conversion.

std::string toLower (const std::string &s)
 Return lowercase version of s.
std::string toUpper (const std::string &s)
 Return uppercase version of s.

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)

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 _It>
_It strtonum (const std::string &str)
 String to integer type determined by template arg.
template<typename _It>
_It strtonum (const std::string &str, _It &i)
 String to integer type detemined 2nd function arg i.

Split.

template<class _OutputIterator>
unsigned split (const std::string &line_r, _OutputIterator result_r, const std::string &sepchars_r=" \t")
 Split line_r into words.
template<class _OutputIterator>
unsigned splitFields (const std::string &line_r, _OutputIterator result_r, const std::string &sepchars_r=":")
 Split line_r into fields.

Join.

template<class _Iterator>
std::string join (_Iterator begin, _Iterator end, const std::string &sep_r=" ")
 Join strings using separator sep_r (defaults to BLANK).
template<class _Container>
std::string join (const _Container &cont_r, const std::string &sep_r=" ")
 Join strings using separator sep_r (defaults to BLANK).

String prefix handling.

bool hasPrefix (const std::string &str_r, const std::string &prefix_r)
 Return whether str_r has prefix prefix_r.
std::string stripPrefix (const std::string &str_r, const std::string &prefix_r)
 Strip a prefix_r from str_r and return the resulting string.

Functions

std::string form (const char *format,...) __attribute__((format(printf
 Printf style construction of std::string.
std::string strerror (int errno_r)
 Return string describing the error_r code.
bool heIsAlNum (char ch)
 What's not decoded.
int heDecodeCh (char ch)
 Hex-digit to number or -1.
std::string stripFirstWord (std::string &line, const bool ltrim_first)
static std::string _getline (std::istream &str, const Trim trim_r)
std::string getline (std::istream &str, const Trim trim_r)
std::string getline (std::istream &str, bool trim)
std::string & replace_all (std::string &str, const std::string &from, const std::string &to)
 Looks for text in string and replaces it in place.


Detailed Description

String related utilities and Regular expressions.

See also:
Regular expressions


Enumeration Type Documentation

enum zypp::str::Trim
 

To define how to trim.

Enumerator:
NO_TRIM 
L_TRIM 
R_TRIM 
TRIM 

Definition at line 392 of file String.h.


Function Documentation

std::string zypp::str::form const char *  format,
  ...
 

Printf style construction of std::string.

Definition at line 31 of file String.cc.

References zypp::str::SafeBuf::_buf, and zypp::str::SafeBuf::asString().

Referenced by zypp::Edition::asString(), zypp::exception_detail::CodeLocation::asString(), zypp::url::checkUrlData(), zypp::target::rpm::RpmDb::doRebuildDatabase(), zypp::solver::detail::ResolverInfoObsoletes::dumpOn(), zypp::solver::detail::ResolverInfoNeededBy::dumpOn(), zypp::solver::detail::ResolverInfoDependsOn::dumpOn(), zypp::solver::detail::ResolverInfoConflictsWith::dumpOn(), zypp::solver::detail::ResolverInfoChildOf::dumpOn(), zypp::media::MediaForbiddenException::dumpOn(), zypp::media::MediaNotEjectedException::dumpOn(), zypp::media::MediaIsSharedException::dumpOn(), zypp::media::MediaNotDesiredException::dumpOn(), zypp::media::MediaCurlSetOptException::dumpOn(), zypp::media::MediaCurlException::dumpOn(), zypp::media::MediaUnsupportedUrlSchemeException::dumpOn(), zypp::media::MediaNotADirException::dumpOn(), zypp::media::MediaNotAFileException::dumpOn(), zypp::media::MediaSystemException::dumpOn(), zypp::media::MediaCurlInitException::dumpOn(), zypp::media::MediaWriteException::dumpOn(), zypp::media::MediaFileNotFoundException::dumpOn(), zypp::media::MediaNotOpenException::dumpOn(), zypp::media::MediaBadFilenameException::dumpOn(), zypp::media::MediaUnmountException::dumpOn(), zypp::media::MediaMountException::dumpOn(), zypp::source::PackageProvider::failOnChecksumError(), zypp::base::Unit::form(), zypp::base::ProfilingFormater::format(), zypp::base::LogControl::LineFormater::format(), zypp::ZYppFactory::getZYpp(), hexstring(), zypp::solver::detail::ResolverInfoObsoletes::message(), zypp::solver::detail::ResolverInfoNeededBy::message(), zypp::solver::detail::ResolverInfoMissingReq::message(), zypp::solver::detail::ResolverInfoMisc::message(), zypp::solver::detail::ResolverInfoDependsOn::message(), zypp::solver::detail::ResolverInfoConflictsWith::message(), zypp::solver::detail::ResolverInfoChildOf::message(), numstring(), octstring(), zypp::solver::detail::operator<<(), zypp::solver::detail::ProblemSolutionIgnoreArchitecture::ProblemSolutionIgnoreArchitecture(), zypp::solver::detail::ProblemSolutionIgnoreConflicts::ProblemSolutionIgnoreConflicts(), zypp::solver::detail::ProblemSolutionIgnoreInstalled::ProblemSolutionIgnoreInstalled(), zypp::solver::detail::ProblemSolutionIgnoreObsoletes::ProblemSolutionIgnoreObsoletes(), zypp::solver::detail::ProblemSolutionInstall::ProblemSolutionInstall(), zypp::solver::detail::ProblemSolutionKeep::ProblemSolutionKeep(), zypp::solver::detail::ProblemSolutionUninstall::ProblemSolutionUninstall(), zypp::solver::detail::ProblemSolutionUnlock::ProblemSolutionUnlock(), zypp::source::SourceImpl::provideFile(), zypp::source::SourceImpl::providePackage(), zypp::source::yum::YUMSourceImpl::providePackages(), zypp::source::yum::YUMSourceImpl::providePatches(), zypp::source::yum::YUMSourceImpl::providePatterns(), zypp::source::yum::YUMSourceImpl::provideProducts(), zypp::source::yum::YUMSourceImpl::provideSelections(), zypp::xml::ParseDef::Impl::skipNode(), zypp::sourceTableAdd(), and strerror().

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 48 of file String.cc.

References form().

Referenced by zypp::media::MediaCD::closeTray(), zypp::media::MediaCD::openTray(), zypp::ExternalProgram::running(), zypp::externalprogram::ExternalDataSource::setBlocking(), and zypp::Exception::strErrno().

bool zypp::str::strToTrue const std::string &  str  ) 
 

Return true if str is 1, true, yes, on.

Definition at line 58 of file String.cc.

References toLower().

Referenced by strToBool().

bool zypp::str::strToFalse const std::string &  str  ) 
 

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

Definition at line 73 of file String.cc.

References toLower().

Referenced by strToBool().

bool zypp::str::@0::heIsAlNum char  ch  )  [inline, static]
 

What's not decoded.

Definition at line 88 of file String.cc.

Referenced by hexencode().

int zypp::str::@0::heDecodeCh char  ch  )  [inline, static]
 

Hex-digit to number or -1.

Definition at line 95 of file String.cc.

Referenced by hexdecode().

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

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

This includes the % character itself, which becomes 25.

Definition at line 107 of file String.cc.

References heIsAlNum().

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

Decode hexencoded XX sequences.

Definition at line 128 of file String.cc.

References heDecodeCh().

Referenced by zypp::capability::ModaliasCap::evaluate().

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

Return lowercase version of s.

Todo:
improve

Definition at line 160 of file String.cc.

Referenced by zypp::addTrustedVendor(), zypp::CheckSum::CheckSum(), zypp::url::UrlBase::cleanupPathName(), zypp::solver::detail::HelixControl::deleteResolvable(), zypp::solver::detail::helixXML(), zypp::solver::detail::HelixControl::installResolvable(), zypp::url::UrlBase::isKnownScheme(), zypp::url::UrlBase::isValidScheme(), zypp::KindOf< _Tp >::operator==(), zypp::url::UrlBase::setScheme(), strToFalse(), strToTrue(), and zypp::trusted().

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

Return uppercase version of s.

Todo:
improve

Definition at line 179 of file String.cc.

Referenced by zypp::target::rpm::RpmDb::exportTrustedKeysInZyppKeyRing(), and zypp::target::rpm::RpmDb::importPubkey().

std::string zypp::str::trim const std::string &  s,
const Trim  trim_r = TRIM
 

Definition at line 198 of file String.cc.

References L_TRIM, NO_TRIM, and R_TRIM.

Referenced by _getline(), zypp::addTrustedVendor(), ltrim(), zypp::parser::IniParser::parse(), and rtrim().

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

Definition at line 232 of file String.cc.

References ltrim().

static std::string zypp::str::_getline std::istream &  str,
const Trim  trim_r
[inline, static]
 

Definition at line 268 of file String.cc.

References trim().

Referenced by getline().

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

Definition at line 283 of file String.cc.

References _getline().

Referenced by zypp::SourceFactory::scanProductsFile().

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

Definition at line 288 of file String.cc.

References _getline(), NO_TRIM, and TRIM.

std::string zypp::str::numstring char  n,
int  w = 0
[inline]
 

Definition at line 107 of file String.h.

References form().

Referenced by zypp::media::MediaSource::asString(), zypp::debug::dumpMemOn(), zypp::media::MediaManager_Impl::findMM(), zypp::solver::detail::HelixControl::HelixControl(), zypp::solver::detail::helixXML(), zypp::solver::detail::HelixControl::installResolvable(), zypp::source::SourceImpl::Verifier::isDesiredMedia(), zypp::MediaVerifier::isDesiredMedia(), zypp::source::MediaSet::rewriteUrl(), zypp::MediaSetAccess::rewriteUrl(), and zypp::syscontent::Writer::Impl::writeXml().

std::string zypp::str::numstring unsigned char  n,
int  w = 0
[inline]
 

Definition at line 108 of file String.h.

References form().

std::string zypp::str::numstring short  n,
int  w = 0
[inline]
 

Definition at line 109 of file String.h.

References form().

std::string zypp::str::numstring unsigned short  n,
int  w = 0
[inline]
 

Definition at line 110 of file String.h.

References form().

std::string zypp::str::numstring int  n,
int  w = 0
[inline]
 

Definition at line 111 of file String.h.

References form().

std::string zypp::str::numstring unsigned  n,
int  w = 0
[inline]
 

Definition at line 112 of file String.h.

References form().

std::string zypp::str::numstring long  n,
int  w = 0
[inline]
 

Definition at line 113 of file String.h.

References form().

std::string zypp::str::numstring unsigned long  n,
int  w = 0
[inline]
 

Definition at line 114 of file String.h.

References form().

std::string zypp::str::numstring long long  n,
int  w = 0
[inline]
 

Definition at line 115 of file String.h.

References form().

std::string zypp::str::numstring unsigned long long  n,
int  w = 0
[inline]
 

Definition at line 116 of file String.h.

References form().

std::string zypp::str::hexstring char  n,
int  w = 4
[inline]
 

Definition at line 131 of file String.h.

References form().

Referenced by zypp::PublicKey::Impl::asString(), zypp::SourceCache::removeSource(), and zypp::SourceCache::storeSource().

std::string zypp::str::hexstring unsigned char  n,
int  w = 4
[inline]
 

Definition at line 132 of file String.h.

References form().

std::string zypp::str::hexstring short  n,
int  w = 10
[inline]
 

Definition at line 133 of file String.h.

References form().

std::string zypp::str::hexstring unsigned short  n,
int  w = 10
[inline]
 

Definition at line 134 of file String.h.

References form().

std::string zypp::str::hexstring int  n,
int  w = 10
[inline]
 

Definition at line 135 of file String.h.

References form().

std::string zypp::str::hexstring unsigned  n,
int  w = 10
[inline]
 

Definition at line 136 of file String.h.

References form().

std::string zypp::str::hexstring long  n,
int  w = 10
[inline]
 

Definition at line 137 of file String.h.

References form().

std::string zypp::str::hexstring unsigned long  n,
int  w = 10
[inline]
 

Definition at line 138 of file String.h.

References form().

std::string zypp::str::hexstring long long  n,
int  w = 0
[inline]
 

Definition at line 139 of file String.h.

References form().

std::string zypp::str::hexstring unsigned long long  n,
int  w = 0
[inline]
 

Definition at line 140 of file String.h.

References form().

std::string zypp::str::octstring char  n,
int  w = 4
[inline]
 

Definition at line 155 of file String.h.

References form().

Referenced by zypp::filesystem::chmod(), and zypp::filesystem::mkdir().

std::string zypp::str::octstring unsigned char  n,
int  w = 4
[inline]
 

Definition at line 156 of file String.h.

References form().

std::string zypp::str::octstring short  n,
int  w = 5
[inline]
 

Definition at line 157 of file String.h.

References form().

std::string zypp::str::octstring unsigned short  n,
int  w = 5
[inline]
 

Definition at line 158 of file String.h.

References form().

std::string zypp::str::octstring int  n,
int  w = 5
[inline]
 

Definition at line 159 of file String.h.

References form().

std::string zypp::str::octstring unsigned  n,
int  w = 5
[inline]
 

Definition at line 160 of file String.h.

References form().

std::string zypp::str::octstring long  n,
int  w = 5
[inline]
 

Definition at line 161 of file String.h.

References form().

std::string zypp::str::octstring unsigned long  n,
int  w = 5
[inline]
 

Definition at line 162 of file String.h.

References form().

std::string zypp::str::octstring long long  n,
int  w = 0
[inline]
 

Definition at line 163 of file String.h.

References form().

std::string zypp::str::octstring unsigned long long  n,
int  w = 0
[inline]
 

Definition at line 164 of file String.h.

References form().

template<typename _It>
unsigned long long zypp::str::strtonum const std::string &  str  )  [inline]
 

String to integer type determined by template arg.

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

Definition at line 181 of file String.h.

Referenced by zypp::Date::Date(), and zypp::source::susetags::MediaMetadataParser::parse().

template<typename _It>
_It zypp::str::strtonum const std::string &  str,
_It &  i
[inline]
 

String to integer type detemined 2nd function arg i.

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

Definition at line 204 of file String.h.

bool zypp::str::strToBool const std::string &  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 222 of file String.h.

References strToFalse(), and strToTrue().

Referenced by zypp::ZConfig::Impl::Impl().

std::string& zypp::str::replace_all std::string &  str,
const std::string &  from,
const std::string &  to
[inline]
 

Looks for text in string and replaces it in place.

Note:
It only performs substtution in one pass

Definition at line 232 of file String.h.

template<class _OutputIterator>
unsigned zypp::str::split const std::string &  line_r,
_OutputIterator  result_r,
const std::string &  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 256 of file String.h.

Referenced by zypp::source::susetags::SelectionTagFileParser::consume(), zypp::source::susetags::PatternTagFileParser::consume(), zypp::source::susetags::PackagesParser::consume(), zypp::source::susetags::PackageDiskUsageParser::consume(), zypp::source::susetags::PackagesLangParser::consume(), zypp::DiskUsageCounter::detectMountPoints(), log_curl(), zypp::source::susetags::ProductMetadataParser::parse(), zypp::source::susetags::ProductMetadataParser::parseFileCheckSum(), zypp::media::ProxyInfoSysconfig::ProxyInfoSysconfig(), and zypp::kvmap::KVMapBase::split().

template<class _OutputIterator>
unsigned zypp::str::splitFields const std::string &  line_r,
_OutputIterator  result_r,
const std::string &  sepchars_r = ":"
 

Split line_r into fields.

Any single character in sepchars_r is treated as a field separator. 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 301 of file String.h.

Referenced by zypp::PublicKey::Impl::readFromFile().

template<class _Iterator>
std::string zypp::str::join _Iterator  begin,
_Iterator  end,
const std::string &  sep_r = " "
 

Join strings using separator sep_r (defaults to BLANK).

Definition at line 337 of file String.h.

Referenced by zypp::KVMap< KVMapOpts >::asString(), zypp::Arch::asString(), join(), zypp::parser::yum::operator<<(), and zypp::TranslatedText::Impl::setText().

template<class _Container>
std::string zypp::str::join const _Container &  cont_r,
const std::string &  sep_r = " "
 

Join strings using separator sep_r (defaults to BLANK).

Definition at line 352 of file String.h.

References join().

std::string zypp::str::ltrim const std::string &  s  )  [inline]
 

Definition at line 401 of file String.h.

References L_TRIM, and trim().

Referenced by zypp::parser::IniParser::parse(), and stripFirstWord().

std::string zypp::str::rtrim const std::string &  s  )  [inline]
 

Definition at line 404 of file String.h.

References R_TRIM, and trim().

Referenced by zypp::parser::IniParser::parse().

bool zypp::str::hasPrefix const std::string &  str_r,
const std::string &  prefix_r
[inline]
 

Return whether str_r has prefix prefix_r.

Definition at line 420 of file String.h.

Referenced by stripPrefix().

std::string zypp::str::stripPrefix const std::string &  str_r,
const std::string &  prefix_r
[inline]
 

Strip a prefix_r from str_r and return the resulting string.

Definition at line 424 of file String.h.

References hasPrefix().


Generated on Sat Sep 5 12:40:56 2009 for zypp by  doxygen 1.4.6