NIM PC Cross Platform SDK
载入中...
搜索中...
未找到
nim_cpp_wrapper_util::Json::Reader类 参考

Unserialize a JSON document into a Value. 更多...

#include <reader.h>

class  ErrorInfo
 
struct  StructuredError
 An error tagged with where in the JSON text it was encountered. 更多...
 
class  Token
 

Public 类型

using Char = char
 
using Location = const Char *
 

Public 成员函数

 Reader ()
 Constructs a Reader allowing all features for parsing.
 
 Reader (const Features &features)
 Constructs a Reader allowing the specified feature set for parsing.
 
bool parse (const std::string &document, Value &root, bool collectComments=true)
 Read a Value from a JSON document.
 
bool parse (const char *beginDoc, const char *endDoc, Value &root, bool collectComments=true)
 Read a Value from a JSON document.
 
bool parse (IStream &is, Value &root, bool collectComments=true)
 Parse from input stream.
 
String getFormatedErrorMessages () const
 Returns a user friendly string that list errors in the parsed document.
 
String getFormattedErrorMessages () const
 Returns a user friendly string that list errors in the parsed document.
 
std::vector< StructuredErrorgetStructuredErrors () const
 Returns a vector of structured errors encountered while parsing.
 
bool pushError (const Value &value, const String &message)
 Add a semantic error message.
 
bool pushError (const Value &value, const String &message, const Value &extra)
 Add a semantic error message with extra context.
 
bool good () const
 Return whether there are any errors.
 

Private 类型

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

Private 成员函数

bool readToken (Token &token)
 
void skipSpaces ()
 
bool match (const Char *pattern, int patternLength)
 
bool readComment ()
 
bool readCStyleComment ()
 
bool readCppStyleComment ()
 
bool readString ()
 
void readNumber ()
 
bool readValue ()
 
bool readObject (Token &token)
 
bool readArray (Token &token)
 
bool decodeNumber (Token &token)
 
bool decodeNumber (Token &token, Value &decoded)
 
bool decodeString (Token &token)
 
bool decodeString (Token &token, String &decoded)
 
bool decodeDouble (Token &token)
 
bool decodeDouble (Token &token, Value &decoded)
 
bool decodeUnicodeCodePoint (Token &token, Location &current, Location end, unsigned int &unicode)
 
bool decodeUnicodeEscapeSequence (Token &token, Location &current, Location end, unsigned int &unicode)
 
bool addError (const String &message, Token &token, Location extra=nullptr)
 
bool recoverFromError (TokenType skipUntilToken)
 
bool addErrorAndRecover (const String &message, Token &token, TokenType skipUntilToken)
 
void skipUntilSpace ()
 
ValuecurrentValue ()
 
Char getNextChar ()
 
void getLocationLineAndColumn (Location location, int &line, int &column) const
 
String getLocationLineAndColumn (Location location) const
 
void addComment (Location begin, Location end, CommentPlacement placement)
 
void skipCommentTokens (Token &token)
 

静态 Private 成员函数

static bool containsNewLine (Location begin, Location end)
 
static String normalizeEOL (Location begin, Location end)
 

Private 属性

Nodes nodes_
 
Errors errors_
 
String document_
 
Location begin_ {}
 
Location end_ {}
 
Location current_ {}
 
Location lastValueEnd_ {}
 
ValuelastValue_ {}
 
String commentsBefore_
 
Features features_
 
bool collectComments_ {}
 

详细描述

Unserialize a JSON document into a Value.

弃用:
Use CharReader and CharReaderBuilder.

成员类型定义说明

◆ Char

◆ Errors

◆ Location

◆ Nodes

using nim_cpp_wrapper_util::Json::Reader::Nodes = std::stack<Value*>
private

成员枚举类型说明

◆ TokenType

枚举值
tokenEndOfStream 
tokenObjectBegin 
tokenObjectEnd 
tokenArrayBegin 
tokenArrayEnd 
tokenString 
tokenNumber 
tokenTrue 
tokenFalse 
tokenNull 
tokenArraySeparator 
tokenMemberSeparator 
tokenComment 
tokenError 

构造及析构函数说明

◆ Reader() [1/2]

nim_cpp_wrapper_util::Json::Reader::Reader ( )

Constructs a Reader allowing all features for parsing.

◆ Reader() [2/2]

nim_cpp_wrapper_util::Json::Reader::Reader ( const Features features)

Constructs a Reader allowing the specified feature set for parsing.

成员函数说明

◆ addComment()

void nim_cpp_wrapper_util::Json::Reader::addComment ( Location  begin,
Location  end,
CommentPlacement  placement 
)
private

◆ addError()

bool nim_cpp_wrapper_util::Json::Reader::addError ( const String message,
Token token,
Location  extra = nullptr 
)
private

◆ addErrorAndRecover()

bool nim_cpp_wrapper_util::Json::Reader::addErrorAndRecover ( const String message,
Token token,
TokenType  skipUntilToken 
)
private

◆ containsNewLine()

bool nim_cpp_wrapper_util::Json::Reader::containsNewLine ( Reader::Location  begin,
Reader::Location  end 
)
staticprivate

◆ currentValue()

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

◆ decodeDouble() [1/2]

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

◆ decodeDouble() [2/2]

bool nim_cpp_wrapper_util::Json::Reader::decodeDouble ( Token token,
Value decoded 
)
private

◆ decodeNumber() [1/2]

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

◆ decodeNumber() [2/2]

bool nim_cpp_wrapper_util::Json::Reader::decodeNumber ( Token token,
Value decoded 
)
private

◆ decodeString() [1/2]

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

◆ decodeString() [2/2]

bool nim_cpp_wrapper_util::Json::Reader::decodeString ( Token token,
String decoded 
)
private

◆ decodeUnicodeCodePoint()

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

◆ decodeUnicodeEscapeSequence()

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

◆ getFormatedErrorMessages()

String nim_cpp_wrapper_util::Json::Reader::getFormatedErrorMessages ( ) const

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

返回
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.
弃用:
Use getFormattedErrorMessages() instead (typo fix).

◆ getFormattedErrorMessages()

String nim_cpp_wrapper_util::Json::Reader::getFormattedErrorMessages ( ) const

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

返回
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.

◆ getLocationLineAndColumn() [1/2]

String nim_cpp_wrapper_util::Json::Reader::getLocationLineAndColumn ( Location  location) const
private

◆ getLocationLineAndColumn() [2/2]

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

◆ getNextChar()

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

◆ getStructuredErrors()

std::vector< Reader::StructuredError > nim_cpp_wrapper_util::Json::Reader::getStructuredErrors ( ) const

Returns a vector of structured errors encountered while parsing.

返回
A (possibly empty) vector of StructuredError objects. Currently only one error can be returned, but the caller should tolerate multiple errors. This can occur if the parser recovers from a non-fatal parse error and then encounters additional errors.

◆ good()

bool nim_cpp_wrapper_util::Json::Reader::good ( ) const

Return whether there are any errors.

返回
true if there are no errors to report false if errors have occurred.

◆ match()

bool nim_cpp_wrapper_util::Json::Reader::match ( const Char pattern,
int  patternLength 
)
private

◆ normalizeEOL()

String nim_cpp_wrapper_util::Json::Reader::normalizeEOL ( Reader::Location  begin,
Reader::Location  end 
)
staticprivate

◆ parse() [1/3]

bool nim_cpp_wrapper_util::Json::Reader::parse ( const char *  beginDoc,
const char *  endDoc,
Value root,
bool  collectComments = true 
)

Read a Value from a JSON document.

参数
beginDocPointer on the beginning of the UTF-8 encoded string of the document to read.
endDocPointer on the end of the UTF-8 encoded string of the document to read. Must be >= beginDoc.
[out]rootContains the root value of the document if it was successfully parsed.
collectCommentstrue to collect comment and allow writing them back during serialization, false to discard comments. This parameter is ignored if Features::allowComments_ is false.
返回
true if the document was successfully parsed, false if an error occurred.

◆ parse() [2/3]

bool nim_cpp_wrapper_util::Json::Reader::parse ( const std::string &  document,
Value root,
bool  collectComments = true 
)

Read a Value from a JSON document.

参数
documentUTF-8 encoded string containing the document to read.
[out]rootContains the root value of the document if it was successfully parsed.
collectCommentstrue to collect comment and allow writing them back during serialization, false to discard comments. This parameter is ignored if Features::allowComments_ is false.
返回
true if the document was successfully parsed, false if an error occurred.

◆ parse() [3/3]

bool nim_cpp_wrapper_util::Json::Reader::parse ( IStream is,
Value root,
bool  collectComments = true 
)

◆ pushError() [1/2]

bool nim_cpp_wrapper_util::Json::Reader::pushError ( const Value value,
const String message 
)

Add a semantic error message.

参数
valueJSON Value location associated with the error
messageThe error message.
返回
true if the error was successfully added, false if the Value offset exceeds the document size.

◆ pushError() [2/2]

bool nim_cpp_wrapper_util::Json::Reader::pushError ( const Value value,
const String message,
const Value extra 
)

Add a semantic error message with extra context.

参数
valueJSON Value location associated with the error
messageThe error message.
extraAdditional JSON Value location to contextualize the error
返回
true if the error was successfully added, false if either Value offset exceeds the document size.

◆ readArray()

bool nim_cpp_wrapper_util::Json::Reader::readArray ( Token token)
private

◆ readComment()

bool nim_cpp_wrapper_util::Json::Reader::readComment ( )
private

◆ readCppStyleComment()

bool nim_cpp_wrapper_util::Json::Reader::readCppStyleComment ( )
private

◆ readCStyleComment()

bool nim_cpp_wrapper_util::Json::Reader::readCStyleComment ( )
private

◆ readNumber()

void nim_cpp_wrapper_util::Json::Reader::readNumber ( )
private

◆ readObject()

bool nim_cpp_wrapper_util::Json::Reader::readObject ( Token token)
private

◆ readString()

bool nim_cpp_wrapper_util::Json::Reader::readString ( )
private

◆ readToken()

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

◆ readValue()

bool nim_cpp_wrapper_util::Json::Reader::readValue ( )
private

◆ recoverFromError()

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

◆ skipCommentTokens()

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

◆ skipSpaces()

void nim_cpp_wrapper_util::Json::Reader::skipSpaces ( )
private

◆ skipUntilSpace()

void nim_cpp_wrapper_util::Json::Reader::skipUntilSpace ( )
private

类成员变量说明

◆ begin_

Location nim_cpp_wrapper_util::Json::Reader::begin_ {}
private

◆ collectComments_

bool nim_cpp_wrapper_util::Json::Reader::collectComments_ {}
private

◆ commentsBefore_

String nim_cpp_wrapper_util::Json::Reader::commentsBefore_
private

◆ current_

Location nim_cpp_wrapper_util::Json::Reader::current_ {}
private

◆ document_

String nim_cpp_wrapper_util::Json::Reader::document_
private

◆ end_

Location nim_cpp_wrapper_util::Json::Reader::end_ {}
private

◆ errors_

Errors nim_cpp_wrapper_util::Json::Reader::errors_
private

◆ features_

Features nim_cpp_wrapper_util::Json::Reader::features_
private

◆ lastValue_

Value* nim_cpp_wrapper_util::Json::Reader::lastValue_ {}
private

◆ lastValueEnd_

Location nim_cpp_wrapper_util::Json::Reader::lastValueEnd_ {}
private

◆ nodes_

Nodes nim_cpp_wrapper_util::Json::Reader::nodes_
private

该类的文档由以下文件生成: