MeVisLab Toolbox Reference
ml::ListParser Class Reference

Parser class for parsing persistent state strings of list objects. More...

#include <mlListParser.h>

Inheritance diagram for ml::ListParser:
ml::ParserBase

Public Types

enum  { kMissingOpenBracket = kNumBaseErrorCodes , kMissingCloseBracket , kUnmatchedQuote , kNumErrorCodes }
 Error codes. More...
 
- Public Types inherited from ml::ParserBase
enum  { kNoError = 0 , kEmptyString , kNumBaseErrorCodes , kEndOfSource = -1 }
 Error codes. More...
 

Public Member Functions

 ListParser ()=default
 Constructor. More...
 
int init (const char *source) override
 Initialize parser and proceed to first character of first item. More...
 
std::pair< int, std::string > nextItem ()
 Return a string to next item's substring Return codes: More...
 
const char * getErrorMessage (int errorCode) override
 Get error string for errorCode. More...
 
- Public Member Functions inherited from ml::ParserBase
 ParserBase ()
 Constructor. More...
 
virtual ~ParserBase ()
 Make destructor virtual to avoid warnings. More...
 
const char * getCurrentPos ()
 Get current parser position. More...
 
bool endOfSource ()
 Return end-of-source flag. More...
 

Static Public Member Functions

static bool needsQuote (const char *itemStr)
 Return true if itemStr needs to be quoted. More...
 
static bool needsQuote (const std::string &itemStr)
 
static std::string quoteString (const std::string &itemStr)
 
- Static Public Member Functions inherited from ml::ParserBase
static char * newString (const std::string &str)
 Convenience method to create a copy of the string str allocated on the heap. More...
 
static void deleteString (char *str)
 Dispose a string allocated with newString() More...
 

Protected Member Functions

int unquoteString (std::string &itemString)
 Convert quoted string to original, unescaped character sequence Assumes that _pNext points to a leading quote, proceeds to the first character after the terminating quote. More...
 
- Protected Member Functions inherited from ml::ParserBase
void skipWhitespace ()
 Proceed to next non-whitespace character. More...
 

Additional Inherited Members

- Protected Attributes inherited from ml::ParserBase
const char * _source
 Source string. More...
 
const char * _pNext
 Pointer to current parser position. More...
 
bool _eos
 End-of-string flag. More...
 

Detailed Description

Parser class for parsing persistent state strings of list objects.

Definition at line 39 of file mlListParser.h.

Member Enumeration Documentation

◆ anonymous enum

anonymous enum

Error codes.

Enumerator
kMissingOpenBracket 
kMissingCloseBracket 
kUnmatchedQuote 
kNumErrorCodes 

Highest error code +1.

Definition at line 82 of file mlListParser.h.

Constructor & Destructor Documentation

◆ ListParser()

ml::ListParser::ListParser ( )
default

Constructor.

Member Function Documentation

◆ getErrorMessage()

const char* ml::ListParser::getErrorMessage ( int  errorCode)
overridevirtual

Get error string for errorCode.

Reimplemented from ml::ParserBase.

Referenced by ml::ListTemplate< T >::setPersistentState().

◆ init()

int ml::ListParser::init ( const char *  source)
overridevirtual

Initialize parser and proceed to first character of first item.

Return codes:

  • kEmptyString for an empty or null source string,
  • kEndOfSource for an empty list ("[]")
  • kMissingOpenBracket for a non-empty string not beginning with '['
  • kMissingCloseBracket for a string containing only "["

Reimplemented from ml::ParserBase.

Referenced by ml::ListTemplate< T >::setPersistentState().

◆ needsQuote() [1/2]

static bool ml::ListParser::needsQuote ( const char *  itemStr)
static

Return true if itemStr needs to be quoted.

◆ needsQuote() [2/2]

static bool ml::ListParser::needsQuote ( const std::string &  itemStr)
static

◆ nextItem()

std::pair<int, std::string> ml::ListParser::nextItem ( )

Return a string to next item's substring Return codes:

  • kEndOfSource if no next item exists
  • kMissingCloseBracket if string ends without closing bracket
  • Any return code of unquoteString()

Referenced by ml::ListTemplate< T >::setPersistentState().

◆ quoteString()

static std::string ml::ListParser::quoteString ( const std::string &  itemStr)
static

◆ unquoteString()

int ml::ListParser::unquoteString ( std::string &  itemString)
protected

Convert quoted string to original, unescaped character sequence Assumes that _pNext points to a leading quote, proceeds to the first character after the terminating quote.

Return kUnmatchedQuote if strings ends without terminating quote.


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