OpenWalnut 1.2.5
|
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:
|
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 :).
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.
source | String to trim |
t | String representing a set containg all trimmable characters |
Definition at line 42 of file WStringUtils.cpp.
Referenced by trim().
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.
os | The output stream where the elements are written to |
l | List containing the elements |
Definition at line 188 of file WStringUtils.h.
References rTrim().
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.
os | The output stream where the elements are written to |
s | set containing the elements |
Definition at line 205 of file WStringUtils.h.
References rTrim().
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.
os | The output stream where the elements are written to |
v | Vector containing the elements |
Definition at line 142 of file WStringUtils.h.
References rTrim().
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.
in | Input stream |
v | Vector where to store the elements. |
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.
source | String to trim |
t | String representing a set containg all trimmable characters |
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).
source | String to tokenize |
compress | If true, charactes matching between two tokens are collapsed and handled as just one character. |
delim | String representing a set containg all characters considered as whitespace. |
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.
source | String to transpose. |
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.
source | String to transpose. |
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.
source | String to trim |
t | String representing a set containg all trimmable characters |
Definition at line 49 of file WStringUtils.cpp.
References lTrim(), and rTrim().
Referenced by operator>>().
const std::string string_utils::WHITESPACE |
We consider the following characters as whitespace:
\r
carriage return\n
newline\t
tab' '
space. These characters are regarded as whitespaces.