Fix failure to parse subrip where there are extra spaces in the time/position line.
[libsub.git] / src / reader_factory.cc
index fd19c0fb4181d241fbf0a09eaf6e27c6999375a4..5d38e4e9ec5a57365eed9c564bb89f59a8e1482e 100644 (file)
 
 */
 
-#include <fstream>
-#include <boost/algorithm/string.hpp>
 #include "reader_factory.h"
-#include "dcp_reader.h"
 #include "stl_binary_reader.h"
 #include "stl_text_reader.h"
+#include "dcp_reader.h"
+#include <libxml++/libxml++.h>
+#include <boost/algorithm/string.hpp>
+#include <fstream>
 
 using std::string;
 using std::ifstream;
@@ -31,19 +32,23 @@ using boost::shared_ptr;
 using namespace sub;
 
 shared_ptr<Reader>
-sub::reader_factory (string file_name)
+sub::reader_factory (boost::filesystem::path file_name)
 {
-       ifstream f (file_name.c_str ());
-       if (!f.good ()) {
-               return shared_ptr<Reader> ();
-       }
-       
-       if (ends_with (file_name, ".xml") || ends_with (file_name, ".XML")) {
-               return shared_ptr<Reader> (new DCPReader (f));
-       }
+       string ext = file_name.extension().string();
+       transform (ext.begin(), ext.end(), ext.begin(), ::tolower);
+
+       if (ext == ".xml") {
+               return shared_ptr<Reader> (new DCPReader (file_name));
+        }
+
+        if (ext == ".mxf") {
+                /* Assume this is some MXF-wrapped SMPTE subtitles */
+                return shared_ptr<Reader> (new DCPReader (file_name));
+        }
 
-       if (ends_with (file_name, ".stl") || ends_with (file_name, ".STL")) {
+       if (ext == ".stl") {
                /* Check the start of the DFC */
+               ifstream f (file_name.string().c_str ());
                char buffer[11];
                f.read (buffer, 11);
                f.seekg (0);