Added support for Mac-style line endings in text files

This commit is contained in:
Moritz Bunkus 2010-03-15 15:20:00 +01:00
parent a05599086d
commit dbad4117fb
4 changed files with 44 additions and 7 deletions

View File

@ -1,3 +1,8 @@
2010-03-15 Moritz Bunkus <moritz@bunkus.org>
* all: enhancement: Added support for old Mac-style line endings
(only '\r' without '\n') in text files.
2010-03-11 Moritz Bunkus <moritz@bunkus.org>
* mmg: enhancement: Added the values "4483M" and "8142M" to the

View File

@ -1223,26 +1223,40 @@ mm_text_io_c::read_next_char(char *buffer) {
std::string
mm_text_io_c::getline() {
std::string s;
char utf8char[8];
if (eof())
throw error_c(Y("end-of-file"));
std::string s;
char utf8char[9];
bool previous_was_carriage_return = false;
while (1) {
memset(utf8char, 0, 8);
memset(utf8char, 0, 9);
int len = read_next_char(utf8char);
if (0 == len)
return s;
if ((1 == len) && (utf8char[0] == '\r'))
if ((1 == len) && (utf8char[0] == '\r')) {
if (previous_was_carriage_return) {
setFilePointer(-1, seek_current);
return s;
}
previous_was_carriage_return = true;
continue;
}
if ((1 == len) && (utf8char[0] == '\n'))
return s;
s += utf8char;
if (previous_was_carriage_return) {
setFilePointer(-len, seek_current);
return s;
}
previous_was_carriage_return = false;
s += utf8char;
}
}
@ -1254,7 +1268,7 @@ mm_text_io_c::get_byte_order() {
void
mm_text_io_c::setFilePointer(int64 offset,
seek_mode mode) {
mm_proxy_io_c::setFilePointer(((0 == offset) && (seek_beginning == mode)) ? bom_len : offset, seek_beginning);
mm_proxy_io_c::setFilePointer(((0 == offset) && (seek_beginning == mode)) ? bom_len : offset, mode);
}
/*

View File

@ -108,3 +108,4 @@ T_257theora_v1_1:0c7d24d5c1efe6ad137ec22feecff888-179acccc0be06f8c72adb94bd95f72
T_258srt_negative_timecodes:784ac656fd308f3e48f6321736c6e207:passed:20091226-220350
T_259mp4_chapters_text_trak:683f37e978f359f5f6edcda64b108d84-eb7426e252b460a63aa7fff2f82411a6:passed:20091230-221546
T_260version_numbers:ok:passed:20100120-131720
T_261line_endings_in_text_files:f30e785929ac88da5f7892890a034f99-f30e785929ac88da5f7892890a034f99-f30e785929ac88da5f7892890a034f99:passed:20100315-151719

View File

@ -0,0 +1,17 @@
#!/usr/bin/ruby -w
class T_261line_endings_in_text_files < Test
def description
return "mkvmerge / different line endings in text files"
end
def run
checksums = %w{unix dos mac}.collect do |style|
merge "data/textsubs/line-endings/subs-#{style}.srt"
hash_tmp
end
return checksums.join "-"
end
end