Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
OpenHarmony
Third Party CJSON
提交
af9c76e3
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,发现更多精彩内容 >>
提交
af9c76e3
编写于
4月 30, 2017
作者:
M
Max Bruckner
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Add get_item_from_pointer: Configurable case sensitivity
上级
2f33e8ec
变更
1
显示空白变更内容
内联
并排
Showing
1 changed file
with
13 addition
and
6 deletion
+13
-6
cJSON_Utils.c
cJSON_Utils.c
+13
-6
未找到文件。
cJSON_Utils.c
浏览文件 @
af9c76e3
...
@@ -254,7 +254,7 @@ static cJSON_bool decode_array_index_from_pointer(const unsigned char * const po
...
@@ -254,7 +254,7 @@ static cJSON_bool decode_array_index_from_pointer(const unsigned char * const po
return
1
;
return
1
;
}
}
CJSON_PUBLIC
(
cJSON
*
)
cJSONUtils_GetPointer
(
cJSON
*
const
object
,
const
char
*
pointer
)
static
cJSON
*
get_item_from_pointer
(
cJSON
*
const
object
,
const
char
*
pointer
,
const
cJSON_bool
case_sensitive
)
{
{
cJSON
*
current_element
=
object
;
cJSON
*
current_element
=
object
;
/* follow path of the pointer */
/* follow path of the pointer */
...
@@ -275,7 +275,7 @@ CJSON_PUBLIC(cJSON *) cJSONUtils_GetPointer(cJSON * const object, const char *po
...
@@ -275,7 +275,7 @@ CJSON_PUBLIC(cJSON *) cJSONUtils_GetPointer(cJSON * const object, const char *po
{
{
current_element
=
current_element
->
child
;
current_element
=
current_element
->
child
;
/* GetObjectItem. */
/* GetObjectItem. */
while
((
current_element
!=
NULL
)
&&
!
compare_pointers
((
unsigned
char
*
)
current_element
->
string
,
(
const
unsigned
char
*
)
pointer
,
fals
e
))
while
((
current_element
!=
NULL
)
&&
!
compare_pointers
((
unsigned
char
*
)
current_element
->
string
,
(
const
unsigned
char
*
)
pointer
,
case_sensitiv
e
))
{
{
current_element
=
current_element
->
next
;
current_element
=
current_element
->
next
;
}
}
...
@@ -294,6 +294,11 @@ CJSON_PUBLIC(cJSON *) cJSONUtils_GetPointer(cJSON * const object, const char *po
...
@@ -294,6 +294,11 @@ CJSON_PUBLIC(cJSON *) cJSONUtils_GetPointer(cJSON * const object, const char *po
return
current_element
;
return
current_element
;
}
}
CJSON_PUBLIC
(
cJSON
*
)
cJSONUtils_GetPointer
(
cJSON
*
const
object
,
const
char
*
pointer
)
{
return
get_item_from_pointer
(
object
,
pointer
,
false
);
}
/* JSON Patch implementation. */
/* JSON Patch implementation. */
static
void
decode_pointer_inplace
(
unsigned
char
*
string
)
static
void
decode_pointer_inplace
(
unsigned
char
*
string
)
{
{
...
@@ -364,6 +369,7 @@ static cJSON *detach_item_from_array(cJSON *array, size_t which)
...
@@ -364,6 +369,7 @@ static cJSON *detach_item_from_array(cJSON *array, size_t which)
/* detach an item at the given path */
/* detach an item at the given path */
static
cJSON
*
detach_path
(
cJSON
*
object
,
const
unsigned
char
*
path
)
static
cJSON
*
detach_path
(
cJSON
*
object
,
const
unsigned
char
*
path
)
{
{
cJSON_bool
case_sensitive
=
false
;
unsigned
char
*
parent_pointer
=
NULL
;
unsigned
char
*
parent_pointer
=
NULL
;
unsigned
char
*
child_pointer
=
NULL
;
unsigned
char
*
child_pointer
=
NULL
;
cJSON
*
parent
=
NULL
;
cJSON
*
parent
=
NULL
;
...
@@ -384,7 +390,7 @@ static cJSON *detach_path(cJSON *object, const unsigned char *path)
...
@@ -384,7 +390,7 @@ static cJSON *detach_path(cJSON *object, const unsigned char *path)
child_pointer
[
0
]
=
'\0'
;
child_pointer
[
0
]
=
'\0'
;
child_pointer
++
;
child_pointer
++
;
parent
=
cJSONUtils_GetPointer
(
object
,
(
char
*
)
parent_pointer
);
parent
=
get_item_from_pointer
(
object
,
(
char
*
)
parent_pointer
,
case_sensitive
);
decode_pointer_inplace
(
child_pointer
);
decode_pointer_inplace
(
child_pointer
);
if
(
cJSON_IsArray
(
parent
))
if
(
cJSON_IsArray
(
parent
))
...
@@ -610,6 +616,7 @@ static void overwrite_item(cJSON * const root, const cJSON replacement)
...
@@ -610,6 +616,7 @@ static void overwrite_item(cJSON * const root, const cJSON replacement)
static
int
apply_patch
(
cJSON
*
object
,
const
cJSON
*
patch
)
static
int
apply_patch
(
cJSON
*
object
,
const
cJSON
*
patch
)
{
{
cJSON_bool
case_sensitive
=
false
;
cJSON
*
path
=
NULL
;
cJSON
*
path
=
NULL
;
cJSON
*
value
=
NULL
;
cJSON
*
value
=
NULL
;
cJSON
*
parent
=
NULL
;
cJSON
*
parent
=
NULL
;
...
@@ -635,7 +642,7 @@ static int apply_patch(cJSON *object, const cJSON *patch)
...
@@ -635,7 +642,7 @@ static int apply_patch(cJSON *object, const cJSON *patch)
else
if
(
opcode
==
TEST
)
else
if
(
opcode
==
TEST
)
{
{
/* compare value: {...} with the given path */
/* compare value: {...} with the given path */
status
=
!
compare_json
(
cJSONUtils_GetPointer
(
object
,
path
->
valuestring
),
cJSON_GetObjectItem
(
patch
,
"value"
));
status
=
!
compare_json
(
get_item_from_pointer
(
object
,
path
->
valuestring
,
case_sensitive
),
cJSON_GetObjectItem
(
patch
,
"value"
));
goto
cleanup
;
goto
cleanup
;
}
}
...
@@ -723,7 +730,7 @@ static int apply_patch(cJSON *object, const cJSON *patch)
...
@@ -723,7 +730,7 @@ static int apply_patch(cJSON *object, const cJSON *patch)
}
}
if
(
opcode
==
COPY
)
if
(
opcode
==
COPY
)
{
{
value
=
cJSONUtils_GetPointer
(
object
,
from
->
valuestring
);
value
=
get_item_from_pointer
(
object
,
from
->
valuestring
,
case_sensitive
);
}
}
if
(
value
==
NULL
)
if
(
value
==
NULL
)
{
{
...
@@ -770,7 +777,7 @@ static int apply_patch(cJSON *object, const cJSON *patch)
...
@@ -770,7 +777,7 @@ static int apply_patch(cJSON *object, const cJSON *patch)
child_pointer
[
0
]
=
'\0'
;
child_pointer
[
0
]
=
'\0'
;
child_pointer
++
;
child_pointer
++
;
}
}
parent
=
cJSONUtils_GetPointer
(
object
,
(
char
*
)
parent_pointer
);
parent
=
get_item_from_pointer
(
object
,
(
char
*
)
parent_pointer
,
case_sensitive
);
decode_pointer_inplace
(
child_pointer
);
decode_pointer_inplace
(
child_pointer
);
/* add, remove, replace, move, copy, test. */
/* add, remove, replace, move, copy, test. */
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录