Fix failure to parse subtitle files with OS X line endings.
authorCarl Hetherington <cth@carlh.net>
Tue, 6 Feb 2018 20:03:59 +0000 (20:03 +0000)
committerCarl Hetherington <cth@carlh.net>
Tue, 6 Feb 2018 20:03:59 +0000 (20:03 +0000)
ChangeLog
src/lib/text_subtitle.cc

index 2e5f54cabd32c6a3d3d87672a4a199b6f3eedeef..a95a9350754972a48a78d9be41542c51758ccf67 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,7 @@
 2018-02-06  Carl Hetherington  <cth@carlh.net>
 
+       * Fix problems with text subtitle files containing OS X line-endings.
+
        * Version 2.11.49 released.
 
 2018-02-05  Carl Hetherington  <cth@carlh.net>
index 2de815459b8ae1f35550f9eaf2053ec460de3f9b..a3c3975e4aba8a80aed05de87c744b150a36db20 100644 (file)
@@ -43,6 +43,13 @@ TextSubtitle::TextSubtitle (shared_ptr<const TextSubtitleContent> content)
 {
        Data in (content->path (0));
 
+       /* Fix OS X line endings */
+       for (int i = 0; i < in.size(); ++i) {
+               if (in.data()[i] == '\r' && ((i == in.size() - 1) || in.data()[i + 1] != '\n')) {
+                       in.data()[i] = '\n';
+               }
+       }
+
        UErrorCode status = U_ZERO_ERROR;
        UCharsetDetector* detector = ucsdet_open (&status);
        ucsdet_setText (detector, reinterpret_cast<const char *> (in.data().get()), in.size(), &status);