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
d035fa58
Commit
d035fa58
authored
Jul 04, 2013
by
Niels
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
- added missing headers
parent
ff41ca8f
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
10 additions
and
12 deletions
+10
-12
JSON.cc
src/JSON.cc
+10
-12
No files found.
src/JSON.cc
View file @
d035fa58
...
@@ -7,11 +7,9 @@
...
@@ -7,11 +7,9 @@
#include <iostream>
#include <iostream>
#include <streambuf>
#include <streambuf>
#include <sstream>
#include <sstream>
#ifndef __cplusplus11
#include <cstring>
#include <cstring>
#include <cstdlib>
#include <cstdlib>
#
endif
#
include <cstddef>
#ifdef __cplusplus11
#ifdef __cplusplus11
using
std
::
to_string
;
using
std
::
to_string
;
...
@@ -576,8 +574,8 @@ std::string JSON::_typename() const {
...
@@ -576,8 +574,8 @@ std::string JSON::_typename() const {
JSON
::
parser
::
parser
(
char
*
s
)
:
_pos
(
0
)
{
JSON
::
parser
::
parser
(
char
*
s
)
:
_pos
(
0
)
{
_buffer
=
new
char
[
strlen
(
s
)
+
1
];
_buffer
=
new
char
[
st
d
::
st
rlen
(
s
)
+
1
];
strcpy
(
_buffer
,
s
);
st
d
::
st
rcpy
(
_buffer
,
s
);
// read first character
// read first character
next
();
next
();
...
@@ -585,7 +583,7 @@ JSON::parser::parser(char* s) : _pos(0) {
...
@@ -585,7 +583,7 @@ JSON::parser::parser(char* s) : _pos(0) {
JSON
::
parser
::
parser
(
std
::
string
&
s
)
:
_pos
(
0
)
{
JSON
::
parser
::
parser
(
std
::
string
&
s
)
:
_pos
(
0
)
{
_buffer
=
new
char
[
s
.
length
()
+
1
];
_buffer
=
new
char
[
s
.
length
()
+
1
];
strcpy
(
_buffer
,
s
.
c_str
());
st
d
::
st
rcpy
(
_buffer
,
s
.
c_str
());
// read first character
// read first character
next
();
next
();
...
@@ -626,7 +624,7 @@ bool JSON::parser::next() {
...
@@ -626,7 +624,7 @@ bool JSON::parser::next() {
std
::
string
JSON
::
parser
::
parseString
()
{
std
::
string
JSON
::
parser
::
parseString
()
{
// get position of closing quotes
// get position of closing quotes
char
*
p
=
strchr
(
_buffer
+
_pos
,
'\"'
);
char
*
p
=
st
d
::
st
rchr
(
_buffer
+
_pos
,
'\"'
);
// if the closing quotes are escaped (viz. *(p-1) is '\\'),
// if the closing quotes are escaped (viz. *(p-1) is '\\'),
// we continue looking for the "right" quotes
// we continue looking for the "right" quotes
...
@@ -634,7 +632,7 @@ std::string JSON::parser::parseString() {
...
@@ -634,7 +632,7 @@ std::string JSON::parser::parseString() {
// length of the string so far
// length of the string so far
const
size_t
length
=
p
-
_buffer
-
_pos
;
const
size_t
length
=
p
-
_buffer
-
_pos
;
// continue checking after escaped quote
// continue checking after escaped quote
p
=
strchr
(
_buffer
+
_pos
+
length
+
1
,
'\"'
);
p
=
st
d
::
st
rchr
(
_buffer
+
_pos
+
length
+
1
,
'\"'
);
}
}
// check if closing quotes were found
// check if closing quotes were found
...
@@ -645,7 +643,7 @@ std::string JSON::parser::parseString() {
...
@@ -645,7 +643,7 @@ std::string JSON::parser::parseString() {
// copy string to return value
// copy string to return value
const
size_t
length
=
p
-
_buffer
-
_pos
;
const
size_t
length
=
p
-
_buffer
-
_pos
;
char
*
tmp
=
new
char
[
length
+
1
];
char
*
tmp
=
new
char
[
length
+
1
];
strncpy
(
tmp
,
_buffer
+
_pos
,
length
);
st
d
::
st
rncpy
(
tmp
,
_buffer
+
_pos
,
length
);
std
::
string
result
(
tmp
);
std
::
string
result
(
tmp
);
delete
[]
tmp
;
delete
[]
tmp
;
...
@@ -659,7 +657,7 @@ std::string JSON::parser::parseString() {
...
@@ -659,7 +657,7 @@ std::string JSON::parser::parseString() {
}
}
void
JSON
::
parser
::
parseTrue
()
{
void
JSON
::
parser
::
parseTrue
()
{
if
(
strncmp
(
_buffer
+
_pos
,
"rue"
,
3
))
{
if
(
st
d
::
st
rncmp
(
_buffer
+
_pos
,
"rue"
,
3
))
{
error
(
"expected true"
);
error
(
"expected true"
);
}
}
...
@@ -670,7 +668,7 @@ void JSON::parser::parseTrue() {
...
@@ -670,7 +668,7 @@ void JSON::parser::parseTrue() {
}
}
void
JSON
::
parser
::
parseFalse
()
{
void
JSON
::
parser
::
parseFalse
()
{
if
(
strncmp
(
_buffer
+
_pos
,
"alse"
,
4
))
{
if
(
st
d
::
st
rncmp
(
_buffer
+
_pos
,
"alse"
,
4
))
{
error
(
"expected false"
);
error
(
"expected false"
);
}
}
...
@@ -681,7 +679,7 @@ void JSON::parser::parseFalse() {
...
@@ -681,7 +679,7 @@ void JSON::parser::parseFalse() {
}
}
void
JSON
::
parser
::
parseNull
()
{
void
JSON
::
parser
::
parseNull
()
{
if
(
strncmp
(
_buffer
+
_pos
,
"ull"
,
3
))
{
if
(
st
d
::
st
rncmp
(
_buffer
+
_pos
,
"ull"
,
3
))
{
error
(
"expected null"
);
error
(
"expected 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