bpp-core  2.1.0
bpp::TextTools Class Reference

Some utilitary functions that work on strings. More...

#include <Bpp/Text/TextTools.h>

List of all members.

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.

Detailed Description

Some utilitary functions that work on strings.

Definition at line 58 of file TextTools.h.


Member Function Documentation

unsigned int TextTools::count ( const std::string &  s,
const std::string &  pattern 
) [static]

Count the occurences of a given pattern in a string.

Parameters:
sThe string to search.
patternThe pattern to use (this is a mere string, not a regexp!).
Returns:
The number of occurences of 'pattern' in 's'.

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.

Parameters:
sThe string to search.
patternThe pattern to use (this is a mere string, not a regexp!).
Returns:
true/false

Definition at line 490 of file TextTools.cpp.

template<class T >
static T bpp::TextTools::fromString ( const std::string &  s) [inline, static]

General template method to convert from string.

Parameters:
sThe string to convert.
Returns:
An object from string t.

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.

Parameters:
sThe string to search.
patternThe pattern to use (this is a mere string, not a regexp!).
Returns:
true/false

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.

Parameters:
sThe string to parse.
scientificNotationcharacter to use for scientific notation (typically 'e' or 'E').
Returns:
true if the given string is the representation of a decimal integer.

Definition at line 244 of file TextTools.cpp.

bool TextTools::isDecimalNumber ( char  c) [static]

Tell is a given character describes a decimal number.

Parameters:
cThe character to check.
Returns:
true if the given character is the reprensentation of a decimal number.

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.

Parameters:
sThe string to parse.
decThe decimal separator.
scientificNotationcharacter to use for scientific notation (typically 'e' or 'E').
Returns:
true if the given string is the representation of a decimal number.

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.

Parameters:
sThe string to check.
Returns:
True if the string has only white characters.

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.

Parameters:
cThe character to check.
Returns:
True if c is one of the following: '\n' or '\r'.

Definition at line 160 of file TextTools.cpp.

bool TextTools::isWhiteSpaceCharacter ( char  c) [static]

Tell if a character is a white space or not.

Parameters:
cThe character to check.
Returns:
True if c is one of the following: ' ', '\t', '\n', '\r' or '\f'.

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.

Parameters:
sThe string to parse.
cThe character to remove.
Returns:
The string with all specified chars removed.

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.

Parameters:
sThe string to parse.
Returns:
A copy of 's' beginning with the first non-white character.

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.

Parameters:
sThe string to parse.
Returns:
A copy of 's' ending with the last non-new line character.

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.

Parameters:
sThe string to parse.
Returns:
A copy of 's' ending with the last non-white character.

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.

Parameters:
sThe string to parse.
Returns:
A copy of 's' without new line characters.

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.

Parameters:
sThe string to parse.
blockBeginningThe character specifying the beginning of each block.
blockEndingThe character specifying the end of each block.
Returns:
The string with all blocks removed.
Exceptions:
ExceptionIf 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.

Parameters:
sThe string to parse.
blockBeginningThe character specifying the beginning of each block.
blockEndingThe character specifying the end of each block.
exceptionsBeginningA vector containing all strings specifying the beginning of blocks that should not be removed.
exceptionsEndingA vector containing all strings specifying the ending of blocks that should not be removed.
Returns:
The string with all blocks removed.
Exceptions:
ExceptionIf 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.

Parameters:
sThe string to parse.
Returns:
A copy of 's' beginning with the first non-white character and ending with the last one.

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.

Parameters:
sThe string to parse.
Returns:
A copy of 's' without white spaces characters.

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.

Parameters:
targetString to be modified
queryThe motif to look for
replacementThe 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.

Parameters:
sThe string to parse.
newSizeThe new string size.
fillThe character to use to fill the string id length < newSize.
Returns:
A string of size newsize which is a copy from the right of s.

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.

Parameters:
sThe string to parse.
newSizeThe new string size.
fillThe character to use to fill the string id length < newSize.
Returns:
A string of size newsize which is a copy from the left of s.

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.

Parameters:
sThe string to parse.
nThe number of tokens.
Returns:
A vector of strings with all 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.

Parameters:
sThe string to search.
patternThe pattern to use (this is a mere string, not a regexp!).
Returns:
true/false

Definition at line 481 of file TextTools.cpp.

Referenced by bpp::AbstractParametrizable::getParameterNameWithoutNamespace(), bpp::AbstractParametrizable::setNamespace(), and bpp::AbstractParameterAliasable::setNamespace().

template<class T >
static T bpp::TextTools::to ( const std::string &  s) [inline, static]

Template to string conversion.

Parameters:
sThe string to parse.
Returns:
An object of class R corresponding to s.

Definition at line 275 of file TextTools.h.

double TextTools::toDouble ( const std::string &  s) throw (Exception) [static]

Convert from string to double.

Parameters:
sThe string to parse.
Returns:
The double corresponding to s.
Exceptions:
Exceptionif 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.

Parameters:
sThe string to parse.
Returns:
The integer corresponding to s.
Exceptions:
Exceptionif 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.

Parameters:
sThe string to analyse.
Returns:
A copy of the string with all chars lowercase.

Definition at line 77 of file TextTools.cpp.

template<class T >
static std::string bpp::TextTools::toString ( t) [inline, static]

General template method to convert to a string.

Parameters:
tThe object to convert.
Returns:
A string equal to t.

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().

template<class T >
static std::string bpp::TextTools::toString ( t,
int  precision 
) [inline, static]

Template string conversion.

Parameters:
tThe object to convert.
precisionTo use (for numbers).
Returns:
A string equal to t.

Definition at line 204 of file TextTools.h.

std::string TextTools::toString ( int  i) [static]

Convert from int to string.

Parameters:
iThe integer to convert.
Returns:
A string equal to i.

Definition at line 269 of file TextTools.cpp.

std::string TextTools::toString ( char  c) [static]

Convert from char to string.

Parameters:
cThe character to convert.
Returns:
A string equal to c.

Definition at line 278 of file TextTools.cpp.

std::string TextTools::toString ( double  d,
int  precision = 6 
) [static]

Convert from double to string.

Parameters:
dThe double to convert.
precisionTo use (for numbers).
Returns:
A string equal to d.

Definition at line 287 of file TextTools.cpp.

std::string TextTools::toUpper ( const std::string &  s) [static]

Make the string uppercase.

Parameters:
sThe string to analyse.
Returns:
A copy of the string with all chars uppercase.

Definition at line 65 of file TextTools.cpp.


The documentation for this class was generated from the following files:
 All Classes Namespaces Files Functions Variables Typedefs Friends