str Namespace Reference

Functions for handling strings of the Standard Template Library. More...


Functions

std::string fmt (size_t size, const char *fmt,...)
 Format a string.
void clean (std::string &str, const char *chars=" \n\t")
 Remove leading and trailing characters from a string.
std::string cleaned (const std::string &str, const char *chars=" \n\t")
 Remove leading and trailing characters from a string.
std::vector< std::string > split (const std::string &str, const char *delims, bool group, unsigned int num_fields=0)
 Split a string to fields.
long str2long (const std::string &str, int base=10)
 Convert a string to signed long.
unsigned long str2ulong (const std::string &str, int base=10)
 Convert a string to unsigned long.
float str2float (const std::string &str)
 Convert a string to float.
template<class T>
std::vector< T > long_vec (const std::string &str)
 Convert a string to a vector of integers using str2long().
std::vector< float > float_vec (const std::string &str)
 Convert a string to a vector of floats using str2float().
std::string chomped (const std::string &str, const char *chars="\n")
 Return a strin with the possible trailing newline removed.
std::string & chomp (std::string &str, const char *chars="\n")
 Remove the possible trailing newline from a string.
bool read_line (std::string &str, FILE *file=stdin, bool do_chomp=false)
 Read a line from a file.


Detailed Description

Functions for handling strings of the Standard Template Library.

Bug:
We assume that the newline is '
', which can cause problems in Windows.


Function Documentation

std::string& str::chomp std::string &  str,
const char *  chars = "\n"
[inline]
 

Remove the possible trailing newline from a string.

Parameters:
str = string to çhomp
chars = characters to remove
Returns:
reference to modified str

std::string str::chomped const std::string &  str,
const char *  chars = "\n"
[inline]
 

Return a strin with the possible trailing newline removed.

Parameters:
str = string to çhomp
chars = characters to remove
Returns:
the string without trailing newline

void str::clean std::string &  str,
const char *  chars = " \n\t"
[inline]
 

Remove leading and trailing characters from a string.

Parameters:
str = the string to be cleaned
chars = the characters to clean from the string

std::string str::cleaned const std::string &  str,
const char *  chars = " \n\t"
[inline]
 

Remove leading and trailing characters from a string.

Parameters:
str = the string to be cleaned
chars = the characters to clean from the string
Returns:
the cleaned string

std::vector<float> str::float_vec const std::string &  str  )  [inline]
 

Convert a string to a vector of floats using str2float().

Parameters:
str = the string to convert
Returns:
a vector of floats
Exceptions:
exceptions as described in str2float()

std::string str::fmt size_t  size,
const char *  fmt,
  ...
[inline]
 

Format a string.

Parameters:
size = maximum size of the resulting string (cut rest)
fmt = the format string as in standard printf()
Returns:
the formatted string

template<class T>
std::vector<T> str::long_vec const std::string &  str  ) 
 

Convert a string to a vector of integers using str2long().

Parameters:
str = the string to convert
Returns:
a vector of integers
Exceptions:
exceptions as described in str2long()

bool str::read_line std::string &  str,
FILE *  file = stdin,
bool  do_chomp = false
[inline]
 

Read a line from a file.

Parameters:
str = the string to read to
file = the file to read from
do_chomp = should we chomp the possible newline at the end
Returns:
false if end of file reached (str will be empty)
Exceptions:
str::io_error if read failed

std::vector<std::string> str::split const std::string &  str,
const char *  delims,
bool  group,
unsigned int  num_fields = 0
[inline]
 

Split a string to fields.

If num_fields is positive, it specifies the maximum number of fields. If the line contains more fields, they are included in the last field as such (also possible delimiters without processing).

Parameters:
str = the string to be splitted
delims = the delimiter characters
group = group subsequent delimiters as one delimeter
num_fields = the maximum number of fields to return
Returns:
fields the vector containing the resulting fields

float str::str2float const std::string &  str  )  [inline]
 

Convert a string to float.

Arbitrary amount of white space is accepted before the float as explained on strtof(3) manual page. Anything after the number is considered as an conversion error.

Parameters:
str = the string to convert
Exceptions:
std::out_of_range if argument was out of range
std::invalid_argument if conversion error occured

long str::str2long const std::string &  str,
int  base = 10
[inline]
 

Convert a string to signed long.

Arbitrary amount of white space is accepted before the number as explained on strtol(3) manual page. Anything after the number is considered as an conversion error.

Parameters:
str = the string to convert
base = base of the coversion
Exceptions:
std::out_of_range if argument was out of range
std::invalid_argument if conversion error occured

unsigned long str::str2ulong const std::string &  str,
int  base = 10
[inline]
 

Convert a string to unsigned long.

Arbitrary amount of white space is accepted before the number as explained on strtol(3) manual page. Anything after the number is considered as an conversion error.

Parameters:
str = the string to convert
base = base of the coversion
Exceptions:
std::out_of_range if argument was out of range
std::invalid_argument if conversion error occured


Generated on Mon Jan 8 15:51:04 2007 for bit by  doxygen 1.4.6