diff options
| author | Carl Hetherington <cth@carlh.net> | 2018-06-21 23:02:39 +0100 |
|---|---|---|
| committer | Carl Hetherington <cth@carlh.net> | 2018-09-16 16:07:14 +0100 |
| commit | 044cde1e20270618b9156d68cba8b3d5558a30ce (patch) | |
| tree | 7733f3fb556549f895a7fac88605dcf56ec5dd8a | |
| parent | 5b603c88793733177301f5d62c4181ebf6f91cf2 (diff) | |
Fix corruption of UTF16 subtitle files.
| -rw-r--r-- | src/lib/text_subtitle.cc | 15 |
1 files changed, 8 insertions, 7 deletions
diff --git a/src/lib/text_subtitle.cc b/src/lib/text_subtitle.cc index a3c3975e4..972e74b66 100644 --- a/src/lib/text_subtitle.cc +++ b/src/lib/text_subtitle.cc @@ -43,13 +43,6 @@ 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); @@ -71,6 +64,14 @@ TextSubtitle::TextSubtitle (shared_ptr<const TextSubtitleContent> content) scoped_array<char> utf8 (new char[utf16_len * 2]); ucnv_fromUChars (to_utf8, utf8.get(), utf16_len * 2, reinterpret_cast<UChar*>(utf16.get()), utf16_len, &status); + /* Fix OS X line endings */ + size_t utf8_len = strlen (utf8.get ()); + for (size_t i = 0; i < utf8_len; ++i) { + if (utf8[i] == '\r' && ((i == utf8_len - 1) || utf8[i + 1] != '\n')) { + utf8[i] = '\n'; + } + } + ucsdet_close (detector); ucnv_close (to_utf16); ucnv_close (to_utf8); |
