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
73df6c93
Commit
73df6c93
authored
Jul 10, 2017
by
Milo Yip
Committed by
GitHub
Jul 10, 2017
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #1008 from pah/fixes/989-parseresult
ParseResult: improve bool conversion and add operator!=
parents
4da20e21
14218aeb
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
22 additions
and
3 deletions
+22
-3
error.h
include/rapidjson/error/error.h
+8
-2
documenttest.cpp
test/unittest/documenttest.cpp
+14
-1
No files found.
include/rapidjson/error/error.h
View file @
73df6c93
...
...
@@ -104,6 +104,8 @@ enum ParseErrorCode {
\see GenericReader::Parse, GenericDocument::Parse
*/
struct
ParseResult
{
//!! Unspecified boolean type
typedef
bool
(
ParseResult
::*
BooleanType
)()
const
;
public
:
//! Default constructor, no error.
ParseResult
()
:
code_
(
kParseErrorNone
),
offset_
(
0
)
{}
...
...
@@ -115,8 +117,8 @@ public:
//! Get the error offset, if \ref IsError(), 0 otherwise.
size_t
Offset
()
const
{
return
offset_
;
}
//!
C
onversion to \c bool, returns \c true, iff !\ref IsError().
operator
bool
()
const
{
return
!
IsError
()
;
}
//!
Explicit c
onversion to \c bool, returns \c true, iff !\ref IsError().
operator
BooleanType
()
const
{
return
!
IsError
()
?
&
ParseResult
::
IsError
:
NULL
;
}
//! Whether the result is an error.
bool
IsError
()
const
{
return
code_
!=
kParseErrorNone
;
}
...
...
@@ -124,6 +126,10 @@ public:
bool
operator
==
(
ParseErrorCode
code
)
const
{
return
code_
==
code
;
}
friend
bool
operator
==
(
ParseErrorCode
code
,
const
ParseResult
&
err
)
{
return
code
==
err
.
code_
;
}
bool
operator
!=
(
const
ParseResult
&
that
)
const
{
return
!
(
*
this
==
that
);
}
bool
operator
!=
(
ParseErrorCode
code
)
const
{
return
!
(
*
this
==
code
);
}
friend
bool
operator
!=
(
ParseErrorCode
code
,
const
ParseResult
&
err
)
{
return
err
!=
code
;
}
//! Reset error code.
void
Clear
()
{
Set
(
kParseErrorNone
);
}
//! Update error code and offset.
...
...
test/unittest/documenttest.cpp
View file @
73df6c93
...
...
@@ -128,8 +128,14 @@ TEST(Document, UnchangedOnParseError) {
Document
doc
;
doc
.
SetArray
().
PushBack
(
0
,
doc
.
GetAllocator
());
ParseResult
noError
;
EXPECT_TRUE
(
noError
);
ParseResult
err
=
doc
.
Parse
(
"{]"
);
EXPECT_TRUE
(
doc
.
HasParseError
());
EXPECT_NE
(
err
,
noError
);
EXPECT_NE
(
err
.
Code
(),
noError
);
EXPECT_NE
(
noError
,
doc
.
GetParseError
());
EXPECT_EQ
(
err
.
Code
(),
doc
.
GetParseError
());
EXPECT_EQ
(
err
.
Offset
(),
doc
.
GetErrorOffset
());
EXPECT_TRUE
(
doc
.
IsArray
());
...
...
@@ -138,6 +144,9 @@ TEST(Document, UnchangedOnParseError) {
err
=
doc
.
Parse
(
"{}"
);
EXPECT_FALSE
(
doc
.
HasParseError
());
EXPECT_FALSE
(
err
.
IsError
());
EXPECT_TRUE
(
err
);
EXPECT_EQ
(
err
,
noError
);
EXPECT_EQ
(
err
.
Code
(),
noError
);
EXPECT_EQ
(
err
.
Code
(),
doc
.
GetParseError
());
EXPECT_EQ
(
err
.
Offset
(),
doc
.
GetErrorOffset
());
EXPECT_TRUE
(
doc
.
IsObject
());
...
...
@@ -488,15 +497,19 @@ TYPED_TEST(DocumentMove, MoveConstructorParseError) {
a
.
Parse
(
"{ 4 = 4]"
);
ParseResult
error
(
a
.
GetParseError
(),
a
.
GetErrorOffset
());
EXPECT_TRUE
(
a
.
HasParseError
());
EXPECT_NE
(
error
,
noError
);
EXPECT_NE
(
error
.
Code
(),
noError
);
EXPECT_NE
(
error
.
Code
(),
noError
.
Code
());
EXPECT_NE
(
error
.
Offset
(),
noError
.
Offset
());
D
b
(
std
::
move
(
a
));
EXPECT_FALSE
(
a
.
HasParseError
());
EXPECT_TRUE
(
b
.
HasParseError
());
EXPECT_EQ
(
a
.
GetParseError
(),
noError
);
EXPECT_EQ
(
a
.
GetParseError
(),
noError
.
Code
());
EXPECT_EQ
(
b
.
GetParseError
(),
error
.
Code
());
EXPECT_EQ
(
a
.
GetErrorOffset
(),
noError
.
Offset
());
EXPECT_EQ
(
b
.
GetParseError
(),
error
);
EXPECT_EQ
(
b
.
GetParseError
(),
error
.
Code
());
EXPECT_EQ
(
b
.
GetErrorOffset
(),
error
.
Offset
());
D
c
(
std
::
move
(
b
));
...
...
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