mirror of
https://github.com/SubtitleEdit/subtitleedit.git
synced 2025-02-01 05:21:40 +01:00
Minor performance fix for split by colon in subtitle formats
This commit is contained in:
parent
9818b11b5c
commit
1167022795
@ -88,8 +88,8 @@ namespace Nikse.SubtitleEdit.Core.SubtitleFormats
|
||||
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);
|
||||
string[] startParts = start.Split(SplitCharColon, StringSplitOptions.RemoveEmptyEntries);
|
||||
string[] endParts = end.Split(SplitCharColon, StringSplitOptions.RemoveEmptyEntries);
|
||||
if (startParts.Length == 4 && endParts.Length == 4)
|
||||
{
|
||||
string text = line.Remove(0, RegexTimeCodes.Match(line).Length - 1).Trim();
|
||||
|
@ -85,8 +85,8 @@ namespace Nikse.SubtitleEdit.Core.SubtitleFormats
|
||||
string start = temp[1];
|
||||
string end = temp[2];
|
||||
|
||||
string[] startParts = start.Split(new[] { ':' }, StringSplitOptions.RemoveEmptyEntries);
|
||||
string[] endParts = end.Split(new[] { ':' }, StringSplitOptions.RemoveEmptyEntries);
|
||||
string[] startParts = start.Split(SplitCharColon, StringSplitOptions.RemoveEmptyEntries);
|
||||
string[] endParts = end.Split(SplitCharColon, StringSplitOptions.RemoveEmptyEntries);
|
||||
if (startParts.Length == 4 && endParts.Length == 4)
|
||||
{
|
||||
try
|
||||
|
@ -80,8 +80,8 @@ namespace Nikse.SubtitleEdit.Core.SubtitleFormats
|
||||
string start = temp[1];
|
||||
string end = temp[2];
|
||||
|
||||
string[] startParts = start.Split(new[] { ':' }, StringSplitOptions.RemoveEmptyEntries);
|
||||
string[] endParts = end.Split(new[] { ':' }, StringSplitOptions.RemoveEmptyEntries);
|
||||
string[] startParts = start.Split(SplitCharColon, StringSplitOptions.RemoveEmptyEntries);
|
||||
string[] endParts = end.Split(SplitCharColon, StringSplitOptions.RemoveEmptyEntries);
|
||||
if (startParts.Length == 4 && endParts.Length == 4)
|
||||
{
|
||||
try
|
||||
|
@ -68,8 +68,8 @@ namespace Nikse.SubtitleEdit.Core.SubtitleFormats
|
||||
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);
|
||||
string[] startParts = start.Split(SplitCharColon, StringSplitOptions.RemoveEmptyEntries);
|
||||
string[] endParts = end.Split(SplitCharColon, StringSplitOptions.RemoveEmptyEntries);
|
||||
if (startParts.Length == 4 && endParts.Length == 4)
|
||||
{
|
||||
string text = line.Remove(0, RegexTimeCodes.Match(line).Length - 1).Trim();
|
||||
|
@ -75,8 +75,8 @@ namespace Nikse.SubtitleEdit.Core.SubtitleFormats
|
||||
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);
|
||||
string[] startParts = start.Split(SplitCharColon, StringSplitOptions.RemoveEmptyEntries);
|
||||
string[] endParts = end.Split(SplitCharColon, StringSplitOptions.RemoveEmptyEntries);
|
||||
if (startParts.Length == 4 && endParts.Length == 4)
|
||||
{
|
||||
string text = line.Remove(0, RegexTimeCodes.Match(line).Length - 1).Trim();
|
||||
|
@ -98,8 +98,8 @@ namespace Nikse.SubtitleEdit.Core.SubtitleFormats
|
||||
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);
|
||||
string[] startParts = start.Split(SplitCharColon, StringSplitOptions.RemoveEmptyEntries);
|
||||
string[] endParts = end.Split(SplitCharColon, StringSplitOptions.RemoveEmptyEntries);
|
||||
if (startParts.Length == 4 && endParts.Length == 4)
|
||||
{
|
||||
p = new Paragraph(DecodeTimeCode(startParts), DecodeTimeCode(endParts), string.Empty);
|
||||
|
@ -220,7 +220,7 @@ namespace Nikse.SubtitleEdit.Core.SubtitleFormats
|
||||
{
|
||||
if (RegexTimeCode.IsMatch(line))
|
||||
{
|
||||
string[] parts = line.Substring(4, 11).Split(new[] { ':' }, StringSplitOptions.RemoveEmptyEntries);
|
||||
string[] parts = line.Substring(4, 11).Split(SplitCharColon, StringSplitOptions.RemoveEmptyEntries);
|
||||
if (parts.Length == 4)
|
||||
{
|
||||
try
|
||||
@ -231,7 +231,7 @@ namespace Nikse.SubtitleEdit.Core.SubtitleFormats
|
||||
}
|
||||
|
||||
var start = DecodeTimeCode(parts);
|
||||
parts = line.Substring(16, 11).Split(new[] { ':' }, StringSplitOptions.RemoveEmptyEntries);
|
||||
parts = line.Substring(16, 11).Split(SplitCharColon, StringSplitOptions.RemoveEmptyEntries);
|
||||
var end = DecodeTimeCode(parts);
|
||||
paragraph = new Paragraph { StartTime = start, EndTime = end };
|
||||
subtitle.Paragraphs.Add(paragraph);
|
||||
|
@ -162,7 +162,7 @@ namespace Nikse.SubtitleEdit.Core.SubtitleFormats
|
||||
|
||||
private static double DecodeTimeToMilliseconds(string time)
|
||||
{
|
||||
string[] parts = time.Split(new[] { ':' }, StringSplitOptions.RemoveEmptyEntries);
|
||||
string[] parts = time.Split(SplitCharColon, StringSplitOptions.RemoveEmptyEntries);
|
||||
return new TimeSpan(0, int.Parse(parts[0]), int.Parse(parts[1]), int.Parse(parts[2]), (int)(int.Parse(parts[3]) * 10.0)).TotalMilliseconds;
|
||||
}
|
||||
|
||||
|
@ -70,8 +70,8 @@ namespace Nikse.SubtitleEdit.Core.SubtitleFormats
|
||||
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);
|
||||
string[] startParts = start.Split(SplitCharColon, StringSplitOptions.RemoveEmptyEntries);
|
||||
string[] endParts = end.Split(SplitCharColon, StringSplitOptions.RemoveEmptyEntries);
|
||||
if (startParts.Length == 4 && endParts.Length == 4)
|
||||
{
|
||||
string text = line.Remove(0, RegexTimeCodes.Match(line).Length - 1).Trim();
|
||||
|
@ -68,8 +68,8 @@ namespace Nikse.SubtitleEdit.Core.SubtitleFormats
|
||||
string start = temp.Substring(0, 11);
|
||||
string end = temp.Substring(13, 11);
|
||||
|
||||
string[] startParts = start.Split(new[] { ':' }, StringSplitOptions.RemoveEmptyEntries);
|
||||
string[] endParts = end.Split(new[] { ':' }, StringSplitOptions.RemoveEmptyEntries);
|
||||
string[] startParts = start.Split(SplitCharColon, StringSplitOptions.RemoveEmptyEntries);
|
||||
string[] endParts = end.Split(SplitCharColon, StringSplitOptions.RemoveEmptyEntries);
|
||||
if (startParts.Length == 4 && endParts.Length == 4)
|
||||
{
|
||||
p = new Paragraph(DecodeTimeCode(startParts), DecodeTimeCode(endParts), string.Empty);
|
||||
|
@ -129,7 +129,6 @@ namespace Nikse.SubtitleEdit.Core.SubtitleFormats
|
||||
var xml = new XmlDocument { XmlResolver = null };
|
||||
xml.LoadXml(sb.ToString().Trim());
|
||||
string lastKey = string.Empty;
|
||||
char[] splitChar = { ':' };
|
||||
foreach (XmlNode node in xml.DocumentElement.SelectNodes("subtitle"))
|
||||
{
|
||||
try
|
||||
@ -143,10 +142,10 @@ namespace Nikse.SubtitleEdit.Core.SubtitleFormats
|
||||
p.Text = innerNode.InnerText.Replace("\\N", Environment.NewLine);
|
||||
break;
|
||||
case "in":
|
||||
p.StartTime = DecodeTimeCode(innerNode.InnerText, splitChar);
|
||||
p.StartTime = DecodeTimeCode(innerNode.InnerText, SplitCharColon);
|
||||
break;
|
||||
case "out":
|
||||
p.EndTime = DecodeTimeCode(innerNode.InnerText, splitChar);
|
||||
p.EndTime = DecodeTimeCode(innerNode.InnerText, SplitCharColon);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
@ -65,7 +65,6 @@ namespace Nikse.SubtitleEdit.Core.SubtitleFormats
|
||||
|
||||
subtitle.Paragraphs.Clear();
|
||||
sb.Clear();
|
||||
char[] splitChar = { ':' };
|
||||
foreach (string line in lines)
|
||||
{
|
||||
if (!string.IsNullOrWhiteSpace(line))
|
||||
@ -79,8 +78,8 @@ namespace Nikse.SubtitleEdit.Core.SubtitleFormats
|
||||
string start = line.Substring(idx + 1, 11);
|
||||
string end = line.Substring(idx + 15, 11);
|
||||
|
||||
string[] startParts = start.Split(splitChar, StringSplitOptions.RemoveEmptyEntries);
|
||||
string[] endParts = end.Split(splitChar, StringSplitOptions.RemoveEmptyEntries);
|
||||
string[] startParts = start.Split(SplitCharColon, StringSplitOptions.RemoveEmptyEntries);
|
||||
string[] endParts = end.Split(SplitCharColon, StringSplitOptions.RemoveEmptyEntries);
|
||||
if (startParts.Length == 4 && endParts.Length == 4)
|
||||
{
|
||||
var p = new Paragraph(DecodeTimeCode(startParts), DecodeTimeCode(endParts), sb.ToString().Trim());
|
||||
|
@ -228,7 +228,6 @@ namespace Nikse.SubtitleEdit.Core.SubtitleFormats
|
||||
xml.LoadXml(sb.ToString().Trim());
|
||||
var nsmgr = new XmlNamespaceManager(xml.NameTable);
|
||||
nsmgr.AddNamespace("w", "http://schemas.openxmlformats.org/wordprocessingml/2006/main");
|
||||
char[] splitChar = { ':' };
|
||||
foreach (XmlNode node in xml.DocumentElement.SelectNodes("//w:tr", nsmgr))
|
||||
{
|
||||
try
|
||||
@ -237,7 +236,7 @@ namespace Nikse.SubtitleEdit.Core.SubtitleFormats
|
||||
XmlNode t = node.SelectSingleNode("w:tc/w:p/w:r/w:t", nsmgr);
|
||||
if (t != null)
|
||||
{
|
||||
p.StartTime = DecodeTimeCode(t.InnerText.Trim(), splitChar);
|
||||
p.StartTime = DecodeTimeCode(t.InnerText.Trim(), SplitCharColon);
|
||||
sb = new StringBuilder();
|
||||
foreach (XmlNode wrNode in node.SelectNodes("w:tc/w:p/w:r", nsmgr))
|
||||
{
|
||||
|
@ -76,12 +76,11 @@ namespace Nikse.SubtitleEdit.Core.SubtitleFormats
|
||||
_errorCount = 0;
|
||||
|
||||
subtitle.Paragraphs.Clear();
|
||||
char[] splitChar = { ':' };
|
||||
foreach (string line in lines)
|
||||
{
|
||||
if (RegexTimeCode.IsMatch(line))
|
||||
{
|
||||
string[] parts = line.Substring(0, 11).Split(splitChar, StringSplitOptions.RemoveEmptyEntries);
|
||||
string[] parts = line.Substring(0, 11).Split(SplitCharColon, StringSplitOptions.RemoveEmptyEntries);
|
||||
if (parts.Length == 4)
|
||||
{
|
||||
try
|
||||
@ -105,7 +104,7 @@ namespace Nikse.SubtitleEdit.Core.SubtitleFormats
|
||||
}
|
||||
else if (RegexTimeCodeEnd.IsMatch(line))
|
||||
{
|
||||
string[] parts = line.Substring(0, 11).Split(splitChar, StringSplitOptions.RemoveEmptyEntries);
|
||||
string[] parts = line.Substring(0, 11).Split(SplitCharColon, StringSplitOptions.RemoveEmptyEntries);
|
||||
if (parts.Length == 4)
|
||||
{
|
||||
var tc = DecodeTimeCode(parts);
|
||||
|
@ -79,8 +79,8 @@ namespace Nikse.SubtitleEdit.Core.SubtitleFormats
|
||||
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);
|
||||
string[] startParts = start.Split(SplitCharColon, StringSplitOptions.RemoveEmptyEntries);
|
||||
string[] endParts = end.Split(SplitCharColon, StringSplitOptions.RemoveEmptyEntries);
|
||||
if (startParts.Length == 4 && endParts.Length == 4)
|
||||
{
|
||||
string text = line.Remove(0, RegexTimeCodes.Match(line).Length - 1).Trim();
|
||||
|
@ -72,8 +72,8 @@ namespace Nikse.SubtitleEdit.Core.SubtitleFormats
|
||||
string start = temp.Substring(5, 11);
|
||||
string end = temp.Substring(12 + 5, 11);
|
||||
|
||||
string[] startParts = start.Split(new[] { ':' }, StringSplitOptions.RemoveEmptyEntries);
|
||||
string[] endParts = end.Split(new[] { ':' }, StringSplitOptions.RemoveEmptyEntries);
|
||||
string[] startParts = start.Split(SplitCharColon, StringSplitOptions.RemoveEmptyEntries);
|
||||
string[] endParts = end.Split(SplitCharColon, StringSplitOptions.RemoveEmptyEntries);
|
||||
if (startParts.Length == 4 && endParts.Length == 4)
|
||||
{
|
||||
string text = line.Remove(0, RegexTimeCodes.Match(line).Length - 1).Trim();
|
||||
|
@ -61,7 +61,6 @@ namespace Nikse.SubtitleEdit.Core.SubtitleFormats
|
||||
_errorCount = 0;
|
||||
var regexTimeCodes = new Regex(@"^\d\d\d\d[\t]+\d\d:\d\d:\d\d:\d\d\t\d\d:\d\d:\d\d:\d\d\t.+\.(tif|tiff|png|bmp|TIF|TIFF|PNG|BMP)", RegexOptions.Compiled);
|
||||
int index = 0;
|
||||
char[] splitChar = { ':' };
|
||||
foreach (string line in lines)
|
||||
{
|
||||
if (regexTimeCodes.IsMatch(line))
|
||||
@ -70,8 +69,8 @@ namespace Nikse.SubtitleEdit.Core.SubtitleFormats
|
||||
string start = temp.Substring(5, 11);
|
||||
string end = temp.Substring(12 + 5, 11);
|
||||
|
||||
string[] startParts = start.Split(splitChar, StringSplitOptions.RemoveEmptyEntries);
|
||||
string[] endParts = end.Split(splitChar, StringSplitOptions.RemoveEmptyEntries);
|
||||
string[] startParts = start.Split(SplitCharColon, StringSplitOptions.RemoveEmptyEntries);
|
||||
string[] endParts = end.Split(SplitCharColon, StringSplitOptions.RemoveEmptyEntries);
|
||||
if (startParts.Length == 4 && endParts.Length == 4)
|
||||
{
|
||||
int lastIndexOfTab = line.LastIndexOf('\t');
|
||||
|
@ -77,7 +77,6 @@ namespace Nikse.SubtitleEdit.Core.SubtitleFormats
|
||||
_errorCount = 0;
|
||||
Paragraph p = null;
|
||||
subtitle.Paragraphs.Clear();
|
||||
char[] splitChar = { ':' };
|
||||
foreach (string line in lines)
|
||||
{
|
||||
if (line.IndexOf(':') == 5 && RegexTimeCodes.IsMatch(line))
|
||||
@ -88,8 +87,8 @@ namespace Nikse.SubtitleEdit.Core.SubtitleFormats
|
||||
string start = line.Substring(7, 11);
|
||||
string end = line.Substring(19, 11);
|
||||
|
||||
string[] startParts = start.Split(splitChar);
|
||||
string[] endParts = end.Split(splitChar);
|
||||
string[] startParts = start.Split(SplitCharColon);
|
||||
string[] endParts = end.Split(SplitCharColon);
|
||||
if (startParts.Length == 4 && endParts.Length == 4)
|
||||
{
|
||||
p = new Paragraph(DecodeTimeCode(startParts), DecodeTimeCode(endParts), string.Empty);
|
||||
|
@ -10,6 +10,8 @@ namespace Nikse.SubtitleEdit.Core.SubtitleFormats
|
||||
{
|
||||
private static IList<SubtitleFormat> _allSubtitleFormats;
|
||||
|
||||
protected static readonly char[] SplitCharColon = new[] { ':' };
|
||||
|
||||
/// <summary>
|
||||
/// Formats supported by Subtitle Edit
|
||||
/// </summary>
|
||||
|
@ -261,9 +261,9 @@ namespace Nikse.SubtitleEdit.Core.SubtitleFormats
|
||||
end.Length == 8 && end[2] == ':' && end[5] == ':')
|
||||
{
|
||||
var p = new Paragraph();
|
||||
var parts = start.Split(new[] { ':' });
|
||||
var parts = start.Split(SplitCharColon);
|
||||
p.StartTime = new TimeCode(int.Parse(parts[0]), int.Parse(parts[1]), int.Parse(parts[2]), 0);
|
||||
parts = end.Split(new[] { ':' });
|
||||
parts = end.Split(SplitCharColon);
|
||||
p.EndTime = new TimeCode(int.Parse(parts[0]), int.Parse(parts[1]), int.Parse(parts[2]), 0);
|
||||
p.Text = text;
|
||||
subtitle.Paragraphs.Add(p);
|
||||
|
@ -140,9 +140,9 @@ namespace Nikse.SubtitleEdit.Core.SubtitleFormats
|
||||
end.Length == 8 && end[2] == ':' && end[5] == ':')
|
||||
{
|
||||
var p = new Paragraph();
|
||||
var parts = start.Split(new[] { ':' });
|
||||
var parts = start.Split(SplitCharColon);
|
||||
p.StartTime = new TimeCode(int.Parse(parts[0]), int.Parse(parts[1]), int.Parse(parts[2]), 0);
|
||||
parts = end.Split(new[] { ':' });
|
||||
parts = end.Split(SplitCharColon);
|
||||
p.EndTime = new TimeCode(int.Parse(parts[0]), int.Parse(parts[1]), int.Parse(parts[2]), 0);
|
||||
p.Text = text;
|
||||
subtitle.Paragraphs.Add(p);
|
||||
|
@ -76,8 +76,8 @@ namespace Nikse.SubtitleEdit.Core.SubtitleFormats
|
||||
string start = temp[0].TrimEnd(',');
|
||||
string end = temp[1].TrimEnd(',');
|
||||
|
||||
string[] startParts = start.Split(new[] { ':' }, StringSplitOptions.RemoveEmptyEntries);
|
||||
string[] endParts = end.Split(new[] { ':' }, StringSplitOptions.RemoveEmptyEntries);
|
||||
string[] startParts = start.Split(SplitCharColon, StringSplitOptions.RemoveEmptyEntries);
|
||||
string[] endParts = end.Split(SplitCharColon, StringSplitOptions.RemoveEmptyEntries);
|
||||
if (startParts.Length == 4 && endParts.Length == 4)
|
||||
{
|
||||
try
|
||||
|
@ -81,7 +81,6 @@ ATTENTION : Pas plus de 40 caractères PAR LIGNE
|
||||
Paragraph p = null;
|
||||
_errorCount = 0;
|
||||
subtitle.Paragraphs.Clear();
|
||||
char[] splitChar = { ':' };
|
||||
foreach (string line in lines)
|
||||
{
|
||||
if (RegexTimeCodes.IsMatch(line))
|
||||
@ -92,8 +91,8 @@ ATTENTION : Pas plus de 40 caractères PAR LIGNE
|
||||
string start = arr[1];
|
||||
string end = arr[2];
|
||||
|
||||
string[] startParts = start.Split(splitChar, StringSplitOptions.RemoveEmptyEntries);
|
||||
string[] endParts = end.Split(splitChar, StringSplitOptions.RemoveEmptyEntries);
|
||||
string[] startParts = start.Split(SplitCharColon, StringSplitOptions.RemoveEmptyEntries);
|
||||
string[] endParts = end.Split(SplitCharColon, StringSplitOptions.RemoveEmptyEntries);
|
||||
if (startParts.Length == 4 && endParts.Length == 4)
|
||||
{
|
||||
p = new Paragraph(DecodeTimeCode(startParts), DecodeTimeCode(endParts), string.Empty);
|
||||
|
@ -154,7 +154,7 @@ namespace Nikse.SubtitleEdit.Core.SubtitleFormats
|
||||
|
||||
private static TimeCode DecodeTimeCode(string timeCode)
|
||||
{
|
||||
string[] arr = timeCode.Split(new[] { ':' }, StringSplitOptions.RemoveEmptyEntries);
|
||||
string[] arr = timeCode.Split(SplitCharColon, StringSplitOptions.RemoveEmptyEntries);
|
||||
return new TimeCode(int.Parse(arr[0]), int.Parse(arr[1]), int.Parse(arr[2]), 0);
|
||||
}
|
||||
|
||||
|
@ -102,7 +102,7 @@ DIGITAL_CINEMA=YES
|
||||
}
|
||||
else if (paragraph != null && expecting == ExpectingLine.TimeStart && RegexTimeCode.IsMatch(line))
|
||||
{
|
||||
string[] parts = line.Split(new[] { ':' }, StringSplitOptions.RemoveEmptyEntries);
|
||||
string[] parts = line.Split(SplitCharColon, StringSplitOptions.RemoveEmptyEntries);
|
||||
if (parts.Length == 4)
|
||||
{
|
||||
try
|
||||
@ -120,7 +120,7 @@ DIGITAL_CINEMA=YES
|
||||
}
|
||||
else if (paragraph != null && expecting == ExpectingLine.TimeEnd && RegexTimeCode.IsMatch(line))
|
||||
{
|
||||
string[] parts = line.Split(new[] { ':' }, StringSplitOptions.RemoveEmptyEntries);
|
||||
string[] parts = line.Split(SplitCharColon, StringSplitOptions.RemoveEmptyEntries);
|
||||
if (parts.Length == 4)
|
||||
{
|
||||
try
|
||||
|
@ -141,14 +141,14 @@ namespace Nikse.SubtitleEdit.Core.SubtitleFormats
|
||||
try
|
||||
{
|
||||
string start = line.Substring(5, 11);
|
||||
var parts = start.Split(new[] { ':' }, StringSplitOptions.RemoveEmptyEntries);
|
||||
var parts = start.Split(SplitCharColon, StringSplitOptions.RemoveEmptyEntries);
|
||||
int startHours = int.Parse(parts[0]);
|
||||
int startMinutes = int.Parse(parts[1]);
|
||||
int startSeconds = int.Parse(parts[2]);
|
||||
int startMilliseconds = FramesToMillisecondsMax999(int.Parse(parts[3]));
|
||||
|
||||
string end = line.Substring(17, 11);
|
||||
parts = end.Split(new[] { ':' }, StringSplitOptions.RemoveEmptyEntries);
|
||||
parts = end.Split(SplitCharColon, StringSplitOptions.RemoveEmptyEntries);
|
||||
int endHours = int.Parse(parts[0]);
|
||||
int endMinutes = int.Parse(parts[1]);
|
||||
int endSeconds = int.Parse(parts[2]);
|
||||
|
@ -84,7 +84,6 @@ namespace Nikse.SubtitleEdit.Core.SubtitleFormats
|
||||
{
|
||||
_errorCount = 0;
|
||||
Paragraph p = null;
|
||||
char[] splitChar = { ':' };
|
||||
foreach (string line in lines)
|
||||
{
|
||||
string s = line.TrimEnd();
|
||||
@ -94,7 +93,7 @@ namespace Nikse.SubtitleEdit.Core.SubtitleFormats
|
||||
{
|
||||
if (p != null)
|
||||
subtitle.Paragraphs.Add(p);
|
||||
p = new Paragraph(DecodeTimeCode(s.Substring(5, 11), splitChar), new TimeCode(0, 0, 0, 0), s.Remove(0, 37).Trim());
|
||||
p = new Paragraph(DecodeTimeCode(s.Substring(5, 11), SplitCharColon), new TimeCode(0, 0, 0, 0), s.Remove(0, 37).Trim());
|
||||
}
|
||||
catch
|
||||
{
|
||||
@ -108,7 +107,7 @@ namespace Nikse.SubtitleEdit.Core.SubtitleFormats
|
||||
{
|
||||
if (p != null)
|
||||
subtitle.Paragraphs.Add(p);
|
||||
p = new Paragraph(DecodeTimeCode(s.Substring(5, 11), splitChar), new TimeCode(0, 0, 0, 0), string.Empty);
|
||||
p = new Paragraph(DecodeTimeCode(s.Substring(5, 11), SplitCharColon), new TimeCode(0, 0, 0, 0), string.Empty);
|
||||
}
|
||||
catch
|
||||
{
|
||||
@ -122,7 +121,7 @@ namespace Nikse.SubtitleEdit.Core.SubtitleFormats
|
||||
{
|
||||
if (p != null)
|
||||
{
|
||||
p.EndTime = DecodeTimeCode(s.Substring(5, 11), splitChar);
|
||||
p.EndTime = DecodeTimeCode(s.Substring(5, 11), SplitCharColon);
|
||||
if (string.IsNullOrWhiteSpace(p.Text))
|
||||
p.Text = s.Remove(0, 37).Trim();
|
||||
else
|
||||
|
@ -74,7 +74,7 @@ namespace Nikse.SubtitleEdit.Core.SubtitleFormats
|
||||
{
|
||||
var temp = s.Substring(0, 8);
|
||||
|
||||
string[] startParts = temp.Split(new[] { ':' }, StringSplitOptions.RemoveEmptyEntries);
|
||||
string[] startParts = temp.Split(SplitCharColon, StringSplitOptions.RemoveEmptyEntries);
|
||||
if (startParts.Length == 3)
|
||||
{
|
||||
try
|
||||
|
@ -92,7 +92,7 @@ namespace Nikse.SubtitleEdit.Core.SubtitleFormats
|
||||
}
|
||||
else if (paragraph != null && expecting == ExpectingLine.TimeStart && RegexTimeCode.IsMatch(line))
|
||||
{
|
||||
string[] parts = line.Split(new[] { ':' }, StringSplitOptions.RemoveEmptyEntries);
|
||||
string[] parts = line.Split(SplitCharColon, StringSplitOptions.RemoveEmptyEntries);
|
||||
if (parts.Length == 4)
|
||||
{
|
||||
try
|
||||
@ -110,7 +110,7 @@ namespace Nikse.SubtitleEdit.Core.SubtitleFormats
|
||||
}
|
||||
else if (paragraph != null && expecting == ExpectingLine.TimeEnd && RegexTimeCode.IsMatch(line))
|
||||
{
|
||||
string[] parts = line.Split(new[] { ':' }, StringSplitOptions.RemoveEmptyEntries);
|
||||
string[] parts = line.Split(SplitCharColon, StringSplitOptions.RemoveEmptyEntries);
|
||||
if (parts.Length == 4)
|
||||
{
|
||||
try
|
||||
|
@ -70,8 +70,8 @@ namespace Nikse.SubtitleEdit.Core.SubtitleFormats
|
||||
string start = temp[1];
|
||||
string end = temp[2];
|
||||
|
||||
string[] startParts = start.Split(new[] { ':' }, StringSplitOptions.RemoveEmptyEntries);
|
||||
string[] endParts = end.Split(new[] { ':' }, StringSplitOptions.RemoveEmptyEntries);
|
||||
string[] startParts = start.Split(SplitCharColon, StringSplitOptions.RemoveEmptyEntries);
|
||||
string[] endParts = end.Split(SplitCharColon, StringSplitOptions.RemoveEmptyEntries);
|
||||
if (startParts.Length == 4 && endParts.Length == 4)
|
||||
{
|
||||
p = new Paragraph(DecodeTimeCode(startParts), DecodeTimeCode(endParts), string.Empty);
|
||||
|
@ -58,7 +58,6 @@ namespace Nikse.SubtitleEdit.Core.SubtitleFormats
|
||||
Paragraph p = null;
|
||||
subtitle.Paragraphs.Clear();
|
||||
_errorCount = 0;
|
||||
char[] splitChar = { ':' };
|
||||
foreach (string line in lines)
|
||||
{
|
||||
if (RegexTimeCodes.IsMatch(line))
|
||||
@ -67,8 +66,8 @@ namespace Nikse.SubtitleEdit.Core.SubtitleFormats
|
||||
string start = temp[0].Trim();
|
||||
string end = temp[1].Trim();
|
||||
|
||||
string[] startParts = start.Split(splitChar, StringSplitOptions.RemoveEmptyEntries);
|
||||
string[] endParts = end.Split(splitChar, StringSplitOptions.RemoveEmptyEntries);
|
||||
string[] startParts = start.Split(SplitCharColon, StringSplitOptions.RemoveEmptyEntries);
|
||||
string[] endParts = end.Split(SplitCharColon, StringSplitOptions.RemoveEmptyEntries);
|
||||
if (startParts.Length == 2 && endParts.Length == 2)
|
||||
{
|
||||
p = new Paragraph(DecodeTimeCode(startParts), DecodeTimeCode(endParts), string.Empty);
|
||||
|
@ -83,8 +83,8 @@ namespace Nikse.SubtitleEdit.Core.SubtitleFormats
|
||||
italic = line[6] == 'I';
|
||||
string start = line.Substring(8, 11);
|
||||
string end = line.Substring(20, 11);
|
||||
string[] startParts = start.Split(new[] { ':' }, StringSplitOptions.RemoveEmptyEntries);
|
||||
string[] endParts = end.Split(new[] { ':' }, StringSplitOptions.RemoveEmptyEntries);
|
||||
string[] startParts = start.Split(SplitCharColon, StringSplitOptions.RemoveEmptyEntries);
|
||||
string[] endParts = end.Split(SplitCharColon, StringSplitOptions.RemoveEmptyEntries);
|
||||
if (startParts.Length == 4 && endParts.Length == 4)
|
||||
{
|
||||
p = new Paragraph(DecodeTimeCode(startParts), DecodeTimeCode(endParts), string.Empty);
|
||||
|
@ -95,7 +95,7 @@ namespace Nikse.SubtitleEdit.Core.SubtitleFormats
|
||||
string text = s.Substring(0, match.Index).Trim();
|
||||
string timeCode = s.Substring(match.Index).Trim();
|
||||
|
||||
string[] startParts = timeCode.Split(new[] { ':' }, StringSplitOptions.RemoveEmptyEntries);
|
||||
string[] startParts = timeCode.Split(SplitCharColon, StringSplitOptions.RemoveEmptyEntries);
|
||||
if (startParts.Length == 4)
|
||||
{
|
||||
try
|
||||
|
@ -68,7 +68,6 @@ namespace Nikse.SubtitleEdit.Core.SubtitleFormats
|
||||
string[] arr = rtf.FromRtf().SplitToLines();
|
||||
var p = new Paragraph();
|
||||
subtitle.Paragraphs.Clear();
|
||||
char[] splitChar = { ':' };
|
||||
foreach (string line in arr)
|
||||
{
|
||||
string s = line.Trim();
|
||||
@ -85,13 +84,13 @@ namespace Nikse.SubtitleEdit.Core.SubtitleFormats
|
||||
{
|
||||
if (!string.IsNullOrEmpty(p.Text))
|
||||
{
|
||||
p.EndTime = DecodeTimeCode(parts[0], splitChar);
|
||||
p.EndTime = DecodeTimeCode(parts[0], SplitCharColon);
|
||||
subtitle.Paragraphs.Add(p);
|
||||
p = new Paragraph();
|
||||
}
|
||||
else
|
||||
{
|
||||
p.StartTime = DecodeTimeCode(parts[0], splitChar);
|
||||
p.StartTime = DecodeTimeCode(parts[0], SplitCharColon);
|
||||
}
|
||||
}
|
||||
catch (Exception exception)
|
||||
|
@ -73,7 +73,6 @@ namespace Nikse.SubtitleEdit.Core.SubtitleFormats
|
||||
bool expectStartTime = true;
|
||||
var p = new Paragraph();
|
||||
subtitle.Paragraphs.Clear();
|
||||
char[] splitChar = { ':' };
|
||||
foreach (string line in lines)
|
||||
{
|
||||
string s = line.Trim().Replace("*", string.Empty);
|
||||
@ -90,8 +89,8 @@ namespace Nikse.SubtitleEdit.Core.SubtitleFormats
|
||||
subtitle.Paragraphs.Add(p);
|
||||
p = new Paragraph();
|
||||
}
|
||||
p.StartTime = DecodeTimeCode(parts[1], splitChar);
|
||||
p.EndTime = DecodeTimeCode(parts[2], splitChar);
|
||||
p.StartTime = DecodeTimeCode(parts[1], SplitCharColon);
|
||||
p.EndTime = DecodeTimeCode(parts[2], SplitCharColon);
|
||||
expectStartTime = false;
|
||||
}
|
||||
catch (Exception exception)
|
||||
|
@ -88,7 +88,7 @@ namespace Nikse.SubtitleEdit.Core.SubtitleFormats
|
||||
}
|
||||
else if (paragraph != null && expecting == ExpectingLine.TimeStart && RegexTimeCode.IsMatch(line))
|
||||
{
|
||||
string[] parts = line.Split(new[] { ':' }, StringSplitOptions.RemoveEmptyEntries);
|
||||
string[] parts = line.Split(SplitCharColon, StringSplitOptions.RemoveEmptyEntries);
|
||||
if (parts.Length == 4)
|
||||
{
|
||||
try
|
||||
@ -106,7 +106,7 @@ namespace Nikse.SubtitleEdit.Core.SubtitleFormats
|
||||
}
|
||||
else if (paragraph != null && expecting == ExpectingLine.TimeEnd && RegexTimeCode.IsMatch(line))
|
||||
{
|
||||
string[] parts = line.Split(new[] { ':' }, StringSplitOptions.RemoveEmptyEntries);
|
||||
string[] parts = line.Split(SplitCharColon, StringSplitOptions.RemoveEmptyEntries);
|
||||
if (parts.Length == 4)
|
||||
{
|
||||
try
|
||||
|
@ -77,7 +77,6 @@ namespace Nikse.SubtitleEdit.Core.SubtitleFormats
|
||||
bool expectStartTime = true;
|
||||
var p = new Paragraph();
|
||||
subtitle.Paragraphs.Clear();
|
||||
char[] splitChar = { ':' };
|
||||
foreach (string line in lines)
|
||||
{
|
||||
string s = line.Trim().Replace("*", string.Empty);
|
||||
@ -94,8 +93,8 @@ namespace Nikse.SubtitleEdit.Core.SubtitleFormats
|
||||
subtitle.Paragraphs.Add(p);
|
||||
p = new Paragraph();
|
||||
}
|
||||
p.StartTime = DecodeTimeCode(parts[1], splitChar);
|
||||
p.EndTime = DecodeTimeCode(parts[2], splitChar);
|
||||
p.StartTime = DecodeTimeCode(parts[1], SplitCharColon);
|
||||
p.EndTime = DecodeTimeCode(parts[2], SplitCharColon);
|
||||
expectStartTime = false;
|
||||
}
|
||||
catch (Exception exception)
|
||||
|
@ -73,7 +73,7 @@ namespace Nikse.SubtitleEdit.Core.SubtitleFormats
|
||||
count++;
|
||||
if (regexTimeCode.IsMatch(line))
|
||||
{
|
||||
string[] parts = line.Substring(0, 11).Split(new[] { ':' }, StringSplitOptions.RemoveEmptyEntries);
|
||||
string[] parts = line.Substring(0, 11).Split(SplitCharColon, StringSplitOptions.RemoveEmptyEntries);
|
||||
if (parts.Length == 4)
|
||||
{
|
||||
try
|
||||
@ -100,7 +100,7 @@ namespace Nikse.SubtitleEdit.Core.SubtitleFormats
|
||||
}
|
||||
else if (regexTimeCodeEnd.IsMatch(line) || (count == lines.Count && regexTimeCodeEnd.IsMatch(line + "\t")))
|
||||
{
|
||||
string[] parts = line.Substring(0, 11).Split(new[] { ':' }, StringSplitOptions.RemoveEmptyEntries);
|
||||
string[] parts = line.Substring(0, 11).Split(SplitCharColon, StringSplitOptions.RemoveEmptyEntries);
|
||||
if (parts.Length == 4)
|
||||
{
|
||||
var tc = DecodeTimeCode(parts);
|
||||
|
@ -126,7 +126,7 @@ namespace Nikse.SubtitleEdit.Core.SubtitleFormats
|
||||
}
|
||||
else if (paragraph != null && expecting == ExpectingLine.TimeStart && (RegexTimeCode.IsMatch(line) || RegexTimeCode2.IsMatch(line.Trim())))
|
||||
{
|
||||
string[] parts = RemoveSpaces(line.Trim()).Split(new[] { ':' }, StringSplitOptions.RemoveEmptyEntries);
|
||||
string[] parts = RemoveSpaces(line.Trim()).Split(SplitCharColon, StringSplitOptions.RemoveEmptyEntries);
|
||||
if (parts.Length == 4)
|
||||
{
|
||||
try
|
||||
@ -144,7 +144,7 @@ namespace Nikse.SubtitleEdit.Core.SubtitleFormats
|
||||
}
|
||||
else if (paragraph != null && expecting == ExpectingLine.TimeEnd && (RegexTimeCode.IsMatch(line) || RegexTimeCode2.IsMatch(line.Trim())))
|
||||
{
|
||||
string[] parts = RemoveSpaces(line.Trim()).Split(new[] { ':' }, StringSplitOptions.RemoveEmptyEntries);
|
||||
string[] parts = RemoveSpaces(line.Trim()).Split(SplitCharColon, StringSplitOptions.RemoveEmptyEntries);
|
||||
if (parts.Length == 4)
|
||||
{
|
||||
try
|
||||
|
@ -61,8 +61,8 @@ namespace Nikse.SubtitleEdit.Core.SubtitleFormats
|
||||
string start = temp.Substring(0, indexOfSeparator).Trim();
|
||||
string end = temp.Substring(indexOfSeparator + 2).Trim();
|
||||
|
||||
string[] startParts = start.Split(new[] { ':' }, StringSplitOptions.RemoveEmptyEntries);
|
||||
string[] endParts = end.Split(new[] { ':' }, StringSplitOptions.RemoveEmptyEntries);
|
||||
string[] startParts = start.Split(SplitCharColon, StringSplitOptions.RemoveEmptyEntries);
|
||||
string[] endParts = end.Split(SplitCharColon, StringSplitOptions.RemoveEmptyEntries);
|
||||
if (startParts.Length == 4 && endParts.Length == 4)
|
||||
{
|
||||
p = new Paragraph(DecodeTimeCode(startParts), DecodeTimeCode(endParts), string.Empty);
|
||||
|
@ -185,13 +185,12 @@ namespace Nikse.SubtitleEdit.Core.SubtitleFormats
|
||||
{
|
||||
var xml = new XmlDocument { XmlResolver = null };
|
||||
xml.LoadXml(xmlAsText);
|
||||
char[] splitChar = { ':' };
|
||||
foreach (XmlNode node in xml.DocumentElement.SelectNodes("TextSection/TextScreen"))
|
||||
{
|
||||
try
|
||||
{
|
||||
var timeCodeIn = DecodeTimeCode(node.SelectSingleNode("TimeCodeIn").InnerText, splitChar);
|
||||
var timeCodeOut = DecodeTimeCode(node.SelectSingleNode("TimeCodeOut").InnerText, splitChar);
|
||||
var timeCodeIn = DecodeTimeCode(node.SelectSingleNode("TimeCodeIn").InnerText, SplitCharColon);
|
||||
var timeCodeOut = DecodeTimeCode(node.SelectSingleNode("TimeCodeOut").InnerText, SplitCharColon);
|
||||
sb.Clear();
|
||||
foreach (XmlNode textBlockNode in node.SelectNodes("TextBlock"))
|
||||
{
|
||||
|
@ -80,7 +80,6 @@ namespace Nikse.SubtitleEdit.Core.SubtitleFormats
|
||||
string verticalAglinment = "0";
|
||||
|
||||
subtitle.Paragraphs.Clear();
|
||||
char[] splitChar = { ':' };
|
||||
char[] splitChars = { ' ', '>' };
|
||||
foreach (string line in lines)
|
||||
{
|
||||
@ -96,7 +95,7 @@ namespace Nikse.SubtitleEdit.Core.SubtitleFormats
|
||||
{
|
||||
verticalAglinment = parts[1].TrimStart('[');
|
||||
formatting = parts[2];
|
||||
paragraph = new Paragraph { StartTime = DecodeTimeCode(parts[3], splitChar), EndTime = DecodeTimeCode(parts[4].TrimEnd(']'), splitChar) };
|
||||
paragraph = new Paragraph { StartTime = DecodeTimeCode(parts[3], SplitCharColon), EndTime = DecodeTimeCode(parts[4].TrimEnd(']'), SplitCharColon) };
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
|
@ -187,13 +187,12 @@ namespace Nikse.SubtitleEdit.Core.SubtitleFormats
|
||||
{
|
||||
var xml = new XmlDocument { XmlResolver = null };
|
||||
xml.LoadXml(xmlAsText);
|
||||
char[] splitChar = { ':' };
|
||||
foreach (XmlNode node in xml.DocumentElement.SelectNodes("FileBody/ContentBlock"))
|
||||
{
|
||||
try
|
||||
{
|
||||
var timeCodeIn = DecodeTimeCode(node.SelectSingleNode("ThreadedObject/TimingObject/TimeIn").Attributes["value"].InnerText, splitChar);
|
||||
var timeCodeOut = DecodeTimeCode(node.SelectSingleNode("ThreadedObject/TimingObject/TimeOut").Attributes["value"].InnerText, splitChar);
|
||||
var timeCodeIn = DecodeTimeCode(node.SelectSingleNode("ThreadedObject/TimingObject/TimeIn").Attributes["value"].InnerText, SplitCharColon);
|
||||
var timeCodeOut = DecodeTimeCode(node.SelectSingleNode("ThreadedObject/TimingObject/TimeOut").Attributes["value"].InnerText, SplitCharColon);
|
||||
sb.Clear();
|
||||
foreach (XmlNode paragraphNode in node.SelectSingleNode("ThreadedObject/Content/SubtitleText/Paragraph").ChildNodes)
|
||||
{
|
||||
|
Loading…
x
Reference in New Issue
Block a user