code::Strings Class Reference

List of all members.

Detailed Description

This is a helper class of functions that do commonly required stuff that is not in the Standard Library.

Author:
Lakshman, Charles Kerr
Version:
Author
lakshman
Date
2009/06/02 20:17:38


Static Public Member Functions

static bool isNumeric (const std::string &s)
static bool samePrefix (const std::string &, const std::string &, char stopWhenReached)
static std::string trimText (const std::string &s)
 removes leading and trailing white space.
static void toLower (std::string &s)
 Convert to lower case.
static void toUpper (std::string &s)
 Convert to upper case.
static void capitalize (std::string &s)
 Capitalize every word.
static size_t split (const std::string &splitme, std::vector< std::string > *setme)
 Split a string on whitespace and put the pieces into a vector.
static size_t split (const std::string &splitme, char delimiter, std::vector< std::string > *setme)
 Split a string on a character and put the pieces into a vector.
static size_t splitWithoutEnds (const std::string &splitme, char delimiter, std::vector< std::string > *setme)
 Split a string on a character and put the pieces into a vector.
static size_t splitOnFirst (const std::string &splitme, char delimiter, std::vector< std::string > *setme)
 Splits the string,s, on the first occurence of the character,sep, passsed in.
static size_t splitToLines (const std::string &s, std::vector< std::string > &setme)
 Splits a text buf into a vector of lines.
static std::string replaceCharacter (const std::string &str, char old_char, char new_char)
 In a string, replace one character with another.
static std::string replaceWhiteSpace (const std::string &str, char new_char)
 Replace every white space character with another character.
static bool similar (const std::string &, const std::string &)
 Compares two strings in a case-insensitive way.
static std::string removeSubstrings (const std::string &original, const std::vector< std::string > &discards)
 Returns the string with any of these substrings removed.
static bool isWhiteSpace (char c)
template<typename Pred>
static size_t countWords (const std::string &s, const Pred &pred, std::string::size_type pos=0)
 Counts the number of words in a string.
static size_t countWords (const std::string &s, std::string::size_type pos=0)
 Convenience form of countWords() which treats whitespace as the delimiter between words.
template<typename Pred>
static bool findNextWord (const std::string &s, std::string::size_type &setme_pos, std::string::size_type &setme_len, const Pred &pred, std::string::size_type pos_in=0)
 Finds the next word in a string.
static bool findNextWord (const std::string &s, std::string::size_type &setme_pos, std::string::size_type &setme_len, std::string::size_type pos_in=0)
 Convenience form of findNextWord() which treats whitespace as the delimiter between words.
static void replace (std::string &s, const std::string &from, const std::string &to)
 Replace all occurences of `from' with `to' in string `s'.
static bool matches (const std::string &pattern, const std::string &test)
 *bl?h.

Classes

struct  DelimiterPred
 STL unary predicate. More...
struct  WhiteSpacePred
 STL unary predicate. More...


Member Function Documentation

static void code::Strings::capitalize ( std::string &  s  )  [static]

Capitalize every word.

static size_t code::Strings::countWords ( const std::string &  s,
std::string::size_type  pos = 0 
) [inline, static]

Convenience form of countWords() which treats whitespace as the delimiter between words.

template<typename Pred>
static size_t code::Strings::countWords ( const std::string &  s,
const Pred &  pred,
std::string::size_type  pos = 0 
) [inline, static]

Counts the number of words in a string.

The predicate `pred' is used to find word breaks.

static bool code::Strings::findNextWord ( const std::string &  s,
std::string::size_type &  setme_pos,
std::string::size_type &  setme_len,
std::string::size_type  pos_in = 0 
) [inline, static]

Convenience form of findNextWord() which treats whitespace as the delimiter between words.

template<typename Pred>
static bool code::Strings::findNextWord ( const std::string &  s,
std::string::size_type &  setme_pos,
std::string::size_type &  setme_len,
const Pred &  pred,
std::string::size_type  pos_in = 0 
) [inline, static]

Finds the next word in a string.

The predicate `pred' is used to find word breaks.

