Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
畅游知识海洋
json
提交
92ee1d56
J
json
项目概览
畅游知识海洋
/
json
与 Fork 源项目一致
从无法访问的项目Fork
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
J
json
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
92ee1d56
编写于
8月 14, 2016
作者:
N
Niels
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
cleanup
上级
4871e394
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
62 addition
and
40 deletion
+62
-40
src/json.hpp
src/json.hpp
+3
-6
src/json.hpp.re2c
src/json.hpp.re2c
+3
-6
test/src/unit-class_lexer.cpp
test/src/unit-class_lexer.cpp
+56
-28
未找到文件。
src/json.hpp
浏览文件 @
92ee1d56
...
...
@@ -7514,11 +7514,6 @@ class basic_json
m_limit
=
m_content
+
len
;
}
/// a lexer from a string literal
explicit
lexer
(
const
typename
string_t
::
value_type
*
buff
)
noexcept
:
lexer
(
reinterpret_cast
<
const
lexer_char_t
*>
(
buff
),
strlen
(
buff
))
{}
/// a lexer from an input stream
explicit
lexer
(
std
::
istream
&
s
)
:
m_stream
(
&
s
),
m_line_buffer
()
...
...
@@ -8881,7 +8876,9 @@ basic_json_parser_63:
public:
/// a parser reading from a string literal
parser
(
const
typename
string_t
::
value_type
*
buff
,
parser_callback_t
cb
=
nullptr
)
:
callback
(
cb
),
m_lexer
(
buff
)
:
callback
(
cb
),
m_lexer
(
reinterpret_cast
<
const
typename
lexer
::
lexer_char_t
*>
(
buff
),
strlen
(
buff
))
{}
/// a parser reading from a string container
...
...
src/json.hpp.re2c
浏览文件 @
92ee1d56
...
...
@@ -7514,11 +7514,6 @@ class basic_json
m_limit = m_content + len;
}
/// a lexer from a string literal
explicit lexer(const typename string_t::value_type* buff) noexcept
: lexer(reinterpret_cast<const lexer_char_t*>(buff), strlen(buff))
{}
/// a lexer from an input stream
explicit lexer(std::istream& s)
: m_stream(&s), m_line_buffer()
...
...
@@ -8178,7 +8173,9 @@ class basic_json
public:
/// a parser reading from a string literal
parser(const typename string_t::value_type* buff, parser_callback_t cb = nullptr)
: callback(cb), m_lexer(buff)
: callback(cb),
m_lexer(reinterpret_cast<const typename lexer::lexer_char_t*>(buff),
strlen(buff))
{}
/// a parser reading from a string container
...
...
test/src/unit-class_lexer.cpp
浏览文件 @
92ee1d56
...
...
@@ -38,43 +38,67 @@ TEST_CASE("lexer class")
{
SECTION
(
"structural characters"
)
{
CHECK
(
json
::
lexer
(
"["
).
scan
()
==
json
::
lexer
::
token_type
::
begin_array
);
CHECK
(
json
::
lexer
(
"]"
).
scan
()
==
json
::
lexer
::
token_type
::
end_array
);
CHECK
(
json
::
lexer
(
"{"
).
scan
()
==
json
::
lexer
::
token_type
::
begin_object
);
CHECK
(
json
::
lexer
(
"}"
).
scan
()
==
json
::
lexer
::
token_type
::
end_object
);
CHECK
(
json
::
lexer
(
","
).
scan
()
==
json
::
lexer
::
token_type
::
value_separator
);
CHECK
(
json
::
lexer
(
":"
).
scan
()
==
json
::
lexer
::
token_type
::
name_separator
);
CHECK
(
json
::
lexer
(
reinterpret_cast
<
const
json
::
lexer
::
lexer_char_t
*>
(
"["
),
1
).
scan
()
==
json
::
lexer
::
token_type
::
begin_array
);
CHECK
(
json
::
lexer
(
reinterpret_cast
<
const
json
::
lexer
::
lexer_char_t
*>
(
"]"
),
1
).
scan
()
==
json
::
lexer
::
token_type
::
end_array
);
CHECK
(
json
::
lexer
(
reinterpret_cast
<
const
json
::
lexer
::
lexer_char_t
*>
(
"{"
),
1
).
scan
()
==
json
::
lexer
::
token_type
::
begin_object
);
CHECK
(
json
::
lexer
(
reinterpret_cast
<
const
json
::
lexer
::
lexer_char_t
*>
(
"}"
),
1
).
scan
()
==
json
::
lexer
::
token_type
::
end_object
);
CHECK
(
json
::
lexer
(
reinterpret_cast
<
const
json
::
lexer
::
lexer_char_t
*>
(
","
),
1
).
scan
()
==
json
::
lexer
::
token_type
::
value_separator
);
CHECK
(
json
::
lexer
(
reinterpret_cast
<
const
json
::
lexer
::
lexer_char_t
*>
(
":"
),
1
).
scan
()
==
json
::
lexer
::
token_type
::
name_separator
);
}
SECTION
(
"literal names"
)
{
CHECK
(
json
::
lexer
(
"null"
).
scan
()
==
json
::
lexer
::
token_type
::
literal_null
);
CHECK
(
json
::
lexer
(
"true"
).
scan
()
==
json
::
lexer
::
token_type
::
literal_true
);
CHECK
(
json
::
lexer
(
"false"
).
scan
()
==
json
::
lexer
::
token_type
::
literal_false
);
CHECK
(
json
::
lexer
(
reinterpret_cast
<
const
json
::
lexer
::
lexer_char_t
*>
(
"null"
),
4
).
scan
()
==
json
::
lexer
::
token_type
::
literal_null
);
CHECK
(
json
::
lexer
(
reinterpret_cast
<
const
json
::
lexer
::
lexer_char_t
*>
(
"true"
),
4
).
scan
()
==
json
::
lexer
::
token_type
::
literal_true
);
CHECK
(
json
::
lexer
(
reinterpret_cast
<
const
json
::
lexer
::
lexer_char_t
*>
(
"false"
),
5
).
scan
()
==
json
::
lexer
::
token_type
::
literal_false
);
}
SECTION
(
"numbers"
)
{
CHECK
(
json
::
lexer
(
"0"
).
scan
()
==
json
::
lexer
::
token_type
::
value_number
);
CHECK
(
json
::
lexer
(
"1"
).
scan
()
==
json
::
lexer
::
token_type
::
value_number
);
CHECK
(
json
::
lexer
(
"2"
).
scan
()
==
json
::
lexer
::
token_type
::
value_number
);
CHECK
(
json
::
lexer
(
"3"
).
scan
()
==
json
::
lexer
::
token_type
::
value_number
);
CHECK
(
json
::
lexer
(
"4"
).
scan
()
==
json
::
lexer
::
token_type
::
value_number
);
CHECK
(
json
::
lexer
(
"5"
).
scan
()
==
json
::
lexer
::
token_type
::
value_number
);
CHECK
(
json
::
lexer
(
"6"
).
scan
()
==
json
::
lexer
::
token_type
::
value_number
);
CHECK
(
json
::
lexer
(
"7"
).
scan
()
==
json
::
lexer
::
token_type
::
value_number
);
CHECK
(
json
::
lexer
(
"8"
).
scan
()
==
json
::
lexer
::
token_type
::
value_number
);
CHECK
(
json
::
lexer
(
"9"
).
scan
()
==
json
::
lexer
::
token_type
::
value_number
);
CHECK
(
json
::
lexer
(
reinterpret_cast
<
const
json
::
lexer
::
lexer_char_t
*>
(
"0"
),
1
).
scan
()
==
json
::
lexer
::
token_type
::
value_number
);
CHECK
(
json
::
lexer
(
reinterpret_cast
<
const
json
::
lexer
::
lexer_char_t
*>
(
"1"
),
1
).
scan
()
==
json
::
lexer
::
token_type
::
value_number
);
CHECK
(
json
::
lexer
(
reinterpret_cast
<
const
json
::
lexer
::
lexer_char_t
*>
(
"2"
),
1
).
scan
()
==
json
::
lexer
::
token_type
::
value_number
);
CHECK
(
json
::
lexer
(
reinterpret_cast
<
const
json
::
lexer
::
lexer_char_t
*>
(
"3"
),
1
).
scan
()
==
json
::
lexer
::
token_type
::
value_number
);
CHECK
(
json
::
lexer
(
reinterpret_cast
<
const
json
::
lexer
::
lexer_char_t
*>
(
"4"
),
1
).
scan
()
==
json
::
lexer
::
token_type
::
value_number
);
CHECK
(
json
::
lexer
(
reinterpret_cast
<
const
json
::
lexer
::
lexer_char_t
*>
(
"5"
),
1
).
scan
()
==
json
::
lexer
::
token_type
::
value_number
);
CHECK
(
json
::
lexer
(
reinterpret_cast
<
const
json
::
lexer
::
lexer_char_t
*>
(
"6"
),
1
).
scan
()
==
json
::
lexer
::
token_type
::
value_number
);
CHECK
(
json
::
lexer
(
reinterpret_cast
<
const
json
::
lexer
::
lexer_char_t
*>
(
"7"
),
1
).
scan
()
==
json
::
lexer
::
token_type
::
value_number
);
CHECK
(
json
::
lexer
(
reinterpret_cast
<
const
json
::
lexer
::
lexer_char_t
*>
(
"8"
),
1
).
scan
()
==
json
::
lexer
::
token_type
::
value_number
);
CHECK
(
json
::
lexer
(
reinterpret_cast
<
const
json
::
lexer
::
lexer_char_t
*>
(
"9"
),
1
).
scan
()
==
json
::
lexer
::
token_type
::
value_number
);
}
SECTION
(
"whitespace"
)
{
// result is end_of_input, because not token is following
CHECK
(
json
::
lexer
(
" "
).
scan
()
==
json
::
lexer
::
token_type
::
end_of_input
);
CHECK
(
json
::
lexer
(
"
\t
"
).
scan
()
==
json
::
lexer
::
token_type
::
end_of_input
);
CHECK
(
json
::
lexer
(
"
\n
"
).
scan
()
==
json
::
lexer
::
token_type
::
end_of_input
);
CHECK
(
json
::
lexer
(
"
\r
"
).
scan
()
==
json
::
lexer
::
token_type
::
end_of_input
);
CHECK
(
json
::
lexer
(
"
\t\n\r\n\t
"
).
scan
()
==
json
::
lexer
::
token_type
::
end_of_input
);
CHECK
(
json
::
lexer
(
reinterpret_cast
<
const
json
::
lexer
::
lexer_char_t
*>
(
" "
),
1
).
scan
()
==
json
::
lexer
::
token_type
::
end_of_input
);
CHECK
(
json
::
lexer
(
reinterpret_cast
<
const
json
::
lexer
::
lexer_char_t
*>
(
"
\t
"
),
1
).
scan
()
==
json
::
lexer
::
token_type
::
end_of_input
);
CHECK
(
json
::
lexer
(
reinterpret_cast
<
const
json
::
lexer
::
lexer_char_t
*>
(
"
\n
"
),
1
).
scan
()
==
json
::
lexer
::
token_type
::
end_of_input
);
CHECK
(
json
::
lexer
(
reinterpret_cast
<
const
json
::
lexer
::
lexer_char_t
*>
(
"
\r
"
),
1
).
scan
()
==
json
::
lexer
::
token_type
::
end_of_input
);
CHECK
(
json
::
lexer
(
reinterpret_cast
<
const
json
::
lexer
::
lexer_char_t
*>
(
"
\t\n\r\n\t
"
),
7
).
scan
()
==
json
::
lexer
::
token_type
::
end_of_input
);
}
}
...
...
@@ -100,7 +124,11 @@ TEST_CASE("lexer class")
{
for
(
int
c
=
1
;
c
<
128
;
++
c
)
{
auto
s
=
std
::
string
(
1
,
c
);
// create string from the ASCII code
const
auto
s
=
std
::
string
(
1
,
c
);
// store scan() result
const
auto
res
=
json
::
lexer
(
reinterpret_cast
<
const
json
::
lexer
::
lexer_char_t
*>
(
s
.
c_str
()),
1
).
scan
();
switch
(
c
)
{
...
...
@@ -122,7 +150,7 @@ TEST_CASE("lexer class")
case
(
'8'
):
case
(
'9'
):
{
CHECK
(
json
::
lexer
(
s
.
c_str
()).
scan
()
!=
json
::
lexer
::
token_type
::
parse_error
);
CHECK
(
res
!=
json
::
lexer
::
token_type
::
parse_error
);
break
;
}
...
...
@@ -132,14 +160,14 @@ TEST_CASE("lexer class")
case
(
'\n'
):
case
(
'\r'
):
{
CHECK
(
json
::
lexer
(
s
.
c_str
()).
scan
()
==
json
::
lexer
::
token_type
::
end_of_input
);
CHECK
(
res
==
json
::
lexer
::
token_type
::
end_of_input
);
break
;
}
// anything else is not expected
default:
{
CHECK
(
json
::
lexer
(
s
.
c_str
()).
scan
()
==
json
::
lexer
::
token_type
::
parse_error
);
CHECK
(
res
==
json
::
lexer
::
token_type
::
parse_error
);
break
;
}
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录