OpenWalnut
1.5.0dev
|
Some utilities for string manipulation and output operations. More...
Classes | |
struct | fromStringImpl |
Conversion class to convert a string to a given target type. More... | |
struct | fromStringImpl< std::string > |
Conversion class to convert a string to a given target type. More... | |
Functions | |
template<typename T > | |
std::string | toString (const T &value) |
Convert a given value to a string. More... | |
std::string | toString (const unsigned char &value) |
Convert a given value to a string. More... | |
template<typename T > | |
std::string | toString (const T &value, const size_t width, const size_t precision) |
Convert a given value to a string. More... | |
template<typename T > | |
T | fromString (const std::string &str) |
Convert a given string to a value of a certain type. More... | |
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. More... | |
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. More... | |
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. More... | |
std::string | toUpper (const std::string &source) |
Transforms all characters in the given string into upper case characters. More... | |
std::string | toLower (const std::string &source) |
Transforms all characters in the given string into lower case characters. More... | |
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). More... | |
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. More... | |
template<class T > | |
std::istream & | operator>> (std::istream &in, std::vector< T > &v) |
Write an input stream into the given vector. More... | |
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. More... | |
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. More... | |
Variables | |
const std::string | WHITESPACE |
We consider the following characters as whitespace: More... | |
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 :).
|
inline |
Convert a given string to a value of a certain type.
The target type must provide a operator>> to work or be a standard scalar type.
T | the source type. |
str | the value to cast to string |
WTypeMismatch | if the string cannot be converted properly. |
Definition at line 173 of file WStringUtils.h.
References string_utils::fromStringImpl< Target >::fromString().
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 304 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 321 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 258 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 281 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, characters matching between two tokens are collapsed and handled as just one character. |
delim | String representing a set containing all characters considered as whitespace. |
Definition at line 69 of file WStringUtils.cpp.
Referenced by PROPERTY_TYPE_HELPER::WStringConversion< WPVBaseTypes::PV_INTERVAL >::create(), PROPERTY_TYPE_HELPER::WStringConversion< WPVBaseTypes::PV_MATRIX4X4 >::create(), PROPERTY_TYPE_HELPER::WStringConversion< WPVBaseTypes::PV_POSITION >::create(), PROPERTY_TYPE_HELPER::WStringConversion< WPVBaseTypes::PV_TRANSFERFUNCTION >::create(), WQtMenuFiltered::filterUpdate(), WReaderEEGASCII::load(), WMReadSimpleTextLineData::load(), WMReadVIM::load(), WItemSelector::newSelector(), operator>>(), WReaderELC::read(), WReaderVTK::readCoords(), WReaderVTK::readData(), WMReadVCL::readData(), WMReadDipoles::readFile(), WReaderVTK::readHARDI(), WReaderFiberVTK::readLines(), WReaderFiberVTK::readPoints(), WReaderVTK::readRectilinearGrid(), WReaderVTK::readScalars(), WReaderVTK::readStructuredPoints(), WReaderVTK::readTensors(), WReaderFiberVTK::readValues(), WReaderVTK::readValuesFromFile(), WReaderVTK::readVectors(), WQtModuleConfig::refreshModuleCheckboxes(), WPropertyStruct< T0, T1, T2, T3, T4, T5, T6, T7, T8, T9 >::setAsString(), and WQtColormapper::WQtTextureListItem::WQtTextureListItem().
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.
Referenced by WMainWindow::handleGLVendor(), WMReadSimpleTextLineData::load(), WReaderVTK::readCoords(), WReaderFiberVTK::readPoints(), WReaderVTK::readRectilinearGrid(), WReaderVTK::readStructuredPoints(), and WReaderFiberVTK::readValues().
|
inline |
Convert a given value to a string.
The input value must provide a operator<< or be a standard scalar type.
T | the source type. You do not need to specify this directly as it can be deducted from the given parameter |
value | the value to cast to string |
Definition at line 120 of file WStringUtils.h.
Referenced by WDataHandler::addSubject(), WModuleProjectFileCombiner::apply(), PROPERTY_TYPE_HELPER::WStringConversion< T >::asString(), PROPERTY_TYPE_HELPER::WStringConversion< WPVBaseTypes::PV_SELECTION >::asString(), WMatrixFixed< ValueT, Rows, Cols, ValueStoreT >::at(), wge::bindTexture(), WGEColormapping::callback(), WDataHandler::clear(), WMHierchClustDisplay::clusterSelection(), WHtreeProcesser::coarseTree(), WMMultiHistogramView::connectors(), WMHistogramView::createFrame(), WMMultiHistogramView::createFrame(), WMHistogramView::createInfo(), WMMultiHistogramView::createInfo(), WMClusterDisplay::createLabel(), WRulerOrtho::createXY(), WRulerOrtho::createXZ(), WRulerOrtho::createYX(), WRulerOrtho::createYZ(), WRulerOrtho::createZX(), WRulerOrtho::createZY(), WMainWindow::event(), WPropertyGroupBase::findProperty(), WHtree::getReport(), WMProbTractDisplay::initSubModules(), WMHierchClustDisplay::moduleMain(), WMHistogramView::moduleMain(), WMMultiHistogramView::moduleMain(), WRulerOrtho::numberToString(), WMeshReaderVTK::operator()(), WGEProjectFileIO::parse(), WQtNetworkEditorProjectFileIO::parse(), WHnode::printAllData(), WHnode::printJointData(), WGEShaderDefine< ValueType >::process(), WMMultiHistogramView::properties(), WMTemplate::properties(), WHtreeProcesser::pruneRandom(), WHtreeProcesser::pruneTree(), WReaderFiberVTK::readHeader(), WDataHandler::removeSubject(), WMClusterDisplayVoxels::renderMesh(), WMWriteMesh::saveJson(), WMWebglSupport::saveSlicesGray(), WMWebglSupport::saveSlicesRGB(), WPropertyBase::set(), WMClusterDisplayVoxels::setButtonLabels(), WProjectFile::threadMain(), WPropertyMatrix4X4Widget::update(), WQtNetworkItem::updater(), wge::vector2label(), WEEGEvent::WEEGEvent(), WMPartition2Mesh::writeLabels(), WHtree::writeTree(), WHtree::writeTreeDebug(), and WHtree::writeTreeOldWalnut().
|
inline |
Convert a given value to a string.
The input value must provide a operator<< or be a standard scalar type. This method additionally allows setting width and precision flags of the used std::stringstream.
T | the source type. You do not need to specify this directly as it can be deducted from the given parameter |
value | the value to cast to string |
precision | the precision |
width | the width |
Definition at line 154 of file WStringUtils.h.
|
inline |
Convert a given value to a string.
The input value must provide a operator<< or be a standard scalar type.
value | the value to cast to string |
Definition at line 134 of file WStringUtils.h.
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(), WReaderVTK::readData(), WReaderVTK::readHARDI(), WReaderFiberVTK::readLines(), WReaderVTK::readScalars(), WReaderVTK::readTensors(), WReaderVTK::readVectors(), 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 WMReadSimpleTextLineData::load(), and operator>>().
|
extern |
We consider the following characters as whitespace:
These characters are regarded as whitespaces.
\r
carriage return\n
newline\t
tab' '
space