Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in / Register
Toggle navigation
O
opencv
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Packages
Packages
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
submodule
opencv
Commits
280cdb5b
Commit
280cdb5b
authored
Nov 02, 2016
by
Vadim Pisarevsky
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #7595 from sovrasov:fs_utf8_bom
parents
6fceb1dd
e955d17c
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
46 additions
and
7 deletions
+46
-7
persistence.cpp
modules/core/src/persistence.cpp
+24
-7
test_io.cpp
modules/core/test/test_io.cpp
+22
-0
No files found.
modules/core/src/persistence.cpp
View file @
280cdb5b
...
...
@@ -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
;
...
...
@@ -4397,15 +4406,22 @@ cvOpenFileStorage( const char* query, CvMemStorage* dststorage, int flags, const
size_t
buf_size
=
1
<<
20
;
const
char
*
yaml_signature
=
"%YAML"
;
const
char
*
json_signature
=
"{"
;
const
char
*
xml_signature
=
"<?xml"
;
char
buf
[
16
];
icvGets
(
fs
,
buf
,
sizeof
(
buf
)
-
2
);
fs
->
fmt
=
strncmp
(
buf
,
yaml_signature
,
strlen
(
yaml_signature
)
)
==
0
?
CV_STORAGE_FORMAT_YAML
:
strncmp
(
buf
,
json_signature
,
strlen
(
json_signature
)
)
==
0
?
CV_STORAGE_FORMAT_JSON
:
CV_STORAGE_FORMAT_XML
;
char
*
bufPtr
=
cv_skip_BOM
(
buf
);
size_t
bufOffset
=
bufPtr
-
buf
;
if
(
strncmp
(
bufPtr
,
yaml_signature
,
strlen
(
yaml_signature
)
)
==
0
)
fs
->
fmt
=
CV_STORAGE_FORMAT_YAML
;
else
if
(
strncmp
(
bufPtr
,
json_signature
,
strlen
(
json_signature
)
)
==
0
)
fs
->
fmt
=
CV_STORAGE_FORMAT_JSON
;
else
if
(
strncmp
(
bufPtr
,
xml_signature
,
strlen
(
xml_signature
)
)
==
0
)
fs
->
fmt
=
CV_STORAGE_FORMAT_XML
;
else
if
(
fs
->
strbufsize
==
bufOffset
)
CV_Error
(
CV_BADARG_ERR
,
"Input file is empty"
);
else
CV_Error
(
CV_BADARG_ERR
,
"Unsupported file storage format"
);
if
(
!
isGZ
)
{
...
...
@@ -4420,6 +4436,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
View file @
280cdb5b
...
...
@@ -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
();
});
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment