PixelLightAPI
.
|
Tokenizer class for parsing texts (also called 'scanner' or 'lexer' -> lexical analysis) More...
#include <Tokenizer.h>
Public Member Functions | |
PLCORE_API | Tokenizer () |
Constructor. | |
~Tokenizer () | |
Destructor. | |
String | GetDelimiters () const |
Get delimiters (characters that a treated as whitespace) | |
void | SetDelimiters (const String &sDelimiters) |
Set delimiters (characters that a treated as whitespace) | |
String | GetSingleChars () const |
Get single characters. | |
void | SetSingleChars (const String &sSingleChars) |
Set single characters. | |
String | GetQuotes () const |
Get characters that are used for quotes. | |
void | SetQuotes (const String &sQuotes) |
Set characters that are used for quotes. | |
String | GetCommentStartTag () const |
Get the string that starts a multi-line comment. | |
void | SetCommentStartTag (const String &sCommentStartTag) |
Set the string that starts a multi-line comment. | |
String | GetCommentEndTag () const |
Get the string that ends a multi-line comment. | |
void | SetCommentEndTag (const String &sCommentEndTag) |
Set the string that ends a multi-line comment. | |
String | GetSingleLineComment () const |
Get the string that starts a single-line comment. | |
void | SetSingleLineComment (const String &sSingleLineComment) |
Set the string that starts a single-line comment. | |
bool | IsCaseSensitive () const |
Get case sensitivity flag. | |
void | SetCaseSensitive (bool bCaseSensitive) |
Set case sensitivity flag. | |
PLCORE_API void | Start (const String &sBuffer) |
Starts the tokenizer on a string. | |
PLCORE_API void | Start (File &cFile) |
Starts the tokenizer on a file. | |
PLCORE_API void | Stop () |
Stops the tokenizer. | |
PLCORE_API Array< String > | GetTokens () |
Reads all tokens until the end of the stream. | |
PLCORE_API String | GetNextToken () |
Reads the next token from the stream. | |
PLCORE_API bool | ExpectToken (const String &sExpected) |
Expects the next token to be equal to a given string. | |
PLCORE_API bool | FindToken (const String &sExpected) |
Finds a given token in the stream. | |
String | GetToken () const |
Returns the current token. | |
bool | CompareToken (const String &sExpected) |
Compares the current token with a given string. | |
uint32 | GetPosition () const |
Returns the current position in the stream. | |
uint32 | GetLine () const |
Returns the current line (counted by ' ' occurrences) | |
PLCORE_API void | PushState () |
Saves the current state of the tokenizer on a state stack. | |
PLCORE_API void | PopState () |
Restores the last saved state from the stack. | |
void | DropState () |
Deletes the last saved state from the stack. | |
bool | ParseNumber (int &nNumber) |
Expects the next token to be a number and returns it as an integer value. | |
bool | ParseNumber (float &fNumber) |
Expects the next token to be a floating point number and returns it as a float value. | |
bool | ParseNumber (double &dNumber) |
Expects the next token to be a floating point number and returns it as a double value. | |
PLCORE_API bool | ParseVector (Array< String > &cVector, const String &sStart="[", const String &sEnd="]", const String &sSeparator=",") |
Expects the next tokens to be a vector and returns it as an array of strings. | |
PLCORE_API bool | ParseVector (Array< int > &cVector, const String &sStart="[", const String &sEnd="]", const String &sSeparator=",") |
Expects the next tokens to be a vector and returns it as an array of ints. | |
PLCORE_API bool | ParseVector (Array< float > &cVector, const String &sStart="[", const String &sEnd="]", const String &sSeparator=",") |
Expects the next tokens to be a vector and returns it as an array of floats. | |
PLCORE_API bool | ParseVector (Array< double > &cVector, const String &sStart="[", const String &sEnd="]", const String &sSeparator=",") |
Expects the next tokens to be a vector and returns it as an array of doubles. | |
PLCORE_API bool | ParseEquation (String &sName, String &sValue, const String &sEquation="") |
Expects the next tokens to be an equation and returns it. | |
bool | ParseEquation (String &sName, int &nValue, const String &sEquation="") |
Expects the next tokens to be an equation and returns it. | |
bool | ParseEquation (String &sName, float &fValue, const String &sEquation="") |
Expects the next tokens to be an equation and returns it. | |
bool | ParseEquation (String &sName, double &dValue, const String &sEquation="") |
Expects the next tokens to be an equation and returns it. |
Tokenizer class for parsing texts (also called 'scanner' or 'lexer' -> lexical analysis)
* Usage example: * Tokenizer cTokenizer; // Tokenizer instance * String sText = "This is a test"; // Text to be parsed * cTokenizer.Start(sText); // Start tokenizer * String sToken; // String for current token * sToken = cTokenizer.GetNextToken(); // Will return 'This' * sToken = cTokenizer.GetNextToken(); // Will return 'is' * sToken = cTokenizer.GetNextToken(); // Will return 'a' * sToken = cTokenizer.GetNextToken(); // Will return 'test' *
PLCORE_API PLCore::Tokenizer::Tokenizer | ( | ) |
PLCore::Tokenizer::~Tokenizer | ( | ) | [inline] |
Destructor.
String PLCore::Tokenizer::GetDelimiters | ( | ) | const [inline] |
Get delimiters (characters that a treated as whitespace)
void PLCore::Tokenizer::SetDelimiters | ( | const String & | sDelimiters | ) | [inline] |
Set delimiters (characters that a treated as whitespace)
[in] | sDelimiters | Delimiter characters |
String PLCore::Tokenizer::GetSingleChars | ( | ) | const [inline] |
Get single characters.
void PLCore::Tokenizer::SetSingleChars | ( | const String & | sSingleChars | ) | [inline] |
Set single characters.
[in] | sSingleChars | Single characters |
String PLCore::Tokenizer::GetQuotes | ( | ) | const [inline] |
Get characters that are used for quotes.
void PLCore::Tokenizer::SetQuotes | ( | const String & | sQuotes | ) | [inline] |
Set characters that are used for quotes.
[in] | sQuotes | Quote characters |
String PLCore::Tokenizer::GetCommentStartTag | ( | ) | const [inline] |
Get the string that starts a multi-line comment.
void PLCore::Tokenizer::SetCommentStartTag | ( | const String & | sCommentStartTag | ) | [inline] |
Set the string that starts a multi-line comment.
[in] | sCommentStartTag | Comment start tag |
String PLCore::Tokenizer::GetCommentEndTag | ( | ) | const [inline] |
Get the string that ends a multi-line comment.
void PLCore::Tokenizer::SetCommentEndTag | ( | const String & | sCommentEndTag | ) | [inline] |
Set the string that ends a multi-line comment.
[in] | sCommentEndTag | Comment end tag |
String PLCore::Tokenizer::GetSingleLineComment | ( | ) | const [inline] |
Get the string that starts a single-line comment.
void PLCore::Tokenizer::SetSingleLineComment | ( | const String & | sSingleLineComment | ) | [inline] |
Set the string that starts a single-line comment.
[in] | sSingleLineComment | Comment start tag |
bool PLCore::Tokenizer::IsCaseSensitive | ( | ) | const [inline] |
Get case sensitivity flag.
void PLCore::Tokenizer::SetCaseSensitive | ( | bool | bCaseSensitive | ) | [inline] |
Set case sensitivity flag.
[in] | bCaseSensitive | 'true' if the text is parsed case sensitive (default is false) |
PLCORE_API void PLCore::Tokenizer::Start | ( | const String & | sBuffer | ) |
Starts the tokenizer on a string.
[in] | sBuffer | String buffer |
PLCORE_API void PLCore::Tokenizer::Start | ( | File & | cFile | ) |
PLCORE_API void PLCore::Tokenizer::Stop | ( | ) |
Stops the tokenizer.
PLCORE_API Array<String> PLCore::Tokenizer::GetTokens | ( | ) |
Reads all tokens until the end of the stream.
PLCORE_API String PLCore::Tokenizer::GetNextToken | ( | ) |
Reads the next token from the stream.
PLCORE_API bool PLCore::Tokenizer::ExpectToken | ( | const String & | sExpected | ) |
Expects the next token to be equal to a given string.
PLCORE_API bool PLCore::Tokenizer::FindToken | ( | const String & | sExpected | ) |
Finds a given token in the stream.
String PLCore::Tokenizer::GetToken | ( | ) | const [inline] |
Returns the current token.
bool PLCore::Tokenizer::CompareToken | ( | const String & | sExpected | ) | [inline] |
Compares the current token with a given string.
uint32 PLCore::Tokenizer::GetPosition | ( | ) | const [inline] |
Returns the current position in the stream.
uint32 PLCore::Tokenizer::GetLine | ( | ) | const [inline] |
Returns the current line (counted by '
' occurrences)
PLCORE_API void PLCore::Tokenizer::PushState | ( | ) |
Saves the current state of the tokenizer on a state stack.
PLCORE_API void PLCore::Tokenizer::PopState | ( | ) |
Restores the last saved state from the stack.
void PLCore::Tokenizer::DropState | ( | ) | [inline] |
Deletes the last saved state from the stack.
bool PLCore::Tokenizer::ParseNumber | ( | int & | nNumber | ) | [inline] |
Expects the next token to be a number and returns it as an integer value.
[out] | nNumber | Receives the number |
bool PLCore::Tokenizer::ParseNumber | ( | float & | fNumber | ) | [inline] |
Expects the next token to be a floating point number and returns it as a float value.
[out] | fNumber | Receives the number |
bool PLCore::Tokenizer::ParseNumber | ( | double & | dNumber | ) | [inline] |
Expects the next token to be a floating point number and returns it as a double value.
[out] | dNumber | Receives the number |
PLCORE_API bool PLCore::Tokenizer::ParseVector | ( | Array< String > & | cVector, |
const String & | sStart = "[" , |
||
const String & | sEnd = "]" , |
||
const String & | sSeparator = "," |
||
) |
Expects the next tokens to be a vector and returns it as an array of strings.
[out] | cVector | Receives the vector elements |
[in] | sStart | Open bracket (e.g. "[") |
[in] | sEnd | Closed bracket (e.g. "]") |
[in] | sSeparator | Separator between the elements (e.g. ","). Can also be "" |
PLCORE_API bool PLCore::Tokenizer::ParseVector | ( | Array< int > & | cVector, |
const String & | sStart = "[" , |
||
const String & | sEnd = "]" , |
||
const String & | sSeparator = "," |
||
) |
Expects the next tokens to be a vector and returns it as an array of ints.
[out] | cVector | Receives the vector elements |
[in] | sStart | Open bracket (e.g. "[") |
[in] | sEnd | Closed bracket (e.g. "]") |
[in] | sSeparator | Separator between the elements (e.g. ","). Can also be "" |
PLCORE_API bool PLCore::Tokenizer::ParseVector | ( | Array< float > & | cVector, |
const String & | sStart = "[" , |
||
const String & | sEnd = "]" , |
||
const String & | sSeparator = "," |
||
) |
Expects the next tokens to be a vector and returns it as an array of floats.
[out] | cVector | Receives the vector elements |
[in] | sStart | Open bracket (e.g. "[") |
[in] | sEnd | Closed bracket (e.g. "]") |
[in] | sSeparator | Separator between the elements (e.g. ","). Can also be "" |
PLCORE_API bool PLCore::Tokenizer::ParseVector | ( | Array< double > & | cVector, |
const String & | sStart = "[" , |
||
const String & | sEnd = "]" , |
||
const String & | sSeparator = "," |
||
) |
Expects the next tokens to be a vector and returns it as an array of doubles.
[out] | cVector | Receives the vector elements |
[in] | sStart | Open bracket (e.g. "[") |
[in] | sEnd | Closed bracket (e.g. "]") |
[in] | sSeparator | Separator between the elements (e.g. ","). Can also be "" |
PLCORE_API bool PLCore::Tokenizer::ParseEquation | ( | String & | sName, |
String & | sValue, | ||
const String & | sEquation = "" |
||
) |
Expects the next tokens to be an equation and returns it.
[out] | sName | Name of the element |
[out] | sValue | Value as a string |
[in] | sEquation | Equation sign (e.g. "=") |
bool PLCore::Tokenizer::ParseEquation | ( | String & | sName, |
int & | nValue, | ||
const String & | sEquation = "" |
||
) | [inline] |
Expects the next tokens to be an equation and returns it.
[out] | sName | Name of the element |
[out] | nValue | Value as an int |
[in] | sEquation | Equation sign (e.g. "=") |
bool PLCore::Tokenizer::ParseEquation | ( | String & | sName, |
float & | fValue, | ||
const String & | sEquation = "" |
||
) | [inline] |
Expects the next tokens to be an equation and returns it.
[out] | sName | Name of the element |
[out] | fValue | Value as a float |
[in] | sEquation | Equation sign (e.g. "=") |
bool PLCore::Tokenizer::ParseEquation | ( | String & | sName, |
double & | dValue, | ||
const String & | sEquation = "" |
||
) | [inline] |
Expects the next tokens to be an equation and returns it.
[out] | sName | Name of the element |
[out] | dValue | Value as a double |
[in] | sEquation | Equation sign (e.g. "=") |
|