Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
OpenHarmony
Third Party CJSON
提交
f69b109c
T
Third Party CJSON
项目概览
OpenHarmony
/
Third Party CJSON
大约 1 年 前同步成功
通知
6
Star
22
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
T
Third Party CJSON
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
f69b109c
编写于
3月 14, 2017
作者:
M
Max Bruckner
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
parse_number: Use parse_buffer
上级
fef1c45b
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
16 addition
and
16 deletion
+16
-16
cJSON.c
cJSON.c
+10
-15
tests/parse_number.c
tests/parse_number.c
+6
-1
未找到文件。
cJSON.c
浏览文件 @
f69b109c
...
...
@@ -202,7 +202,7 @@ typedef struct
#define buffer_at_offset(buffer) ((buffer)->content + (buffer)->offset)
/* Parse the input text to generate a number, and populate the result into item. */
static
const
unsigned
char
*
parse_number
(
cJSON
*
const
item
,
const
unsigned
char
*
const
input
)
static
const
unsigned
char
*
parse_number
(
cJSON
*
const
item
,
parse_buffer
*
const
input_buffer
)
{
double
number
=
0
;
unsigned
char
*
after_end
=
NULL
;
...
...
@@ -210,16 +210,17 @@ static const unsigned char *parse_number(cJSON * const item, const unsigned char
unsigned
char
decimal_point
=
get_decimal_point
();
size_t
i
=
0
;
if
(
input
==
NULL
)
if
(
(
input_buffer
==
NULL
)
||
(
input_buffer
->
content
==
NULL
)
)
{
return
NULL
;
}
/* copy the number into a temporary buffer and replace '.' with the decimal point
* of the current locale (for strtod) */
for
(
i
=
0
;
(
i
<
(
sizeof
(
number_c_string
)
-
1
))
&&
(
input
[
i
]
!=
'\0'
);
i
++
)
* of the current locale (for strtod)
* This also takes care of '\0' not necessarily being available for marking the end of the input */
for
(
i
=
0
;
(
i
<
(
sizeof
(
number_c_string
)
-
1
))
&&
can_access_at_index
(
input_buffer
,
i
);
i
++
)
{
switch
(
input
[
i
])
switch
(
buffer_at_offset
(
input_buffer
)
[
i
])
{
case
'0'
:
case
'1'
:
...
...
@@ -235,7 +236,7 @@ static const unsigned char *parse_number(cJSON * const item, const unsigned char
case
'-'
:
case
'e'
:
case
'E'
:
number_c_string
[
i
]
=
input
[
i
];
number_c_string
[
i
]
=
buffer_at_offset
(
input_buffer
)
[
i
];
break
;
case
'.'
:
...
...
@@ -273,7 +274,8 @@ loop_end:
item
->
type
=
cJSON_Number
;
return
input
+
(
after_end
-
number_c_string
);
input_buffer
->
offset
+=
(
size_t
)(
after_end
-
number_c_string
);
return
buffer_at_offset
(
input_buffer
);
}
/* don't ask me, but the original cJSON_SetNumberValue returns an integer or double */
...
...
@@ -1151,14 +1153,7 @@ static const unsigned char *parse_value(cJSON * const item, parse_buffer * cons
/* number */
if
(
can_access_at_index
(
input_buffer
,
0
)
&&
((
buffer_at_offset
(
input_buffer
)[
0
]
==
'-'
)
||
((
buffer_at_offset
(
input_buffer
)[
0
]
>=
'0'
)
&&
(
buffer_at_offset
(
input_buffer
)[
0
]
<=
'9'
))))
{
content_pointer
=
parse_number
(
item
,
buffer_at_offset
(
input_buffer
));
if
(
content_pointer
==
NULL
)
{
return
NULL
;
}
input_buffer
->
offset
=
(
size_t
)(
content_pointer
-
input_buffer
->
content
);
return
buffer_at_offset
(
input_buffer
);
return
parse_number
(
item
,
input_buffer
);
}
/* array */
if
(
can_access_at_index
(
input_buffer
,
0
)
&&
(
buffer_at_offset
(
input_buffer
)[
0
]
==
'['
))
...
...
tests/parse_number.c
浏览文件 @
f69b109c
...
...
@@ -45,7 +45,12 @@ static void assert_is_number(cJSON *number_item)
static
void
assert_parse_number
(
const
char
*
string
,
int
integer
,
double
real
)
{
TEST_ASSERT_NOT_NULL
(
parse_number
(
item
,
(
const
unsigned
char
*
)
string
));
parse_buffer
buffer
;
buffer
.
content
=
(
const
unsigned
char
*
)
string
;
buffer
.
length
=
strlen
(
string
)
+
sizeof
(
""
);
buffer
.
offset
=
0
;
TEST_ASSERT_NOT_NULL
(
parse_number
(
item
,
&
buffer
));
assert_is_number
(
item
);
TEST_ASSERT_EQUAL_INT
(
integer
,
item
->
valueint
);
TEST_ASSERT_EQUAL_DOUBLE
(
real
,
item
->
valuedouble
);
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录