rippled
Loading...
Searching...
No Matches
Classes | Public Types | Public Member Functions | Static Public Attributes | Private Types | Private Member Functions | Private Attributes | List of all members
Json::Reader Class Reference

Unserialize a JSON document into a Value. More...

#include <json_reader.h>

Collaboration diagram for Json::Reader:
Collaboration graph
[legend]

Classes

class  ErrorInfo
 
class  Token
 

Public Types

using Char = char
 
using Location = Char const *
 

Public Member Functions

 Reader ()=default
 Constructs a Reader allowing all features for parsing.
 
bool parse (std::string const &document, Value &root)
 Read a Value from a JSON document.
 
bool parse (char const *beginDoc, char const *endDoc, Value &root)
 Read a Value from a JSON document.
 
bool parse (std::istream &is, Value &root)
 Parse from input stream.
 
template<class BufferSequence >
bool parse (Value &root, BufferSequence const &bs)
 Read a Value from a JSON buffer sequence.
 
std::string getFormatedErrorMessages () const
 Returns a user friendly string that list errors in the parsed document.
 

Static Public Attributes

static constexpr unsigned nest_limit {25}
 

Private Types

enum  TokenType {
  tokenEndOfStream = 0 , tokenObjectBegin , tokenObjectEnd , tokenArrayBegin ,
  tokenArrayEnd , tokenString , tokenInteger , tokenDouble ,
  tokenTrue , tokenFalse , tokenNull , tokenArraySeparator ,
  tokenMemberSeparator , tokenComment , tokenError
}
 
using Errors = std::deque< ErrorInfo >
 
using Nodes = std::stack< Value * >
 

Private Member Functions

bool expectToken (TokenType type, Token &token, char const *message)
 
bool readToken (Token &token)
 
void skipSpaces ()
 
bool match (Location pattern, int patternLength)
 
bool readComment ()
 
bool readCStyleComment ()
 
bool readCppStyleComment ()
 
bool readString ()
 
Reader::TokenType readNumber ()
 
bool readValue (unsigned depth)
 
bool readObject (Token &token, unsigned depth)
 
bool readArray (Token &token, unsigned depth)
 
bool decodeNumber (Token &token)
 
bool decodeString (Token &token)
 
bool decodeString (Token &token, std::string &decoded)
 
bool decodeDouble (Token &token)
 
bool decodeUnicodeCodePoint (Token &token, Location &current, Location end, unsigned int &unicode)
 
bool decodeUnicodeEscapeSequence (Token &token, Location &current, Location end, unsigned int &unicode)
 
bool addError (std::string const &message, Token &token, Location extra=0)
 
bool recoverFromError (TokenType skipUntilToken)
 
bool addErrorAndRecover (std::string const &message, Token &token, TokenType skipUntilToken)
 
void skipUntilSpace ()
 
ValuecurrentValue ()
 
Char getNextChar ()
 
void getLocationLineAndColumn (Location location, int &line, int &column) const
 
std::string getLocationLineAndColumn (Location location) const
 
void skipCommentTokens (Token &token)
 

Private Attributes

Nodes nodes_
 
Errors errors_
 
std::string document_
 
Location begin_
 
Location end_
 
Location current_
 
Location lastValueEnd_
 
ValuelastValue_
 

Detailed Description

Unserialize a JSON document into a Value.

Definition at line 19 of file json_reader.h.

Member Typedef Documentation

◆ Char

using Json::Reader::Char = char

Definition at line 22 of file json_reader.h.

◆ Location

using Json::Reader::Location = Char const*

Definition at line 23 of file json_reader.h.

◆ Errors

Definition at line 114 of file json_reader.h.

◆ Nodes

Definition at line 182 of file json_reader.h.

Member Enumeration Documentation

◆ TokenType

Enumerator
tokenEndOfStream 
tokenObjectBegin 
tokenObjectEnd 
tokenArrayBegin 
tokenArrayEnd 
tokenString 
tokenInteger 
tokenDouble 
tokenTrue 
tokenFalse 
tokenNull 
tokenArraySeparator 
tokenMemberSeparator 
tokenComment 
tokenError 

Definition at line 76 of file json_reader.h.

Constructor & Destructor Documentation

◆ Reader()

Json::Reader::Reader ( )
default

Constructs a Reader allowing all features for parsing.

Member Function Documentation

◆ parse() [1/4]

bool Json::Reader::parse ( std::string const &  document,
Value root 
)

Read a Value from a JSON document.

Parameters
documentUTF-8 encoded string containing the document to read.
root[out] Contains the root value of the document if it was successfully parsed.
Returns
true if the document was successfully parsed, false if an error occurred.

Definition at line 59 of file json_reader.cpp.

◆ parse() [2/4]

bool Json::Reader::parse ( char const *  beginDoc,
char const *  endDoc,
Value root 
)

Read a Value from a JSON document.

Parameters
documentUTF-8 encoded string containing the document to read.
root[out] Contains the root value of the document if it was successfully parsed.
Returns
true if the document was successfully parsed, false if an error occurred.

Definition at line 83 of file json_reader.cpp.

◆ parse() [3/4]

bool Json::Reader::parse ( std::istream is,
Value root 
)

Parse from input stream.

See also
Json::operator>>(std::istream&, Json::Value&).

Definition at line 68 of file json_reader.cpp.

◆ parse() [4/4]

template<class BufferSequence >
bool Json::Reader::parse ( Value root,
BufferSequence const &  bs 
)

Read a Value from a JSON buffer sequence.

Parameters
root[out] Contains the root value of the document if it was successfully parsed.
UTF-8encoded buffer sequence.
Returns
true if the buffer was successfully parsed, false if an error occurred.

Definition at line 195 of file json_reader.h.

◆ getFormatedErrorMessages()

std::string Json::Reader::getFormatedErrorMessages ( ) const

Returns a user friendly string that list errors in the parsed document.

Returns
Formatted error message with the list of errors with their location in the parsed document. An empty string is returned if no error occurred during parsing.

Definition at line 915 of file json_reader.cpp.

◆ expectToken()

bool Json::Reader::expectToken ( TokenType  type,
Token token,
char const *  message 
)
private

Definition at line 177 of file json_reader.cpp.

◆ readToken()

bool Json::Reader::readToken ( Token token)
private

Definition at line 188 of file json_reader.cpp.

◆ skipSpaces()

void Json::Reader::skipSpaces ( )
private

Definition at line 277 of file json_reader.cpp.

◆ match()

bool Json::Reader::match ( Location  pattern,
int  patternLength 
)
private

Definition at line 291 of file json_reader.cpp.

◆ readComment()

bool Json::Reader::readComment ( )
private

Definition at line 307 of file json_reader.cpp.

◆ readCStyleComment()

bool Json::Reader::readCStyleComment ( )
private

Definition at line 321 of file json_reader.cpp.

◆ readCppStyleComment()

bool Json::Reader::readCppStyleComment ( )
private

Definition at line 335 of file json_reader.cpp.

◆ readString()

bool Json::Reader::readString ( )
private

Definition at line 383 of file json_reader.cpp.

◆ readNumber()

Reader::TokenType Json::Reader::readNumber ( )
private

Definition at line 349 of file json_reader.cpp.

◆ readValue()

bool Json::Reader::readValue ( unsigned  depth)
private

Definition at line 117 of file json_reader.cpp.

◆ readObject()

bool Json::Reader::readObject ( Token token,
unsigned  depth 
)
private

Definition at line 401 of file json_reader.cpp.

◆ readArray()

bool Json::Reader::readArray ( Token token,
unsigned  depth 
)
private

Definition at line 474 of file json_reader.cpp.

◆ decodeNumber()

bool Json::Reader::decodeNumber ( Token token)
private

Definition at line 527 of file json_reader.cpp.

◆ decodeString() [1/2]

bool Json::Reader::decodeString ( Token token)
private

Definition at line 648 of file json_reader.cpp.

◆ decodeString() [2/2]

bool Json::Reader::decodeString ( Token token,
std::string decoded 
)
private

Definition at line 660 of file json_reader.cpp.

◆ decodeDouble()

bool Json::Reader::decodeDouble ( Token token)
private

Definition at line 610 of file json_reader.cpp.

◆ decodeUnicodeCodePoint()

bool Json::Reader::decodeUnicodeCodePoint ( Token token,
Location current,
Location  end,
unsigned int &  unicode 
)
private

Definition at line 739 of file json_reader.cpp.

◆ decodeUnicodeEscapeSequence()

bool Json::Reader::decodeUnicodeEscapeSequence ( Token token,
Location current,
Location  end,
unsigned int &  unicode 
)
private

Definition at line 782 of file json_reader.cpp.

◆ addError()

bool Json::Reader::addError ( std::string const &  message,
Token token,
Location  extra = 0 
)
private

Definition at line 819 of file json_reader.cpp.

◆ recoverFromError()

bool Json::Reader::recoverFromError ( TokenType  skipUntilToken)
private

Definition at line 830 of file json_reader.cpp.

◆ addErrorAndRecover()

bool Json::Reader::addErrorAndRecover ( std::string const &  message,
Token token,
TokenType  skipUntilToken 
)
private

Definition at line 849 of file json_reader.cpp.

◆ skipUntilSpace()

void Json::Reader::skipUntilSpace ( )
private

◆ currentValue()

Value & Json::Reader::currentValue ( )
private

Definition at line 859 of file json_reader.cpp.

◆ getNextChar()

Reader::Char Json::Reader::getNextChar ( )
private

Definition at line 865 of file json_reader.cpp.

◆ getLocationLineAndColumn() [1/2]

void Json::Reader::getLocationLineAndColumn ( Location  location,
int &  line,
int &  column 
) const
private

Definition at line 874 of file json_reader.cpp.

◆ getLocationLineAndColumn() [2/2]

std::string Json::Reader::getLocationLineAndColumn ( Location  location) const
private

Definition at line 906 of file json_reader.cpp.

◆ skipCommentTokens()

void Json::Reader::skipCommentTokens ( Token token)
private

Definition at line 168 of file json_reader.cpp.

Member Data Documentation

◆ nest_limit

constexpr unsigned Json::Reader::nest_limit {25}
staticconstexpr

Definition at line 73 of file json_reader.h.

◆ nodes_

Nodes Json::Reader::nodes_
private

Definition at line 183 of file json_reader.h.

◆ errors_

Errors Json::Reader::errors_
private

Definition at line 184 of file json_reader.h.

◆ document_

std::string Json::Reader::document_
private

Definition at line 185 of file json_reader.h.

◆ begin_

Location Json::Reader::begin_
private

Definition at line 186 of file json_reader.h.

◆ end_

Location Json::Reader::end_
private

Definition at line 187 of file json_reader.h.

◆ current_

Location Json::Reader::current_
private

Definition at line 188 of file json_reader.h.

◆ lastValueEnd_

Location Json::Reader::lastValueEnd_
private

Definition at line 189 of file json_reader.h.

◆ lastValue_

Value* Json::Reader::lastValue_
private

Definition at line 190 of file json_reader.h.