Skip to content
项目
群组
代码片段
帮助
正在加载...
登录
切换导航
F
freeswitch
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分枝图
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
分枝图
统计图
创建新议题
作业
提交
议题看板
打开侧边栏
张华
freeswitch
Commits
10b81454
提交
10b81454
authored
2月 11, 2013
作者:
Eliot Gable
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Add cJSON_Duplicate() function from upstream source.
上级
89980756
隐藏空白字符变更
内嵌
并排
正在显示
2 个修改的文件
包含
34 行增加
和
0 行删除
+34
-0
switch_json.h
src/include/switch_json.h
+7
-0
switch_json.c
src/switch_json.c
+27
-0
没有找到文件。
src/include/switch_json.h
浏览文件 @
10b81454
...
...
@@ -114,6 +114,13 @@ SWITCH_DECLARE(void) cJSON_DeleteItemFromObject(cJSON *object,const char *stri
SWITCH_DECLARE
(
void
)
cJSON_ReplaceItemInArray
(
cJSON
*
array
,
int
which
,
cJSON
*
newitem
);
SWITCH_DECLARE
(
void
)
cJSON_ReplaceItemInObject
(
cJSON
*
object
,
const
char
*
string
,
cJSON
*
newitem
);
/* Duplicate a cJSON item */
SWITCH_DECLARE
(
cJSON
*
)
cJSON_Duplicate
(
cJSON
*
item
,
int
recurse
);
/* Duplicate will create a new, identical cJSON item to the one you pass, in new memory that will
need to be released. With recurse!=0, it will duplicate any children connected to the item.
The item->next and ->prev pointers are always zero on return from Duplicate. */
#define cJSON_AddNullToObject(object,name) cJSON_AddItemToObject(object, name, cJSON_CreateNull())
#define cJSON_AddTrueToObject(object,name) cJSON_AddItemToObject(object, name, cJSON_CreateTrue())
#define cJSON_AddFalseToObject(object,name) cJSON_AddItemToObject(object, name, cJSON_CreateFalse())
...
...
src/switch_json.c
浏览文件 @
10b81454
...
...
@@ -527,3 +527,30 @@ SWITCH_DECLARE(cJSON *)cJSON_CreateIntArray(int *numbers,int count) {int i;cJ
SWITCH_DECLARE
(
cJSON
*
)
cJSON_CreateFloatArray
(
float
*
numbers
,
int
count
)
{
int
i
;
cJSON
*
n
=
0
,
*
p
=
0
,
*
a
=
cJSON_CreateArray
();
for
(
i
=
0
;
a
&&
i
<
count
;
i
++
){
n
=
cJSON_CreateNumber
(
numbers
[
i
]);
if
(
!
i
)
a
->
child
=
n
;
else
suffix_object
(
p
,
n
);
p
=
n
;}
return
a
;}
SWITCH_DECLARE
(
cJSON
*
)
cJSON_CreateDoubleArray
(
double
*
numbers
,
int
count
)
{
int
i
;
cJSON
*
n
=
0
,
*
p
=
0
,
*
a
=
cJSON_CreateArray
();
for
(
i
=
0
;
a
&&
i
<
count
;
i
++
){
n
=
cJSON_CreateNumber
(
numbers
[
i
]);
if
(
!
i
)
a
->
child
=
n
;
else
suffix_object
(
p
,
n
);
p
=
n
;}
return
a
;}
SWITCH_DECLARE
(
cJSON
*
)
cJSON_CreateStringArray
(
const
char
**
strings
,
int
count
)
{
int
i
;
cJSON
*
n
=
0
,
*
p
=
0
,
*
a
=
cJSON_CreateArray
();
for
(
i
=
0
;
a
&&
i
<
count
;
i
++
){
n
=
cJSON_CreateString
(
strings
[
i
]);
if
(
!
i
)
a
->
child
=
n
;
else
suffix_object
(
p
,
n
);
p
=
n
;}
return
a
;}
/* Duplication */
SWITCH_DECLARE
(
cJSON
*
)
cJSON_Duplicate
(
cJSON
*
item
,
int
recurse
)
{
cJSON
*
newitem
,
*
cptr
,
*
nptr
=
0
,
*
newchild
;
/* Bail on bad ptr */
if
(
!
item
)
return
0
;
/* Create new item */
newitem
=
cJSON_New_Item
();
if
(
!
newitem
)
return
0
;
/* Copy over all vars */
newitem
->
type
=
item
->
type
&
(
~
cJSON_IsReference
),
newitem
->
valueint
=
item
->
valueint
,
newitem
->
valuedouble
=
item
->
valuedouble
;
if
(
item
->
valuestring
)
{
newitem
->
valuestring
=
cJSON_strdup
(
item
->
valuestring
);
if
(
!
newitem
->
valuestring
)
{
cJSON_Delete
(
newitem
);
return
0
;}}
if
(
item
->
string
)
{
newitem
->
string
=
cJSON_strdup
(
item
->
string
);
if
(
!
newitem
->
string
)
{
cJSON_Delete
(
newitem
);
return
0
;}}
/* If non-recursive, then we're done! */
if
(
!
recurse
)
return
newitem
;
/* Walk the ->next chain for the child. */
cptr
=
item
->
child
;
while
(
cptr
)
{
newchild
=
cJSON_Duplicate
(
cptr
,
1
);
/* Duplicate (with recurse) each item in the ->next chain */
if
(
!
newchild
)
{
cJSON_Delete
(
newitem
);
return
0
;}
if
(
nptr
)
{
nptr
->
next
=
newchild
,
newchild
->
prev
=
nptr
;
nptr
=
newchild
;}
/* If newitem->child already set, then crosswire ->prev and ->next and move on */
else
{
newitem
->
child
=
newchild
;
nptr
=
newchild
;}
/* Set newitem->child and move to it */
cptr
=
cptr
->
next
;
}
return
newitem
;
}
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论