Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
OpenHarmony
Third Party CJSON
提交
4932c80f
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看板
提交
4932c80f
编写于
4月 30, 2017
作者:
M
Max Bruckner
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
refactor cJSONUtils_FindPointerFromObjectTo
上级
674a6788
变更
2
显示空白变更内容
内联
并排
Showing
2 changed file
with
24 addition
and
22 deletion
+24
-22
cJSON_Utils.c
cJSON_Utils.c
+23
-21
cJSON_Utils.h
cJSON_Utils.h
+1
-1
未找到文件。
cJSON_Utils.c
浏览文件 @
4932c80f
...
...
@@ -148,10 +148,10 @@ static void cJSONUtils_PointerEncodedstrcpy(unsigned char *destination, const un
destination
[
0
]
=
'\0'
;
}
CJSON_PUBLIC
(
char
*
)
cJSONUtils_FindPointerFromObjectTo
(
c
JSON
*
object
,
cJSON
*
target
)
CJSON_PUBLIC
(
char
*
)
cJSONUtils_FindPointerFromObjectTo
(
c
onst
cJSON
*
const
object
,
const
cJSON
*
const
target
)
{
size_t
c
=
0
;
cJSON
*
obj
=
0
;
size_t
c
hild_index
=
0
;
cJSON
*
current_child
=
0
;
if
(
object
==
target
)
{
...
...
@@ -159,42 +159,44 @@ CJSON_PUBLIC(char *) cJSONUtils_FindPointerFromObjectTo(cJSON *object, cJSON *ta
return
(
char
*
)
cJSONUtils_strdup
((
const
unsigned
char
*
)
""
);
}
/* recursively search all children of the object */
for
(
obj
=
object
->
child
;
obj
;
(
void
)(
obj
=
obj
->
next
),
c
++
)
/* recursively search all children of the object
or array
*/
for
(
current_child
=
object
->
child
;
current_child
!=
NULL
;
(
void
)(
current_child
=
current_child
->
next
),
child_index
++
)
{
unsigned
char
*
found
=
(
unsigned
char
*
)
cJSONUtils_FindPointerFromObjectTo
(
obj
,
target
);
if
(
found
)
unsigned
char
*
target_pointer
=
(
unsigned
char
*
)
cJSONUtils_FindPointerFromObjectTo
(
current_child
,
target
);
/* found the target? */
if
(
target_pointer
!=
NULL
)
{
if
(
cJSON_IsArray
(
object
))
{
/* reserve enough memory for a 64 bit integer + '/' and '\0' */
unsigned
char
*
ret
=
(
unsigned
char
*
)
cJSON_malloc
(
strlen
((
char
*
)
found
)
+
23
);
unsigned
char
*
full_pointer
=
(
unsigned
char
*
)
cJSON_malloc
(
strlen
((
char
*
)
target_pointer
)
+
20
+
sizeof
(
"/"
)
);
/* check if conversion to unsigned long is valid
* This should be eliminated at compile time by dead code elimination
* if size_t is an alias of unsigned long, or if it is bigger */
if
(
c
>
ULONG_MAX
)
if
(
c
hild_index
>
ULONG_MAX
)
{
cJSON_free
(
found
);
cJSON_free
(
target_pointer
);
return
NULL
;
}
sprintf
((
char
*
)
ret
,
"/%lu%s"
,
(
unsigned
long
)
c
,
found
);
/* /<array_index><path> */
cJSON_free
(
found
);
sprintf
((
char
*
)
full_pointer
,
"/%lu%s"
,
(
unsigned
long
)
child_index
,
target_pointer
);
/* /<array_index><path> */
cJSON_free
(
target_pointer
);
return
(
char
*
)
ret
;
return
(
char
*
)
full_pointer
;
}
else
if
(
cJSON_IsObject
(
object
))
if
(
cJSON_IsObject
(
object
))
{
unsigned
char
*
ret
=
(
unsigned
char
*
)
cJSON_malloc
(
strlen
((
char
*
)
found
)
+
cJSONUtils_PointerEncodedstrlen
((
unsigned
char
*
)
obj
->
string
)
+
2
);
*
ret
=
'/'
;
cJSONUtils_PointerEncodedstrcpy
(
ret
+
1
,
(
unsigned
char
*
)
obj
->
string
);
strcat
((
char
*
)
ret
,
(
char
*
)
found
);
cJSON_free
(
found
);
unsigned
char
*
full_pointer
=
(
unsigned
char
*
)
cJSON_malloc
(
strlen
((
char
*
)
target_pointer
)
+
cJSONUtils_PointerEncodedstrlen
((
unsigned
char
*
)
current_child
->
string
)
+
2
);
full_pointer
[
0
]
=
'/'
;
cJSONUtils_PointerEncodedstrcpy
(
full_pointer
+
1
,
(
unsigned
char
*
)
current_child
->
string
);
strcat
((
char
*
)
full_pointer
,
(
char
*
)
target_pointer
);
cJSON_free
(
target_pointer
);
return
(
char
*
)
ret
;
return
(
char
*
)
full_pointer
;
}
/* reached leaf of the tree, found nothing */
cJSON_free
(
found
);
cJSON_free
(
target_pointer
);
return
NULL
;
}
}
...
...
cJSON_Utils.h
浏览文件 @
4932c80f
...
...
@@ -60,7 +60,7 @@ CJSON_PUBLIC(cJSON *) cJSONUtils_MergePatch(cJSON *target, cJSON *patch);
CJSON_PUBLIC
(
cJSON
*
)
cJSONUtils_GenerateMergePatch
(
cJSON
*
from
,
cJSON
*
to
);
/* Given a root object and a target object, construct a pointer from one to the other. */
CJSON_PUBLIC
(
char
*
)
cJSONUtils_FindPointerFromObjectTo
(
c
JSON
*
object
,
cJSON
*
target
);
CJSON_PUBLIC
(
char
*
)
cJSONUtils_FindPointerFromObjectTo
(
c
onst
cJSON
*
const
object
,
const
cJSON
*
const
target
);
/* Sorts the members of the object into alphabetical order. */
CJSON_PUBLIC
(
void
)
cJSONUtils_SortObject
(
cJSON
*
object
);
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录