|
bpp-core
2.1.0
|
Some utilitary functions that work on strings. More...
#include <Bpp/Text/TextTools.h>
Static Public Member Functions | |
| static bool | isEmpty (const std::string &s) |
| Tell if a string is empty. | |
| static std::string | toUpper (const std::string &s) |
| Make the string uppercase. | |
| static std::string | toLower (const std::string &s) |
| Make the string lowercase. | |
| static bool | isWhiteSpaceCharacter (char c) |
| Tell if a character is a white space or not. | |
| static std::string | removeWhiteSpaces (const std::string &s) |
| Remove all white spaces characters in a string. | |
| static std::string | removeFirstWhiteSpaces (const std::string &s) |
| Remove all white spaces characters at the beginning of a string. | |
| static std::string | removeLastWhiteSpaces (const std::string &s) |
| Remove all white spaces characters at the end of a string. | |
| static std::string | removeSurroundingWhiteSpaces (const std::string &s) |
| Remove all white spaces characters at the beginning and the end of a string. | |
| static bool | isNewLineCharacter (char c) |
| Tell if a character is a new line character or not. | |
| static std::string | removeNewLines (const std::string &s) |
| Remove all new line characters in a string. | |
| static std::string | removeLastNewLines (const std::string &s) |
| Remove all new line characters at the end of a string. | |
| static bool | isDecimalNumber (char c) |
| Tell is a given character describes a decimal number. | |
| static bool | isDecimalNumber (const std::string &s, char dec= '.', char scientificNotation= 'e') |
| Tell is a given character string describes a decimal number. | |
| static bool | isDecimalInteger (const std::string &s, char scientificNotation= 'e') |
| Tell is a given character string describes a decimal integer. | |
| template<class T > | |
| static std::string | toString (T t) |
| General template method to convert to a string. | |
| template<class T > | |
| static std::string | toString (T t, int precision) |
| Template string conversion. | |
| template<class T > | |
| static T | fromString (const std::string &s) |
| General template method to convert from string. | |
| static std::string | toString (int i) |
| Convert from int to string. | |
| static std::string | toString (char c) |
| Convert from char to string. | |
| static std::string | toString (double d, int precision=6) |
| Convert from double to string. | |
| static int | toInt (const std::string &s) throw (Exception) |
| Convert from string to int. | |
| static double | toDouble (const std::string &s) throw (Exception) |
| Convert from string to double. | |
| template<class T > | |
| static T | to (const std::string &s) |
| Template to string conversion. | |
| static 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. | |
| static 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. | |
| static std::vector< std::string > | split (const std::string &s, size_t n) |
| Split a string into parts of size 'n'. | |
| static std::string | removeSubstrings (const std::string &s, char blockBeginning, char blockEnding) throw (Exception) |
| Remove substrings from a string. | |
| static std::string | removeSubstrings (const std::string &s, char blockBeginning, char blockEnding, std::vector< std::string > &exceptionsBeginning, std::vector< std::string > &exceptionsEnding) throw (Exception) |
| Remove substrings from a string, unless they match some specific substrings. | |
| static std::string | removeChar (const std::string &s, char c) |
| Remove all occurences of a character in a string. | |
| static unsigned int | count (const std::string &s, const std::string &pattern) |
| Count the occurences of a given pattern in a string. | |
| static bool | startsWith (const std::string &s, const std::string &pattern) |
| Tell is a string begins with a certain motif. | |
| static bool | endsWith (const std::string &s, const std::string &pattern) |
| Tell is a string ends with a certain motif. | |
| static bool | hasSubstring (const std::string &s, const std::string &pattern) |
| Tell is a string contains a certain motif. | |
| static 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. | |
Some utilitary functions that work on strings.
Definition at line 58 of file TextTools.h.
| unsigned int TextTools::count | ( | const std::string & | s, |
| const std::string & | pattern | ||
| ) | [static] |
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 467 of file TextTools.cpp.
Referenced by bpp::NestedStringTokenizer::NestedStringTokenizer().
| bool TextTools::endsWith | ( | const std::string & | s, |
| const std::string & | pattern | ||
| ) | [static] |
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 490 of file TextTools.cpp.
| static T bpp::TextTools::fromString | ( | const std::string & | s | ) | [inline, static] |
General template method to convert from string.
| s | The string to convert. |
Definition at line 217 of file TextTools.h.
| bool TextTools::hasSubstring | ( | const std::string & | s, |
| const std::string & | pattern | ||
| ) | [static] |
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 499 of file TextTools.cpp.
| bool TextTools::isDecimalInteger | ( | const std::string & | s, |
| char | scientificNotation = 'e' |
||
| ) | [static] |
Tell is a given character string describes a decimal integer.
NB: 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 244 of file TextTools.cpp.
| bool TextTools::isDecimalNumber | ( | char | c | ) | [static] |
Tell is a given character describes a decimal number.
| c | The character to check. |
Definition at line 205 of file TextTools.cpp.
| bool TextTools::isDecimalNumber | ( | const std::string & | s, |
| char | dec = '.', |
||
| char | scientificNotation = 'e' |
||
| ) | [static] |
Tell is a given character string describes a decimal number.
NB: 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 216 of file TextTools.cpp.
| bool TextTools::isEmpty | ( | const std::string & | s | ) | [static] |
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 52 of file TextTools.cpp.
Referenced by bpp::FileTools::getNextLine(), bpp::ApplicationTools::getVectorParameter(), bpp::ApplicationTools::parameterExists(), bpp::KeyvalTools::parseProcedure(), bpp::BppODiscreteDistributionFormat::read(), and bpp::DataTable::read().
| bool TextTools::isNewLineCharacter | ( | char | c | ) | [static] |
Tell if a character is a new line character or not.
| c | The character to check. |
Definition at line 160 of file TextTools.cpp.
| bool TextTools::isWhiteSpaceCharacter | ( | char | c | ) | [static] |
Tell if a character is a white space or not.
| c | The character to check. |
Definition at line 89 of file TextTools.cpp.
| std::string TextTools::removeChar | ( | const std::string & | s, |
| char | c | ||
| ) | [static] |
Remove all occurences of a character in a string.
| s | The string to parse. |
| c | The character to remove. |
Definition at line 446 of file TextTools.cpp.
| std::string TextTools::removeFirstWhiteSpaces | ( | const std::string & | s | ) | [static] |
Remove all white spaces characters at the beginning of a string.
| s | The string to parse. |
Definition at line 121 of file TextTools.cpp.
Referenced by bpp::KeyvalTools::parseProcedure().
| std::string TextTools::removeLastNewLines | ( | const std::string & | s | ) | [static] |
Remove all new line characters at the end of a string.
| s | The string to parse. |
Definition at line 189 of file TextTools.cpp.
| std::string TextTools::removeLastWhiteSpaces | ( | const std::string & | s | ) | [static] |
Remove all white spaces characters at the end of a string.
| s | The string to parse. |
Definition at line 137 of file TextTools.cpp.
| std::string TextTools::removeNewLines | ( | const std::string & | s | ) | [static] |
Remove all new line characters in a string.
| s | The string to parse. |
Definition at line 168 of file TextTools.cpp.
| std::string TextTools::removeSubstrings | ( | const std::string & | s, |
| char | blockBeginning, | ||
| char | blockEnding | ||
| ) | throw (Exception) [static] |
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 353 of file TextTools.cpp.
| std::string TextTools::removeSubstrings | ( | const std::string & | s, |
| char | blockBeginning, | ||
| char | blockEnding, | ||
| std::vector< std::string > & | exceptionsBeginning, | ||
| std::vector< std::string > & | exceptionsEnding | ||
| ) | throw (Exception) [static] |
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 385 of file TextTools.cpp.
| std::string TextTools::removeSurroundingWhiteSpaces | ( | const std::string & | s | ) | [static] |
Remove all white spaces characters at the beginning and the end of a string.
| s | The string to parse. |
Definition at line 153 of file TextTools.cpp.
| std::string TextTools::removeWhiteSpaces | ( | const std::string & | s | ) | [static] |
Remove all white spaces characters in a string.
| s | The string to parse. |
Definition at line 100 of file TextTools.cpp.
| void TextTools::replaceAll | ( | std::string & | target, |
| const std::string & | query, | ||
| const std::string & | replacement | ||
| ) | [static] |
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 513 of file TextTools.cpp.
| std::string TextTools::resizeLeft | ( | const std::string & | s, |
| size_t | newSize, | ||
| char | fill = ' ' |
||
| ) | [static] |
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. |
Definition at line 328 of file TextTools.cpp.
Referenced by bpp::ApplicationTools::displayGauge().
| std::string TextTools::resizeRight | ( | const std::string & | s, |
| size_t | newSize, | ||
| char | fill = ' ' |
||
| ) | [static] |
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. |
Definition at line 318 of file TextTools.cpp.
Referenced by bpp::ApplicationTools::displayGauge(), and bpp::ApplicationTools::displayResult().
| std::vector< std::string > TextTools::split | ( | const std::string & | s, |
| size_t | n | ||
| ) | [static] |
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. |
Definition at line 338 of file TextTools.cpp.
| bool TextTools::startsWith | ( | const std::string & | s, |
| const std::string & | pattern | ||
| ) | [static] |
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 481 of file TextTools.cpp.
Referenced by bpp::AbstractParametrizable::getParameterNameWithoutNamespace(), bpp::AbstractParametrizable::setNamespace(), and bpp::AbstractParameterAliasable::setNamespace().
| static T bpp::TextTools::to | ( | const std::string & | s | ) | [inline, static] |
Template to string conversion.
| s | The string to parse. |
Definition at line 275 of file TextTools.h.
| double TextTools::toDouble | ( | const std::string & | s | ) | throw (Exception) [static] |
Convert from string to double.
| s | The string to parse. |
| Exception | if the string does not specify a valid number. |
Definition at line 307 of file TextTools.cpp.
Referenced by bpp::ApplicationTools::getDoubleParameter(), bpp::NumCalcApplicationTools::getVector(), and bpp::BppODiscreteDistributionFormat::read().
| int TextTools::toInt | ( | const std::string & | s | ) | throw (Exception) [static] |
Convert from string to int.
| s | The string to parse. |
| Exception | if the string does not specify a valid number. |
Definition at line 296 of file TextTools.cpp.
Referenced by bpp::ApplicationTools::getIntParameter(), bpp::NumCalcApplicationTools::getVector(), bpp::BppODiscreteDistributionFormat::read(), and bpp::NumCalcApplicationTools::seqFromString().
| std::string TextTools::toLower | ( | const std::string & | s | ) | [static] |
Make the string lowercase.
| s | The string to analyse. |
Definition at line 77 of file TextTools.cpp.
| static std::string bpp::TextTools::toString | ( | T | t | ) | [inline, static] |
General template method to convert to a string.
| t | The object to convert. |
Definition at line 189 of file TextTools.h.
Referenced by bpp::DirichletDiscreteDistribution::applyParameters(), bpp::SvgGraphicDevice::colorToText(), bpp::RescaledHmmLikelihood::computeForward_(), bpp::ContingencyTableTest::ContingencyTableTest(), 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::EigenValue< Real >::EigenValue(), bpp::PgfGraphicDevice::end(), bpp::SimpleDiscreteDistribution::fireParameterChanged(), bpp::MixtureOfDiscreteDistributions::fireParameterChanged(), bpp::Simplex::fireParameterChanged(), bpp::ApplicationTools::getBooleanParameter(), bpp::XFigColorManager::getColor(), bpp::IntervalConstraint::getDescription(), bpp::ApplicationTools::getDoubleParameter(), bpp::AbstractFontManager< int >::getFont(), bpp::ApplicationTools::getIntParameter(), bpp::ApplicationTools::getParameter(), bpp::NumCalcApplicationTools::getParameterGrid(), bpp::AbstractDiscreteDistribution::getValueCategory(), bpp::ApplicationTools::getVectorParameter(), bpp::ReparametrizationFunctionWrapper::init_(), bpp::BppODiscreteDistributionFormat::initialize_(), bpp::MixtureOfDiscreteDistributions::MixtureOfDiscreteDistributions(), bpp::AbstractOptimizer::printPoint(), bpp::BppODiscreteDistributionFormat::read(), 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::SimpleDiscreteDistribution::SimpleDiscreteDistribution(), bpp::Simplex::Simplex(), bpp::Range< T >::toString(), and bpp::BppODiscreteDistributionFormat::write().
| static std::string bpp::TextTools::toString | ( | T | t, |
| int | precision | ||
| ) | [inline, static] |
Template string conversion.
| t | The object to convert. |
| precision | To use (for numbers). |
Definition at line 204 of file TextTools.h.
| std::string TextTools::toString | ( | int | i | ) | [static] |
Convert from int to string.
| i | The integer to convert. |
Definition at line 269 of file TextTools.cpp.
| std::string TextTools::toString | ( | char | c | ) | [static] |
Convert from char to string.
| c | The character to convert. |
Definition at line 278 of file TextTools.cpp.
| std::string TextTools::toString | ( | double | d, |
| int | precision = 6 |
||
| ) | [static] |
Convert from double to string.
| d | The double to convert. |
| precision | To use (for numbers). |
Definition at line 287 of file TextTools.cpp.
| std::string TextTools::toUpper | ( | const std::string & | s | ) | [static] |
Make the string uppercase.
| s | The string to analyse. |
Definition at line 65 of file TextTools.cpp.