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
e0c26e44
Commit
e0c26e44
authored
May 02, 2015
by
miloyip
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix the test, and refactor to simplify
parent
ae645a2c
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
32 additions
and
39 deletions
+32
-39
schema.h
include/rapidjson/schema.h
+30
-38
schematest.cpp
test/unittest/schematest.cpp
+2
-1
No files found.
include/rapidjson/schema.h
View file @
e0c26e44
...
...
@@ -66,14 +66,14 @@ public:
virtual
bool
BeginValue
(
Context
&
)
const
{
return
true
;
}
virtual
bool
Null
()
const
{
return
enum_
.
IsArray
()
?
CheckEnum
(
GenericValue
<
Encoding
>
().
Move
())
:
true
;
}
virtual
bool
Bool
(
bool
b
)
const
{
return
enum_
.
IsArray
()
?
CheckEnum
(
GenericValue
<
Encoding
>
(
b
).
Move
())
:
true
;
}
virtual
bool
Int
(
int
i
)
const
{
return
enum_
.
IsArray
()
?
CheckEnum
(
GenericValue
<
Encoding
>
(
i
).
Move
())
:
true
;
}
virtual
bool
Uint
(
unsigned
u
)
const
{
return
enum_
.
IsArray
()
?
CheckEnum
(
GenericValue
<
Encoding
>
(
u
).
Move
())
:
true
;
}
virtual
bool
Int64
(
int64_t
i
)
const
{
return
enum_
.
IsArray
()
?
CheckEnum
(
GenericValue
<
Encoding
>
(
i
).
Move
())
:
true
;
}
virtual
bool
Uint64
(
uint64_t
u
)
const
{
return
enum_
.
IsArray
()
?
CheckEnum
(
GenericValue
<
Encoding
>
(
u
).
Move
())
:
true
;
}
virtual
bool
Double
(
double
d
)
const
{
return
enum_
.
IsArray
()
?
CheckEnum
(
GenericValue
<
Encoding
>
(
d
).
Move
())
:
true
;
}
virtual
bool
String
(
const
Ch
*
s
,
SizeType
length
,
bool
)
const
{
return
enum_
.
IsArray
()
?
CheckEnum
(
GenericValue
<
Encoding
>
(
s
,
length
).
Move
())
:
true
;
}
virtual
bool
Null
()
const
{
return
!
enum_
.
IsArray
()
||
CheckEnum
(
GenericValue
<
Encoding
>
().
Move
())
;
}
virtual
bool
Bool
(
bool
b
)
const
{
return
!
enum_
.
IsArray
()
||
CheckEnum
(
GenericValue
<
Encoding
>
(
b
).
Move
())
;
}
virtual
bool
Int
(
int
i
)
const
{
return
!
enum_
.
IsArray
()
||
CheckEnum
(
GenericValue
<
Encoding
>
(
i
).
Move
())
;
}
virtual
bool
Uint
(
unsigned
u
)
const
{
return
!
enum_
.
IsArray
()
||
CheckEnum
(
GenericValue
<
Encoding
>
(
u
).
Move
())
;
}
virtual
bool
Int64
(
int64_t
i
)
const
{
return
!
enum_
.
IsArray
()
||
CheckEnum
(
GenericValue
<
Encoding
>
(
i
).
Move
())
;
}
virtual
bool
Uint64
(
uint64_t
u
)
const
{
return
!
enum_
.
IsArray
()
||
CheckEnum
(
GenericValue
<
Encoding
>
(
u
).
Move
())
;
}
virtual
bool
Double
(
double
d
)
const
{
return
!
enum_
.
IsArray
()
||
CheckEnum
(
GenericValue
<
Encoding
>
(
d
).
Move
())
;
}
virtual
bool
String
(
const
Ch
*
s
,
SizeType
length
,
bool
)
const
{
return
!
enum_
.
IsArray
()
||
CheckEnum
(
GenericValue
<
Encoding
>
(
s
,
length
).
Move
())
;
}
virtual
bool
StartObject
(
Context
&
)
const
{
return
true
;
}
virtual
bool
Key
(
Context
&
,
const
Ch
*
,
SizeType
,
bool
)
const
{
return
true
;
}
virtual
bool
EndObject
(
Context
&
,
SizeType
)
const
{
return
true
;
}
...
...
@@ -494,6 +494,9 @@ public:
return
BaseSchema
<
Encoding
>::
String
(
str
,
length
,
copy
)
&&
length
>=
minLength_
&&
length
<=
maxLength_
;
}
virtual
bool
StartObject
(
Context
&
)
const
{
return
false
;
}
virtual
bool
Key
(
Context
&
,
const
Ch
*
,
SizeType
,
bool
)
const
{
return
false
;
}
virtual
bool
EndObject
(
Context
&
,
SizeType
)
const
{
return
false
;
}
virtual
bool
StartArray
(
Context
&
)
const
{
return
true
;
}
virtual
bool
EndArray
(
Context
&
,
SizeType
)
const
{
return
true
;
}
...
...
@@ -787,6 +790,7 @@ template <typename Encoding, typename OutputHandler = BaseReaderHandler<Encoding
class
GenericSchemaValidator
{
public
:
typedef
typename
Encoding
::
Ch
Ch
;
//!< Character type derived from Encoding.
typedef
GenericSchema
<
Encoding
>
SchemaType
;
GenericSchemaValidator
(
const
Schema
&
schema
,
...
...
@@ -822,38 +826,21 @@ public:
documentStack_
.
Clear
();
};
bool
Null
()
{
return
BeginValue
()
&&
PopSchema
().
Null
()
?
outputHandler_
.
Null
()
:
false
;
}
bool
Bool
(
bool
b
)
{
return
BeginValue
()
&&
PopSchema
().
Bool
(
b
)
?
outputHandler_
.
Bool
(
b
)
:
false
;
}
bool
Int
(
int
i
)
{
return
BeginValue
()
&&
PopSchema
().
Int
(
i
)
?
outputHandler_
.
Int
(
i
)
:
false
;
}
bool
Uint
(
unsigned
u
)
{
return
BeginValue
()
&&
PopSchema
().
Uint
(
u
)
?
outputHandler_
.
Uint
(
u
)
:
false
;
}
bool
Int64
(
int64_t
i64
)
{
return
BeginValue
()
&&
PopSchema
().
Int64
(
i64
)
?
outputHandler_
.
Int64
(
i64
)
:
false
;
}
bool
Uint64
(
uint64_t
u64
)
{
return
BeginValue
()
&&
PopSchema
().
Uint64
(
u64
)
?
outputHandler_
.
Uint64
(
u64
)
:
false
;
}
bool
Double
(
double
d
)
{
return
BeginValue
()
&&
PopSchema
().
Double
(
d
)
?
outputHandler_
.
Double
(
d
)
:
false
;
}
bool
String
(
const
Ch
*
str
,
SizeType
length
,
bool
copy
)
{
return
BeginValue
()
&&
PopSchema
().
String
(
str
,
length
,
copy
)
?
outputHandler_
.
String
(
str
,
length
,
copy
)
:
false
;
}
bool
StartObject
()
{
return
BeginValue
()
&&
CurrentSchema
().
StartObject
(
CurrentContext
())
?
outputHandler_
.
StartObject
()
:
false
;
}
bool
Key
(
const
Ch
*
str
,
SizeType
len
,
bool
copy
)
{
return
CurrentSchema
().
Key
(
CurrentContext
(),
str
,
len
,
copy
)
?
outputHandler_
.
Key
(
str
,
len
,
copy
)
:
false
;
}
bool
Null
()
{
return
BeginValue
()
&&
CurrentSchema
().
Null
()
&&
EndValue
()
&&
outputHandler_
.
Null
();
}
bool
Bool
(
bool
b
)
{
return
BeginValue
()
&&
CurrentSchema
().
Bool
(
b
)
&&
EndValue
()
&&
outputHandler_
.
Bool
(
b
);
}
bool
Int
(
int
i
)
{
return
BeginValue
()
&&
CurrentSchema
().
Int
(
i
)
&&
EndValue
()
&&
outputHandler_
.
Int
(
i
);
}
bool
Uint
(
unsigned
u
)
{
return
BeginValue
()
&&
CurrentSchema
().
Uint
(
u
)
&&
EndValue
()
&&
outputHandler_
.
Uint
(
u
);
}
bool
Int64
(
int64_t
i64
)
{
return
BeginValue
()
&&
CurrentSchema
().
Int64
(
i64
)
&&
EndValue
()
&&
outputHandler_
.
Int64
(
i64
);
}
bool
Uint64
(
uint64_t
u64
)
{
return
BeginValue
()
&&
CurrentSchema
().
Uint64
(
u64
)
&&
EndValue
()
&&
outputHandler_
.
Uint64
(
u64
);
}
bool
Double
(
double
d
)
{
return
BeginValue
()
&&
CurrentSchema
().
Double
(
d
)
&&
EndValue
()
&&
outputHandler_
.
Double
(
d
);
}
bool
String
(
const
Ch
*
str
,
SizeType
length
,
bool
copy
)
{
return
BeginValue
()
&&
CurrentSchema
().
String
(
str
,
length
,
copy
)
&&
EndValue
()
&&
outputHandler_
.
String
(
str
,
length
,
copy
);
}
bool
EndObject
(
SizeType
memberCount
)
{
if
(
CurrentSchema
().
EndObject
(
CurrentContext
(),
memberCount
))
{
PopSchema
();
return
outputHandler_
.
EndObject
(
memberCount
);
}
else
return
false
;
}
bool
StartObject
()
{
return
BeginValue
()
&&
CurrentSchema
().
StartObject
(
CurrentContext
())
&&
outputHandler_
.
StartObject
();
}
bool
Key
(
const
Ch
*
str
,
SizeType
len
,
bool
copy
)
{
return
CurrentSchema
().
Key
(
CurrentContext
(),
str
,
len
,
copy
)
&&
outputHandler_
.
Key
(
str
,
len
,
copy
);
}
bool
EndObject
(
SizeType
memberCount
)
{
return
CurrentSchema
().
EndObject
(
CurrentContext
(),
memberCount
)
&&
EndValue
()
&&
outputHandler_
.
EndObject
(
memberCount
);
}
bool
StartArray
()
{
return
BeginValue
()
&&
CurrentSchema
().
StartArray
(
CurrentContext
())
?
outputHandler_
.
StartArray
()
:
false
;
}
bool
EndArray
(
SizeType
elementCount
)
{
if
(
CurrentSchema
().
EndArray
(
CurrentContext
(),
elementCount
))
{
PopSchema
();
return
outputHandler_
.
EndArray
(
elementCount
);
}
else
return
false
;
}
bool
EndArray
(
SizeType
elementCount
)
{
return
CurrentSchema
().
EndArray
(
CurrentContext
(),
elementCount
)
&&
EndValue
()
&&
outputHandler_
.
EndArray
(
elementCount
);
}
private
:
typedef
BaseSchema
<
Encoding
>
BaseSchemaType
;
...
...
@@ -874,6 +861,11 @@ private:
}
}
bool
EndValue
()
{
PopSchema
();
return
true
;
}
void
PushSchema
(
const
BaseSchemaType
&
schema
)
{
*
schemaStack_
.
template
Push
<
Context
>
()
=
Context
(
&
schema
);
}
const
BaseSchemaType
&
PopSchema
()
{
return
*
schemaStack_
.
template
Pop
<
Context
>
(
1
)
->
schema
;
}
const
BaseSchemaType
&
CurrentSchema
()
{
return
*
schemaStack_
.
template
Top
<
Context
>
()
->
schema
;
}
...
...
@@ -881,7 +873,7 @@ private:
static
const
size_t
kDefaultSchemaStackCapacity
=
256
;
static
const
size_t
kDefaultDocumentStackCapacity
=
256
;
const
Schema
&
schema_
;
const
Schema
Type
&
schema_
;
BaseReaderHandler
<
Encoding
>
nullOutputHandler_
;
OutputHandler
&
outputHandler_
;
internal
::
Stack
<
Allocator
>
schemaStack_
;
//!< stack to store the current path of schema (BaseSchemaType *)
...
...
test/unittest/schematest.cpp
View file @
e0c26e44
...
...
@@ -431,7 +431,7 @@ TEST(SchemaValidator, ObjectInArray) {
sd
.
Parse
(
"{
\"
type
\"
:
\"
array
\"
,
\"
items
\"
: {
\"
type
\"
:
\"
string
\"
}}"
);
Schema
s
(
sd
);
VALIDATE
(
s
,
"[]"
,
true
);
VALIDATE
(
s
,
"[
\"
a
\"
]"
,
true
);
VALIDATE
(
s
,
"[1]"
,
false
);
VALIDATE
(
s
,
"[{}]"
,
false
);
}
\ No newline at end of file
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