Added some refact from #1566

fix #1566
This commit is contained in:
Nikolaj Olsson 2016-02-14 20:23:11 +01:00
parent 1fb9af1d6d
commit 1caa4782d7
5 changed files with 20 additions and 32 deletions

View File

@ -246,23 +246,23 @@ namespace Nikse.SubtitleEdit.Core.SubtitleFormats
}
string text = lineSb.ToString();
int noOfLines = Utilities.CountTagInText(text, '|') + 1;
if (Utilities.CountTagInText(text, "{y:i}") == noOfLines && text.StartsWith("{y:i}"))
if (Utilities.CountTagInText(text, "{y:i}") == noOfLines && text.StartsWith("{y:i}", StringComparison.Ordinal))
text = "{Y:i}" + text.Replace("{y:i}", string.Empty);
else if (Utilities.CountTagInText(text, "{y:b}") == noOfLines && text.StartsWith("{y:b}"))
else if (Utilities.CountTagInText(text, "{y:b}") == noOfLines && text.StartsWith("{y:b}", StringComparison.Ordinal))
text = "{Y:b}" + text.Replace("{y:b}", string.Empty);
else if (Utilities.CountTagInText(text, "{y:u}") == noOfLines && text.StartsWith("{y:u}"))
else if (Utilities.CountTagInText(text, "{y:u}") == noOfLines && text.StartsWith("{y:u}", StringComparison.Ordinal))
text = "{Y:u}" + text.Replace("{y:u}", string.Empty);
else if (Utilities.CountTagInText(text, "{y:u}{y:i}") == noOfLines && text.StartsWith("{y:u}{y:i}"))
else if (Utilities.CountTagInText(text, "{y:u}{y:i}") == noOfLines && text.StartsWith("{y:u}{y:i}", StringComparison.Ordinal))
text = "{Y:u}{Y:i}" + text.Replace("{y:u}", string.Empty).Replace("{y:i}", string.Empty);
else if (Utilities.CountTagInText(text, "{y:i}{y:u}") == noOfLines && text.StartsWith("{y:i}{y:u}"))
else if (Utilities.CountTagInText(text, "{y:i}{y:u}") == noOfLines && text.StartsWith("{y:i}{y:u}", StringComparison.Ordinal))
text = "{Y:i}{Y:u}" + text.Replace("{y:i}", string.Empty).Replace("{y:u}", string.Empty);
else if (Utilities.CountTagInText(text, "{y:i}{y:b}") == noOfLines && text.StartsWith("{y:i}{y:b}"))
else if (Utilities.CountTagInText(text, "{y:i}{y:b}") == noOfLines && text.StartsWith("{y:i}{y:b}", StringComparison.Ordinal))
text = "{Y:i}{Y:b}" + text.Replace("{y:i}", string.Empty).Replace("{y:b}", string.Empty);
else if (Utilities.CountTagInText(text, "{y:b}{y:i}") == noOfLines && text.StartsWith("{y:b}{y:i}"))
else if (Utilities.CountTagInText(text, "{y:b}{y:i}") == noOfLines && text.StartsWith("{y:b}{y:i}", StringComparison.Ordinal))
text = "{Y:b}{Y:i}" + text.Replace("{y:i}", string.Empty).Replace("{y:b}", string.Empty);
else if (Utilities.CountTagInText(text, "{y:b}{y:u}") == noOfLines && text.StartsWith("{y:b}{y:u}"))
else if (Utilities.CountTagInText(text, "{y:b}{y:u}") == noOfLines && text.StartsWith("{y:b}{y:u}", StringComparison.Ordinal))
text = "{Y:b}{Y:u}" + text.Replace("{y:b}", string.Empty).Replace("{y:u}", string.Empty);
else if (Utilities.CountTagInText(text, "{y:u}{y:b}") == noOfLines && text.StartsWith("{y:u}{y:b}"))
else if (Utilities.CountTagInText(text, "{y:u}{y:b}") == noOfLines && text.StartsWith("{y:u}{y:b}", StringComparison.Ordinal))
text = "{Y:u}{Y:b}" + text.Replace("{y:u}", string.Empty).Replace("{y:b}", string.Empty);
if (Utilities.CountTagInText(text, "{y:i}") == 1 && noOfLines == 1)
@ -285,6 +285,7 @@ namespace Nikse.SubtitleEdit.Core.SubtitleFormats
_lineNumber = 0;
var lineSb = new StringBuilder();
var pre = new StringBuilder();
char[] splitChar = { '|' };
foreach (string line in lines)
{
_lineNumber++;
@ -304,7 +305,7 @@ namespace Nikse.SubtitleEdit.Core.SubtitleFormats
int endFrame = int.Parse(frames[1]);
string post = string.Empty;
string[] parts = text.Split(new[] { '|' }, StringSplitOptions.RemoveEmptyEntries);
string[] parts = text.Split(splitChar, StringSplitOptions.RemoveEmptyEntries);
int count = 0;
lineSb.Clear();

View File

@ -92,8 +92,8 @@ namespace Nikse.SubtitleEdit.Core.SubtitleFormats
subtitle.Paragraphs.Add(lastParagraph);
var arr = line.Split('\t');
TimeCode start = DecodeTimeCode(arr[1]);
TimeCode end = DecodeTimeCode(arr[2]);
TimeCode start = DecodeTimeCodeFrames(arr[1], SplitCharColon);
TimeCode end = DecodeTimeCodeFrames(arr[2], SplitCharColon);
lastParagraph = new Paragraph(start, end, string.Empty);
success = true;
}
@ -113,19 +113,5 @@ namespace Nikse.SubtitleEdit.Core.SubtitleFormats
subtitle.Renumber();
}
private static TimeCode DecodeTimeCode(string s)
{
var parts = s.Split(':');
//00:00:07:12
string hour = parts[0];
string minutes = parts[1];
string seconds = parts[2];
string frames = parts[3];
TimeCode tc = new TimeCode(int.Parse(hour), int.Parse(minutes), int.Parse(seconds), FramesToMillisecondsMax999(int.Parse(frames)));
return tc;
}
}
}

View File

@ -101,13 +101,13 @@ namespace Nikse.SubtitleEdit.Core.SubtitleFormats
var paragraph = new Paragraph();
ExpectingLine expecting = ExpectingLine.TimeCodes;
_errorCount = 0;
char[] splitChars = { ':', ',', '.' };
subtitle.Paragraphs.Clear();
foreach (string line in lines)
{
if (regexTimeCodes.IsMatch(line))
{
string[] parts = line.Split(new[] { ':', ',', '.' }, StringSplitOptions.RemoveEmptyEntries);
string[] parts = line.Split(splitChars, StringSplitOptions.RemoveEmptyEntries);
if (parts.Length == 8)
{
try

View File

@ -209,11 +209,11 @@ namespace Nikse.SubtitleEdit.Core
public string ToShortStringHHMMSSFF()
{
string s = ToHHMMSSFF();
if (s.StartsWith("0:00:"))
if (s.StartsWith("0:00:", StringComparison.Ordinal))
s = s.Remove(0, 5);
if (s.StartsWith("00:"))
if (s.StartsWith("00:", StringComparison.Ordinal))
s = s.Remove(0, 3);
if (s.StartsWith("00:"))
if (s.StartsWith("00:", StringComparison.Ordinal))
s = s.Remove(0, 3);
return s;
}

View File

@ -2072,6 +2072,7 @@ namespace Nikse.SubtitleEdit.Core
if (!string.IsNullOrEmpty(matroskaSubtitleInfo.CodecPrivate))
{
bool footerOn = false;
char[] splitChars = { ':', '.' };
foreach (string line in lines)
{
if (footerOn)
@ -2093,7 +2094,7 @@ namespace Nikse.SubtitleEdit.Core
var arr = line.Split(',');
if (arr.Length > 3)
{
arr = arr[1].Split(new[] { ':', '.' });
arr = arr[1].Split(splitChars);
if (arr.Length == 4)
{
int hour;