cisst-saw
|
#include <cmnTokenizer.h>
Public Types | |
typedef std::vector< const char * > | TokensContainer |
typedef TokensContainer::size_type | size_type |
Public Member Functions | |
cmnTokenizer () | |
~cmnTokenizer () | |
void | SetDelimiters (const char *delimiters) |
void | SetQuoteMarkers (const char *markers) |
void | SetEscapeMarkers (const char *markers) |
const char * | GetDelimiters (void) const |
const char * | GetQuoteMarkers (void) const |
const char * | GetEscapeMarkers (void) const |
void | Parse (const char *string) throw (std::runtime_error) |
void | Parse (const std::string &string) throw (std::runtime_error) |
size_type | GetNumTokens (void) const |
const char * | GetToken (size_type num) const |
const char *const * | GetTokensArray (void) const |
void | GetArgvTokens (std::vector< const char * > &argvTokens) const |
Static Public Member Functions | |
static const char * | GetDefaultDelimiters (void) |
static const char * | GetDefaultQuoteMarkers (void) |
static const char * | GetDefaultEscapeMarkers (void) |
cmnTokenizer provides a convenient interface for parsing a string into a set of tokens. The parsing uses several sets of control characters:
Delimiters: Separate tokens. A sequence of delimiters which is not quoted or escaped is ignored, and a new token begins after it.
Quote markers: Enclose parts of, or complete, tokens. Anything between a pair of identical quote markers is included in a token.
Escape markers: Quote the character immediately following them.
The default values for delimiters is whitespace (space, tab, CR); for quote markers is the set of double and single quotation marks (",'); for escape markers is backslash (). But the user can override them by calling the appropriate method.
A cmnTokenizer object maintains an internal copy of the tokenized text, and can return a pointer to an array of pointer, after the fashion of argv.
typedef TokensContainer::size_type cmnTokenizer::size_type |
typedef std::vector<const char *> cmnTokenizer::TokensContainer |
cmnTokenizer::cmnTokenizer | ( | ) |
cmnTokenizer::~cmnTokenizer | ( | ) |
void cmnTokenizer::GetArgvTokens | ( | std::vector< const char * > & | argvTokens | ) | const |
This method will fill the input vector with the tokens, but first set the 0-index element to NULL, to follow the argv convention, where argv[0] contains the "name of the program".
|
inlinestatic |
|
inlinestatic |
|
inlinestatic |
|
inline |
|
inline |
|
inline |
Return the number of tokens stored. Note that the last token is a NULL.
|
inline |
const char* cmnTokenizer::GetToken | ( | size_type | num | ) | const |
Return the specified token.
num | the token number (0..GetNumTokens()) |
const char* const* cmnTokenizer::GetTokensArray | ( | void | ) | const |
Return the array of tokens in an argv fashion.
void cmnTokenizer::Parse | ( | const char * | string | ) | |
throw | ( | std::runtime_error | |||
) |
Parse the input string and store the tokens internally. If there is a syntax error (e.g., unclosed quotes) throw an exception.
string | the text to be parsed. |
|
inline |
|
inline |
|
inline |
|
inline |