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
cb2102a2
Commit
cb2102a2
authored
May 10, 2015
by
Niels
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
some pretty-printing
parent
072dc255
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
13 additions
and
19 deletions
+13
-19
src/json.hpp
src/json.hpp
+12
-18
src/json.hpp.re2c
src/json.hpp.re2c
+1
-1
No files found.
src/json.hpp
View file @
cb2102a2
...
@@ -291,12 +291,6 @@ class basic_json
...
@@ -291,12 +291,6 @@ class basic_json
using
parser_callback_t
=
std
::
function
<
bool
(
int
depth
,
parse_event_t
event
,
using
parser_callback_t
=
std
::
function
<
bool
(
int
depth
,
parse_event_t
event
,
const
basic_json
&
parsed
)
>
;
const
basic_json
&
parsed
)
>
;
/// default parser callback returns true to keep all elements
static
bool
default_callback
(
int
,
parse_event_t
,
const
basic_json
&
)
{
return
true
;
}
/*!
/*!
@brief comparison operator for JSON value types
@brief comparison operator for JSON value types
...
@@ -1994,13 +1988,13 @@ class basic_json
...
@@ -1994,13 +1988,13 @@ class basic_json
/////////////////////
/////////////////////
/// deserialize from string
/// deserialize from string
static
basic_json
parse
(
const
string_t
&
s
,
parser_callback_t
cb
=
default_callback
)
static
basic_json
parse
(
const
string_t
&
s
,
parser_callback_t
cb
=
nullptr
)
{
{
return
parser
(
s
,
cb
).
parse
();
return
parser
(
s
,
cb
).
parse
();
}
}
/// deserialize from stream
/// deserialize from stream
static
basic_json
parse
(
std
::
istream
&
i
,
parser_callback_t
cb
=
default_callback
)
static
basic_json
parse
(
std
::
istream
&
i
,
parser_callback_t
cb
=
nullptr
)
{
{
return
parser
(
i
,
cb
).
parse
();
return
parser
(
i
,
cb
).
parse
();
}
}
...
@@ -4579,14 +4573,14 @@ basic_json_parser_59:
...
@@ -4579,14 +4573,14 @@ basic_json_parser_59:
{
{
public:
public:
/// constructor for strings
/// constructor for strings
inline
parser
(
const
string_t
&
s
,
parser_callback_t
cb
=
default_callback
)
:
callback
(
cb
),
m_lexer
(
s
)
inline
parser
(
const
string_t
&
s
,
parser_callback_t
cb
=
nullptr
)
:
callback
(
cb
),
m_lexer
(
s
)
{
{
// read first token
// read first token
get_token
();
get_token
();
}
}
/// a parser reading from an input stream
/// a parser reading from an input stream
inline
parser
(
std
::
istream
&
_is
,
parser_callback_t
cb
=
default_callback
)
:
callback
(
cb
),
inline
parser
(
std
::
istream
&
_is
,
parser_callback_t
cb
=
nullptr
)
:
callback
(
cb
),
m_lexer
(
&
_is
)
m_lexer
(
&
_is
)
{
{
// read first token
// read first token
...
@@ -4613,7 +4607,7 @@ basic_json_parser_59:
...
@@ -4613,7 +4607,7 @@ basic_json_parser_59:
{
{
case
(
lexer
:
:
token_type
::
begin_object
)
:
case
(
lexer
:
:
token_type
::
begin_object
)
:
{
{
if
(
keep
and
(
keep
=
callback
(
depth
++
,
parse_event_t
::
object_start
,
result
)))
if
(
keep
and
(
not
callback
or
(
keep
=
callback
(
depth
++
,
parse_event_t
::
object_start
,
result
)
)))
{
{
// explicitly set result to object to cope with {}
// explicitly set result to object to cope with {}
result
.
m_type
=
value_t
::
object
;
result
.
m_type
=
value_t
::
object
;
...
@@ -4627,7 +4621,7 @@ basic_json_parser_59:
...
@@ -4627,7 +4621,7 @@ basic_json_parser_59:
if
(
last_token
==
lexer
::
token_type
::
end_object
)
if
(
last_token
==
lexer
::
token_type
::
end_object
)
{
{
get_token
();
get_token
();
if
(
keep
and
not
(
keep
=
callback
(
--
depth
,
parse_event_t
::
object_end
,
result
)
))
if
(
keep
and
callback
and
not
callback
(
--
depth
,
parse_event_t
::
object_end
,
result
))
{
{
result
=
basic_json
(
value_t
::
discarded
);
result
=
basic_json
(
value_t
::
discarded
);
}
}
...
@@ -4653,7 +4647,7 @@ basic_json_parser_59:
...
@@ -4653,7 +4647,7 @@ basic_json_parser_59:
bool
keep_tag
=
false
;
bool
keep_tag
=
false
;
if
(
keep
)
if
(
keep
)
{
{
keep_tag
=
callback
(
depth
,
parse_event_t
::
key
,
basic_json
(
key
))
;
keep_tag
=
callback
?
callback
(
depth
,
parse_event_t
::
key
,
basic_json
(
key
))
:
true
;
}
}
// parse separator (:)
// parse separator (:)
...
@@ -4673,7 +4667,7 @@ basic_json_parser_59:
...
@@ -4673,7 +4667,7 @@ basic_json_parser_59:
// closing }
// closing }
expect
(
lexer
::
token_type
::
end_object
);
expect
(
lexer
::
token_type
::
end_object
);
get_token
();
get_token
();
if
(
keep
and
not
callback
(
--
depth
,
parse_event_t
::
object_end
,
result
))
if
(
keep
and
callback
and
not
callback
(
--
depth
,
parse_event_t
::
object_end
,
result
))
{
{
result
=
basic_json
(
value_t
::
discarded
);
result
=
basic_json
(
value_t
::
discarded
);
}
}
...
@@ -4683,7 +4677,7 @@ basic_json_parser_59:
...
@@ -4683,7 +4677,7 @@ basic_json_parser_59:
case
(
lexer
:
:
token_type
::
begin_array
)
:
case
(
lexer
:
:
token_type
::
begin_array
)
:
{
{
if
(
keep
and
(
keep
=
callback
(
depth
++
,
parse_event_t
::
array_start
,
result
)))
if
(
keep
and
(
not
callback
or
(
keep
=
callback
(
depth
++
,
parse_event_t
::
array_start
,
result
)
)))
{
{
// explicitly set result to object to cope with []
// explicitly set result to object to cope with []
result
.
m_type
=
value_t
::
array
;
result
.
m_type
=
value_t
::
array
;
...
@@ -4697,7 +4691,7 @@ basic_json_parser_59:
...
@@ -4697,7 +4691,7 @@ basic_json_parser_59:
if
(
last_token
==
lexer
::
token_type
::
end_array
)
if
(
last_token
==
lexer
::
token_type
::
end_array
)
{
{
get_token
();
get_token
();
if
(
not
callback
(
--
depth
,
parse_event_t
::
array_end
,
result
))
if
(
callback
and
not
callback
(
--
depth
,
parse_event_t
::
array_end
,
result
))
{
{
result
=
basic_json
(
value_t
::
discarded
);
result
=
basic_json
(
value_t
::
discarded
);
}
}
...
@@ -4728,7 +4722,7 @@ basic_json_parser_59:
...
@@ -4728,7 +4722,7 @@ basic_json_parser_59:
// closing ]
// closing ]
expect
(
lexer
::
token_type
::
end_array
);
expect
(
lexer
::
token_type
::
end_array
);
get_token
();
get_token
();
if
(
keep
and
not
callback
(
--
depth
,
parse_event_t
::
array_end
,
result
))
if
(
keep
and
callback
and
not
callback
(
--
depth
,
parse_event_t
::
array_end
,
result
))
{
{
result
=
basic_json
(
value_t
::
discarded
);
result
=
basic_json
(
value_t
::
discarded
);
}
}
...
@@ -4805,7 +4799,7 @@ basic_json_parser_59:
...
@@ -4805,7 +4799,7 @@ basic_json_parser_59:
}
}
}
}
if
(
keep
and
not
callback
(
depth
,
parse_event_t
::
value
,
result
))
if
(
keep
and
callback
and
not
callback
(
depth
,
parse_event_t
::
value
,
result
))
{
{
result
=
basic_json
(
value_t
::
discarded
);
result
=
basic_json
(
value_t
::
discarded
);
}
}
...
...
src/json.hpp.re2c
View file @
cb2102a2
...
@@ -3953,7 +3953,7 @@ class basic_json
...
@@ -3953,7 +3953,7 @@ class basic_json
bool keep_tag = false;
bool keep_tag = false;
if (keep)
if (keep)
{
{
keep_tag = callback ? callback(depth, parse_event_t::key, basic_json(key)) : true;
keep_tag = callback ? callback(depth, parse_event_t::key, basic_json(key)) : true;
}
}
// parse separator (:)
// parse separator (:)
...
...
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