Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
J
json
Project
Overview
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
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Chen Yisong
json
Commits
19043d20
Commit
19043d20
authored
Jan 13, 2015
by
Niels
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
this should fix #28
parent
d47b0e74
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
189 additions
and
27 deletions
+189
-27
Makefile.am
Makefile.am
+3
-1
json.h
header_only/json.h
+81
-11
json.cc
src/json.cc
+81
-11
json_unit.cc
test/json_unit.cc
+24
-4
No files found.
Makefile.am
View file @
19043d20
...
@@ -34,6 +34,8 @@ parser:
...
@@ -34,6 +34,8 @@ parser:
make
CXXFLAGS
=
""
json_parser
make
CXXFLAGS
=
""
json_parser
header_only/json.h
:
$(CORE_SOURCES)
header_only/json.h
:
$(CORE_SOURCES)
cat
$(CORE_SOURCES)
|
$(SED)
's/#include "json.h"//'
>
header_only/json.h
$(AM_V_GEN)
$(AM_V_at)
mkdir
-p
header_only
$(AM_V_at)
cat
$(CORE_SOURCES)
|
$(SED)
's/#include "json.h"//'
>
header_only/json.h
BUILT_SOURCES
=
header_only/json.h
BUILT_SOURCES
=
header_only/json.h
header_only/json.h
View file @
19043d20
...
@@ -1898,13 +1898,27 @@ json::iterator::iterator(json* j) : object_(j)
...
@@ -1898,13 +1898,27 @@ json::iterator::iterator(json* j) : object_(j)
{
{
if
(
object_
->
type_
==
json
::
value_type
::
array
)
if
(
object_
->
type_
==
json
::
value_type
::
array
)
{
{
if
(
object_
->
empty
())
{
object_
=
nullptr
;
}
else
{
vi_
=
new
array_t
::
iterator
(
object_
->
value_
.
array
->
begin
());
vi_
=
new
array_t
::
iterator
(
object_
->
value_
.
array
->
begin
());
}
}
if
(
object_
->
type_
==
json
::
value_type
::
object
)
}
else
if
(
object_
->
type_
==
json
::
value_type
::
object
)
{
if
(
object_
->
empty
())
{
object_
=
nullptr
;
}
else
{
{
oi_
=
new
object_t
::
iterator
(
object_
->
value_
.
object
->
begin
());
oi_
=
new
object_t
::
iterator
(
object_
->
value_
.
object
->
begin
());
}
}
}
}
}
}
}
json
::
iterator
::
iterator
(
const
json
::
iterator
&
o
)
:
object_
(
o
.
object_
)
json
::
iterator
::
iterator
(
const
json
::
iterator
&
o
)
:
object_
(
o
.
object_
)
...
@@ -1913,11 +1927,25 @@ json::iterator::iterator(const json::iterator& o) : object_(o.object_)
...
@@ -1913,11 +1927,25 @@ json::iterator::iterator(const json::iterator& o) : object_(o.object_)
{
{
if
(
object_
->
type_
==
json
::
value_type
::
array
)
if
(
object_
->
type_
==
json
::
value_type
::
array
)
{
{
vi_
=
new
array_t
::
iterator
(
*
(
o
.
vi_
));
if
(
object_
->
empty
())
{
object_
=
nullptr
;
}
}
if
(
object_
->
type_
==
json
::
value_type
::
object
)
else
{
vi_
=
new
array_t
::
iterator
(
object_
->
value_
.
array
->
begin
());
}
}
else
if
(
object_
->
type_
==
json
::
value_type
::
object
)
{
{
oi_
=
new
object_t
::
iterator
(
*
(
o
.
oi_
));
if
(
object_
->
empty
())
{
object_
=
nullptr
;
}
else
{
oi_
=
new
object_t
::
iterator
(
object_
->
value_
.
object
->
begin
());
}
}
}
}
}
}
}
...
@@ -2091,13 +2119,27 @@ json::const_iterator::const_iterator(const json* j) : object_(j)
...
@@ -2091,13 +2119,27 @@ json::const_iterator::const_iterator(const json* j) : object_(j)
{
{
if
(
object_
->
type_
==
json
::
value_type
::
array
)
if
(
object_
->
type_
==
json
::
value_type
::
array
)
{
{
if
(
object_
->
empty
())
{
object_
=
nullptr
;
}
else
{
vi_
=
new
array_t
::
const_iterator
(
object_
->
value_
.
array
->
begin
());
vi_
=
new
array_t
::
const_iterator
(
object_
->
value_
.
array
->
begin
());
}
}
if
(
object_
->
type_
==
json
::
value_type
::
object
)
}
else
if
(
object_
->
type_
==
json
::
value_type
::
object
)
{
if
(
object_
->
empty
())
{
object_
=
nullptr
;
}
else
{
{
oi_
=
new
object_t
::
const_iterator
(
object_
->
value_
.
object
->
begin
());
oi_
=
new
object_t
::
const_iterator
(
object_
->
value_
.
object
->
begin
());
}
}
}
}
}
}
}
json
::
const_iterator
::
const_iterator
(
const
json
::
const_iterator
&
o
)
:
object_
(
o
.
object_
)
json
::
const_iterator
::
const_iterator
(
const
json
::
const_iterator
&
o
)
:
object_
(
o
.
object_
)
...
@@ -2106,11 +2148,25 @@ json::const_iterator::const_iterator(const json::const_iterator& o) : object_(o.
...
@@ -2106,11 +2148,25 @@ json::const_iterator::const_iterator(const json::const_iterator& o) : object_(o.
{
{
if
(
object_
->
type_
==
json
::
value_type
::
array
)
if
(
object_
->
type_
==
json
::
value_type
::
array
)
{
{
vi_
=
new
array_t
::
const_iterator
(
*
(
o
.
vi_
));
if
(
object_
->
empty
())
{
object_
=
nullptr
;
}
}
if
(
object_
->
type_
==
json
::
value_type
::
object
)
else
{
{
oi_
=
new
object_t
::
const_iterator
(
*
(
o
.
oi_
));
vi_
=
new
array_t
::
const_iterator
(
object_
->
value_
.
array
->
begin
());
}
}
else
if
(
object_
->
type_
==
json
::
value_type
::
object
)
{
if
(
object_
->
empty
())
{
object_
=
nullptr
;
}
else
{
oi_
=
new
object_t
::
const_iterator
(
object_
->
value_
.
object
->
begin
());
}
}
}
}
}
}
}
...
@@ -2121,11 +2177,25 @@ json::const_iterator::const_iterator(const json::iterator& o) : object_(o.object
...
@@ -2121,11 +2177,25 @@ json::const_iterator::const_iterator(const json::iterator& o) : object_(o.object
{
{
if
(
object_
->
type_
==
json
::
value_type
::
array
)
if
(
object_
->
type_
==
json
::
value_type
::
array
)
{
{
vi_
=
new
array_t
::
const_iterator
(
*
(
o
.
vi_
));
if
(
object_
->
empty
())
{
object_
=
nullptr
;
}
}
if
(
object_
->
type_
==
json
::
value_type
::
object
)
else
{
{
oi_
=
new
object_t
::
const_iterator
(
*
(
o
.
oi_
));
vi_
=
new
array_t
::
const_iterator
(
object_
->
value_
.
array
->
begin
());
}
}
else
if
(
object_
->
type_
==
json
::
value_type
::
object
)
{
if
(
object_
->
empty
())
{
object_
=
nullptr
;
}
else
{
oi_
=
new
object_t
::
const_iterator
(
object_
->
value_
.
object
->
begin
());
}
}
}
}
}
}
}
...
...
src/json.cc
View file @
19043d20
...
@@ -1446,13 +1446,27 @@ json::iterator::iterator(json* j) : object_(j)
...
@@ -1446,13 +1446,27 @@ json::iterator::iterator(json* j) : object_(j)
{
{
if
(
object_
->
type_
==
json
::
value_type
::
array
)
if
(
object_
->
type_
==
json
::
value_type
::
array
)
{
{
if
(
object_
->
empty
())
{
object_
=
nullptr
;
}
else
{
vi_
=
new
array_t
::
iterator
(
object_
->
value_
.
array
->
begin
());
vi_
=
new
array_t
::
iterator
(
object_
->
value_
.
array
->
begin
());
}
}
if
(
object_
->
type_
==
json
::
value_type
::
object
)
}
else
if
(
object_
->
type_
==
json
::
value_type
::
object
)
{
if
(
object_
->
empty
())
{
object_
=
nullptr
;
}
else
{
{
oi_
=
new
object_t
::
iterator
(
object_
->
value_
.
object
->
begin
());
oi_
=
new
object_t
::
iterator
(
object_
->
value_
.
object
->
begin
());
}
}
}
}
}
}
}
json
::
iterator
::
iterator
(
const
json
::
iterator
&
o
)
:
object_
(
o
.
object_
)
json
::
iterator
::
iterator
(
const
json
::
iterator
&
o
)
:
object_
(
o
.
object_
)
...
@@ -1461,11 +1475,25 @@ json::iterator::iterator(const json::iterator& o) : object_(o.object_)
...
@@ -1461,11 +1475,25 @@ json::iterator::iterator(const json::iterator& o) : object_(o.object_)
{
{
if
(
object_
->
type_
==
json
::
value_type
::
array
)
if
(
object_
->
type_
==
json
::
value_type
::
array
)
{
{
vi_
=
new
array_t
::
iterator
(
*
(
o
.
vi_
));
if
(
object_
->
empty
())
{
object_
=
nullptr
;
}
}
if
(
object_
->
type_
==
json
::
value_type
::
object
)
else
{
vi_
=
new
array_t
::
iterator
(
object_
->
value_
.
array
->
begin
());
}
}
else
if
(
object_
->
type_
==
json
::
value_type
::
object
)
{
{
oi_
=
new
object_t
::
iterator
(
*
(
o
.
oi_
));
if
(
object_
->
empty
())
{
object_
=
nullptr
;
}
else
{
oi_
=
new
object_t
::
iterator
(
object_
->
value_
.
object
->
begin
());
}
}
}
}
}
}
}
...
@@ -1639,13 +1667,27 @@ json::const_iterator::const_iterator(const json* j) : object_(j)
...
@@ -1639,13 +1667,27 @@ json::const_iterator::const_iterator(const json* j) : object_(j)
{
{
if
(
object_
->
type_
==
json
::
value_type
::
array
)
if
(
object_
->
type_
==
json
::
value_type
::
array
)
{
{
if
(
object_
->
empty
())
{
object_
=
nullptr
;
}
else
{
vi_
=
new
array_t
::
const_iterator
(
object_
->
value_
.
array
->
begin
());
vi_
=
new
array_t
::
const_iterator
(
object_
->
value_
.
array
->
begin
());
}
}
if
(
object_
->
type_
==
json
::
value_type
::
object
)
}
else
if
(
object_
->
type_
==
json
::
value_type
::
object
)
{
if
(
object_
->
empty
())
{
object_
=
nullptr
;
}
else
{
{
oi_
=
new
object_t
::
const_iterator
(
object_
->
value_
.
object
->
begin
());
oi_
=
new
object_t
::
const_iterator
(
object_
->
value_
.
object
->
begin
());
}
}
}
}
}
}
}
json
::
const_iterator
::
const_iterator
(
const
json
::
const_iterator
&
o
)
:
object_
(
o
.
object_
)
json
::
const_iterator
::
const_iterator
(
const
json
::
const_iterator
&
o
)
:
object_
(
o
.
object_
)
...
@@ -1654,11 +1696,25 @@ json::const_iterator::const_iterator(const json::const_iterator& o) : object_(o.
...
@@ -1654,11 +1696,25 @@ json::const_iterator::const_iterator(const json::const_iterator& o) : object_(o.
{
{
if
(
object_
->
type_
==
json
::
value_type
::
array
)
if
(
object_
->
type_
==
json
::
value_type
::
array
)
{
{
vi_
=
new
array_t
::
const_iterator
(
*
(
o
.
vi_
));
if
(
object_
->
empty
())
{
object_
=
nullptr
;
}
}
if
(
object_
->
type_
==
json
::
value_type
::
object
)
else
{
{
oi_
=
new
object_t
::
const_iterator
(
*
(
o
.
oi_
));
vi_
=
new
array_t
::
const_iterator
(
object_
->
value_
.
array
->
begin
());
}
}
else
if
(
object_
->
type_
==
json
::
value_type
::
object
)
{
if
(
object_
->
empty
())
{
object_
=
nullptr
;
}
else
{
oi_
=
new
object_t
::
const_iterator
(
object_
->
value_
.
object
->
begin
());
}
}
}
}
}
}
}
...
@@ -1669,11 +1725,25 @@ json::const_iterator::const_iterator(const json::iterator& o) : object_(o.object
...
@@ -1669,11 +1725,25 @@ json::const_iterator::const_iterator(const json::iterator& o) : object_(o.object
{
{
if
(
object_
->
type_
==
json
::
value_type
::
array
)
if
(
object_
->
type_
==
json
::
value_type
::
array
)
{
{
vi_
=
new
array_t
::
const_iterator
(
*
(
o
.
vi_
));
if
(
object_
->
empty
())
{
object_
=
nullptr
;
}
}
if
(
object_
->
type_
==
json
::
value_type
::
object
)
else
{
{
oi_
=
new
object_t
::
const_iterator
(
*
(
o
.
oi_
));
vi_
=
new
array_t
::
const_iterator
(
object_
->
value_
.
array
->
begin
());
}
}
else
if
(
object_
->
type_
==
json
::
value_type
::
object
)
{
if
(
object_
->
empty
())
{
object_
=
nullptr
;
}
else
{
oi_
=
new
object_t
::
const_iterator
(
object_
->
value_
.
object
->
begin
());
}
}
}
}
}
}
}
...
...
test/json_unit.cc
View file @
19043d20
...
@@ -20,8 +20,8 @@ TEST_CASE("array")
...
@@ -20,8 +20,8 @@ TEST_CASE("array")
CHECK
(
j
.
dump
()
==
"[]"
);
CHECK
(
j
.
dump
()
==
"[]"
);
// iterators
// iterators
CHECK
(
j
.
begin
()
!
=
j
.
end
());
CHECK
(
j
.
begin
()
=
=
j
.
end
());
CHECK
(
j
.
cbegin
()
!
=
j
.
cend
());
CHECK
(
j
.
cbegin
()
=
=
j
.
cend
());
// container members
// container members
CHECK
(
j
.
size
()
==
0
);
CHECK
(
j
.
size
()
==
0
);
...
@@ -291,6 +291,16 @@ TEST_CASE("array")
...
@@ -291,6 +291,16 @@ TEST_CASE("array")
json
j_should_be_an_array
=
{
{
"foo"
,
"bar"
},
{
"baz"
,
"bat"
}
};
json
j_should_be_an_array
=
{
{
"foo"
,
"bar"
},
{
"baz"
,
"bat"
}
};
CHECK
(
j_should_be_an_array
.
type
()
==
json
::
value_type
::
object
);
CHECK
(
j_should_be_an_array
.
type
()
==
json
::
value_type
::
object
);
}
}
SECTION
(
"Iterators and empty arrays"
)
{
json
j
(
json
::
value_type
::
array
);
for
(
json
::
iterator
it
=
j
.
begin
();
it
!=
j
.
end
();
++
it
)
{}
for
(
json
::
const_iterator
it
=
j
.
begin
();
it
!=
j
.
end
();
++
it
)
{}
for
(
json
::
const_iterator
it
=
j
.
cbegin
();
it
!=
j
.
cend
();
++
it
)
{}
for
(
auto
el
:
j
)
{}
for
(
const
auto
el
:
j
)
{}
}
}
}
TEST_CASE
(
"object"
)
TEST_CASE
(
"object"
)
...
@@ -308,8 +318,8 @@ TEST_CASE("object")
...
@@ -308,8 +318,8 @@ TEST_CASE("object")
CHECK
(
j
.
dump
()
==
"{}"
);
CHECK
(
j
.
dump
()
==
"{}"
);
// iterators
// iterators
CHECK
(
j
.
begin
()
!
=
j
.
end
());
CHECK
(
j
.
begin
()
=
=
j
.
end
());
CHECK
(
j
.
cbegin
()
!
=
j
.
cend
());
CHECK
(
j
.
cbegin
()
=
=
j
.
cend
());
// container members
// container members
CHECK
(
j
.
size
()
==
0
);
CHECK
(
j
.
size
()
==
0
);
...
@@ -674,6 +684,16 @@ TEST_CASE("object")
...
@@ -674,6 +684,16 @@ TEST_CASE("object")
CHECK
(
element
.
get
<
int
>
()
>=
0
);
CHECK
(
element
.
get
<
int
>
()
>=
0
);
}
}
}
}
SECTION
(
"Iterators and empty objects"
)
{
json
j
(
json
::
value_type
::
object
);
for
(
json
::
iterator
it
=
j
.
begin
();
it
!=
j
.
end
();
++
it
)
{}
for
(
json
::
const_iterator
it
=
j
.
begin
();
it
!=
j
.
end
();
++
it
)
{}
for
(
json
::
const_iterator
it
=
j
.
cbegin
();
it
!=
j
.
cend
();
++
it
)
{}
for
(
auto
el
:
j
)
{}
for
(
const
auto
el
:
j
)
{}
}
}
}
TEST_CASE
(
"null"
)
TEST_CASE
(
"null"
)
...
...
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