str Namespace Reference

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

long str2long (const char *str, bool *ok)
 Convert a string to numeric value.
double str2float (const char *str, bool *ok)
long str2long (std::string *str, bool *ok)
double str2float (std::string *str, bool *ok)

Functions

bool read_line (std::string *str, FILE *file=stdin, bool do_chomp=false)
 Read a line from a file.
bool read_string (std::string *str, size_t length, FILE *file=stdin)
 Read a string of given length from a file.
bool read_file (std::string *str, FILE *file, size_t length=0)
 Read a file to string.
void chomp (std::string *str)
 Remove the possible trailing newline from a string.
void clean (std::string *str, const char *chars)
 Remove leading and trailing characters from a string.
void split (const std::string *str, const char *delims, bool group, std::vector< std::string > *fields, int num_fields=0)
 Split a string to fields.
void split_with_quotes (std::string *str, const char *delims, bool group, std::vector< std::string > *fields)
 Split a string to fields while processing quotes \, ', ".


Detailed Description

Functions for handling strings of the Standard Template Library.

Function Documentation

void str::clean std::string *  str,
const char *  chars
 

Remove leading and trailing characters from a string.

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

bool str::read_file std::string *  str,
FILE *  file,
size_t  length = 0
 

Read a file to string.

Parameters:
str = the string to read to
file = the file to read from
length = the maximum size of the file (0 = read all)
Returns:
false if read failed for some reason (see errno for details)

bool str::read_line std::string *  str,
FILE *  file = stdin,
bool  do_chomp = false
 

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 no more lines in the file

bool str::read_string std::string *  str,
size_t  length,
FILE *  file = stdin
 

Read a string of given length from a file.

Parameters:
str = the string to read to
length = the bytes to read
file = the file to read from
Returns:
false if could not read length bytes

void str::split const std::string *  str,
const char *  delims,
bool  group,
std::vector< std::string > *  fields,
int  num_fields = 0
 

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
fields = the vector containing the resulting fields
num_fields = the maximum number of fields to return

void str::split_with_quotes std::string *  str,
const char *  delims,
bool  group,
std::vector< std::string > *  fields
 

Split a string to fields while processing quotes \, ', ".

The function modifies str by removing quotes and preserving only the first delimiter from groups of delimiters. All quotation marks can be used to quote other quotation marks, and backslash can be used to quote backslash too.

Warning:
Delimeters must not include quotation chars.
Parameters:
str = the string to be splitted
delims = the delimiter characters
group = group subsequent delimiters as one delimeter
fields = the vector containing the resulting fields

long str::str2long const char *  str,
bool *  ok
 

Convert a string to numeric value.

Parameters:
str = the string to convert
ok = set to false if the whole string could not be converted.
Returns:
the numeric value.


Generated on Tue Apr 8 09:58:19 2008 for GoCam by  doxygen 1.4.6