[opencv] 131/251: core: fix FileStorage format detection in case of .gz archives

Nobuhiro Iwamatsu iwamatsu at moszumanska.debian.org
Sun Aug 27 23:27:34 UTC 2017


This is an automated email from the git hooks/post-receive script.

iwamatsu pushed a commit to annotated tag 3.3.0
in repository opencv.

commit ec7ce814011002093a07b03c13fdba1c2f258417
Author: Alexander Alekhin <alexander.alekhin at intel.com>
Date:   Thu Jul 20 19:58:36 2017 +0300

    core: fix FileStorage format detection in case of .gz archives
---
 modules/core/src/persistence.cpp | 20 +++++++++++++++++---
 1 file changed, 17 insertions(+), 3 deletions(-)

diff --git a/modules/core/src/persistence.cpp b/modules/core/src/persistence.cpp
index ef655e0..a675784 100644
--- a/modules/core/src/persistence.cpp
+++ b/modules/core/src/persistence.cpp
@@ -4270,11 +4270,25 @@ cvOpenFileStorage( const char* query, CvMemStorage* dststorage, int flags, const
 
         if( fmt == CV_STORAGE_FORMAT_AUTO && filename )
         {
-            const char* dot_pos = strrchr( filename, '.' );
+            const char* dot_pos = NULL;
+            const char* dot_pos2 = NULL;
+            // like strrchr() implementation, but save two last positions simultaneously
+            for (const char* pos = filename; pos[0] != 0; pos++)
+            {
+                if (pos[0] == '.')
+                {
+                    dot_pos2 = dot_pos;
+                    dot_pos = pos;
+                }
+            }
+            if (cv_strcasecmp(dot_pos, ".gz") && dot_pos2 != NULL)
+            {
+                dot_pos = dot_pos2;
+            }
             fs->fmt
-                = cv_strcasecmp( dot_pos, ".xml" )
+                = (cv_strcasecmp(dot_pos, ".xml") || cv_strcasecmp(dot_pos, ".xml.gz"))
                 ? CV_STORAGE_FORMAT_XML
-                : cv_strcasecmp( dot_pos, ".json" )
+                : (cv_strcasecmp(dot_pos, ".json") || cv_strcasecmp(dot_pos, ".json.gz"))
                 ? CV_STORAGE_FORMAT_JSON
                 : CV_STORAGE_FORMAT_YAML
                 ;

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/debian-science/packages/opencv.git



More information about the debian-science-commits mailing list