ContRap-Core
Public Types | Public Member Functions

crp::StringTokenizer Class Reference

Class StringTokenizer implements a decomposition of a string into tokens separated by a set of delimiters. More...

#include <stringtokenizer.h>

Public Types

enum  WhitespaceMode { IGNORE_WHITESPACES, DELIMITERS, DELIMITERS_IGNORE }
 

Whitespace treatement enumeration type.

More...

Public Member Functions

 StringTokenizer (const std::string &str="", const std::string &delim="", const std::string &ls="\"", const std::string &le="\"", char esc= '\\', const std::string &comment="//")
 Starts a tokenizer on a string.
 ~StringTokenizer ()
 Terminates the tokenizer.
bool has_more_tokens ()
 Checks if there are mor tokens ahead.
std::string next_token ()
 Returns the next token.
std::string look_ahead (int n=1)
 Returns the token, which is n-tokens ahead.
std::string get_rest_string ()
 Returns the rest of the parsed string.
const std::string & get_input_string ()
 Returns the whole string.
void append (const std::string &string)
 Appends a string to the input.
std::string till_symbol (const std::string &symbol)
 Skips parsing till a symbol is reached.
void reset (const std::string &string="", int position=0)
 Resets the parser.
int get_row ()
 Returns the row position.
int get_column ()
 Returns the column position.
int get_position ()
 Returns the current position.
void set_position (int npos)
 Sets the current position.
int move (int number)
 Moves the tokenizer by the given number of characters.
bool is_at_line_start ()
 Returns true if the tokenizer at the start of a new line.
void set_whitespace_mode (WhitespaceMode status)
 Determines if white spaces are treated as delimiters.
void set_ignore_delimiters (bool ignore)
 Determines the delimiters policy.
void set_ignore_comments (bool status)
 Ignores comments.
void set_ignore_literals (bool status)
 Sets the literal return property.
void save ()
 Saves the current tokeinzer state.
void restore ()
 Restores previously saved state.
void ignore ()
 Ignores the previously saved state.
void insert (const std::string &text)
 Inserts a string before the current position.

Detailed Description

Class StringTokenizer implements a decomposition of a string into tokens separated by a set of delimiters.


Member Enumeration Documentation

Whitespace treatement enumeration type.

Enumerator:
IGNORE_WHITESPACES 
DELIMITERS 
DELIMITERS_IGNORE 

Constructor & Destructor Documentation

crp::StringTokenizer::StringTokenizer ( const std::string &  str = "",
const std::string &  delim = "",
const std::string &  ls = "\"",
const std::string &  le = "\"",
char  esc = '\\',
const std::string &  comment = "//" 
)

Starts a tokenizer on a string.

Parameters:
strString to tokenize
delimString of delimiters separated by spaces (white spaces are delimiters in any case if not ignored)
lsSymbol which initiates a literal copy
leSymbol which stops a literal copy
escEscape character
commentLine comment string
crp::StringTokenizer::~StringTokenizer ( ) [inline]

Terminates the tokenizer.


Member Function Documentation

void crp::StringTokenizer::append ( const std::string &  string)

Appends a string to the input.

Parameters:
stringString to append
int crp::StringTokenizer::get_column ( ) [inline]

Returns the column position.

Returns:
Returns the position in the line of the current text
const std::string& crp::StringTokenizer::get_input_string ( )

Returns the whole string.

Returns:
Parsed string
int crp::StringTokenizer::get_position ( )

Returns the current position.

Returns:
Current position within the complete string
std::string crp::StringTokenizer::get_rest_string ( )

Returns the rest of the parsed string.

Returns:
Unparsed part of the string
int crp::StringTokenizer::get_row ( ) [inline]

Returns the row position.

Returns:
The line number of the current position in the text
bool crp::StringTokenizer::has_more_tokens ( )

Checks if there are mor tokens ahead.

Returns:
true If there is at least one token more
void crp::StringTokenizer::ignore ( )

Ignores the previously saved state.

void crp::StringTokenizer::insert ( const std::string &  text)

Inserts a string before the current position.

This effectively changes the input string.

Parameters:
textText to insert.
bool crp::StringTokenizer::is_at_line_start ( ) [inline]

Returns true if the tokenizer at the start of a new line.

Returns:
True if there are now symbols before the tokenizer position or if the symbol preceding the tokenizer is a new line.
std::string crp::StringTokenizer::look_ahead ( int  n = 1)

Returns the token, which is n-tokens ahead.

Parameters:
nHow far to look
int crp::StringTokenizer::move ( int  number)

Moves the tokenizer by the given number of characters.

Parameters:
numberNumber of characters
Returns:
Number of really moved characters
std::string crp::StringTokenizer::next_token ( )

Returns the next token.

Returns:
Next token
void crp::StringTokenizer::reset ( const std::string &  string = "",
int  position = 0 
)

Resets the parser.

Parameters:
stringNew string
positionNew position
void crp::StringTokenizer::restore ( )

Restores previously saved state.

void crp::StringTokenizer::save ( )

Saves the current tokeinzer state.

You can use nested calls to save and restore.

void crp::StringTokenizer::set_ignore_comments ( bool  status) [inline]

Ignores comments.

Parameters:
statusTrue if comments should be ignored (false by default)
void crp::StringTokenizer::set_ignore_delimiters ( bool  ignore) [inline]

Determines the delimiters policy.

Parameters:
ignoreTrue if delimiters should be ignored (false by default)
void crp::StringTokenizer::set_ignore_literals ( bool  status) [inline]

Sets the literal return property.

If set to false the tokenizer returns literal constants with literal delimiters and as pure strings else. In the second case it is not possible to decide if the token is a literal or not. The property is by default false.

Parameters:
statusTrue if literals should be ignored (false by default)
void crp::StringTokenizer::set_position ( int  npos)

Sets the current position.

Parameters:
nposNew position
void crp::StringTokenizer::set_whitespace_mode ( WhitespaceMode  status) [inline]

Determines if white spaces are treated as delimiters.

If white spaces are not treated as delimiters only the delimiters from the delimiter string are used. If the property is DELIMITERS_IGNORE the white spaces are used as delimiters but never returned by the tokenizer.

Parameters:
ignoreStatus of white space treatement
std::string crp::StringTokenizer::till_symbol ( const std::string &  symbol)

Skips parsing till a symbol is reached.

Returns:
Substring of the parsed string till symbol

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