diff --git a/libse/SubtitleFormats/UnknownSubtitle44.cs b/libse/SubtitleFormats/UnknownSubtitle44.cs index 1844cb3c3..315a2c738 100644 --- a/libse/SubtitleFormats/UnknownSubtitle44.cs +++ b/libse/SubtitleFormats/UnknownSubtitle44.cs @@ -136,17 +136,5 @@ namespace Nikse.SubtitleEdit.Core.SubtitleFormats subtitle.Renumber(); } - private static TimeCode DecodeTimeCode(string[] parts) - { - //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; - } - } } diff --git a/libse/SubtitleFormats/UnknownSubtitle45.cs b/libse/SubtitleFormats/UnknownSubtitle45.cs index 70908f409..2c19f9a74 100644 --- a/libse/SubtitleFormats/UnknownSubtitle45.cs +++ b/libse/SubtitleFormats/UnknownSubtitle45.cs @@ -73,7 +73,7 @@ ST 0 EB 3.10 sb.AppendLine(line); string rtf = sb.ToString().Trim(); - if (!rtf.StartsWith("{\\rtf")) + if (!rtf.StartsWith("{\\rtf", StringComparison.Ordinal)) return; string[] arr = rtf.FromRtf().SplitToLines(); @@ -93,7 +93,7 @@ ST 0 EB 3.10 string[] endParts = end.Split(new[] { '.' }, StringSplitOptions.RemoveEmptyEntries); if (startParts.Length == 2 && endParts.Length == 2) { - p = new Paragraph(DecodeTimeCode(startParts), DecodeTimeCode(endParts), string.Empty); + p = new Paragraph(DecodeTimeCode(startParts), DecodeTimeCode(endParts), string.Empty); //00119.12 subtitle.Paragraphs.Add(p); } } @@ -115,14 +115,5 @@ ST 0 EB 3.10 subtitle.Renumber(); } - private static TimeCode DecodeTimeCode(string[] parts) - { - //00119.12 - string seconds = parts[0]; - string frames = parts[1]; - TimeCode tc = new TimeCode(0, 0, int.Parse(seconds), FramesToMillisecondsMax999(int.Parse(frames))); - return tc; - } - } } diff --git a/libse/SubtitleFormats/UnknownSubtitle46.cs b/libse/SubtitleFormats/UnknownSubtitle46.cs index 488e62793..ac682054e 100644 --- a/libse/SubtitleFormats/UnknownSubtitle46.cs +++ b/libse/SubtitleFormats/UnknownSubtitle46.cs @@ -67,12 +67,8 @@ namespace Nikse.SubtitleEdit.Core.SubtitleFormats arr = timeCode.Substring(0, 10).Split(':'); if (arr.Length == 4) { - int hours = int.Parse(arr[0]); - int minutes = int.Parse(arr[1]); - int seconds = int.Parse(arr[2]); - int frames = int.Parse(arr[3]); p = new Paragraph(); - p.StartTime = new TimeCode(hours, minutes, seconds, FramesToMillisecondsMax999(frames)); + p.StartTime = DecodeTimeCode(arr); p.Text = s.Substring(0, s.IndexOf(timeCode, StringComparison.Ordinal)).Trim(); subtitle.Paragraphs.Add(p); } diff --git a/libse/SubtitleFormats/UnknownSubtitle47.cs b/libse/SubtitleFormats/UnknownSubtitle47.cs index 3386cfdcf..ba920b9da 100644 --- a/libse/SubtitleFormats/UnknownSubtitle47.cs +++ b/libse/SubtitleFormats/UnknownSubtitle47.cs @@ -60,12 +60,8 @@ namespace Nikse.SubtitleEdit.Core.SubtitleFormats var arr = s.Substring(0, 10).Split(':'); if (arr.Length == 4) { - int hours = int.Parse(arr[0]); - int minutes = int.Parse(arr[1]); - int seconds = int.Parse(arr[2]); - int frames = int.Parse(arr[3]); var p = new Paragraph(); - p.StartTime = new TimeCode(hours, minutes, seconds, FramesToMillisecondsMax999(frames)); + p.StartTime = DecodeTimeCode(arr); p.Text = s.Remove(0, 10).Trim(); subtitle.Paragraphs.Add(p); } diff --git a/libse/SubtitleFormats/UnknownSubtitle5.cs b/libse/SubtitleFormats/UnknownSubtitle5.cs index 64d5d6ca2..ba7fed15a 100644 --- a/libse/SubtitleFormats/UnknownSubtitle5.cs +++ b/libse/SubtitleFormats/UnknownSubtitle5.cs @@ -43,11 +43,11 @@ namespace Nikse.SubtitleEdit.Core.SubtitleFormats XmlNode paragraph = xml.CreateElement("text"); XmlAttribute start = xml.CreateAttribute("start"); - start.InnerText = string.Format("{0}", p.StartTime.TotalMilliseconds / 1000).Replace(",", "."); + start.InnerText = string.Format("{0}", p.StartTime.TotalMilliseconds / 1000).Replace(',', '.'); paragraph.Attributes.Append(start); XmlAttribute duration = xml.CreateAttribute("dur"); - duration.InnerText = string.Format("{0}", p.Duration.TotalMilliseconds / 1000).Replace(",", "."); + duration.InnerText = string.Format("{0}", p.Duration.TotalMilliseconds / 1000).Replace(',', '.'); paragraph.Attributes.Append(duration); paragraph.InnerText = p.Text; @@ -87,10 +87,10 @@ namespace Nikse.SubtitleEdit.Core.SubtitleFormats { string start = node.Attributes["start"].InnerText; if (!string.IsNullOrEmpty(start)) - start = start.Replace(",", "."); + start = start.Replace(',', '.'); string end = node.Attributes["dur"].InnerText; if (!string.IsNullOrEmpty(end)) - end = end.Replace(",", "."); + end = end.Replace(',', '.'); string text = node.InnerText; subtitle.Paragraphs.Add(new Paragraph(text, Convert.ToDouble(start, System.Globalization.CultureInfo.InvariantCulture) * TimeCode.BaseUnit, TimeCode.BaseUnit * (Convert.ToDouble(start, System.Globalization.CultureInfo.InvariantCulture) + Convert.ToDouble(end, System.Globalization.CultureInfo.InvariantCulture)))); diff --git a/libse/SubtitleFormats/UnknownSubtitle50.cs b/libse/SubtitleFormats/UnknownSubtitle50.cs index 360f1b2ec..233202699 100644 --- a/libse/SubtitleFormats/UnknownSubtitle50.cs +++ b/libse/SubtitleFormats/UnknownSubtitle50.cs @@ -139,7 +139,7 @@ namespace Nikse.SubtitleEdit.Core.SubtitleFormats } else { - if (line.StartsWith("||")) + if (line.StartsWith("||", StringComparison.Ordinal)) line = "" + line.Replace("||", string.Empty) + ""; p.Text = (p.Text + Environment.NewLine + line).Trim(); expecting = ExpectingLine.TimeCodes; diff --git a/libse/SubtitleFormats/UnknownSubtitle51.cs b/libse/SubtitleFormats/UnknownSubtitle51.cs index fdb963753..aacb9347f 100644 --- a/libse/SubtitleFormats/UnknownSubtitle51.cs +++ b/libse/SubtitleFormats/UnknownSubtitle51.cs @@ -75,7 +75,7 @@ namespace Nikse.SubtitleEdit.Core.SubtitleFormats subtitle.Paragraphs.Add(p); } } - else if (line.StartsWith("//")) + else if (line.StartsWith("//", StringComparison.Ordinal)) { // comment } diff --git a/libse/SubtitleFormats/UnknownSubtitle53.cs b/libse/SubtitleFormats/UnknownSubtitle53.cs index 72fa2b8ab..9a86bb90c 100644 --- a/libse/SubtitleFormats/UnknownSubtitle53.cs +++ b/libse/SubtitleFormats/UnknownSubtitle53.cs @@ -71,12 +71,8 @@ namespace Nikse.SubtitleEdit.Core.SubtitleFormats string[] arr = s.Substring(0, 11).Split(':'); if (arr.Length == 4) { - int hours = int.Parse(arr[0]); - int minutes = int.Parse(arr[1]); - int seconds = int.Parse(arr[2]); - int frames = int.Parse(arr[3]); - p.StartTime = new TimeCode(hours, minutes, seconds, FramesToMillisecondsMax999(frames)); - string text = s.Remove(0, 11).Trim(); + p.StartTime = DecodeTimeCode(arr); + string text = s.Substring(11).Trim(); p.Text = text; if (text.Length > 1 && Utilities.IsInteger(text.Substring(0, 2))) _errorCount++; diff --git a/libse/SubtitleFormats/UnknownSubtitle56.cs b/libse/SubtitleFormats/UnknownSubtitle56.cs index e16337c3b..81cf1d3a0 100644 --- a/libse/SubtitleFormats/UnknownSubtitle56.cs +++ b/libse/SubtitleFormats/UnknownSubtitle56.cs @@ -63,6 +63,7 @@ namespace Nikse.SubtitleEdit.Core.SubtitleFormats bool expectStartTime = true; var p = new Paragraph(); subtitle.Paragraphs.Clear(); + char[] splitChars = { '.', ':' }; foreach (string line in lines) { string s = line.Trim(); @@ -79,8 +80,8 @@ namespace Nikse.SubtitleEdit.Core.SubtitleFormats subtitle.Paragraphs.Add(p); p = new Paragraph(); } - p.StartTime = DecodeTimeCode(parts[1]); - p.EndTime = DecodeTimeCode(parts[2]); + p.StartTime = DecodeTimeCode(parts[1], splitChars); + p.EndTime = DecodeTimeCode(parts[2], splitChars); expectStartTime = false; } catch (Exception exception) @@ -120,18 +121,5 @@ namespace Nikse.SubtitleEdit.Core.SubtitleFormats subtitle.Renumber(); } - private static TimeCode DecodeTimeCode(string part) - { - string[] parts = part.Split(new[] { '.', ':' }, StringSplitOptions.RemoveEmptyEntries); - - //00:00:07:12 - string hour = parts[0]; - string minutes = parts[1]; - string seconds = parts[2]; - string frames = parts[3]; - - return new TimeCode(int.Parse(hour), int.Parse(minutes), int.Parse(seconds), FramesToMillisecondsMax999(int.Parse(frames))); - } - } } diff --git a/libse/SubtitleFormats/UnknownSubtitle57.cs b/libse/SubtitleFormats/UnknownSubtitle57.cs index 91f3f6a1f..5f513acff 100644 --- a/libse/SubtitleFormats/UnknownSubtitle57.cs +++ b/libse/SubtitleFormats/UnknownSubtitle57.cs @@ -61,22 +61,19 @@ namespace Nikse.SubtitleEdit.Core.SubtitleFormats _errorCount = 0; Paragraph p = null; subtitle.Paragraphs.Clear(); + char[] splitChars = { ':', '.' }; foreach (string line in lines) { - if (RegexTimeCodes.IsMatch(line)) + var match = RegexTimeCodes.Match(line); + if (match.Success) { - string temp = line.Substring(0, RegexTimeCodes.Match(line).Length); - string start = temp.Substring(0, 11); - string end = temp.Substring(12, 11); - - string[] startParts = start.Split(new[] { ':', '.' }, StringSplitOptions.RemoveEmptyEntries); - string[] endParts = end.Split(new[] { ':', '.' }, StringSplitOptions.RemoveEmptyEntries); - if (startParts.Length == 4 && endParts.Length == 4 && line.Length >= 23) + string temp = line.Substring(0, match.Length); + if (line.Length >= 23) { string text = line.Remove(0, 23).Trim(); if (!text.Contains(Environment.NewLine)) text = text.Replace("//", Environment.NewLine); - p = new Paragraph(DecodeTimeCode(startParts), DecodeTimeCode(endParts), text); + p = new Paragraph(DecodeTimeCode(temp.Substring(0, 11), splitChars), DecodeTimeCode(temp.Substring(12, 11), splitChars), text); subtitle.Paragraphs.Add(p); } } diff --git a/libse/SubtitleFormats/UnknownSubtitle58.cs b/libse/SubtitleFormats/UnknownSubtitle58.cs index efacb358f..689afafad 100644 --- a/libse/SubtitleFormats/UnknownSubtitle58.cs +++ b/libse/SubtitleFormats/UnknownSubtitle58.cs @@ -62,7 +62,7 @@ namespace Nikse.SubtitleEdit.Core.SubtitleFormats sb.AppendLine(line); string rtf = sb.ToString().Trim(); - if (!rtf.StartsWith("{\\rtf")) + if (!rtf.StartsWith("{\\rtf", StringComparison.Ordinal)) return; string[] arr = rtf.FromRtf().SplitToLines();