Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
OpenHarmony
Third Party CJSON
提交
ee579ecb
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,发现更多精彩内容 >>
提交
ee579ecb
编写于
3月 19, 2016
作者:
D
Dave Gamble
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Integrate patch for handling broken unicode surrogate pairs, with
thanks to kolman and Irwan Djajadi on SourceForge.
上级
a6a75645
变更
1
显示空白变更内容
内联
并排
Showing
1 changed file
with
12 addition
and
10 deletion
+12
-10
cJSON.c
cJSON.c
+12
-10
未找到文件。
cJSON.c
浏览文件 @
ee579ecb
...
...
@@ -192,16 +192,18 @@ static unsigned parse_hex4(const char *str)
static
const
unsigned
char
firstByteMark
[
7
]
=
{
0x00
,
0x00
,
0xC0
,
0xE0
,
0xF0
,
0xF8
,
0xFC
};
static
const
char
*
parse_string
(
cJSON
*
item
,
const
char
*
str
)
{
const
char
*
ptr
=
str
+
1
;
char
*
ptr2
;
char
*
out
;
int
len
=
0
;
unsigned
uc
,
uc2
;
const
char
*
ptr
=
str
+
1
,
*
end_ptr
=
str
+
1
;
char
*
ptr2
;
char
*
out
;
int
len
=
0
;
unsigned
uc
,
uc2
;
if
(
*
str
!=
'\"'
)
{
ep
=
str
;
return
0
;}
/* not a string! */
while
(
*
ptr
!=
'\"'
&&
*
ptr
&&
++
len
)
if
(
*
ptr
++
==
'\\'
)
ptr
++
;
/* Skip escaped quotes. */
while
(
*
end_ptr
!=
'\"'
&&
*
end_ptr
&&
++
len
)
if
(
*
end_ptr
++
==
'\\'
)
end_
ptr
++
;
/* Skip escaped quotes. */
out
=
(
char
*
)
cJSON_malloc
(
len
+
1
);
/* This is how long we need for the string, roughly. */
if
(
!
out
)
return
0
;
item
->
valuestring
=
out
;
/* assign here so out will be deleted during cJSON_Delete() later */
item
->
type
=
cJSON_String
;
ptr
=
str
+
1
;
ptr2
=
out
;
while
(
*
ptr
!=
'\"'
&&
*
ptr
)
while
(
ptr
<
end_
ptr
)
{
if
(
*
ptr
!=
'\\'
)
*
ptr2
++=*
ptr
++
;
else
...
...
@@ -216,14 +218,16 @@ static const char *parse_string(cJSON *item,const char *str)
case
't'
:
*
ptr2
++=
'\t'
;
break
;
case
'u'
:
/* transcode utf16 to utf8. */
uc
=
parse_hex4
(
ptr
+
1
);
ptr
+=
4
;
/* get the unicode char. */
if
(
ptr
>=
end_ptr
)
{
ep
=
str
;
return
0
;}
/* invalid */
if
((
uc
>=
0xDC00
&&
uc
<=
0xDFFF
)
||
uc
==
0
)
break
;
/* check for invalid.
*/
if
((
uc
>=
0xDC00
&&
uc
<=
0xDFFF
)
||
uc
==
0
)
{
ep
=
str
;
return
0
;}
/* check for invalid.
*/
if
(
uc
>=
0xD800
&&
uc
<=
0xDBFF
)
/* UTF16 surrogate pairs. */
{
if
(
ptr
[
1
]
!=
'\\'
||
ptr
[
2
]
!=
'u'
)
break
;
/* missing second-half of surrogate. */
if
(
ptr
+
6
>
end_ptr
)
{
ep
=
str
;
return
0
;}
/* invalid */
if
(
ptr
[
1
]
!=
'\\'
||
ptr
[
2
]
!=
'u'
)
{
ep
=
str
;
return
0
;}
/* missing second-half of surrogate. */
uc2
=
parse_hex4
(
ptr
+
3
);
ptr
+=
6
;
if
(
uc2
<
0xDC00
||
uc2
>
0xDFFF
)
break
;
/* invalid second-half of surrogate.
*/
if
(
uc2
<
0xDC00
||
uc2
>
0xDFFF
)
{
ep
=
str
;
return
0
;}
/* invalid second-half of surrogate.
*/
uc
=
0x10000
+
(((
uc
&
0x3FF
)
<<
10
)
|
(
uc2
&
0x3FF
));
}
...
...
@@ -244,8 +248,6 @@ static const char *parse_string(cJSON *item,const char *str)
}
*
ptr2
=
0
;
if
(
*
ptr
==
'\"'
)
ptr
++
;
item
->
valuestring
=
out
;
item
->
type
=
cJSON_String
;
return
ptr
;
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录