Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
J
json
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Libraries
json
Commits
a8f62ca0
Commit
a8f62ca0
authored
Jul 15, 2013
by
Niels Lohmann
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
+ a fix for C++98
parent
9a567d9d
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
42 additions
and
12 deletions
+42
-12
src/JSON.cc
src/JSON.cc
+42
-12
No files found.
src/JSON.cc
View file @
a8f62ca0
...
...
@@ -21,12 +21,10 @@
// HELPER FUNCTION //
/////////////////////
#ifdef __cplusplus11
using
std
::
to_string
;
#else
inline
std
::
string
to_string
(
double
f
)
{
#ifndef __cplusplus11
inline
std
::
string
int_to_string
(
int
i
)
{
std
::
stringstream
s
;
s
<<
f
;
s
<<
i
;
return
s
.
str
();
}
#endif
...
...
@@ -321,11 +319,23 @@ const std::string JSON::toString() const {
}
case
(
number
):
{
return
to_string
(
_value
.
number
);
#ifdef __cplusplus11
return
std
::
to_string
(
_value
.
number
);
#else
std
::
stringstream
s
;
s
<<
_value
.
number
;
return
s
.
str
();
#endif
}
case
(
number_float
):
{
return
to_string
(
_value
.
number_float
);
#ifdef __cplusplus11
return
std
::
to_string
(
_value
.
number_float
);
#else
std
::
stringstream
s
;
s
<<
_value
.
number_float
;
return
s
.
str
();
#endif
}
case
(
array
):
{
...
...
@@ -435,11 +445,19 @@ JSON& JSON::operator[](int index) {
#endif
if
(
_type
!=
array
)
{
throw
std
::
runtime_error
(
"cannot add entry with index "
+
to_string
(
index
)
+
" to "
+
_typename
());
#ifdef __cplusplus11
throw
std
::
runtime_error
(
"cannot add entry with index "
+
std
::
to_string
(
index
)
+
" to "
+
_typename
());
#else
throw
std
::
runtime_error
(
"cannot add entry with index "
+
int_to_string
(
index
)
+
" to "
+
_typename
());
#endif
}
if
(
index
>=
(
int
)
_value
.
array
->
size
())
{
throw
std
::
runtime_error
(
"cannot access element at index "
+
to_string
(
index
));
#ifdef __cplusplus11
throw
std
::
runtime_error
(
"cannot access element at index "
+
std
::
to_string
(
index
));
#else
throw
std
::
runtime_error
(
"cannot access element at index "
+
int_to_string
(
index
));
#endif
}
return
_value
.
array
->
at
(
index
);
...
...
@@ -448,11 +466,19 @@ JSON& JSON::operator[](int index) {
/// operator to get an element in an object
const
JSON
&
JSON
::
operator
[](
const
int
index
)
const
{
if
(
_type
!=
array
)
{
throw
std
::
runtime_error
(
"cannot get entry with index "
+
to_string
(
index
)
+
" from "
+
_typename
());
#ifdef __cplusplus11
throw
std
::
runtime_error
(
"cannot get entry with index "
+
std
::
to_string
(
index
)
+
" from "
+
_typename
());
#else
throw
std
::
runtime_error
(
"cannot get entry with index "
+
int_to_string
(
index
)
+
" from "
+
_typename
());
#endif
}
if
(
index
>=
(
int
)
_value
.
array
->
size
())
{
throw
std
::
runtime_error
(
"cannot access element at index "
+
to_string
(
index
));
#ifdef __cplusplus11
throw
std
::
runtime_error
(
"cannot access element at index "
+
std
::
to_string
(
index
));
#else
throw
std
::
runtime_error
(
"cannot access element at index "
+
int_to_string
(
index
));
#endif
}
return
_value
.
array
->
at
(
index
);
...
...
@@ -744,7 +770,11 @@ JSON::parser::~parser() {
}
void
JSON
::
parser
::
error
(
std
::
string
msg
=
""
)
{
throw
std
::
runtime_error
(
"parse error at position "
+
to_string
(
_pos
)
+
": "
+
msg
+
", last read: '"
+
_current
+
"'"
);
#ifdef __cplusplus11
throw
std
::
runtime_error
(
"parse error at position "
+
std
::
to_string
(
_pos
)
+
": "
+
msg
+
", last read: '"
+
_current
+
"'"
);
#else
throw
std
::
runtime_error
(
"parse error at position "
+
int_to_string
(
_pos
)
+
": "
+
msg
+
", last read: '"
+
_current
+
"'"
);
#endif
}
bool
JSON
::
parser
::
next
()
{
...
...
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