bpp-core  2.2.0
bpp::StringTokenizer Class Reference

A tokenizer for strings. More...

#include <Bpp/Text/StringTokenizer.h>

+ Inheritance diagram for bpp::StringTokenizer:
+ Collaboration diagram for bpp::StringTokenizer:

Public Member Functions

 StringTokenizer (const std::string &s, const std::string &delimiters=" \\", bool solid=false, bool allowEmptyTokens=false)
 Build a new StringTokenizer from a string. More...
 
virtual ~StringTokenizer ()
 
 StringTokenizer ()
 
const std::string & nextToken () throw (Exception)
 Get the next available token. If no token is availbale, throw an Exception. More...
 
bool hasMoreToken () const
 Tell if some tokens are still available. More...
 
size_t numberOfRemainingTokens () const
 Tell how many tokens are available. More...
 
const std::string & getToken (size_t pos) const
 Get a particular token. More...
 
const std::deque< std::string > & getTokens () const
 Retrieve all tokens. More...
 
void removeEmptyTokens ()
 remove all empty token from the current position. More...
 
std::string unparseRemainingTokens () const
 

Protected Attributes

std::deque< std::string > tokens_
 Where the tokens are stored. More...
 
std::deque< std::string > splits_
 
size_t currentPosition_
 the current position in the token list. More...
 

Detailed Description

A tokenizer for strings.

Splits a string according to a given (set of) delimiter(s).

Definition at line 58 of file StringTokenizer.h.

Constructor & Destructor Documentation

◆ StringTokenizer() [1/2]

StringTokenizer::StringTokenizer ( const std::string &  s,
const std::string &  delimiters = " \t\n\f\r",
bool  solid = false,
bool  allowEmptyTokens = false 
)

Build a new StringTokenizer from a string.

Parameters
sThe string to parse.
delimitersChars that must be considered as delimiters.
solidIf true, delimiters is considered as a single bloc delimiter.
allowEmptyTokensTell if empty tokens are allowed or should be ignored.

Definition at line 46 of file StringTokenizer.cpp.

References splits_, and tokens_.

◆ ~StringTokenizer()

virtual bpp::StringTokenizer::~StringTokenizer ( )
inlinevirtual

Definition at line 81 of file StringTokenizer.h.

◆ StringTokenizer() [2/2]

bpp::StringTokenizer::StringTokenizer ( )
inline

Definition at line 84 of file StringTokenizer.h.

Member Function Documentation

◆ getToken()

const std::string& bpp::StringTokenizer::getToken ( size_t  pos) const
inline

Get a particular token.

Do not move the iterator.

Parameters
posThe index of the token.
Returns
the token at position 'pos'.

Definition at line 119 of file StringTokenizer.h.

References tokens_.

Referenced by bpp::NumCalcApplicationTools::seqFromString().

◆ getTokens()

const std::deque<std::string>& bpp::StringTokenizer::getTokens ( ) const
inline

Retrieve all tokens.

Returns
A reference toward the vector of tokens.

Definition at line 126 of file StringTokenizer.h.

References tokens_.

Referenced by bpp::DataTable::read().

◆ hasMoreToken()

◆ nextToken()

◆ numberOfRemainingTokens()

size_t bpp::StringTokenizer::numberOfRemainingTokens ( ) const
inline

Tell how many tokens are available.

Returns
the number of tokens available.

Definition at line 109 of file StringTokenizer.h.

References currentPosition_, and tokens_.

Referenced by bpp::ApplicationTools::getMatrixParameter(), bpp::ApplicationTools::getVectorParameter(), bpp::NumCalcApplicationTools::seqFromString(), and unparseRemainingTokens().

◆ removeEmptyTokens()

void StringTokenizer::removeEmptyTokens ( )

remove all empty token from the current position.

Definition at line 104 of file StringTokenizer.cpp.

References currentPosition_, and tokens_.

◆ unparseRemainingTokens()

std::string StringTokenizer::unparseRemainingTokens ( ) const
Returns
The remaining tokens as if the original corresponding string was not parsed.

Definition at line 112 of file StringTokenizer.cpp.

References currentPosition_, numberOfRemainingTokens(), splits_, and tokens_.

Member Data Documentation

◆ currentPosition_

size_t bpp::StringTokenizer::currentPosition_
protected

the current position in the token list.

Definition at line 67 of file StringTokenizer.h.

Referenced by hasMoreToken(), nextToken(), numberOfRemainingTokens(), removeEmptyTokens(), and unparseRemainingTokens().

◆ splits_

std::deque<std::string> bpp::StringTokenizer::splits_
protected

Definition at line 64 of file StringTokenizer.h.

Referenced by StringTokenizer(), and unparseRemainingTokens().

◆ tokens_

std::deque<std::string> bpp::StringTokenizer::tokens_
protected

The documentation for this class was generated from the following files: