Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in / Register
Toggle navigation
R
rapidjson
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Packages
Packages
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
submodule
rapidjson
Commits
418a5829
Commit
418a5829
authored
Jul 09, 2014
by
Philipp A. Hartmann
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
update documentation of ParseResult and related functions
parent
2fcb9997
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
27 additions
and
3 deletions
+27
-3
document.h
include/rapidjson/document.h
+3
-3
error.h
include/rapidjson/error/error.h
+21
-0
reader.h
include/rapidjson/reader.h
+3
-0
No files found.
include/rapidjson/document.h
View file @
418a5829
...
...
@@ -1326,13 +1326,13 @@ public:
//!@name Handling parse errors
//!@{
//! Whether a parse error
w
as occured in the last parsing.
//! Whether a parse error
h
as occured in the last parsing.
bool
HasParseError
()
const
{
return
parseResult_
.
IsError
();
}
//! Get the
message of parsing error
.
//! Get the
\ref ParseErrorCode of last parsing
.
ParseErrorCode
GetParseError
()
const
{
return
parseResult_
.
Code
();
}
//! Get the
offset in character of the parsing error
.
//! Get the
position of last parsing error in input, 0 otherwise
.
size_t
GetErrorOffset
()
const
{
return
parseResult_
.
Offset
();
}
//!@}
...
...
include/rapidjson/error/error.h
View file @
418a5829
...
...
@@ -59,22 +59,43 @@ enum ParseErrorCode {
kParseErrorNumberMissExponent
//!< Miss exponent in number.
};
//! Result of parsing (wraps ParseErrorCode)
/*!
\code
Document doc;
ParseResult ok = doc.Parse("[42]");
if (!ok) {
fprintf(stderr, "JSON parse error: %s (%u)",
GetParseError_En(ok.Code()), ok.Offset());
exit(EXIT_FAILURE);
}
\endcode
\see GenericReader::Parse, GenericDocument::Parse
*/
struct
ParseResult
{
//! Default constructor, no error.
ParseResult
()
:
code_
(
kParseErrorNone
),
offset_
(
0
)
{}
//! Constructor to set an error.
ParseResult
(
ParseErrorCode
code
,
size_t
offset
)
:
code_
(
code
),
offset_
(
offset
)
{}
//! Get the error code.
ParseErrorCode
Code
()
const
{
return
code_
;
}
//! Get the error offset, if \ref IsError(), 0 otherwise.
size_t
Offset
()
const
{
return
offset_
;
}
//! Conversion to \c bool, returns \c true, iff !\ref IsError().
operator
bool
()
const
{
return
!
IsError
();
}
//! Whether the result is an error.
bool
IsError
()
const
{
return
code_
!=
kParseErrorNone
;
}
bool
operator
==
(
const
ParseResult
&
that
)
const
{
return
code_
==
that
.
code_
;
}
bool
operator
==
(
ParseErrorCode
code
)
const
{
return
code_
==
code
;
}
friend
bool
operator
==
(
ParseErrorCode
code
,
const
ParseResult
&
err
)
{
return
code
==
err
.
code_
;
}
//! Reset error code.
void
Clear
()
{
Set
(
kParseErrorNone
);
}
//! Update error code and offset.
void
Set
(
ParseErrorCode
code
,
size_t
offset
=
0
)
{
code_
=
code
;
offset_
=
offset
;
}
private
:
...
...
include/rapidjson/reader.h
View file @
418a5829
...
...
@@ -324,10 +324,13 @@ public:
return
Parse
<
kParseDefaultFlags
>
(
is
,
handler
);
}
//! Whether a parse error has occured in the last parsing.
bool
HasParseError
()
const
{
return
parseResult_
.
IsError
();
}
//! Get the \ref ParseErrorCode of last parsing.
ParseErrorCode
GetParseErrorCode
()
const
{
return
parseResult_
.
Code
();
}
//! Get the position of last parsing error in input, 0 otherwise.
size_t
GetErrorOffset
()
const
{
return
parseResult_
.
Offset
();
}
private
:
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment