Dv::String Namespace Reference

Functions

size_t split (const std::string &input, const std::string &separator, std::vector< std::string > &output) throw ()
 Split a string consisting of substrings separated by a separator string.
size_t split_and_trim (const std::string &input, const std::string &separator, std::vector< std::string > &output) throw ()
 Split and trim the results.
std::string & tolower (std::string &s) throw ()
 Change (in-place) all chars in string to lower case.
std::string & toupper (std::string &s) throw ()
 Change (in-place) all chars in string to upper case.
std::string & trim (std::string &s) throw ()
 Remove leading and trailing white noise (as defined by isspace(3)) The argument is changed and returned.
std::string trim (const std::string &s) throw ()
 Remove leading and trailing white noise (as defined by isspace(3)) The argument is changed and returned.
std::string & despace (std::string &s, char c= '-') throw ()
 Replace each space character in s by a given character.
char * trim (char *pc) throw ()
 Remove leading and trailing white noise (' ','\n','\t') from C string.

Function Documentation

size_t Dv::String::split ( const std::string &  input,
const std::string &  separator,
std::vector< std::string > &  output 
) throw ()

Split a string consisting of substrings separated by a separator string.

The substrings will be appended to the output vector.

Parameters:
input string, e.g. 'abcXYZdefXYZ1234' (with 'XYZ' the separator string)
separator string, e.g. 'XYZ' in the above example
output vector, e.g. { 'abc', 'def', '1234' }
Returns:
the number of strings added to output, e.g. 3

Some borderline cases (each time with '/' as separator):

 '/abc/def' yields { '', 'abc', 'def' }
 'abc/def/1234' yields { 'abc', 'def', '1234' }
 'abc/def/' yields { 'abc', 'def', '' }
size_t Dv::String::split_and_trim ( const std::string &  input,
const std::string &  separator,
std::vector< std::string > &  output 
) throw ()

Split and trim the results.

Split as in Dv::String::split and, in addition, trim the results before appending them to the vector.

Parameters:
input string, e.g. 'abcXYZdefXYZ1234' (with 'XYZ' the separator string)
separator string, e.g. 'XYZ' in the above example
output vector, e.g. { 'abc', 'def', '1234' }
Returns:
the number of strings added to output, e.g. 3
std::string& Dv::String::tolower ( std::string &  s  )  throw ()

Change (in-place) all chars in string to lower case.

Parameters:
s string to convert.
Returns:
reference to first argument.
std::string& Dv::String::toupper ( std::string &  s  )  throw ()

Change (in-place) all chars in string to upper case.

Parameters:
s string to convert.
Returns:
reference to first argument.
std::string& Dv::String::trim ( std::string &  s  )  throw ()

Remove leading and trailing white noise (as defined by isspace(3)) The argument is changed and returned.

Parameters:
s string to trim
Returns:
reference to the argument
std::string Dv::String::trim ( const std::string &  s  )  throw ()

Remove leading and trailing white noise (as defined by isspace(3)) The argument is changed and returned.

Parameters:
s string to trim
Returns:
trimmed version of s
std::string& Dv::String::despace ( std::string &  s,
char  c = '-' 
) throw ()

Replace each space character in s by a given character.

A character x is a space character is isspace(x) is true.

Parameters:
s string to despace
c replacement char
Returns:
s
char* Dv::String::trim ( char *  pc  )  throw ()

Remove leading and trailing white noise (' ','\n','\t') from C string.

Parameters:
pc C-string to trim.
Returns:
pointer to first non-white-space character in the argument.
Warning:
The argument is changed. Since the return value points to the first non-white-space char in the argument, the following is a recepy for disaster:
  char* pc = new char[10];
  ..
  pc = trim(pc);
  delete[] pc;

dvutil-1.0.10 [ 5 December, 2009]