Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
OpenHarmony
Third Party CJSON
提交
33193ea5
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,发现更多精彩内容 >>
提交
33193ea5
编写于
5月 02, 2017
作者:
M
Max Bruckner
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Internal function get_array_item
上级
acb0ca88
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
49 addition
and
40 deletion
+49
-40
cJSON.c
cJSON.c
+48
-39
cJSON.h
cJSON.h
+1
-1
未找到文件。
cJSON.c
浏览文件 @
33193ea5
...
...
@@ -1665,16 +1665,33 @@ CJSON_PUBLIC(int) cJSON_GetArraySize(const cJSON *array)
return
(
int
)
i
;
}
CJSON_PUBLIC
(
cJSON
*
)
cJSON_GetArrayItem
(
const
cJSON
*
array
,
int
item
)
static
cJSON
*
get_array_item
(
const
cJSON
*
array
,
size_t
index
)
{
cJSON
*
c
=
array
?
array
->
child
:
NULL
;
while
(
c
&&
item
>
0
)
cJSON
*
current_child
=
NULL
;
if
(
array
==
NULL
)
{
item
--
;
c
=
c
->
next
;
return
NULL
;
}
current_child
=
array
->
child
;
while
((
current_child
!=
NULL
)
&&
(
index
>
0
))
{
index
--
;
current_child
=
current_child
->
next
;
}
return
current_child
;
}
CJSON_PUBLIC
(
cJSON
*
)
cJSON_GetArrayItem
(
const
cJSON
*
array
,
int
index
)
{
if
(
index
<
0
)
{
return
NULL
;
}
return
c
;
return
get_array_item
(
array
,
(
size_t
)
index
)
;
}
static
cJSON
*
get_object_item
(
const
cJSON
*
const
object
,
const
char
*
const
name
,
const
cJSON_bool
case_sensitive
)
...
...
@@ -1844,17 +1861,6 @@ CJSON_PUBLIC(cJSON *) cJSON_DetachItemViaPointer(cJSON *parent, cJSON * const it
return
item
;
}
static
cJSON
*
DetachItemFromArray
(
cJSON
*
array
,
size_t
which
)
{
cJSON
*
c
=
array
->
child
;
while
(
c
&&
(
which
>
0
))
{
c
=
c
->
next
;
which
--
;
}
return
cJSON_DetachItemViaPointer
(
array
,
c
);
}
CJSON_PUBLIC
(
cJSON
*
)
cJSON_DetachItemFromArray
(
cJSON
*
array
,
int
which
)
{
if
(
which
<
0
)
...
...
@@ -1862,7 +1868,7 @@ CJSON_PUBLIC(cJSON *) cJSON_DetachItemFromArray(cJSON *array, int which)
return
NULL
;
}
return
DetachItemFromArray
(
array
,
(
size_t
)
which
);
return
cJSON_DetachItemViaPointer
(
array
,
get_array_item
(
array
,
(
size_t
)
which
)
);
}
CJSON_PUBLIC
(
void
)
cJSON_DeleteItemFromArray
(
cJSON
*
array
,
int
which
)
...
...
@@ -1889,21 +1895,24 @@ CJSON_PUBLIC(void) cJSON_DeleteItemFromObject(cJSON *object, const char *string)
/* Replace array/object items with new ones. */
CJSON_PUBLIC
(
void
)
cJSON_InsertItemInArray
(
cJSON
*
array
,
int
which
,
cJSON
*
newitem
)
{
cJSON
*
c
=
array
->
child
;
while
(
c
&&
(
which
>
0
))
cJSON
*
after_inserted
=
NULL
;
if
(
which
<
0
)
{
c
=
c
->
next
;
which
--
;
return
;
}
if
(
!
c
)
after_inserted
=
get_array_item
(
array
,
(
size_t
)
which
);
if
(
after_inserted
==
NULL
)
{
cJSON_AddItemToArray
(
array
,
newitem
);
return
;
}
newitem
->
next
=
c
;
newitem
->
prev
=
c
->
prev
;
c
->
prev
=
newitem
;
if
(
c
==
array
->
child
)
newitem
->
next
=
after_inserted
;
newitem
->
prev
=
after_inserted
->
prev
;
after_inserted
->
prev
=
newitem
;
if
(
after_inserted
==
array
->
child
)
{
array
->
child
=
newitem
;
}
...
...
@@ -1915,23 +1924,20 @@ CJSON_PUBLIC(void) cJSON_InsertItemInArray(cJSON *array, int which, cJSON *newit
static
void
ReplaceItemInArray
(
cJSON
*
array
,
size_t
which
,
cJSON
*
newitem
)
{
cJSON
*
c
=
array
->
child
;
while
(
c
&&
(
which
>
0
))
{
c
=
c
->
next
;
which
--
;
}
if
(
!
c
)
cJSON
*
replaced
=
get_array_item
(
array
,
which
);
if
(
replaced
==
NULL
)
{
return
;
}
newitem
->
next
=
c
->
next
;
newitem
->
prev
=
c
->
prev
;
newitem
->
next
=
replaced
->
next
;
newitem
->
prev
=
replaced
->
prev
;
if
(
newitem
->
next
)
{
newitem
->
next
->
prev
=
newitem
;
}
if
(
c
==
array
->
child
)
if
(
replaced
==
array
->
child
)
{
array
->
child
=
newitem
;
}
...
...
@@ -1939,8 +1945,11 @@ static void ReplaceItemInArray(cJSON *array, size_t which, cJSON *newitem)
{
newitem
->
prev
->
next
=
newitem
;
}
c
->
next
=
c
->
prev
=
NULL
;
cJSON_Delete
(
c
);
replaced
->
next
=
NULL
;
replaced
->
prev
=
NULL
;
cJSON_Delete
(
replaced
);
}
CJSON_PUBLIC
(
void
)
cJSON_ReplaceItemInArray
(
cJSON
*
array
,
int
which
,
cJSON
*
newitem
)
{
...
...
cJSON.h
浏览文件 @
33193ea5
...
...
@@ -153,7 +153,7 @@ CJSON_PUBLIC(void) cJSON_Delete(cJSON *c);
/* Returns the number of items in an array (or object). */
CJSON_PUBLIC
(
int
)
cJSON_GetArraySize
(
const
cJSON
*
array
);
/* Retrieve item number "item" from array "array". Returns NULL if unsuccessful. */
CJSON_PUBLIC
(
cJSON
*
)
cJSON_GetArrayItem
(
const
cJSON
*
array
,
int
i
tem
);
CJSON_PUBLIC
(
cJSON
*
)
cJSON_GetArrayItem
(
const
cJSON
*
array
,
int
i
ndex
);
/* Get item "string" from object. Case insensitive. */
CJSON_PUBLIC
(
cJSON
*
)
cJSON_GetObjectItem
(
const
cJSON
*
object
,
const
char
*
string
);
CJSON_PUBLIC
(
cJSON
*
)
cJSON_GetObjectItemCaseSensitive
(
const
cJSON
*
const
object
,
const
char
*
const
string
);
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录