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
8557151d
Unverified
Commit
8557151d
authored
Mar 12, 2018
by
Niels Lohmann
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
♻
adjusting lexer/parser in symmetry to #1006
parent
b56ac864
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
34 additions
and
12 deletions
+34
-12
lexer.hpp
include/nlohmann/detail/input/lexer.hpp
+3
-2
parser.hpp
include/nlohmann/detail/input/parser.hpp
+2
-1
json.hpp
single_include/nlohmann/json.hpp
+5
-3
Makefile
test/Makefile
+1
-0
unit-alt-string.cpp
test/src/unit-alt-string.cpp
+23
-6
No files found.
include/nlohmann/detail/input/lexer.hpp
View file @
8557151d
...
...
@@ -32,6 +32,7 @@ class lexer
using
number_integer_t
=
typename
BasicJsonType
::
number_integer_t
;
using
number_unsigned_t
=
typename
BasicJsonType
::
number_unsigned_t
;
using
number_float_t
=
typename
BasicJsonType
::
number_float_t
;
using
string_t
=
typename
BasicJsonType
::
string_t
;
public
:
/// token types for the parser
...
...
@@ -1130,7 +1131,7 @@ scan_number_done:
}
/// return current string value (implicitly resets the token; useful only once)
st
d
::
string
&&
move_string
()
st
ring_t
&&
move_string
()
{
return
std
::
move
(
token_buffer
);
}
...
...
@@ -1260,7 +1261,7 @@ scan_number_done:
std
::
vector
<
char
>
token_string
{};
/// buffer for variable-length tokens (numbers, strings)
st
d
::
string
token_buffer
{};
st
ring_t
token_buffer
{};
/// a description of occurred lexer errors
const
char
*
error_message
=
""
;
...
...
include/nlohmann/detail/input/parser.hpp
View file @
8557151d
...
...
@@ -32,6 +32,7 @@ class parser
using
number_integer_t
=
typename
BasicJsonType
::
number_integer_t
;
using
number_unsigned_t
=
typename
BasicJsonType
::
number_unsigned_t
;
using
number_float_t
=
typename
BasicJsonType
::
number_float_t
;
using
string_t
=
typename
BasicJsonType
::
string_t
;
using
lexer_t
=
lexer
<
BasicJsonType
>
;
using
token_type
=
typename
lexer_t
::
token_type
;
...
...
@@ -175,7 +176,7 @@ class parser
}
// parse values
st
d
::
string
key
;
st
ring_t
key
;
BasicJsonType
value
;
while
(
true
)
{
...
...
single_include/nlohmann/json.hpp
View file @
8557151d
...
...
@@ -1871,6 +1871,7 @@ class lexer
using
number_integer_t
=
typename
BasicJsonType
::
number_integer_t
;
using
number_unsigned_t
=
typename
BasicJsonType
::
number_unsigned_t
;
using
number_float_t
=
typename
BasicJsonType
::
number_float_t
;
using
string_t
=
typename
BasicJsonType
::
string_t
;
public
:
/// token types for the parser
...
...
@@ -2969,7 +2970,7 @@ scan_number_done:
}
/// return current string value (implicitly resets the token; useful only once)
st
d
::
string
&&
move_string
()
st
ring_t
&&
move_string
()
{
return
std
::
move
(
token_buffer
);
}
...
...
@@ -3099,7 +3100,7 @@ scan_number_done:
std
::
vector
<
char
>
token_string
{};
/// buffer for variable-length tokens (numbers, strings)
st
d
::
string
token_buffer
{};
st
ring_t
token_buffer
{};
/// a description of occurred lexer errors
const
char
*
error_message
=
""
;
...
...
@@ -3155,6 +3156,7 @@ class parser
using
number_integer_t
=
typename
BasicJsonType
::
number_integer_t
;
using
number_unsigned_t
=
typename
BasicJsonType
::
number_unsigned_t
;
using
number_float_t
=
typename
BasicJsonType
::
number_float_t
;
using
string_t
=
typename
BasicJsonType
::
string_t
;
using
lexer_t
=
lexer
<
BasicJsonType
>
;
using
token_type
=
typename
lexer_t
::
token_type
;
...
...
@@ -3298,7 +3300,7 @@ class parser
}
// parse values
st
d
::
string
key
;
st
ring_t
key
;
BasicJsonType
value
;
while
(
true
)
{
...
...
test/Makefile
View file @
8557151d
...
...
@@ -9,6 +9,7 @@ CPPFLAGS += -I ../single_include -I . -I thirdparty/catch -I thirdparty/fifo_map
SOURCES
=
src/unit.cpp
\
src/unit-algorithms.cpp
\
src/unit-allocator.cpp
\
src/unit-alt-string.cpp
\
src/unit-capacity.cpp
\
src/unit-cbor.cpp
\
src/unit-class_const_iterator.cpp
\
...
...
test/src/unit-alt-string.cpp
View file @
8557151d
...
...
@@ -42,7 +42,7 @@ class alt_string
using
value_type
=
std
::
string
::
value_type
;
alt_string
(
const
char
*
str
)
:
str_impl
(
str
)
{}
alt_string
(
const
char
*
str
,
size_t
count
)
:
str_impl
(
str
,
count
)
{}
alt_string
(
const
char
*
str
,
s
td
::
s
ize_t
count
)
:
str_impl
(
str
,
count
)
{}
alt_string
(
size_t
count
,
char
chr
)
:
str_impl
(
count
,
chr
)
{}
alt_string
()
=
default
;
...
...
@@ -70,17 +70,17 @@ class alt_string
return
str_impl
!=
op
;
}
size_t
size
()
const
noexcept
s
td
::
s
ize_t
size
()
const
noexcept
{
return
str_impl
.
size
();
}
void
resize
(
size_t
n
)
void
resize
(
s
td
::
s
ize_t
n
)
{
str_impl
.
resize
(
n
);
}
void
resize
(
size_t
n
,
char
c
)
void
resize
(
s
td
::
s
ize_t
n
,
char
c
)
{
str_impl
.
resize
(
n
,
c
);
}
...
...
@@ -101,12 +101,12 @@ class alt_string
return
str_impl
.
c_str
();
}
char
&
operator
[](
in
t
index
)
char
&
operator
[](
std
::
size_
t
index
)
{
return
str_impl
[
index
];
}
const
char
&
operator
[](
in
t
index
)
const
const
char
&
operator
[](
std
::
size_
t
index
)
const
{
return
str_impl
[
index
];
}
...
...
@@ -121,6 +121,16 @@ class alt_string
return
str_impl
.
back
();
}
void
clear
()
{
str_impl
.
clear
();
}
const
value_type
*
data
()
{
return
str_impl
.
data
();
}
private
:
std
::
string
str_impl
;
};
...
...
@@ -192,4 +202,11 @@ TEST_CASE("alternative string type")
CHECK
(
dump
==
R"({"list":[1,0,2]})"
);
}
}
SECTION
(
"parse"
)
{
auto
doc
=
alt_json
::
parse
(
"{
\"
foo
\"
:
\"
bar
\"
}"
);
alt_string
dump
=
doc
.
dump
();
CHECK
(
dump
==
R"({"foo":"bar"})"
);
}
}
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