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
61461ec4
Commit
61461ec4
authored
Jul 05, 2013
by
Niels
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
- fixes from Harro
parent
23ada516
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
96 additions
and
13 deletions
+96
-13
JSON.cc
src/JSON.cc
+31
-6
JSON.h
src/JSON.h
+1
-1
JSON_test.cc
test/JSON_test.cc
+64
-6
No files found.
src/JSON.cc
View file @
61461ec4
...
...
@@ -643,6 +643,7 @@ std::string JSON::parser::parseString() {
const
size_t
length
=
p
-
_buffer
-
_pos
;
char
*
tmp
=
new
char
[
length
+
1
];
std
::
strncpy
(
tmp
,
_buffer
+
_pos
,
length
);
tmp
[
length
]
=
0
;
std
::
string
result
(
tmp
);
delete
[]
tmp
;
...
...
@@ -838,11 +839,11 @@ JSON::iterator::iterator(JSON* j) : _object(j), _vi(nullptr), _oi(nullptr) {
JSON
::
iterator
::
iterator
(
const
JSON
::
iterator
&
o
)
:
_object
(
o
.
_object
),
_vi
(
nullptr
),
_oi
(
nullptr
)
{
switch
(
_object
->
_type
)
{
case
(
array
):
{
_vi
=
new
std
::
vector
<
JSON
>::
iterator
(
static_cast
<
std
::
vector
<
JSON
>*>
(
_object
->
_payload
)
->
begin
(
));
_vi
=
new
std
::
vector
<
JSON
>::
iterator
(
*
(
o
.
_vi
));
break
;
}
case
(
object
):
{
_oi
=
new
std
::
map
<
std
::
string
,
JSON
>::
iterator
(
static_cast
<
std
::
map
<
std
::
string
,
JSON
>*>
(
_object
->
_payload
)
->
begin
(
));
_oi
=
new
std
::
map
<
std
::
string
,
JSON
>::
iterator
(
*
(
o
.
_oi
));
break
;
}
default
:
...
...
@@ -857,6 +858,18 @@ JSON::iterator::~iterator() {
JSON
::
iterator
&
JSON
::
iterator
::
operator
=
(
const
JSON
::
iterator
&
o
)
{
_object
=
o
.
_object
;
switch
(
_object
->
_type
)
{
case
(
array
):
{
_vi
=
new
std
::
vector
<
JSON
>::
iterator
(
*
(
o
.
_vi
));
break
;
}
case
(
object
):
{
_oi
=
new
std
::
map
<
std
::
string
,
JSON
>::
iterator
(
*
(
o
.
_oi
));
break
;
}
default
:
break
;
}
return
*
this
;
}
...
...
@@ -985,11 +998,11 @@ JSON::const_iterator::const_iterator(const JSON* j) : _object(j), _vi(nullptr),
JSON
::
const_iterator
::
const_iterator
(
const
JSON
::
const_iterator
&
o
)
:
_object
(
o
.
_object
),
_vi
(
nullptr
),
_oi
(
nullptr
)
{
switch
(
_object
->
_type
)
{
case
(
array
):
{
_vi
=
new
std
::
vector
<
JSON
>::
const_iterator
(
static_cast
<
std
::
vector
<
JSON
>*>
(
_object
->
_payload
)
->
begin
(
));
_vi
=
new
std
::
vector
<
JSON
>::
const_iterator
(
*
(
o
.
_vi
));
break
;
}
case
(
object
):
{
_oi
=
new
std
::
map
<
std
::
string
,
JSON
>::
const_iterator
(
static_cast
<
std
::
map
<
std
::
string
,
JSON
>*>
(
_object
->
_payload
)
->
begin
(
));
_oi
=
new
std
::
map
<
std
::
string
,
JSON
>::
const_iterator
(
*
(
o
.
_oi
));
break
;
}
default
:
...
...
@@ -1000,11 +1013,11 @@ JSON::const_iterator::const_iterator(const JSON::const_iterator& o) : _object(o.
JSON
::
const_iterator
::
const_iterator
(
const
JSON
::
iterator
&
o
)
:
_object
(
o
.
_object
),
_vi
(
nullptr
),
_oi
(
nullptr
)
{
switch
(
_object
->
_type
)
{
case
(
array
):
{
_vi
=
new
std
::
vector
<
JSON
>::
const_iterator
(
static_cast
<
std
::
vector
<
JSON
>*>
(
_object
->
_payload
)
->
begin
(
));
_vi
=
new
std
::
vector
<
JSON
>::
const_iterator
(
*
(
o
.
_vi
));
break
;
}
case
(
object
):
{
_oi
=
new
std
::
map
<
std
::
string
,
JSON
>::
const_iterator
(
static_cast
<
std
::
map
<
std
::
string
,
JSON
>*>
(
_object
->
_payload
)
->
begin
(
));
_oi
=
new
std
::
map
<
std
::
string
,
JSON
>::
const_iterator
(
*
(
o
.
_oi
));
break
;
}
default
:
...
...
@@ -1019,6 +1032,18 @@ JSON::const_iterator::~const_iterator() {
JSON
::
const_iterator
&
JSON
::
const_iterator
::
operator
=
(
const
JSON
::
const_iterator
&
o
)
{
_object
=
o
.
_object
;
switch
(
_object
->
_type
)
{
case
(
array
):
{
_vi
=
new
std
::
vector
<
JSON
>::
const_iterator
(
*
(
o
.
_vi
));
break
;
}
case
(
object
):
{
_oi
=
new
std
::
map
<
std
::
string
,
JSON
>::
const_iterator
(
*
(
o
.
_oi
));
break
;
}
default
:
break
;
}
return
*
this
;
}
...
...
src/JSON.h
View file @
61461ec4
...
...
@@ -6,8 +6,8 @@
#endif
// allow us to use "nullptr" everywhere
#ifndef nullptr
#include <cstddef>
#ifndef nullptr
#define nullptr NULL
#endif
...
...
test/JSON_test.cc
View file @
61461ec4
...
...
@@ -202,21 +202,79 @@ void test_array() {
#endif
// iterators
for
(
JSON
::
iterator
i
=
a
.
begin
();
i
!=
a
.
end
();
++
i
)
{
std
::
cerr
<<
*
i
<<
'\n'
;
{
size_t
count
=
0
;
for
(
JSON
::
iterator
i
=
a
.
begin
();
i
!=
a
.
end
();
++
i
)
{
std
::
cerr
<<
*
i
<<
'\n'
;
count
++
;
}
assert
(
count
==
a
.
size
());
}
{
/*
size_t count = 0;
for (JSON::const_iterator i = a.begin(); i != a.end(); ++i) {
std::cerr << *i << '\n';
count++;
}
assert(count == a.size());
*/
}
for
(
JSON
::
const_iterator
i
=
a
.
cbegin
();
i
!=
a
.
cend
();
++
i
)
{
std
::
cerr
<<
*
i
<<
'\n'
;
{
size_t
count
=
0
;
for
(
JSON
::
const_iterator
i
=
a
.
cbegin
();
i
!=
a
.
cend
();
++
i
)
{
std
::
cerr
<<
*
i
<<
'\n'
;
count
++
;
}
assert
(
count
==
a
.
size
());
}
#ifdef __cplusplus11
for
(
auto
element
:
a
)
{
std
::
cerr
<<
element
<<
'\n'
;
{
size_t
count
=
0
;
for
(
auto
element
:
a
)
{
std
::
cerr
<<
element
<<
'\n'
;
count
++
;
}
assert
(
count
==
a
.
size
());
}
#endif
{
JSON
::
iterator
i
;
size_t
count
=
0
;
for
(
i
=
a
.
begin
();
i
!=
a
.
end
();
++
i
)
{
std
::
cerr
<<
*
i
<<
'\n'
;
count
++
;
}
assert
(
count
==
a
.
size
());
}
{
/*
JSON::const_iterator i;
size_t count = 0;
for (i = a.begin(); i != a.end(); ++i) {
std::cerr << *i << '\n';
count++;
}
assert(count == a.size());
*/
}
{
JSON
::
const_iterator
i
;
size_t
count
=
0
;
for
(
i
=
a
.
cbegin
();
i
!=
a
.
cend
();
++
i
)
{
std
::
cerr
<<
*
i
<<
'\n'
;
count
++
;
}
assert
(
count
==
a
.
size
());
}
{
// get payload
std
::
vector
<
JSON
>*
array
=
static_cast
<
std
::
vector
<
JSON
>*>
(
a
.
data
());
assert
(
array
->
size
()
==
a
.
size
());
...
...
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