static bool code::Strings::isNumeric ( const std::string &  s  )  [static]

static bool code::Strings::isWhiteSpace ( char  c  )  [inline, static]

static bool code::Strings::matches ( const std::string &  pattern,
const std::string &  test 
) [static]

*bl?h.

* matches Goopblah.jpg for example...

static std::string code::Strings::removeSubstrings ( const std::string &  original,
const std::vector< std::string > &  discards 
) [static]

Returns the string with any of these substrings removed.

static void code::Strings::replace ( std::string &  s,
const std::string &  from,
const std::string &  to 
) [static]

Replace all occurences of `from' with `to' in string `s'.

static std::string code::Strings::replaceCharacter ( const std::string &  str,
char  old_char,
char  new_char 
) [static]

In a string, replace one character with another.

One useful application is

  str = replaceCharacter( str, ' ', '_' );
  

which replaces white spaces with underscores. Note that this does nothing to tabs and new line characters.

Parameters:
str string on which to operate
old_char character to replace
new_char replacement character
See also:
replaceWhiteSpace

static std::string code::Strings::replaceWhiteSpace ( const std::string &  str,
char  new_char 
) [static]

Replace every white space character with another character.

Parameters:
str string on which to operate
new_char replacement character

static bool code::Strings::samePrefix ( const std::string &  ,
const std::string &  ,
char  stopWhenReached 
) [static]

static bool code::Strings::similar ( const std::string &  ,
const std::string &   
) [static]

Compares two strings in a case-insensitive way.

static size_t code::Strings::split ( const std::string &  splitme,
char  delimiter,
std::vector< std::string > *  setme 
) [static]

Split a string on a character and put the pieces into a vector.

Parameters:
splitme the string to split
delimiter split token to search for in `splitme'
setme result
Returns:
number of fields Note that splitting a string /hello/ based on / will give you three string with an empty string representing the location of the beginning and ending slashes.
See also:
splitWithoutEnds to avoid getting these empty strings

static size_t code::Strings::split ( const std::string &  splitme,
std::vector< std::string > *  setme 
) [static]

Split a string on whitespace and put the pieces into a vector.

Parameters:
splitme string to split
setme split strings are stored here
Returns:
number of strings added to `setme'

static size_t code::Strings::splitOnFirst ( const std::string &  splitme,
char  delimiter,
std::vector< std::string > *  setme 
) [static]

Splits the string,s, on the first occurence of the character,sep, passsed in.

The pieces are placed into the vector passed in. Returns 2 if sep is in the string and zero if sep is not in the string.

Thus, the split produce a maximum of two pieces. In the absence of the sep character, no pieces are added to the vector, and zero is returned.

Parameters:
splitme the string to split
delimiter split token to search for in `splitme'
setme result
Returns:
number of fields

static size_t code::Strings::splitToLines ( const std::string &  s,
std::vector< std::string > &  setme 
) [static]

Splits a text buf into a vector of lines.

"a\nb\nc" -> "a", "b", "c" "a\nb\n\nc" -> "a", "b", "", "c" "a\nb\n\nc\n" -> "a", "b", "", "c"

static size_t code::Strings::splitWithoutEnds ( const std::string &  splitme,
char  delimiter,
std::vector< std::string > *  setme 
) [static]

Split a string on a character and put the pieces into a vector.

Parameters:
splitme the string to split
delimiter split token to search for in `splitme'
setme result
Returns:
number of fields Note that splitting a string /hello/ based on / will give you just one string. To get empty strings for the the location of the beginning and ending slashes,
See also:
split

static void code::Strings::toLower ( std::string &  s  )  [static]

Convert to lower case.

static void code::Strings::toUpper ( std::string &  s  )  [static]

Convert to upper case.

static std::string code::Strings::trimText ( const std::string &  s  )  [static]

removes leading and trailing white space.


Generated on Fri May 4 13:40:12 2012 for WDSS-IIw2 by  doxygen 1.4.7