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

Static Public Member Functions

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

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.
 
- Protected Member Functions inherited from ml::ParserBase
void skipWhitespace ()
 Proceed to next non-whitespace character.
 

Additional Inherited Members

- Protected Attributes inherited from ml::ParserBase
const char_source
 Source string.
 
const char_pNext
 Pointer to current parser position.
 
bool _eos
 End-of-string flag.
 

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

Error codes.

Enumerator
kMissingOpenBracket 
kMissingCloseBracket 
kUnmatchedQuote 
kNumErrorCodes 

Highest error code +1.

Definition at line 66 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.

◆ 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.

◆ 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()

◆ 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: