jvar
JS inspired Variant and Json
jvar::JsonParser Class Reference

Detailed Description

JsonParser class parses a json string into a Variant structure.

#include <json.h>

+ Inheritance diagram for jvar::JsonParser:
+ Collaboration diagram for jvar::JsonParser:

Public Types

enum  { FLAG_FLEXQUOTES = 0x1, FLAG_OBJECTONLY = 0x2, FLAG_ARRAYONLY = 0x4 }

Public Member Functions

 JsonParser (Variant &outvar, const char *jsontxt, uint flags=0)
bool eof ()
bool failed ()
const std::string & errMsg ()
const char * c_str ()
const std::string & token ()
bool tokenEquals (const char *val)
void advance ()
void advance (const char *match)
void setError (const char *msg)
void stripQuotes (bool allowsingle)
void captureDelim (const char *delim)

Protected Member Functions

void parseObject (Variant &var)
void parseMembers (Variant &var)
void parseArray (Variant &var)
void parseElements (Variant &var)
void parseValue (Variant &var)
void parseNum (Variant &var)
void parseString (Variant &var)
bool isString (const std::string &s, bool requirequotes)
bool isArray (const std::string &s)
bool isObject (const std::string &s)
bool isNum (const std::string &s)
bool charWord (char c)
bool charPunc (char c)
bool charBrac (char c)

Protected Attributes

uint mFlags

Member Enumeration Documentation

anonymous enum
Enumerator:
FLAG_FLEXQUOTES 

Allow flexible quotes (single quotes or no quotes in some cases)

FLAG_OBJECTONLY 

Start with parsing an object

FLAG_ARRAYONLY 

Start with parsing an array


Constructor & Destructor Documentation

jvar::JsonParser::JsonParser ( Variant outvar,
const char *  jsontxt,
uint  flags = 0 
)

Constructor

Parameters:
outvarVariant which will contain the parsed data structure
jsontxtJson text to parse
flagsFlags

References jvar::Parser::advance(), jvar::Parser::c_str(), jvar::Parser::eof(), jvar::Parser::errMsg(), jvar::Parser::failed(), FLAG_ARRAYONLY, FLAG_OBJECTONLY, jvar::Parser::setError(), jvar::Parser::token(), and jvar::Parser::tokenEquals().


Member Function Documentation

void jvar::Parser::advance ( ) [inline, inherited]

Advances to the next token by parsing it

Referenced by jvar::Parser::advance(), JsonParser(), and jvar::Variant::path().

void jvar::Parser::advance ( const char *  match) [inherited]

Advances if a matching token is found

Parameters:
matchString to match

References jvar::Parser::advance(), jvar::Parser::c_str(), jvar::Parser::setError(), jvar::Parser::token(), and jvar::Parser::tokenEquals().

const char* jvar::Parser::c_str ( ) [inline, inherited]

Returns the current token

Returns:
Pointer to current token

References jvar::Parser::token().

Referenced by jvar::Parser::advance(), and JsonParser().

bool jvar::Parser::eof ( ) [inline, inherited]

Is the entire text parsed

Returns:
True if at the end of text has reached

Referenced by JsonParser(), and jvar::Variant::path().

const std::string& jvar::Parser::errMsg ( ) [inline, inherited]

Returns the error message

Returns:
Reference to the formatted error message string

Referenced by JsonParser().

bool jvar::Parser::failed ( ) [inline, inherited]

Was there a failure

Returns:
True if there was an error, false otherwise

Referenced by JsonParser(), and jvar::Variant::parseJson().

void jvar::Parser::setError ( const char *  msg) [inherited]

Sets an error message and signal failure

Parameters:
msgError text

Referenced by jvar::Parser::advance(), JsonParser(), and jvar::Parser::Parser().

void jvar::Parser::stripQuotes ( bool  allowsingle) [inherited]

Strip quotes from the current token string if found

Parameters:
allowsingleIf true, also allows stripping single quotes
const std::string& jvar::Parser::token ( ) [inline, inherited]

Returns the current token

Returns:
Reference to current token

Referenced by jvar::Parser::advance(), jvar::Parser::c_str(), JsonParser(), jvar::Variant::path(), and jvar::Parser::tokenEquals().

bool jvar::Parser::tokenEquals ( const char *  val) [inline, inherited]

Compares the current token with a string

Parameters:
valString to compare
Returns:
True if equal, false otherwise

References jvar::Parser::token().

Referenced by jvar::Parser::advance(), JsonParser(), and jvar::Variant::path().


The documentation for this class was generated from the following files:
 All Classes Functions Variables Enumerator