Merge pull request #1076 from ivandrofly/refactor

Refactor (SubtitleFormats|Forms|Logic)
This commit is contained in:
Nikolaj Olsson 2015-07-29 22:19:05 +02:00
commit dfadfdd735
6 changed files with 23 additions and 25 deletions

View File

@ -1200,7 +1200,7 @@ namespace Nikse.SubtitleEdit.Forms
{
_namesEtcList.Remove(undo.UndoWord);
_namesEtcListUppercase.Remove(undo.UndoWord.ToUpper());
if (_languageName.StartsWith("en_") && !undo.UndoWord.EndsWith('s'))
if (_languageName.StartsWith("en_", StringComparison.Ordinal) && !undo.UndoWord.EndsWith('s'))
{
_namesEtcList.Remove(undo.UndoWord + "s");
_namesEtcListUppercase.Remove(undo.UndoWord.ToUpper() + "S");

View File

@ -134,7 +134,7 @@ namespace Nikse.SubtitleEdit.Forms
if (i == numericUpDownParts.Value - 1)
noOfLines = (int)(_subtitle.Paragraphs.Count - ((numericUpDownParts.Value - 1) * partSize));
Subtitle temp = new Subtitle();
var temp = new Subtitle();
temp.Header = _subtitle.Header;
int size = 0;
for (int number = 0; number < noOfLines; number++)
@ -146,7 +146,7 @@ namespace Nikse.SubtitleEdit.Forms
startNumber += noOfLines;
_parts.Add(temp);
ListViewItem lvi = new ListViewItem(string.Format("{0:#,###,###}", noOfLines));
var lvi = new ListViewItem(string.Format("{0:#,###,###}", noOfLines));
lvi.SubItems.Add(string.Format("{0:#,###,###}", size));
lvi.SubItems.Add(fileNameNoExt + ".Part" + (i + 1) + format.Extension);
listViewParts.Items.Add(lvi);
@ -166,7 +166,7 @@ namespace Nikse.SubtitleEdit.Forms
if (currentSize + size > nextLimit + 4 && _parts.Count < numericUpDownParts.Value - 1)
{
_parts.Add(temp);
ListViewItem lvi = new ListViewItem(string.Format("{0:#,###,###}", temp.Paragraphs.Count));
var lvi = new ListViewItem(string.Format("{0:#,###,###}", temp.Paragraphs.Count));
lvi.SubItems.Add(string.Format("{0:#,###,###}", currentSize));
lvi.SubItems.Add(fileNameNoExt + ".Part" + _parts.Count + format.Extension);
listViewParts.Items.Add(lvi);
@ -182,7 +182,7 @@ namespace Nikse.SubtitleEdit.Forms
}
}
_parts.Add(temp);
ListViewItem lvi2 = new ListViewItem(string.Format("{0:#,###,###}", temp.Paragraphs.Count));
var lvi2 = new ListViewItem(string.Format("{0:#,###,###}", temp.Paragraphs.Count));
lvi2.SubItems.Add(string.Format("{0:#,###,###}", currentSize));
lvi2.SubItems.Add(fileNameNoExt + ".Part" + numericUpDownParts.Value + ".srt");
listViewParts.Items.Add(lvi2);

View File

@ -4,7 +4,6 @@
// This code is based on https://gist.github.com/automatonic/3725443
public class MurMurHash3
{
private const uint seed = 144;
/// <summary>
@ -86,4 +85,4 @@
}
}
}
}

View File

