StringUtility.h File Reference

Defines functions for manipulating strings. More...

#include <assert.h>
#include <string>
#include <vector>
#include <algorithm>

Functions

void ToLower (std::string &str)
 Transforms a string to lower case.
void ToUpper (std::string &str)
 Transforms a string to upper case.
bool Match (char c, const char *match)
 Matches a single character to a string of characters.
bool IsInteger (const std::string &str, int *val=NULL)
 Determines if the given string is an integer.
bool IsWholeInteger (const std::string &str, int *val=NULL)
 Determines if the given string is strictly an integer.
bool IsFloat (const std::string &str, float *val=NULL)
 Determines if the given string is a float.
bool IsBoolean (const std::string &str, bool *val=NULL)
 Determines if the given string is a boolean (0, 1, T, F, True, False, etc.).
void Replace (std::string &str, const char *match, char replace)
 Replaces matching characters with a spacific single char.
void Replace (std::string &str, const char *match, const char *replace)
 Replaces matching characters with a spacific string.
std::string Trim (const std::string &str, const char *what=" \t\n\r")
 Trims leading and ending characters from a string.
std::vector< std::string > Split (const std::string &str, const char *delim=" ", bool skipDeliminator=true)
 Splits a string into multiple substrings.
size_t Split (const std::string &str, const char *delim, std::vector< std::string > &result, bool skipDeliminator=true)
 Splits a string into multiple substrings.

Detailed Description

Defines functions for manipulating strings.

Author:
Joe Forte
Date:
8/4/2008

Function Documentation

bool IsBoolean ( const std::string &  str,
bool *  val = NULL 
)

Determines if the given string is a boolean (0, 1, T, F, True, False, etc.).

Parameters:
[in] str the string to check.
[out] val the bool that the string represents. Defaults to NULL.
Returns:
true if str represents a boolean, false otherwise.
bool IsFloat ( const std::string &  str,
float *  val = NULL 
)

Determines if the given string is a float.

Parameters:
[in] str the string to check.
[out] val the float that the string represents. Defaults to NULL.
Returns:
true if str represents an float, false otherwise.
bool IsInteger ( const std::string &  str,
int *  val = NULL 
)

Determines if the given string is an integer.

Parameters:
[in] str the string to check.
[out] val the integer that the string represents. Defaults to NULL.
Returns:
true if str represents an integer, false otherwise.
bool IsWholeInteger ( const std::string &  str,
int *  val = NULL 
)

Determines if the given string is strictly an integer.

Parameters:
[in] str the string to check.
[out] val the integer that the string represents. Defaults to NULL.
Returns:
true if str represents an integer, false otherwise.
bool Match ( char  c,
const char *  match 
) [inline]

Matches a single character to a string of characters.

Parameters:
[in] c the character to find a match for.
[in] match a string of characters to match c against.
Returns:
True if c matches a character in match, false otherwise.
void Replace ( std::string &  str,
const char *  match,
const char *  replace 
)

Replaces matching characters with a spacific string.

Parameters:
[in] str the string to alter.
[in] match the characters to match.
[in] replace the character string to replace matches with.
void Replace ( std::string &  str,
const char *  match,
char  replace 
)

Replaces matching characters with a spacific single char.

Parameters:
[in] str the string to alter.
[in] match the characters to match.
[in] replace the character to replace matches with.
size_t Split ( const std::string &  str,
const char *  delim,
std::vector< std::string > &  result,
bool  skipDeliminator = true 
)

Splits a string into multiple substrings.

Parameters:
[in] str the string to split.
[in] delim a string of deliminating characters. Each individual character in the string is considered a deliminator.
[out] result stores the split substrings of str.
[in] skipDeliminator set to false to not have deliminators present in the output. Defaults to true.
Returns:
The number of substrings added to result.
std::vector<std::string> Split ( const std::string &  str,
const char *  delim = " ",
bool  skipDeliminator = true 
)

Splits a string into multiple substrings.

Parameters:
[in] str the string to split.
[in] delim a string of deliminating characters. Each individual character in the string is considered a deliminator. Defaults to " ".
[in] skipDeliminator set to false to not have deliminators present in the output. Defaults to true.
Returns:
The vector of substrings split from str.
void ToLower ( std::string &  str  )  [inline]

Transforms a string to lower case.

Parameters:
[in,out] str the string to make lower case.
void ToUpper ( std::string &  str  )  [inline]

Transforms a string to upper case.

Parameters:
[in,out] str the string to make upper case.
std::string Trim ( const std::string &  str,
const char *  what = " \t\n\r" 
)

Trims leading and ending characters from a string.

Parameters:
[in] str the string to trim.
[in] what the characters to be trimed. Defaults to space and newline characters.
Returns:
the trimmed string.
Generated on Mon Apr 5 19:08:05 2010 for BrickOut |ReDuX| by  doxygen 1.6.3