OpenWalnut 1.2.5
Functions | Variables
string_utils Namespace Reference

Some utilities for string manipulation and output operations. More...

Functions

std::string rTrim (const std::string &source, const std::string &t=WHITESPACE)
 Trims any occurence of each character given in parameter t from the end (or right side) of the given string.
std::string lTrim (const std::string &source, const std::string &t=WHITESPACE)
 Trims any occurence of each character given in parameter t from the start (or left side) of the given string.
std::string trim (const std::string &source, const std::string &t=WHITESPACE)
 Trims any occurence of each character given in parameter t from both ends (right and left side) of the given string.
std::string toUpper (const std::string &source)
 Transforms all characters in the given string into upper case characters.
std::string toLower (const std::string &source)
 Transforms all characters in the given string into lower case characters.
std::vector< std::string > tokenize (const std::string &source, const std::string &delim=WHITESPACE, bool compress=true)
 Splits the given string into a vector of strings (so called tokens).
template<class T >
std::ostream & operator<< (std::ostream &os, const std::vector< T > &v)
 Writes every vector to an output stream such as cout, if its elements have an output operator defined.
template<class T >
std::istream & operator>> (std::istream &in, std::vector< T > &v)
 Write an input stream into the given vector.
template<class T >
std::ostream & operator<< (std::ostream &os, const std::list< T > &l)
 Writes every list to an output stream such as cout, if its elements have an output operator defined.
template<class T >
std::ostream & operator<< (std::ostream &os, const std::set< T > &s)
 Writes every set to an output stream such as cout, if its elements have an output operator defined.

Variables

const std::string WHITESPACE
 We consider the following characters as whitespace:

Detailed Description

Some utilities for string manipulation and output operations.

Please note that the overloaded ostream output operators aren't in a separate namespace but the string manipulation functions. This is because of short use of e.g. the << operator instead of string_utils::operator( cout, myVector).

The reason for not using the Boost trimming functions is, that Boost providing just Whitespace trimming depending on the current locale, but we might want to trim other character sets too.

The reason for not using the Boost case switching functions is that we want those functions to return a std::string copy which is modified to make some call chains ala: foo( rTrim( toLower( str ), "bar" ) );.

The reason for not using Boosts Tokenizer is, that this tokenizer, is much most simplest to use :).


Function Documentation

std::string string_utils::lTrim ( const std::string &  source,
const std::string &  t = WHITESPACE 
)

Trims any occurence of each character given in parameter t from the start (or left side) of the given string.

Parameters:
sourceString to trim
tString representing a set containg all trimmable characters
Returns:
A copy of the trimmed string

Definition at line 42 of file WStringUtils.cpp.

Referenced by trim().

template<class T >
std::ostream& string_utils::operator<< ( std::ostream &  os,
const std::list< T > &  l 
)

Writes every list to an output stream such as cout, if its elements have an output operator defined.

Parameters:
osThe output stream where the elements are written to
lList containing the elements
Returns:
The output stream again.

Definition at line 188 of file WStringUtils.h.

References rTrim().

template<class T >
std::ostream& string_utils::operator<< ( std::ostream &  os,
const std::set< T > &  s 
)

Writes every set to an output stream such as cout, if its elements have an output operator defined.

Parameters:
osThe output stream where the elements are written to
sset containing the elements
Returns:
The output stream again.

Definition at line 205 of file WStringUtils.h.

References rTrim().

template<class T >
std::ostream& string_utils::operator<< ( std::ostream &  os,
const std::vector< T > &  v 
)

Writes every vector to an output stream such as cout, if its elements have an output operator defined.

Parameters:
osThe output stream where the elements are written to
vVector containing the elements
Returns:
The output stream again.

Definition at line 142 of file WStringUtils.h.

References rTrim().

template<class T >
std::istream& string_utils::operator>> ( std::istream &  in,
std::vector< T > &  v 
)

Write an input stream into the given vector.

The delimiter is implicitly set to ", ". Also wrapping brackets '[' ']' are expected. In general this is the opposite of the output operator above.

Warning:
The inputstream is first written into a string then the convertion into T via boost::lexical_cast takes place.
The delimiter should not be in an elements string representation since then the tokenizer may gets confused
Parameters:
inInput stream
vVector where to store the elements.
Returns:
The input stream again

Definition at line 165 of file WStringUtils.h.

References tokenize(), and trim().

std::string string_utils::rTrim ( const std::string &  source,
const std::string &  t = WHITESPACE 
)

Trims any occurence of each character given in parameter t from the end (or right side) of the given string.

Parameters:
sourceString to trim
tString representing a set containg all trimmable characters
Returns:
A copy of the trimmed string

Definition at line 35 of file WStringUtils.cpp.

Referenced by operator<<(), and trim().

std::vector< std::string > string_utils::tokenize ( const std::string &  source,
const std::string &  delim = WHITESPACE,
bool  compress = true 
)

Splits the given string into a vector of strings (so called tokens).

Parameters:
sourceString to tokenize
compressIf true, charactes matching between two tokens are collapsed and handled as just one character.
delimString representing a set containg all characters considered as whitespace.
Returns:
A vector of strings containing the tokens.

Definition at line 69 of file WStringUtils.cpp.

Referenced by PROPERTY_TYPE_HELPER::WStringConversion< WPVBaseTypes::PV_POSITION >::create(), PROPERTY_TYPE_HELPER::WStringConversion< WPVBaseTypes::PV_MATRIX4X4 >::create(), WItemSelector::newSelector(), and operator>>().

std::string string_utils::toLower ( const std::string &  source)

Transforms all characters in the given string into lower case characters.

Parameters:
sourceString to transpose.
Returns:
A copy of the lower case only string

Definition at line 62 of file WStringUtils.cpp.

std::string string_utils::toUpper ( const std::string &  source)

Transforms all characters in the given string into upper case characters.

Parameters:
sourceString to transpose.
Returns:
A copy of the upper case only string

Definition at line 55 of file WStringUtils.cpp.

Referenced by WEEGPositionsLibrary::getPosition(), and WEEGPositionsLibrary::WEEGPositionsLibrary().

std::string string_utils::trim ( const std::string &  source,
const std::string &  t = WHITESPACE 
)

Trims any occurence of each character given in parameter t from both ends (right and left side) of the given string.

Parameters:
sourceString to trim
tString representing a set containg all trimmable characters
Returns:
A copy of the trimmed string

Definition at line 49 of file WStringUtils.cpp.

References lTrim(), and rTrim().

Referenced by operator>>().


Variable Documentation

const std::string string_utils::WHITESPACE

We consider the following characters as whitespace:

These characters are regarded as whitespaces.

  • \r carriage return
  • \n newline
  • \t tab
  • ' ' space
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends