Improved support for wsrt files + allow for \r\r\n newline

This commit is contained in:
Nikolaj Olsson 2016-07-06 22:24:34 +02:00
parent d5d6e9af49
commit 73d4e82974
4 changed files with 17 additions and 7 deletions

View File

@ -87,7 +87,7 @@ namespace Nikse.SubtitleEdit.Core
public static string[] SplitToLines(this string source)
{
return source.Replace("\r\n", "\n").Replace('\r', '\n').Replace('\u2028', '\n').Split('\n');
return source.Replace("\r\r\n", "\n").Replace("\r\n", "\n").Replace('\r', '\n').Replace('\u2028', '\n').Split('\n');
}
// http://www.codeproject.com/Articles/43726/Optimizing-string-operations-in-C

View File

@ -126,7 +126,6 @@ namespace Nikse.SubtitleEdit.Core
_paragraphs = new List<Paragraph>();
var lines = new List<string>();
StreamReader sr;
if (useThisEncoding != null)
{
@ -164,8 +163,7 @@ namespace Nikse.SubtitleEdit.Core
}
encoding = sr.CurrentEncoding;
while (!sr.EndOfStream)
lines.Add(sr.ReadLine());
var lines = sr.ReadToEnd().SplitToLines().ToList();
sr.Close();
foreach (SubtitleFormat subtitleFormat in SubtitleFormat.AllSubtitleFormats)
@ -572,6 +570,8 @@ namespace Nikse.SubtitleEdit.Core
public string GetFastHashCode()
{
var sb = new StringBuilder(Paragraphs.Count * 50);
if (Header != null)
sb.Append(Header.Trim());
for (int i = 0; i < Paragraphs.Count; i++)
{
var p = Paragraphs[i];

View File

@ -12,6 +12,7 @@ namespace Nikse.SubtitleEdit.Core.SubtitleFormats
private StringBuilder _errors;
private int _lineNumber;
private bool _isMsFrames;
private bool _isWsrt;
private enum ExpectingLine
{
@ -73,7 +74,7 @@ namespace Nikse.SubtitleEdit.Core.SubtitleFormats
_errors = new StringBuilder();
_lineNumber = 0;
_isMsFrames = true;
_isWsrt = fileName != null && fileName.EndsWith(".wsrt", StringComparison.OrdinalIgnoreCase);
_paragraph = new Paragraph();
_expecting = ExpectingLine.Number;
_errorCount = 0;
@ -168,6 +169,15 @@ namespace Nikse.SubtitleEdit.Core.SubtitleFormats
case ExpectingLine.Text:
if (!string.IsNullOrWhiteSpace(line) || IsText(next))
{
if (_isWsrt && !string.IsNullOrEmpty(line))
{
for (int i = 30; i < 40; i++)
{
line = line.Replace("<" + i + ">", "<i>");
line = line.Replace("</" + i + ">", "</i>");
}
}
if (_paragraph.Text.Length > 0)
_paragraph.Text += Environment.NewLine;
_paragraph.Text += RemoveBadChars(line).TrimEnd().Replace(Environment.NewLine + Environment.NewLine, Environment.NewLine);

View File

@ -1,7 +1,7 @@

Microsoft Visual Studio Solution File, Format Version 12.00
Microsoft Visual Studio Solution File, Format Version 14.00
# Visual Studio 14
VisualStudioVersion = 14.0.25420.1
VisualStudioVersion = 14.0.23107.0
MinimumVisualStudioVersion = 14.0.23107.0
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SubtitleEdit", "SubtitleEdit.csproj", "{511A5B59-1C35-4719-8536-23B19AF9B21A}"
ProjectSection(ProjectDependencies) = postProject