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

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

Classes

class  ErrorInfo
 
class  Token
 

Public Types

using Char = char
 
using Location = const Char *
 

Public Member Functions

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

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, const char *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 36 of file json_reader.h.

Member Typedef Documentation

◆ Char

using Json::Reader::Char = char

Definition at line 39 of file json_reader.h.

◆ Location

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

Definition at line 40 of file json_reader.h.

◆ Errors

Definition at line 131 of file json_reader.h.

◆ Nodes

Definition at line 199 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 93 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 74 of file json_reader.cpp.

◆ parse() [2/4]

bool Json::Reader::parse ( const char *  beginDoc,
const char *  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 98 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 83 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 212 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 931 of file json_reader.cpp.

◆ expectToken()

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

Definition at line 192 of file json_reader.cpp.

◆ readToken()

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

Definition at line 203 of file json_reader.cpp.

◆ skipSpaces()

void Json::Reader::skipSpaces ( )
private

Definition at line 292 of file json_reader.cpp.

◆ match()

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

Definition at line 306 of file json_reader.cpp.

◆ readComment()

bool Json::Reader::readComment ( )
private

Definition at line 322 of file json_reader.cpp.

◆ readCStyleComment()

bool Json::Reader::readCStyleComment ( )
private

Definition at line 336 of file json_reader.cpp.

◆ readCppStyleComment()

bool Json::Reader::readCppStyleComment ( )
private

Definition at line 350 of file json_reader.cpp.

◆ readString()

bool Json::Reader::readString ( )
private

Definition at line 398 of file json_reader.cpp.

◆ readNumber()

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

Definition at line 364 of file json_reader.cpp.

◆ readValue()

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

Definition at line 132 of file json_reader.cpp.

◆ readObject()

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

Definition at line 416 of file json_reader.cpp.

◆ readArray()

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

Definition at line 489 of file json_reader.cpp.

◆ decodeNumber()

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

Definition at line 542 of file json_reader.cpp.

◆ decodeString() [1/2]

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

Definition at line 663 of file json_reader.cpp.

◆ decodeString() [2/2]

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

Definition at line 675 of file json_reader.cpp.

◆ decodeDouble()

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

Definition at line 625 of file json_reader.cpp.

◆ decodeUnicodeCodePoint()

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

Definition at line 754 of file json_reader.cpp.

◆ decodeUnicodeEscapeSequence()

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

Definition at line 797 of file json_reader.cpp.

◆ addError()

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

Definition at line 834 of file json_reader.cpp.

◆ recoverFromError()

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

Definition at line 845 of file json_reader.cpp.

◆ addErrorAndRecover()

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

Definition at line 864 of file json_reader.cpp.

◆ skipUntilSpace()

void Json::Reader::skipUntilSpace ( )
private

◆ currentValue()

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

Definition at line 874 of file json_reader.cpp.

◆ getNextChar()

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

Definition at line 880 of file json_reader.cpp.

◆ getLocationLineAndColumn() [1/2]

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

Definition at line 889 of file json_reader.cpp.

◆ getLocationLineAndColumn() [2/2]

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

Definition at line 921 of file json_reader.cpp.

◆ skipCommentTokens()

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

Definition at line 183 of file json_reader.cpp.

Member Data Documentation

◆ nest_limit

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

Definition at line 90 of file json_reader.h.

◆ nodes_

Nodes Json::Reader::nodes_
private

Definition at line 200 of file json_reader.h.

◆ errors_

Errors Json::Reader::errors_
private

Definition at line 201 of file json_reader.h.

◆ document_

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

Definition at line 202 of file json_reader.h.

◆ begin_

Location Json::Reader::begin_
private

Definition at line 203 of file json_reader.h.

◆ end_

Location Json::Reader::end_
private

Definition at line 204 of file json_reader.h.

◆ current_

Location Json::Reader::current_
private

Definition at line 205 of file json_reader.h.

◆ lastValueEnd_

Location Json::Reader::lastValueEnd_
private

Definition at line 206 of file json_reader.h.

◆ lastValue_

Value* Json::Reader::lastValue_
private

Definition at line 207 of file json_reader.h.