stringutil Namespace Reference


Enumerations

enum  Trim { NO_TRIM = 0x00, L_TRIM = 0x01, R_TRIM = 0x02, TRIM = (L_TRIM|R_TRIM) }

Functions

std::string form (const char *format,...) __attribute__((format(printf
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)
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)
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)
template<typename _It >
_It strtonum (const std::string &str, _It &i)
std::string getline (std::istream &str, bool trim=false)
 read one line from a stream Return one line read from istream. Afterwards the streampos is behind the delimiting '
' (or at EOF). The delimiting '
' is not returned.
std::string getline (std::istream &str, const Trim trim_r)
 read one line from a stream
unsigned split (const std::string line_r, std::vector< std::string > &words_r, const std::string &sep_t=" \t", const bool singlesep_r=false)
std::string join (const std::vector< std::string > &words_r, const std::string &sep_r=" ")
std::list< std::string > splitToLines (const std::string text_r, const std::string &sep_r="\n")
std::string stripFirstWord (std::string &value, const bool ltrim_first=false)
std::string ltrim (const std::string &s)
std::string rtrim (const std::string &s)
std::string trim (const std::string &s, const Trim trim_r=TRIM)
std::string toLower (const std::string &s)
std::string toUpper (const std::string &s)
std::ostream & dumpOn (std::ostream &str, const std::list< std::string > &l, const bool numbered=false)
std::ostream & dumpOn (std::ostream &str, const std::vector< std::string > &l, const bool numbered=false)
static std::string _getline (std::istream &str, const Trim trim_r)

Variables

const unsigned tmpBuffLen = 1024
char tmpBuff [tmpBuffLen]

Detailed Description

Utility functions for std::strings. Most of them based on stringutil::form.


Enumeration Type Documentation

Enumerator:
NO_TRIM 
L_TRIM 
R_TRIM 
TRIM 


Function Documentation

static std::string stringutil::_getline ( std::istream &  str,
const Trim  trim_r 
) [inline, static]

References tmpBuff, tmpBuffLen, and trim().

Referenced by getline().

std::ostream & stringutil::dumpOn ( std::ostream &  str,
const std::vector< std::string > &  l,
const bool  numbered = false 
)

std::ostream & stringutil::dumpOn ( std::ostream &  str,
const std::list< std::string > &  l,
const bool  numbered = false 
)

Helper for stream output

std::string std::string stringutil::form ( const char *  format,
  ... 
) [inline]

Printf style building of strings via format string.

 std::string ex( stringutil::form( "Example number %d", 1 ) );
 std::cout << ex << stringutil::form( " and number %d.", 2 ) << endl;

 Will print: Example number 1 and number 2.
 

Referenced by PathInfo::clean_dir(), hexstring(), numstring(), and octstring().

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

read one line from a stream

like above but with allows to specify trimming direction

References _getline().

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

read one line from a stream Return one line read from istream. Afterwards the streampos is behind the delimiting '
' (or at EOF). The delimiting '
' is not returned.

