Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
OpenHarmony
Third Party CJSON
提交
1749de02
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,发现更多精彩内容 >>
提交
1749de02
编写于
3月 03, 2017
作者:
M
Max Bruckner
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
print_number: return boolean instead of pointer
上级
748f4bfd
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
11 addition
and
13 deletion
+11
-13
cJSON.c
cJSON.c
+8
-9
tests/print_number.c
tests/print_number.c
+3
-4
未找到文件。
cJSON.c
浏览文件 @
1749de02
...
...
@@ -327,14 +327,14 @@ static void update_offset(printbuffer * const buffer)
}
/* Removes trailing zeroes from the end of a printed number */
static
unsigned
char
*
trim_trailing_zeroes
(
printbuffer
*
const
buffer
)
static
cJSON_bool
trim_trailing_zeroes
(
printbuffer
*
const
buffer
)
{
size_t
offset
=
0
;
unsigned
char
*
content
=
NULL
;
if
((
buffer
==
NULL
)
||
(
buffer
->
buffer
==
NULL
)
||
(
buffer
->
offset
<
1
))
{
return
NULL
;
return
false
;
}
offset
=
buffer
->
offset
-
1
;
...
...
@@ -354,11 +354,11 @@ static unsigned char *trim_trailing_zeroes(printbuffer * const buffer)
buffer
->
offset
=
offset
;
return
content
+
offset
;
return
true
;
}
/* Render the number nicely from the given item into a string. */
static
unsigned
char
*
print_number
(
const
cJSON
*
const
item
,
printbuffer
*
const
output_buffer
,
const
internal_hooks
*
const
hooks
)
static
cJSON_bool
print_number
(
const
cJSON
*
const
item
,
printbuffer
*
const
output_buffer
,
const
internal_hooks
*
const
hooks
)
{
unsigned
char
*
output_pointer
=
NULL
;
double
d
=
item
->
valuedouble
;
...
...
@@ -367,7 +367,7 @@ static unsigned char *print_number(const cJSON * const item, printbuffer * const
if
(
output_buffer
==
NULL
)
{
return
NULL
;
return
false
;
}
/* This is a nice tradeoff. */
...
...
@@ -399,7 +399,7 @@ static unsigned char *print_number(const cJSON * const item, printbuffer * const
/* sprintf failed */
if
(
length
<
0
)
{
return
NULL
;
return
false
;
}
output_buffer
->
offset
+=
(
size_t
)
length
;
...
...
@@ -409,7 +409,7 @@ static unsigned char *print_number(const cJSON * const item, printbuffer * const
return
trim_trailing_zeroes
(
output_buffer
);
}
return
output_buffer
->
buffer
;
return
true
;
}
/* parse 4 digit hexadecimal number */
...
...
@@ -1069,8 +1069,7 @@ static cJSON_bool print_value(const cJSON * const item, const size_t depth, cons
}
break
;
case
cJSON_Number
:
output
=
print_number
(
item
,
output_buffer
,
hooks
);
break
;
return
print_number
(
item
,
output_buffer
,
hooks
);
case
cJSON_Raw
:
{
size_t
raw_length
=
0
;
...
...
tests/print_number.c
浏览文件 @
1749de02
...
...
@@ -37,7 +37,7 @@ static void assert_print_number(const char *expected, double input)
memset
(
item
,
0
,
sizeof
(
item
));
cJSON_SetNumberValue
(
item
,
input
);
TEST_ASSERT_
NOT_NULL
_MESSAGE
(
print_number
(
item
,
&
buffer
,
&
global_hooks
),
"Failed to print number."
);
TEST_ASSERT_
TRUE
_MESSAGE
(
print_number
(
item
,
&
buffer
,
&
global_hooks
),
"Failed to print number."
);
TEST_ASSERT_EQUAL_STRING_MESSAGE
(
expected
,
buffer
.
buffer
,
"Printed number is not as expected."
);
}
...
...
@@ -91,14 +91,13 @@ static void trim_trailing_zeroes_should_trim_trailing_zeroes(void)
{
printbuffer
buffer
;
unsigned
char
number
[
100
];
unsigned
char
*
pointer
=
NULL
;
buffer
.
length
=
sizeof
(
number
);
buffer
.
buffer
=
number
;
strcpy
((
char
*
)
number
,
"10.00"
);
buffer
.
offset
=
sizeof
(
"10.00"
)
-
1
;
pointer
=
trim_trailing_zeroes
(
&
buffer
);
TEST_ASSERT_EQUAL_UINT8
(
'\0'
,
*
pointer
);
TEST_ASSERT_TRUE
(
trim_trailing_zeroes
(
&
buffer
)
);
TEST_ASSERT_EQUAL_UINT8
(
'\0'
,
buffer
.
buffer
[
buffer
.
offset
]
);
TEST_ASSERT_EQUAL_STRING
(
"10"
,
number
);
TEST_ASSERT_EQUAL_UINT
(
sizeof
(
"10"
)
-
1
,
buffer
.
offset
);
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录