@ -7,7 +7,7 @@ namespace Nikse.SubtitleEdit.Logic.SubtitleFormats
{
public class UnknownSubtitle4 : SubtitleFormat
{
private static Regex regexTimeCodes = new Regex(@"^\d\d:\d\d:\d\d.\d+, \d\d:\d\d:\d\d.\d+$", RegexOptions.Compiled);
private readonly static Regex regexTimeCodes = new Regex(@"^\d\d:\d\d:\d\d.\d+, \d\d:\d\d:\d\d.\d+$", RegexOptions.Compiled);
private enum ExpectingLine
{
@ -81,11 +81,12 @@ namespace Nikse.SubtitleEdit.Logic.SubtitleFormats
_errorCount = 0;
subtitle.Paragraphs.Clear();
char[] splitChars = { ':', ',', '.', ' ' };
foreach (string line in lines)
{
if (line.IndexOf(':') == 2 && regexTimeCodes.IsMatch(line))
{
string[] parts = line.Split(new[] { ':', ',', '.', ' ' }, StringSplitOptions.RemoveEmptyEntries);
string[] parts = line.Split(splitChars, StringSplitOptions.RemoveEmptyEntries);
if (parts.Length == 8)
{
try

View File

@ -9,7 +9,7 @@ namespace Nikse.SubtitleEdit.Logic.SubtitleFormats
public class UnknownSubtitle40 : SubtitleFormat
{
// 0:01 0:03
private static Regex regexTimeCodes = new Regex(@"^\d+:\d\d \d+:\d\d$", RegexOptions.Compiled);
private static readonly Regex regexTimeCodes = new Regex(@"^\d+:\d\d \d+:\d\d$", RegexOptions.Compiled);
public override string Extension
{
@ -59,6 +59,7 @@ namespace Nikse.SubtitleEdit.Logic.SubtitleFormats
Paragraph p = null;
subtitle.Paragraphs.Clear();
_errorCount = 0;
char[] splitChar = { ':' };
foreach (string line in lines)
{
if (regexTimeCodes.IsMatch(line))
@ -67,8 +68,8 @@ namespace Nikse.SubtitleEdit.Logic.SubtitleFormats
string start = temp[0].Trim();
string end = temp[1].Trim();
string[] startParts = start.Split(new[] { ':' }, StringSplitOptions.RemoveEmptyEntries);
string[] endParts = end.Split(new[] { ':' }, StringSplitOptions.RemoveEmptyEntries);
string[] startParts = start.Split(splitChar, StringSplitOptions.RemoveEmptyEntries);
string[] endParts = end.Split(splitChar, StringSplitOptions.RemoveEmptyEntries);
if (startParts.Length == 2 && endParts.Length == 2)
{
p = new Paragraph(DecodeTimeCode(startParts), DecodeTimeCode(endParts), string.Empty);
@ -95,11 +96,9 @@ namespace Nikse.SubtitleEdit.Logic.SubtitleFormats
private static TimeCode DecodeTimeCode(string[] parts)
{
//00:00:07:12
string minutes = parts[0];
string seconds = parts[1];
TimeCode tc = new TimeCode(0, int.Parse(minutes), int.Parse(seconds), 0);
return tc;
var minutes = int.Parse(parts[0]);
var seconds = int.Parse(parts[1]);
return new TimeCode(0, minutes, seconds, 0);
}
}

View File

@ -6,9 +6,8 @@ namespace Nikse.SubtitleEdit.Logic.SubtitleFormats
{
public class UnknownSubtitle41 : SubtitleFormat
{
private static Regex regexTimeCodes1 = new Regex(@"^\d+.\d$", RegexOptions.Compiled);
private static Regex regexTimeCodes2 = new Regex(@"^\d+.\d\d$", RegexOptions.Compiled);
private static readonly Regex regexTimeCodes1 = new Regex(@"^\d+.\d$", RegexOptions.Compiled);
private static readonly Regex regexTimeCodes2 = new Regex(@"^\d+.\d\d$", RegexOptions.Compiled);
public override string Extension
{
@ -88,7 +87,7 @@ namespace Nikse.SubtitleEdit.Logic.SubtitleFormats
if (regexTimeCodes1.Match(line).Success || regexTimeCodes2.Match(line).Success)
{
p = new Paragraph();
sb = new StringBuilder();
sb.Clear();
p.StartTime = DecodeTimeCode(line.Split('.'));
textOn = true;
}
@ -120,10 +119,10 @@ namespace Nikse.SubtitleEdit.Logic.SubtitleFormats
private static TimeCode DecodeTimeCode(string[] parts)
{
Configuration.Settings.General.CurrentFrameRate = 24.0;
string frames16 = parts[0];
string frames = parts[1];
return new TimeCode(0, 0, 0, FramesToMilliseconds(16 * int.Parse(frames16) + int.Parse(frames)));
var frames16 = int.Parse(parts[0]);
var frames = int.Parse(parts[1]);
return new TimeCode(0, 0, 0, FramesToMilliseconds(16 * frames16 + frames));
}
}
}
}