If trim is true, the string returned is trimmed (surrounding whitespaces removed).

 ifstream s( "somefile" );

 while ( s ) {
   string l = getline( s );
   if ( !(s.fail() || s.bad()) ) {

     // l contains valid data to be consumed.
     // In case it makes any difference to you:
     if ( s.good() ) {
       // A delimiting '
' was read. } else { // s.eof() is set: There's no '
' at the end of file. // Note: The line returned may netvertheless be empty if trimed is true. } } }

References _getline(), NO_TRIM, and TRIM.

Referenced by ModulesConf::parseFile(), ExternalDataSource::receiveLine(), and IniParser::scanner_get().

std::string stringutil::hexstring ( unsigned long long  n,
int  w = 0 
) [inline]

References form().

std::string stringutil::hexstring ( long long  n,
int  w = 0 
) [inline]

References form().

std::string stringutil::hexstring ( unsigned long  n,
int  w = 10 
) [inline]

References form().

std::string stringutil::hexstring ( long  n,
int  w = 10 
) [inline]

References form().

std::string stringutil::hexstring ( unsigned  n,
int  w = 10 
) [inline]

References form().

std::string stringutil::hexstring ( int  n,
int  w = 10 
) [inline]

References form().

std::string stringutil::hexstring ( unsigned short  n,
int  w = 10 
) [inline]

References form().

std::string stringutil::hexstring ( short  n,
int  w = 10 
) [inline]

References form().

std::string stringutil::hexstring ( unsigned char  n,
int  w = 4 
) [inline]

References form().

std::string stringutil::hexstring ( char  n,
int  w = 4 
) [inline]

Print 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"
 

References form().

std::string stringutil::join ( const std::vector< std::string > &  words_r,
const std::string &  sep_r = " " 
)

Join strinngs in words_r using separator sep_r

std::string stringutil::ltrim ( const std::string &  s  ) 

Return string with leading/trailing/surrounding whitespace removed

Referenced by stripFirstWord(), and trim().

std::string stringutil::numstring ( unsigned long long  n,
int  w = 0 
) [inline]

References form().

std::string stringutil::numstring ( long long  n,
int  w = 0 
) [inline]

References form().

std::string stringutil::numstring ( unsigned long  n,
int  w = 0 
) [inline]

References form().

std::string stringutil::numstring ( long  n,
int  w = 0 
) [inline]

References form().

std::string stringutil::numstring ( unsigned  n,
int  w = 0 
) [inline]

References form().

std::string stringutil::numstring ( int  n,
int  w = 0 
) [inline]

References form().

std::string stringutil::numstring ( unsigned short  n,
int  w = 0 
) [inline]

References form().

std::string stringutil::numstring ( short  n,
int  w = 0 
) [inline]

References form().

std::string stringutil::numstring ( unsigned char  n,
int  w = 0 
) [inline]

References form().

std::string stringutil::numstring ( char  n,
int  w = 0 
) [inline]

Print 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  "
 

References form().

std::string stringutil::octstring ( unsigned long long  n,
int  w = 0 
) [inline]

References form().

std::string stringutil::octstring ( long long  n,
int  w = 0 
) [inline]

References form().

std::string stringutil::octstring ( unsigned long  n,
int  w = 5 
) [inline]

References form().

std::string stringutil::octstring ( long  n,
int  w = 5 
) [inline]

References form().

std::string stringutil::octstring ( unsigned  n,
int  w = 5 
) [inline]

References form().

std::string stringutil::octstring ( int  n,
int  w = 5 
) [inline]

References form().

std::string stringutil::octstring ( unsigned short  n,
int  w = 5 
) [inline]

References form().

std::string stringutil::octstring ( short  n,
int  w = 5 
) [inline]

References form().

std::string stringutil::octstring ( unsigned char  n,
int  w = 4 
) [inline]

References form().

std::string stringutil::octstring ( char  n,
int  w = 4 
) [inline]

Print 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 "
 

References form().

Referenced by PathInfo::chmod(), and PathInfo::mkdir().

std::string stringutil::rtrim ( const std::string &  s  ) 

Referenced by trim().

unsigned stringutil::split ( const std::string  line_r,
std::vector< std::string > &  words_r,
const std::string &  sep_t = " \t",
const bool  singlesep_r = false 
)

Split line into words

singlesep_r = false: Separator is any nonenmpty sequence of characters listed in sep_t. Leading trailing separators are ignored.

Example: singlesep_r = false, sep_t = ":"

 ""        -> words 0
 ":"       -> words 0
 "a"       -> words 1  |a|
 "::a"     -> words 1  |a|
 "::a::"   -> words 1  |a|
 ":a::b:c:"-> words 3  |a|b|c|
 

singlesep_r = true: Separator is any single character occuring in sep_t. Leading trailing separators are not ignored (i.e will cause an empty word).

Example: singlesep_r = true, sep_t = ":"

 ""        -> words 0
 ":"       -> words 2  |||
 "a"       -> words 1  |a|
 ":a"      -> words 2  ||a|
 "a:"      -> words 2  |a||
 ":a:"     -> words 3  ||a||
 

Referenced by splitToLines().

std::list<std::string> stringutil::splitToLines ( const std::string  text_r,
const std::string &  sep_r = "\n" 
) [inline]

Split string into a list of lines using any< > char in sep_r as line delimiter. The delimiter is stripped from the line.

 splitToLines( "start\n\nend" ) -> { "start", "", "end" }
 

References split().

string stringutil::stripFirstWord ( std::string &  value,
const bool  ltrim_first = false 
)

Strip the first word (delimited by blank or tab) from value, and return it. Adjust value to start with the second word afterwards.

If value starts with blank or tab, the first word is empty and value will be ltrimmed afterwards.

If ltrim_first is true, value will be ltrimmed before stripping the first word. Thus first word is empty, iff value is empty or contains whitespace only.

 stripFirstWord( "1st" )             ==  "1st" and value truncated to ""
 stripFirstWord( "1st word" )        ==  "1st" and value truncated to "word"
 stripFirstWord( " 1st word" )       ==  ""    and value truncated to "1st word"
 stripFirstWord( " 1st word", true ) ==  "1st" and value truncated to "word"
 

References ltrim().

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

String to integer type detemined function arg: time_t t; strtonum( "42", t );

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

String to integer type determined by template arg: time_t t = strtonum<time_t>( "42" );

Referenced by set_log_filename().

std::string stringutil::toLower ( const std::string &  s  ) 

Return string converted to lower/upper case

std::string stringutil::toUpper ( const std::string &  s  ) 

std::string stringutil::trim ( const std::string &  s,
const Trim  trim_r = TRIM 
) [inline]

References L_TRIM, ltrim(), NO_TRIM, R_TRIM, rtrim(), and TRIM.

Referenced by _getline().


Variable Documentation

Referenced by _getline().

const unsigned stringutil::tmpBuffLen = 1024

Referenced by _getline().


Generated on a sunny day for yast2-core by doxygen 1.5.9