Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
OpenHarmony
Third Party CJSON
提交
748f4bfd
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,发现更多精彩内容 >>
提交
748f4bfd
编写于
3月 03, 2017
作者:
M
Max Bruckner
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
print_object: return boolean instead of pointer
上级
bea1d102
变更
2
显示空白变更内容
内联
并排
Showing
2 changed file
with
14 addition
and
19 deletion
+14
-19
cJSON.c
cJSON.c
+12
-17
tests/print_object.c
tests/print_object.c
+2
-2
未找到文件。
cJSON.c
浏览文件 @
748f4bfd
...
...
@@ -817,7 +817,7 @@ static cJSON_bool print_value(const cJSON * const item, const size_t depth, cons
static
const
unsigned
char
*
parse_array
(
cJSON
*
const
item
,
const
unsigned
char
*
input
,
const
unsigned
char
**
const
ep
,
const
internal_hooks
*
const
hooks
);
static
cJSON_bool
print_array
(
const
cJSON
*
const
item
,
const
size_t
depth
,
const
cJSON_bool
format
,
printbuffer
*
const
output_buffer
,
const
internal_hooks
*
const
hooks
);
static
const
unsigned
char
*
parse_object
(
cJSON
*
const
item
,
const
unsigned
char
*
input
,
const
unsigned
char
**
const
ep
,
const
internal_hooks
*
const
hooks
);
static
unsigned
char
*
print_object
(
const
cJSON
*
const
item
,
const
size_t
depth
,
const
cJSON_bool
format
,
printbuffer
*
const
output_buffer
,
const
internal_hooks
*
const
hooks
);
static
cJSON_bool
print_object
(
const
cJSON
*
const
item
,
const
size_t
depth
,
const
cJSON_bool
format
,
printbuffer
*
const
output_buffer
,
const
internal_hooks
*
const
hooks
);
/* Utility to jump whitespace and cr/lf */
static
const
unsigned
char
*
skip_whitespace
(
const
unsigned
char
*
in
)
...
...
@@ -1098,8 +1098,7 @@ static cJSON_bool print_value(const cJSON * const item, const size_t depth, cons
case
cJSON_Array
:
return
print_array
(
item
,
depth
,
format
,
output_buffer
,
hooks
);
case
cJSON_Object
:
output
=
print_object
(
item
,
depth
,
format
,
output_buffer
,
hooks
);
break
;
return
print_object
(
item
,
depth
,
format
,
output_buffer
,
hooks
);
default:
output
=
NULL
;
break
;
...
...
@@ -1342,26 +1341,23 @@ fail:
}
/* Render an object to text. */
static
unsigned
char
*
print_object
(
const
cJSON
*
const
item
,
const
size_t
depth
,
const
cJSON_bool
format
,
printbuffer
*
const
output_buffer
,
const
internal_hooks
*
const
hooks
)
static
cJSON_bool
print_object
(
const
cJSON
*
const
item
,
const
size_t
depth
,
const
cJSON_bool
format
,
printbuffer
*
const
output_buffer
,
const
internal_hooks
*
const
hooks
)
{
unsigned
char
*
output
=
NULL
;
unsigned
char
*
output_pointer
=
NULL
;
size_t
length
=
0
;
size_t
output_offset
=
0
;
cJSON
*
current_item
=
item
->
child
;
if
(
output_buffer
==
NULL
)
{
return
NULL
;
return
false
;
}
/* Compose the output: */
output_offset
=
output_buffer
->
offset
;
length
=
format
?
2
:
1
;
/* fmt: {\n */
output_pointer
=
ensure
(
output_buffer
,
length
+
1
,
hooks
);
if
(
output_pointer
==
NULL
)
{
return
NULL
;
return
false
;
}
*
output_pointer
++
=
'{'
;
...
...
@@ -1379,7 +1375,7 @@ static unsigned char *print_object(const cJSON * const item, const size_t depth,
output_pointer
=
ensure
(
output_buffer
,
depth
+
1
,
hooks
);
if
(
output_pointer
==
NULL
)
{
return
NULL
;
return
false
;
}
for
(
i
=
0
;
i
<
depth
+
1
;
i
++
)
{
...
...
@@ -1391,7 +1387,7 @@ static unsigned char *print_object(const cJSON * const item, const size_t depth,
/* print key */
if
(
print_string_ptr
((
unsigned
char
*
)
current_item
->
string
,
output_buffer
,
hooks
)
==
NULL
)
{
return
NULL
;
return
false
;
}
update_offset
(
output_buffer
);
...
...
@@ -1399,7 +1395,7 @@ static unsigned char *print_object(const cJSON * const item, const size_t depth,
output_pointer
=
ensure
(
output_buffer
,
length
,
hooks
);
if
(
output_pointer
==
NULL
)
{
return
NULL
;
return
false
;
}
*
output_pointer
++
=
':'
;
if
(
format
)
...
...
@@ -1411,7 +1407,7 @@ static unsigned char *print_object(const cJSON * const item, const size_t depth,
/* print value */
if
(
!
print_value
(
current_item
,
depth
+
1
,
format
,
output_buffer
,
hooks
))
{
return
NULL
;
return
false
;
}
update_offset
(
output_buffer
);
...
...
@@ -1420,7 +1416,7 @@ static unsigned char *print_object(const cJSON * const item, const size_t depth,
output_pointer
=
ensure
(
output_buffer
,
length
+
1
,
hooks
);
if
(
output_pointer
==
NULL
)
{
return
NULL
;
return
false
;
}
if
(
current_item
->
next
)
{
...
...
@@ -1440,7 +1436,7 @@ static unsigned char *print_object(const cJSON * const item, const size_t depth,
output_pointer
=
ensure
(
output_buffer
,
format
?
(
depth
+
2
)
:
2
,
hooks
);
if
(
output_pointer
==
NULL
)
{
return
NULL
;
return
false
;
}
if
(
format
)
{
...
...
@@ -1452,9 +1448,8 @@ static unsigned char *print_object(const cJSON * const item, const size_t depth,
}
*
output_pointer
++
=
'}'
;
*
output_pointer
=
'\0'
;
output
=
(
output_buffer
->
buffer
)
+
output_offset
;
return
output
;
return
true
;
}
/* Get Array size/item / object item. */
...
...
tests/print_object.c
浏览文件 @
748f4bfd
...
...
@@ -50,10 +50,10 @@ static void assert_print_object(const char * const expected, const char * const
memset
(
item
,
0
,
sizeof
(
item
));
TEST_ASSERT_NOT_NULL_MESSAGE
(
parse_object
(
item
,
(
const
unsigned
char
*
)
input
,
&
error_pointer
,
&
global_hooks
),
"Failed to parse object."
);
TEST_ASSERT_
NOT_NULL
_MESSAGE
(
print_object
(
item
,
0
,
false
,
&
unformatted_buffer
,
&
global_hooks
),
"Failed to print unformatted string."
);
TEST_ASSERT_
TRUE
_MESSAGE
(
print_object
(
item
,
0
,
false
,
&
unformatted_buffer
,
&
global_hooks
),
"Failed to print unformatted string."
);
TEST_ASSERT_EQUAL_STRING_MESSAGE
(
input
,
printed_unformatted
,
"Unformatted object is not correct."
);
TEST_ASSERT_
NOT_NULL
_MESSAGE
(
print_object
(
item
,
0
,
true
,
&
formatted_buffer
,
&
global_hooks
),
"Failed to print formatted string."
);
TEST_ASSERT_
TRUE
_MESSAGE
(
print_object
(
item
,
0
,
true
,
&
formatted_buffer
,
&
global_hooks
),
"Failed to print formatted string."
);
TEST_ASSERT_EQUAL_STRING_MESSAGE
(
expected
,
printed_formatted
,
"Formatted ojbect is not correct."
);
reset
(
item
);
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录