bpp-core3
3.0.0
|
Some utilitary functions that work on strings. More...
Functions | |
bool | isEmpty (const std::string &s) |
Tell if a string is empty. A string is considered to be 'empty' if it is only made of white spaces. More... | |
std::string | toUpper (const std::string &s) |
Make the string uppercase. More... | |
std::string | toLower (const std::string &s) |
Make the string lowercase. More... | |
bool | isWhiteSpaceCharacter (char c) |
Tell if a character is a white space or not. More... | |
std::string | removeWhiteSpaces (const std::string &s) |
Remove all white spaces characters in a string. More... | |
std::string | removeFirstWhiteSpaces (const std::string &s) |
Remove all white spaces characters at the beginning of a string. More... | |
std::string | removeLastWhiteSpaces (const std::string &s) |
Remove all white spaces characters at the end of a string. More... | |
std::string | removeSurroundingWhiteSpaces (const std::string &s) |
Remove all white spaces characters at the beginning and the end of a string. More... | |
bool | isNewLineCharacter (char c) |
Tell if a character is a new line character or not. More... | |
std::string | removeNewLines (const std::string &s) |
Remove all new line characters in a string. More... | |
std::string | removeLastNewLines (const std::string &s) |
Remove all new line characters at the end of a string. More... | |
bool | isDecimalNumber (char c) |
Tell is a given character describes a decimal number. More... | |
bool | isDecimalNumber (const std::string &s, char dec='.', char scientificNotation='e') |
Tell is a given character string describes a decimal number. FIXME : for now, this parser will not recognize thousands delimiters, and not the scientific notation neither. More... | |
bool | isDecimalInteger (const std::string &s, char scientificNotation='e') |
Tell is a given character string describes a decimal integer. FIXME: for now, this parser will not recognize thousands delimiters, and not the scientific notation neither. More... | |
int | toInt (const std::string &s, char scientificNotation='e') |
Convert from string to int. More... | |
double | toDouble (const std::string &s, char dec='.', char scientificNotation='e') |
Convert from string to double. More... | |
std::string | resizeRight (const std::string &s, std::size_t newSize, char fill) |
std::string | resizeLeft (const std::string &s, std::size_t newSize, char fill) |
std::vector< std::string > | split (const std::string &s, std::size_t n) |
std::string | removeSubstrings (const std::string &s, char blockBeginning, char blockEnding) |
Remove substrings from a string. All substrings beginning with blockBeginning and ending with blockEnding will be removed. Nesting blocks are allowed, the most extern block will be removed. More... | |
std::string | removeSubstrings (const std::string &s, char blockBeginning, char blockEnding, std::vector< std::string > &exceptionsBeginning, std::vector< std::string > &exceptionsEnding) |
Remove substrings from a string, unless they match some specific substrings. All substrings beginning with blockBeginning and ending with blockEnding will be removed, except if they begin with a string included in the vector exceptionsBeginning or end with a string included in the vector exceptionsEnding. Nesting blocks are allowed, the most extern block will be removed. More... | |
std::string | removeChar (const std::string &s, char c) |
Remove all occurences of a character in a string. More... | |
std::size_t | count (const std::string &s, const std::string &pattern) |
Count the occurences of a given pattern in a string. More... | |
bool | startsWith (const std::string &s, const std::string &pattern) |
Tell is a string begins with a certain motif. More... | |
bool | endsWith (const std::string &s, const std::string &pattern) |
Tell is a string ends with a certain motif. More... | |
bool | hasSubstring (const std::string &s, const std::string &pattern) |
Tell is a string contains a certain motif. More... | |
void | replaceAll (std::string &target, const std::string &query, const std::string &replacement) |
Replacement of all non-overlapping occurrences of a certain motif in a string. More... | |
template<class T > | |
std::string | toString (T t) |
General template method to convert to a string. More... | |
template<class T > | |
std::string | toString (T t, int precision) |
Template string conversion. More... | |
template<class T > | |
T | fromString (const std::string &s) |
General template method to convert from string. More... | |
template<class T > | |
T | to (const std::string &s) |
Template to string conversion. More... | |
std::string | resizeRight (const std::string &s, size_t newSize, char fill=' ') |
Send a string of size 'newSize', which is a copy of 's' truncated or filled with character 'fill' at the end. More... | |
std::string | resizeLeft (const std::string &s, size_t newSize, char fill=' ') |
Send a string of size 'newSize', which is a copy of 's' truncated or filled with character 'fill' at the beginning. More... | |
std::vector< std::string > | split (const std::string &s, size_t n) |
Split a string into parts of size 'n'. The last part may contain < n chars. More... | |
Some utilitary functions that work on strings.
std::size_t bpp::TextTools::count | ( | const std::string & | s, |
const std::string & | pattern | ||
) |
Count the occurences of a given pattern in a string.
s | The string to search. |
pattern | The pattern to use (this is a mere string, not a regexp!). |
Definition at line 388 of file TextTools.cpp.
Referenced by bpp::ContingencyTableTest::ContingencyTableTest(), bpp::NewtonOneDimension::doStep(), bpp::NestedStringTokenizer::NestedStringTokenizer(), and to().
bool bpp::TextTools::endsWith | ( | const std::string & | s, |
const std::string & | pattern | ||
) |
Tell is a string ends with a certain motif.
s | The string to search. |
pattern | The pattern to use (this is a mere string, not a regexp!). |
Definition at line 411 of file TextTools.cpp.
Referenced by to().
T bpp::TextTools::fromString | ( | const std::string & | s | ) |
General template method to convert from string.
s | The string to convert. |
Definition at line 140 of file TextTools.h.
References toDouble(), and toInt().
bool bpp::TextTools::hasSubstring | ( | const std::string & | s, |
const std::string & | pattern | ||
) |
Tell is a string contains a certain motif.
s | The string to search. |
pattern | The pattern to use (this is a mere string, not a regexp!). |
Definition at line 420 of file TextTools.cpp.
Referenced by removeSubstrings(), and to().
bool bpp::TextTools::isDecimalInteger | ( | const std::string & | s, |
char | scientificNotation = 'e' |
||
) |
Tell is a given character string describes a decimal integer. FIXME: for now, this parser will not recognize thousands delimiters, and not the scientific notation neither.
s | The string to parse. |
scientificNotation | character to use for scientific notation (typically 'e' or 'E'). |
Definition at line 173 of file TextTools.cpp.
References isDecimalNumber(), and isEmpty().
Referenced by toInt().
bool bpp::TextTools::isDecimalNumber | ( | char | c | ) |
Tell is a given character describes a decimal number.
c | The character to check. |
Definition at line 131 of file TextTools.cpp.
Referenced by isDecimalInteger(), isDecimalNumber(), and toDouble().
bool bpp::TextTools::isDecimalNumber | ( | const std::string & | s, |
char | dec = '.' , |
||
char | scientificNotation = 'e' |
||
) |
Tell is a given character string describes a decimal number. FIXME : for now, this parser will not recognize thousands delimiters, and not the scientific notation neither.
s | The string to parse. |
dec | The decimal separator. |
scientificNotation | character to use for scientific notation (typically 'e' or 'E'). |
Definition at line 135 of file TextTools.cpp.
References isDecimalNumber(), and isEmpty().
bool bpp::TextTools::isEmpty | ( | const std::string & | s | ) |
Tell if a string is empty. A string is considered to be 'empty' if it is only made of white spaces.
s | The string to check. |
Definition at line 20 of file TextTools.cpp.
Referenced by bpp::KeyvalTools::changeKeyvals(), bpp::ApplicationTools::getMatrixParameter(), bpp::FileTools::getNextLine(), bpp::ApplicationTools::getStringParameter(), bpp::ApplicationTools::getVectorOfVectorsParameter(), bpp::ApplicationTools::getVectorParameter(), isDecimalInteger(), isDecimalNumber(), bpp::ApplicationTools::parameterExists(), bpp::KeyvalTools::parseProcedure(), bpp::DataTable::read(), bpp::Table< T >::read(), and bpp::BppODiscreteDistributionFormat::readDiscreteDistribution().
bool bpp::TextTools::isNewLineCharacter | ( | char | c | ) |
Tell if a character is a new line character or not.
c | The character to check. |
Definition at line 104 of file TextTools.cpp.
Referenced by removeLastNewLines(), and removeNewLines().
bool bpp::TextTools::isWhiteSpaceCharacter | ( | char | c | ) |
Tell if a character is a white space or not.
c | The character to check. |
Definition at line 53 of file TextTools.cpp.
std::string bpp::TextTools::removeChar | ( | const std::string & | s, |
char | c | ||
) |
Remove all occurences of a character in a string.
s | The string to parse. |
c | The character to remove. |
Definition at line 379 of file TextTools.cpp.
Referenced by to().
std::string bpp::TextTools::removeFirstWhiteSpaces | ( | const std::string & | s | ) |
Remove all white spaces characters at the beginning of a string.
s | The string to parse. |
Definition at line 69 of file TextTools.cpp.
Referenced by bpp::KeyvalTools::changeKeyvals(), and bpp::KeyvalTools::parseProcedure().
std::string bpp::TextTools::removeLastNewLines | ( | const std::string & | s | ) |
Remove all new line characters at the end of a string.
s | The string to parse. |
Definition at line 120 of file TextTools.cpp.
References isNewLineCharacter().
std::string bpp::TextTools::removeLastWhiteSpaces | ( | const std::string & | s | ) |
Remove all white spaces characters at the end of a string.
s | The string to parse. |
Definition at line 79 of file TextTools.cpp.
std::string bpp::TextTools::removeNewLines | ( | const std::string & | s | ) |
Remove all new line characters in a string.
s | The string to parse. |
Definition at line 108 of file TextTools.cpp.
References isNewLineCharacter().
std::string bpp::TextTools::removeSubstrings | ( | const std::string & | s, |
char | blockBeginning, | ||
char | blockEnding | ||
) |
Remove substrings from a string. All substrings beginning with blockBeginning and ending with blockEnding will be removed. Nesting blocks are allowed, the most extern block will be removed.
s | The string to parse. |
blockBeginning | The character specifying the beginning of each block. |
blockEnding | The character specifying the end of each block. |
Exception | If some blocks are not well formed. |
Definition at line 282 of file TextTools.cpp.
Referenced by to().
std::string bpp::TextTools::removeSubstrings | ( | const std::string & | s, |
char | blockBeginning, | ||
char | blockEnding, | ||
std::vector< std::string > & | exceptionsBeginning, | ||
std::vector< std::string > & | exceptionsEnding | ||
) |
Remove substrings from a string, unless they match some specific substrings. All substrings beginning with blockBeginning and ending with blockEnding will be removed, except if they begin with a string included in the vector exceptionsBeginning or end with a string included in the vector exceptionsEnding. Nesting blocks are allowed, the most extern block will be removed.
s | The string to parse. |
blockBeginning | The character specifying the beginning of each block. |
blockEnding | The character specifying the end of each block. |
exceptionsBeginning | A vector containing all strings specifying the beginning of blocks that should not be removed. |
exceptionsEnding | A vector containing all strings specifying the ending of blocks that should not be removed. |
Exception | If some blocks are not well formed. |
Definition at line 311 of file TextTools.cpp.
References hasSubstring(), and toString().
std::string bpp::TextTools::removeSurroundingWhiteSpaces | ( | const std::string & | s | ) |
Remove all white spaces characters at the beginning and the end of a string.
s | The string to parse. |
Definition at line 90 of file TextTools.cpp.
Referenced by bpp::KeyvalTools::changeKeyvals(), and bpp::KeyvalTools::multipleKeyvals().
std::string bpp::TextTools::removeWhiteSpaces | ( | const std::string & | s | ) |
Remove all white spaces characters in a string.
s | The string to parse. |
Definition at line 57 of file TextTools.cpp.
Referenced by bpp::ComputationTree::ComputationTree(), and bpp::AttributesTools::getAttributesMap().
void bpp::TextTools::replaceAll | ( | std::string & | target, |
const std::string & | query, | ||
const std::string & | replacement | ||
) |
Replacement of all non-overlapping occurrences of a certain motif in a string.
target | String to be modified |
query | The motif to look for |
replacement | The replacement string |
Definition at line 427 of file TextTools.cpp.
Referenced by to().
std::string bpp::TextTools::resizeLeft | ( | const std::string & | s, |
size_t | newSize, | ||
char | fill = ' ' |
||
) |
Send a string of size 'newSize', which is a copy of 's' truncated or filled with character 'fill' at the beginning.
s | The string to parse. |
newSize | The new string size. |
fill | The character to use to fill the string id length < newSize. |
std::string bpp::TextTools::resizeLeft | ( | const std::string & | s, |
std::size_t | newSize, | ||
char | fill | ||
) |
Definition at line 244 of file TextTools.cpp.
Referenced by bpp::ApplicationTools::displayGauge(), and to().
std::string bpp::TextTools::resizeRight | ( | const std::string & | s, |
size_t | newSize, | ||
char | fill = ' ' |
||
) |
Send a string of size 'newSize', which is a copy of 's' truncated or filled with character 'fill' at the end.
s | The string to parse. |
newSize | The new string size. |
fill | The character to use to fill the string id length < newSize. |
std::string bpp::TextTools::resizeRight | ( | const std::string & | s, |
std::size_t | newSize, | ||
char | fill | ||
) |
Definition at line 226 of file TextTools.cpp.
Referenced by bpp::ApplicationTools::displayGauge(), bpp::ApplicationTools::displayResult(), and to().
std::vector<std::string> bpp::TextTools::split | ( | const std::string & | s, |
size_t | n | ||
) |
Split a string into parts of size 'n'. The last part may contain < n chars.
s | The string to parse. |
n | The number of tokens. |
std::vector<std::string> bpp::TextTools::split | ( | const std::string & | s, |
std::size_t | n | ||
) |
Definition at line 263 of file TextTools.cpp.
References bpp::IntegerTools::divideDown(), and bpp::IntegerTools::divideUp().
Referenced by to().
bool bpp::TextTools::startsWith | ( | const std::string & | s, |
const std::string & | pattern | ||
) |
Tell is a string begins with a certain motif.
s | The string to search. |
pattern | The pattern to use (this is a mere string, not a regexp!). |
Definition at line 402 of file TextTools.cpp.
Referenced by bpp::AbstractParametrizable::getParameterNameWithoutNamespace(), bpp::AbstractParametrizable::setNamespace(), bpp::AbstractParameterAliasable::setNamespace(), and to().
T bpp::TextTools::to | ( | const std::string & | s | ) |
Template to string conversion.
s | The string to parse. |
Definition at line 170 of file TextTools.h.
References count(), endsWith(), hasSubstring(), removeChar(), removeSubstrings(), replaceAll(), resizeLeft(), resizeRight(), split(), and startsWith().
double bpp::TextTools::toDouble | ( | const std::string & | s, |
char | dec = '.' , |
||
char | scientificNotation = 'e' |
||
) |
Convert from string to double.
s | The string to parse. |
dec | The decimal separator. |
scientificNotation | character to use for scientific notation (typically 'e' or 'E'). |
Exception | if the string does not specify a valid number. |
Definition at line 217 of file TextTools.cpp.
References isDecimalNumber().
Referenced by fromString(), bpp::ApplicationTools::getDoubleParameter(), bpp::NumCalcApplicationTools::getVector(), bpp::IntervalConstraint::readDescription(), bpp::BppODiscreteDistributionFormat::readDiscreteDistribution(), and bpp::ComputationTree::readFormula_().
int bpp::TextTools::toInt | ( | const std::string & | s, |
char | scientificNotation = 'e' |
||
) |
Convert from string to int.
s | The string to parse. |
scientificNotation | character to use for scientific notation (typically 'e' or 'E'). |
Exception | if the string does not specify a valid number. |
Definition at line 208 of file TextTools.cpp.
References isDecimalInteger().
Referenced by fromString(), bpp::ApplicationTools::getIntParameter(), bpp::NumCalcApplicationTools::getVector(), bpp::BppODiscreteDistributionFormat::readDiscreteDistribution(), and bpp::NumCalcApplicationTools::seqFromString().
std::string bpp::TextTools::toLower | ( | const std::string & | s | ) |
Make the string lowercase.
s | The string to analyse. |
Definition at line 41 of file TextTools.cpp.
std::string bpp::TextTools::toString | ( | T | t | ) |
General template method to convert to a string.
t | The object to convert. |
Definition at line 115 of file TextTools.h.
Referenced by bpp::ParametrizableCollection< N >::addObject(), bpp::AbstractParameterAliasable::aliasParameters(), bpp::DirichletDiscreteDistribution::applyParameters(), bpp::AutoCorrelationTransitionMatrix::AutoCorrelationTransitionMatrix(), bpp::SvgGraphicDevice::colorToText(), bpp::RescaledHmmLikelihood::computeForward_(), bpp::FunctionTools::computeGrid(), bpp::ContingencyTableTest::ContingencyTableTest(), bpp::GlobalGraph::deleteNode(), bpp::DirichletDiscreteDistribution::DirichletDiscreteDistribution(), bpp::ApplicationTools::displayGauge(), bpp::ApplicationTools::displayUnlimitedGauge(), bpp::GoldenSectionSearch::doInit(), bpp::BrentOneDimension::doInit(), bpp::NewtonOneDimension::doStep(), bpp::SvgGraphicDevice::drawCircle(), bpp::SvgGraphicDevice::drawLine(), bpp::SvgGraphicDevice::drawRect(), bpp::SvgGraphicDevice::drawText(), bpp::XFigGraphicDevice::drawText(), bpp::GlobalGraph::edgeMustExist_(), bpp::AssociationGraphImplObserver< N, E, TreeGraphImpl >::edgeToString(), bpp::EigenValue< Real >::EigenValue(), bpp::PgfGraphicDevice::end(), bpp::AutoCorrelationTransitionMatrix::fireParameterChanged(), bpp::SimpleDiscreteDistribution::fireParameterChanged(), bpp::MixtureOfDiscreteDistributions::fireParameterChanged(), bpp::Simplex::fireParameterChanged(), bpp::FullHmmTransitionMatrix::FullHmmTransitionMatrix(), bpp::ApplicationTools::getBooleanParameter(), bpp::AbstractDiscreteDistribution::getCategoryIndex(), bpp::XFigColorManager::getColor(), bpp::GlobalGraph::getDegree(), bpp::IntervalConstraint::getDescription(), bpp::ApplicationTools::getDoubleParameter(), bpp::AssociationGraphImplObserver< N, E, TreeGraphImpl >::getEdgeGraphid(), bpp::TreeGraphImpl< GraphImpl >::getFatherOfNode(), bpp::AbstractFontManager< int >::getFont(), bpp::ApplicationTools::getIntParameter(), bpp::ApplicationTools::getMatrixParameter(), bpp::AssociationGraphImplObserver< N, E, TreeGraphImpl >::getNodeGraphid(), bpp::ApplicationTools::getParameter(), bpp::NumCalcApplicationTools::getParameterGrid(), bpp::ParametrizableCollection< N >::getParametersForObject(), bpp::AbstractDiscreteDistribution::getValueCategory(), bpp::ApplicationTools::getVectorOfVectorsParameter(), bpp::ApplicationTools::getVectorParameter(), bpp::ReparametrizationFunctionWrapper::init_(), bpp::BppODiscreteDistributionFormat::initialize_(), bpp::GlobalGraph::isLeaf(), bpp::GlobalGraph::link(), bpp::MixtureOfDiscreteDistributions::MixtureOfDiscreteDistributions(), bpp::GlobalGraph::nodeMustExist_(), bpp::AssociationGraphImplObserver< N, E, TreeGraphImpl >::nodeToString(), bpp::ConstantOperator::output(), bpp::AbstractOptimizer::printPoint(), bpp::BppODiscreteDistributionFormat::readDiscreteDistribution(), removeSubstrings(), bpp::AttributesTools::resolveVariables(), bpp::SimpleDiscreteDistribution::restrictToConstraint(), bpp::PgfGraphicDevice::setCurrentBackgroundColor(), bpp::PgfGraphicDevice::setCurrentForegroundColor(), bpp::PgfGraphicDevice::setCurrentLayer(), bpp::AbstractGraphicDevice::setCurrentLineType(), bpp::PgfGraphicDevice::setCurrentLineType(), bpp::XFigGraphicDevice::setCurrentLineType(), bpp::Simplex::setFrequencies(), bpp::FullHmmTransitionMatrix::setTransitionProbabilities(), bpp::SimpleDiscreteDistribution::SimpleDiscreteDistribution(), bpp::Simplex::Simplex(), bpp::GlobalGraph::switchNodes(), bpp::RGBColor::toString(), bpp::Number< unsigned int >::toString(), bpp::Font::toString(), bpp::Range< T >::toString(), bpp::GlobalGraph::unlinkInEdgeStructure_(), bpp::GlobalGraph::unlinkInNodeStructure_(), and bpp::BppODiscreteDistributionFormat::writeDiscreteDistribution().
std::string bpp::TextTools::toString | ( | T | t, |
int | precision | ||
) |
Template string conversion.
t | The object to convert. |
precision | To use (for numbers). |
Definition at line 128 of file TextTools.h.
std::string bpp::TextTools::toUpper | ( | const std::string & | s | ) |
Make the string uppercase.
s | The string to analyse. |
Definition at line 29 of file TextTools.cpp.