diff --git a/MP42/MP42SSAParser.m b/MP42/MP42SSAParser.m index e5e136a..6f93369 100644 --- a/MP42/MP42SSAParser.m +++ b/MP42/MP42SSAParser.m @@ -193,8 +193,22 @@ } [sc scanString:@"," intoString:nil]; } + + // Trim '\0' from string end. + NSUInteger index = string.length; + unichar c; + while (index > 0) { + c = [string characterAtIndex:index - 1]; + if (c == '\0') { + index--; + } + else { + break; + } + } - value = [sc.string substringFromIndex:sc.scanLocation]; + NSRange range = NSMakeRange(sc.scanLocation, index - sc.scanLocation); + value = [sc.string substringWithRange:range]; if (value) { [valuesArray addObject:value]; } diff --git a/MP42/MP42TextSubConverter.m b/MP42/MP42TextSubConverter.m index f1439c7..5078e66 100644 --- a/MP42/MP42TextSubConverter.m +++ b/MP42/MP42TextSubConverter.m @@ -58,7 +58,7 @@ if (sampleBuffer->size > 1) { NSString *text = [[NSString alloc] initWithBytes:sampleBuffer->data - length:sampleBuffer->size - 1 + length:sampleBuffer->size encoding:NSUTF8StringEncoding]; if (_converter && text.length) {