Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
Greenplum
Opencv
提交
38483fe7
O
Opencv
项目概览
Greenplum
/
Opencv
10 个月 前同步成功
通知
7
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
O
Opencv
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
前往新版Gitcode,体验更适合开发者的 AI 搜索 >>
提交
38483fe7
编写于
11月 01, 2016
作者:
V
Vladislav Sovrasov
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Skip UTF-8 BOM in FileStorage
上级
6c125331
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
37 addition
and
2 deletion
+37
-2
modules/core/src/persistence.cpp
modules/core/src/persistence.cpp
+15
-2
modules/core/test/test_io.cpp
modules/core/test/test_io.cpp
+22
-0
未找到文件。
modules/core/src/persistence.cpp
浏览文件 @
38483fe7
...
...
@@ -96,6 +96,15 @@ static inline bool cv_isspace(char c)
return
(
9
<=
c
&&
c
<=
13
)
||
c
==
' '
;
}
static
inline
char
*
cv_skip_BOM
(
char
*
ptr
)
{
if
((
uchar
)
ptr
[
0
]
==
0xef
&&
(
uchar
)
ptr
[
1
]
==
0xbb
&&
(
uchar
)
ptr
[
2
]
==
0xbf
)
//UTF-8 BOM
{
return
ptr
+
3
;
}
return
ptr
;
}
static
char
*
icv_itoa
(
int
_val
,
char
*
buffer
,
int
/*radix*/
)
{
const
int
radix
=
10
;
...
...
@@ -4399,10 +4408,13 @@ cvOpenFileStorage( const char* query, CvMemStorage* dststorage, int flags, const
const
char
*
json_signature
=
"{"
;
char
buf
[
16
];
icvGets
(
fs
,
buf
,
sizeof
(
buf
)
-
2
);
char
*
bufPtr
=
cv_skip_BOM
(
buf
);
size_t
bufOffset
=
bufPtr
-
buf
;
fs
->
fmt
=
strncmp
(
buf
,
yaml_signature
,
strlen
(
yaml_signature
)
)
==
0
=
strncmp
(
buf
Ptr
,
yaml_signature
,
strlen
(
yaml_signature
)
)
==
0
?
CV_STORAGE_FORMAT_YAML
:
strncmp
(
buf
,
json_signature
,
strlen
(
json_signature
)
)
==
0
:
strncmp
(
buf
Ptr
,
json_signature
,
strlen
(
json_signature
)
)
==
0
?
CV_STORAGE_FORMAT_JSON
:
CV_STORAGE_FORMAT_XML
;
...
...
@@ -4420,6 +4432,7 @@ cvOpenFileStorage( const char* query, CvMemStorage* dststorage, int flags, const
buf_size
=
MAX
(
buf_size
,
(
size_t
)(
CV_FS_MAX_LEN
*
2
+
1024
)
);
}
icvRewind
(
fs
);
fs
->
strbufpos
=
bufOffset
;
fs
->
str_hash
=
cvCreateMap
(
0
,
sizeof
(
CvStringHash
),
sizeof
(
CvStringHashNode
),
fs
->
memstorage
,
256
);
...
...
modules/core/test/test_io.cpp
浏览文件 @
38483fe7
...
...
@@ -928,3 +928,25 @@ TEST(Core_InputOutput, filestorage_json_comment)
EXPECT_EQ
(
str
,
String
(
"value"
));
}
TEST
(
Core_InputOutput
,
filestorage_utf8_bom
)
{
EXPECT_NO_THROW
(
{
String
content
=
"
\xEF\xBB\xBF
<?xml version=
\"
1.0
\"
?>
\n
<opencv_storage>
\n
</opencv_storage>
\n
"
;
cv
::
FileStorage
fs
(
content
,
cv
::
FileStorage
::
READ
|
cv
::
FileStorage
::
MEMORY
);
fs
.
release
();
});
EXPECT_NO_THROW
(
{
String
content
=
"
\xEF\xBB\xBF
%YAML:1.0
\n
"
;
cv
::
FileStorage
fs
(
content
,
cv
::
FileStorage
::
READ
|
cv
::
FileStorage
::
MEMORY
);
fs
.
release
();
});
EXPECT_NO_THROW
(
{
String
content
=
"
\xEF\xBB\xBF
{
\n
}
\n
"
;
cv
::
FileStorage
fs
(
content
,
cv
::
FileStorage
::
READ
|
cv
::
FileStorage
::
MEMORY
);
fs
.
release
();
});
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录