mirror of
https://github.com/Tencent/rapidjson.git
synced 2025-03-09 19:24:23 +01:00
GenericDocument: add implicit conversion to ParseResult
To simplify the error handling, this commit adds an implicit conversion of GenericDocument to ParseResult, allowing code like (already in the documentation): ParseResult ok = doc.Parse(json); if (!ok) // ...
This commit is contained in:
parent
8ec389f167
commit
98959e2820
@ -1986,6 +1986,17 @@ public:
|
||||
//! Get the position of last parsing error in input, 0 otherwise.
|
||||
size_t GetErrorOffset() const { return parseResult_.Offset(); }
|
||||
|
||||
//! Implicit conversion to get the last parse result
|
||||
/*! \return \ref ParseResult of the last parse operation
|
||||
|
||||
\code
|
||||
Document doc;
|
||||
ParseResult ok = doc.Parse(json);
|
||||
if (!ok)
|
||||
printf( "JSON parse error: %s (%u)\n", GetParseError_En(ok.Code()), ok.Offset());
|
||||
\endcode
|
||||
*/
|
||||
operator ParseResult() const { return parseResult_; }
|
||||
//!@}
|
||||
|
||||
//! Get the allocator of this document.
|
||||
|
Loading…
x
Reference in New Issue
Block a user