From fa7bc921f3fdf492dd8742bb5b778c7e4b38d98f Mon Sep 17 00:00:00 2001 From: Carl Hetherington Date: Tue, 6 Feb 2018 20:03:59 +0000 Subject: Fix failure to parse subtitle files with OS X line endings. --- ChangeLog | 2 ++ src/lib/text_subtitle.cc | 7 +++++++ 2 files changed, 9 insertions(+) diff --git a/ChangeLog b/ChangeLog index 2e5f54cab..a95a93507 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,7 @@ 2018-02-06 Carl Hetherington + * Fix problems with text subtitle files containing OS X line-endings. + * Version 2.11.49 released. 2018-02-05 Carl Hetherington diff --git a/src/lib/text_subtitle.cc b/src/lib/text_subtitle.cc index 2de815459..a3c3975e4 100644 --- a/src/lib/text_subtitle.cc +++ b/src/lib/text_subtitle.cc @@ -43,6 +43,13 @@ TextSubtitle::TextSubtitle (shared_ptr 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 (in.data().get()), in.size(), &status); -- cgit v1.2.3