use regex to match [mM][iI][dD] file extension for MIDI files, thus making it case...
authorPaul Davis <paul@linuxaudiosystems.com>
Wed, 16 Jan 2013 17:09:52 +0000 (17:09 +0000)
committerPaul Davis <paul@linuxaudiosystems.com>
Wed, 16 Jan 2013 17:09:52 +0000 (17:09 +0000)
git-svn-id: svn://localhost/ardour2/branches/3.0@13855 d708f5d6-7413-0410-9779-e7cbd77b26cf

libs/ardour/ardour/smf_source.h
libs/ardour/smf_source.cc

index b94ffb250f7351b6cbb9cee1480db301cda82778..26437c6c24b3ef4ac12bf8ea67ab197c70d310ff 100644 (file)
@@ -45,7 +45,7 @@ public:
 
        virtual ~SMFSource ();
 
-       bool safe_file_extension (const std::string& path) const {
+        bool safe_file_extension (const std::string& path) const {
                return safe_midi_file_extension(path);
        }
 
index e0462efb08137f9cb14e8004e32f3aed4e4b2d1d..626676ea83286a479738628e8813e8b727f0c0fe 100644 (file)
@@ -24,6 +24,7 @@
 #include <sys/stat.h>
 #include <unistd.h>
 #include <errno.h>
+#include <regex.h>
 
 #include "pbd/pathscanner.h"
 #include "pbd/stl_delete.h"
@@ -449,7 +450,22 @@ SMFSource::mark_midi_streaming_write_completed (Evoral::Sequence<Evoral::Musical
 bool
 SMFSource::safe_midi_file_extension (const string& file)
 {
-       return (file.rfind(".mid") != string::npos) || (file.rfind (".MID") != string::npos);
+       static regex_t compiled_pattern;
+       static bool compile = true;
+       const int nmatches = 2;
+       regmatch_t matches[nmatches];
+       
+       if (compile && regcomp (&compiled_pattern, "[mM][iI][dD]$", REG_EXTENDED)) {
+               return false;
+       } else {
+               compile = false;
+       }
+       
+       if (regexec (&compiled_pattern, file.c_str(), nmatches, matches, 0)) {
+               return false;
+       }
+
+       return true;
 }
 
 void