Fix Windows debug build.
[dcpomatic.git] / src / lib / string_text_file.cc
index 78c119df63255708977ac6928e4ae2958e60fc28..919693dd85d6b14bc6ab82c16d555ae706ea50a3 100644 (file)
 
 */
 
-#include "string_text_file.h"
+
 #include "cross.h"
 #include "exceptions.h"
+#include "string_text_file.h"
 #include "string_text_file_content.h"
-#include <sub/subrip_reader.h>
+#include <sub/collect.h>
 #include <sub/ssa_reader.h>
 #include <sub/stl_binary_reader.h>
-#include <sub/collect.h>
-#include <unicode/ucsdet.h>
+#include <sub/subrip_reader.h>
 #include <unicode/ucnv.h>
+#include <unicode/ucsdet.h>
 #include <iostream>
 
 #include "i18n.h"
 
-using std::vector;
+
 using std::cout;
-using std::string;
 using std::shared_ptr;
-using boost::scoped_array;
+using std::string;
+using std::vector;
 using boost::optional;
+using boost::scoped_array;
 using dcp::ArrayData;
 using namespace dcpomatic;
 
+
 StringTextFile::StringTextFile (shared_ptr<const StringTextFileContent> content)
 {
        string ext = content->path(0).extension().string();
        transform (ext.begin(), ext.end(), ext.begin(), ::tolower);
 
-       sub::Reader* reader = 0;
+       std::unique_ptr<sub::Reader> reader;
 
        if (ext == ".stl") {
-               FILE* f = fopen_boost (content->path(0), "rb");
+               auto f = fopen_boost (content->path(0), "rb");
                if (!f) {
                        throw OpenFileError (content->path(0), errno, OpenFileError::READ);
                }
                try {
-                       reader = new sub::STLBinaryReader (f);
+                       reader.reset(new sub::STLBinaryReader(f));
                } catch (...) {
                        fclose (f);
                        throw;
@@ -100,35 +103,35 @@ StringTextFile::StringTextFile (shared_ptr<const StringTextFileContent> content)
                ucnv_close (to_utf8);
 
                if (ext == ".srt") {
-                       reader = new sub::SubripReader (utf8.get());
+                       reader.reset(new sub::SubripReader(utf8.get()));
                } else if (ext == ".ssa" || ext == ".ass") {
-                       reader = new sub::SSAReader (utf8.get());
+                       reader.reset(new sub::SSAReader(utf8.get()));
                }
        }
 
        if (reader) {
-               _subtitles = sub::collect<vector<sub::Subtitle> > (reader->subtitles ());
+               _subtitles = sub::collect<vector<sub::Subtitle>>(reader->subtitles());
        }
-
-       delete reader;
 }
 
+
 /** @return time of first subtitle, if there is one */
 optional<ContentTime>
 StringTextFile::first () const
 {
        if (_subtitles.empty()) {
-               return optional<ContentTime>();
+               return {};
        }
 
        return ContentTime::from_seconds(_subtitles[0].from.all_as_seconds());
 }
 
+
 ContentTime
 StringTextFile::length () const
 {
        if (_subtitles.empty ()) {
-               return ContentTime ();
+               return {};
        }
 
        return ContentTime::from_seconds (_subtitles.back().to.all_as_seconds ());