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 38 of file json_reader.h.

Member Typedef Documentation

◆ Char

using Json::Reader::Char = char

Definition at line 41 of file json_reader.h.

◆ Location

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

Definition at line 42 of file json_reader.h.

◆ Errors

Definition at line 133 of file json_reader.h.

◆ Nodes

Definition at line 201 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 95 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 78 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 102 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 87 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 214 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 934 of file json_reader.cpp.

◆ expectToken()

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

Definition at line 196 of file json_reader.cpp.

◆ readToken()

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

Definition at line 207 of file json_reader.cpp.

◆ skipSpaces()

void Json::Reader::skipSpaces ( )
private

Definition at line 296 of file json_reader.cpp.

◆ match()

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

Definition at line 310 of file json_reader.cpp.

◆ readComment()

bool Json::Reader::readComment ( )
private

Definition at line 326 of file json_reader.cpp.

◆ readCStyleComment()

bool Json::Reader::readCStyleComment ( )
private

Definition at line 340 of file json_reader.cpp.

◆ readCppStyleComment()

bool Json::Reader::readCppStyleComment ( )
private

Definition at line 354 of file json_reader.cpp.

◆ readString()

bool Json::Reader::readString ( )
private

Definition at line 402 of file json_reader.cpp.

◆ readNumber()

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

Definition at line 368 of file json_reader.cpp.

◆ readValue()

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

Definition at line 136 of file json_reader.cpp.

◆ readObject()

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

Definition at line 420 of file json_reader.cpp.

◆ readArray()

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

Definition at line 493 of file json_reader.cpp.

◆ decodeNumber()

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

Definition at line 546 of file json_reader.cpp.

◆ decodeString() [1/2]

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

Definition at line 667 of file json_reader.cpp.

◆ decodeString() [2/2]

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

Definition at line 679 of file json_reader.cpp.

◆ decodeDouble()

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

Definition at line 629 of file json_reader.cpp.

◆ decodeUnicodeCodePoint()

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

Definition at line 758 of file json_reader.cpp.

◆ decodeUnicodeEscapeSequence()

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

Definition at line 801 of file json_reader.cpp.

◆ addError()

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

Definition at line 838 of file json_reader.cpp.

◆ recoverFromError()

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

Definition at line 849 of file json_reader.cpp.

◆ addErrorAndRecover()

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

Definition at line 868 of file json_reader.cpp.

◆ skipUntilSpace()

void Json::Reader::skipUntilSpace ( )
private

◆ currentValue()

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

Definition at line 878 of file json_reader.cpp.

◆ getNextChar()

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

Definition at line 884 of file json_reader.cpp.

◆ getLocationLineAndColumn() [1/2]

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

Definition at line 893 of file json_reader.cpp.

◆ getLocationLineAndColumn() [2/2]

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

Definition at line 925 of file json_reader.cpp.

◆ skipCommentTokens()

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

Definition at line 187 of file json_reader.cpp.

Member Data Documentation

◆ nest_limit

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

Definition at line 92 of file json_reader.h.

◆ nodes_

Nodes Json::Reader::nodes_
private

Definition at line 202 of file json_reader.h.

◆ errors_

Errors Json::Reader::errors_
private

Definition at line 203 of file json_reader.h.

◆ document_

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

Definition at line 204 of file json_reader.h.

◆ begin_

Location Json::Reader::begin_
private

Definition at line 205 of file json_reader.h.

◆ end_

Location Json::Reader::end_
private

Definition at line 206 of file json_reader.h.

◆ current_

Location Json::Reader::current_
private

Definition at line 207 of file json_reader.h.

◆ lastValueEnd_

Location Json::Reader::lastValueEnd_
private

Definition at line 208 of file json_reader.h.

◆ lastValue_

Value* Json::Reader::lastValue_
private

Definition at line 209 of file json_reader.h.