Skip to content

Commit ec7ce81

Browse files
committed
core: fix FileStorage format detection in case of .gz archives
1 parent 5bc2919 commit ec7ce81

File tree

1 file changed

+17
-3
lines changed

1 file changed

+17
-3
lines changed

modules/core/src/persistence.cpp

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4270,11 +4270,25 @@ cvOpenFileStorage( const char* query, CvMemStorage* dststorage, int flags, const
42704270

42714271
if( fmt == CV_STORAGE_FORMAT_AUTO && filename )
42724272
{
4273-
const char* dot_pos = strrchr( filename, '.' );
4273+
const char* dot_pos = NULL;
4274+
const char* dot_pos2 = NULL;
4275+
// like strrchr() implementation, but save two last positions simultaneously
4276+
for (const char* pos = filename; pos[0] != 0; pos++)
4277+
{
4278+
if (pos[0] == '.')
4279+
{
4280+
dot_pos2 = dot_pos;
4281+
dot_pos = pos;
4282+
}
4283+
}
4284+
if (cv_strcasecmp(dot_pos, ".gz") && dot_pos2 != NULL)
4285+
{
4286+
dot_pos = dot_pos2;
4287+
}
42744288
fs->fmt
4275-
= cv_strcasecmp( dot_pos, ".xml" )
4289+
= (cv_strcasecmp(dot_pos, ".xml") || cv_strcasecmp(dot_pos, ".xml.gz"))
42764290
? CV_STORAGE_FORMAT_XML
4277-
: cv_strcasecmp( dot_pos, ".json" )
4291+
: (cv_strcasecmp(dot_pos, ".json") || cv_strcasecmp(dot_pos, ".json.gz"))
42784292
? CV_STORAGE_FORMAT_JSON
42794293
: CV_STORAGE_FORMAT_YAML
42804294
;

0 commit comments

Comments
 (0)