Optimize "SplitToLines" method (about 60% faster)

This commit is contained in:
Nikolaj Olsson 2017-11-26 17:35:00 +01:00
parent 59017a3a02
commit 4b18695126
68 changed files with 258 additions and 167 deletions

View File

@ -1,6 +1,7 @@
using Nikse.SubtitleEdit.Core.TransportStream;
using Nikse.SubtitleEdit.Core.VobSub;
using System;
using System.Collections.Generic;
using System.IO;
using System.Text;
@ -39,7 +40,7 @@ namespace Nikse.SubtitleEdit.Core
}
}
public static string[] ReadAllLinesShared(string path, Encoding encoding)
public static List<string> ReadAllLinesShared(string path, Encoding encoding)
{
return encoding.GetString(ReadAllBytesShared(path)).SplitToLines();
}

View File

@ -41,7 +41,7 @@ namespace Nikse.SubtitleEdit.Core.Forms.FixCommonErrors
string oldText = p.Text;
var lines = HtmlUtil.RemoveHtmlTags(p.Text).SplitToLines();
if (lines.Length == 2 && lines[0].TrimStart().StartsWith('-') && lines[1].TrimStart().StartsWith('-'))
if (lines.Count == 2 && lines[0].TrimStart().StartsWith('-') && lines[1].TrimStart().StartsWith('-'))
{ // dialog
lines = p.Text.SplitToLines();
string line = lines[0].Trim();

View File

@ -36,7 +36,7 @@ namespace Nikse.SubtitleEdit.Core.Forms.FixCommonErrors
if (text.IndexOf(Environment.NewLine, StringComparison.Ordinal) > 1)
{
var lines = text.SplitToLines();
for (int k = 0; k < lines.Length; k++)
for (int k = 0; k < lines.Count; k++)
lines[k] = Helper.RemoveSpacesBeginLineAfterEllipses(lines[k]);
text = string.Join(Environment.NewLine, lines);
}

View File

@ -25,7 +25,7 @@ namespace Nikse.SubtitleEdit.Core.Forms.FixCommonErrors
else
{
var lines = text.SplitToLines();
for (int k = 0; k < lines.Length; k++)
for (int k = 0; k < lines.Count; k++)
{
lines[k] = Helper.FixDoubleGreaterThanHelper(lines[k]);
}

View File

@ -16,8 +16,8 @@ namespace Nikse.SubtitleEdit.Core.Forms.FixCommonErrors
if (text.Contains("..") && callbacks.AllowFix(p, fixAction))
{
var oldText = text;
string[] lines = text.SplitToLines();
for (int k = 0; k < lines.Length; k++)
var lines = text.SplitToLines();
for (int k = 0; k < lines.Count; k++)
{
lines[k] = Helper.FixEllipsesStartHelper(lines[k]);
}

View File

@ -141,7 +141,7 @@ namespace Nikse.SubtitleEdit.Core.Forms.FixCommonErrors
if (!p.Text.StartsWith("--", StringComparison.Ordinal))
{
var arr = p.Text.SplitToLines();
if (arr.Length == 2 && arr[0].Length > 1 && arr[1].Length > 1)
if (arr.Count == 2 && arr[0].Length > 1 && arr[1].Length > 1)
{
if (arr[0][0] == '-' && arr[0][1] != ' ')
arr[0] = arr[0].Insert(1, " ");
@ -203,7 +203,7 @@ namespace Nikse.SubtitleEdit.Core.Forms.FixCommonErrors
if (p.Text.Length > 5 && p.Text.Contains(musicSymbols))
{
var lines = p.Text.SplitToLines();
for (var lineIndex = 0; lineIndex < lines.Length; lineIndex++)
for (var lineIndex = 0; lineIndex < lines.Count; lineIndex++)
{
foreach (var musicSymbol in musicSymbols)
{

View File

@ -112,7 +112,7 @@ namespace Nikse.SubtitleEdit.Core.Forms.FixCommonErrors
if (p.Text != null && p.Text.Contains(Environment.NewLine))
{
var arr = p.Text.SplitToLines();
if (arr.Length == 2 && arr[1].Length > 1)
if (arr.Count == 2 && arr[1].Length > 1)
{
string text = arr[1];
string pre = string.Empty;

View File

@ -153,7 +153,7 @@ namespace Nikse.SubtitleEdit.Core.Forms.FixCommonErrors
if (text.Contains(" - ") && !text.Contains(Environment.NewLine))
{
var noTagLines = HtmlUtil.RemoveHtmlTags(text.Replace(" - ", Environment.NewLine), true).SplitToLines();
if (noTagLines.Length == 2)
if (noTagLines.Count == 2)
{
string part0 = noTagLines[0];
string part1 = noTagLines[1];
@ -181,7 +181,7 @@ namespace Nikse.SubtitleEdit.Core.Forms.FixCommonErrors
string temp = Utilities.AutoBreakLine(text, 99, 33, language);
var arr = text.SplitToLines();
var arrTemp = temp.SplitToLines();
if (arrTemp.Length == 2 && arr.Length == 2)
if (arrTemp.Count == 2 && arr.Count == 2)
{
var secLine = HtmlUtil.RemoveHtmlTags(arr[1]).TrimStart();
var secLineTemp = HtmlUtil.RemoveHtmlTags(arrTemp[1]).TrimStart();
@ -193,7 +193,7 @@ namespace Nikse.SubtitleEdit.Core.Forms.FixCommonErrors
{
string temp = Utilities.AutoBreakLine(text, language);
var arrTemp = temp.SplitToLines();
if (arrTemp.Length == 2)
if (arrTemp.Count == 2)
{
var secLineTemp = HtmlUtil.RemoveHtmlTags(arrTemp[1]).TrimStart();
if (secLineTemp.StartsWith('-'))
@ -259,7 +259,7 @@ namespace Nikse.SubtitleEdit.Core.Forms.FixCommonErrors
{
bool remove = true;
var noTagparts = HtmlUtil.RemoveHtmlTags(text).SplitToLines();
if (noTagparts.Length == 2)
if (noTagparts.Count == 2)
{
if (noTagparts[0].TrimStart().StartsWith('-') && noTagparts[1].Contains(": "))
remove = false;
@ -393,7 +393,7 @@ namespace Nikse.SubtitleEdit.Core.Forms.FixCommonErrors
if (startHyphenCount == 1 && totalSpaceHyphen == 0)
{
var parts = textCache.SplitToLines();
if (parts.Length == 2 && !string.IsNullOrWhiteSpace(parts[0]))
if (parts.Count == 2 && !string.IsNullOrWhiteSpace(parts[0]))
{
var part0 = parts[0].TrimEnd();
bool doAdd = "!?.".Contains(part0[part0.Length - 1]) || language == "ko";

View File

@ -101,7 +101,7 @@ namespace Nikse.SubtitleEdit.Core.Forms
foreach (string line in lines)
{
int indexOfColon = line.IndexOf(':');
bool isLastColon = count == lines.Length - 1 && !HtmlUtil.RemoveHtmlTags(line).TrimEnd(':').Contains(':');
bool isLastColon = count == lines.Count - 1 && !HtmlUtil.RemoveHtmlTags(line).TrimEnd(':').Contains(':');
if (indexOfColon <= 0 || IsInsideBrackets(line, indexOfColon) || (isLastColon && Utilities.CountTagInText(HtmlUtil.RemoveHtmlTags(line), ' ') > 1))
{
newText = (newText + Environment.NewLine + line).Trim();
@ -119,7 +119,7 @@ namespace Nikse.SubtitleEdit.Core.Forms
{
string s = line;
string l1Trim = HtmlUtil.RemoveHtmlTags(lines[0]).TrimEnd('"');
if (count == 1 && lines.Length == 2 && !l1Trim.EndsWith('.') &&
if (count == 1 && lines.Count == 2 && !l1Trim.EndsWith('.') &&
!l1Trim.EndsWith('!') &&
!l1Trim.EndsWith('?'))
{
@ -199,7 +199,7 @@ namespace Nikse.SubtitleEdit.Core.Forms
remove = false;
string l1Trimmed = HtmlUtil.RemoveHtmlTags(lines[0]).TrimEnd('"');
if (count == 1 && lines.Length == 2 && !l1Trimmed.EndsWith('.') &&
if (count == 1 && lines.Count == 2 && !l1Trimmed.EndsWith('.') &&
!l1Trimmed.EndsWith('!') &&
!l1Trimmed.EndsWith('?') &&
!l1Trimmed.EndsWith("--", StringComparison.Ordinal) &&
@ -259,7 +259,7 @@ namespace Nikse.SubtitleEdit.Core.Forms
{
string s = line;
string l1Trim = HtmlUtil.RemoveHtmlTags(lines[0]).TrimEnd('"');
if (count == 1 && lines.Length == 2 && !l1Trim.EndsWith('.') &&
if (count == 1 && lines.Count == 2 && !l1Trim.EndsWith('.') &&
!l1Trim.EndsWith('!') &&
!l1Trim.EndsWith('?'))
{
@ -331,7 +331,7 @@ namespace Nikse.SubtitleEdit.Core.Forms
int indexOfDialogChar = newText.IndexOf('-');
bool insertDash = true;
var arr = newText.SplitToLines();
if (arr.Length == 2 && arr[0].Length > 1 && arr[1].Length > 1)
if (arr.Count == 2 && arr[0].Length > 1 && arr[1].Length > 1)
{
string arr0 = new StrippableText(arr[0]).StrippedText;
var arr1Strippable = new StrippableText(arr[1]);
@ -487,7 +487,7 @@ namespace Nikse.SubtitleEdit.Core.Forms
{
var stSub = new StrippableText(s, pre, post);
string strippedText = stSub.StrippedText;
if ((lineNumber == parts.Length - 1 && st.Post.Contains('?')) || stSub.Post.Contains('?'))
if ((lineNumber == parts.Count - 1 && st.Post.Contains('?')) || stSub.Post.Contains('?'))
strippedText += "?";
if (!StartsAndEndsWithHearImpairedTags(strippedText))
{
@ -543,7 +543,7 @@ namespace Nikse.SubtitleEdit.Core.Forms
if (s.Contains("<i>") && !s.Contains("</i>") && st.Post.Contains("</i>"))
st.Post = st.Post.Replace("</i>", string.Empty);
if (lineNumber == parts.Length - 1)
if (lineNumber == parts.Count - 1)
{
if (st.Post.Replace("♪", string.Empty).Replace("♫", string.Empty).Trim().Length == 0)
{
@ -1052,7 +1052,7 @@ namespace Nikse.SubtitleEdit.Core.Forms
}
}
var lines = text.SplitToLines();
if (lines.Length == 2 && text != oldText)
if (lines.Count == 2 && text != oldText)
{
if (lines[0] == "-" && lines[1] == "-")
return string.Empty;
@ -1093,7 +1093,7 @@ namespace Nikse.SubtitleEdit.Core.Forms
return lines[0];
}
}
if (lines.Length == 2)
if (lines.Count == 2)
{
if (string.IsNullOrWhiteSpace(lines[1].Replace(".", string.Empty).Replace("?", string.Empty).Replace("!", string.Empty).Replace("-", string.Empty).Replace("—", string.Empty)))
{
@ -1106,7 +1106,7 @@ namespace Nikse.SubtitleEdit.Core.Forms
lines = text.SplitToLines();
}
}
if (lines.Length == 1 && text != oldText && Utilities.GetNumberOfLines(oldText) == 2)
if (lines.Count == 1 && text != oldText && Utilities.GetNumberOfLines(oldText) == 2)
{
if ((oldText.StartsWith('-') || oldText.StartsWith("<i>-", StringComparison.Ordinal)) &&
(oldText.Contains("." + Environment.NewLine) || oldText.Contains(".</i>" + Environment.NewLine) ||

View File

@ -64,7 +64,7 @@ namespace Nikse.SubtitleEdit.Core.Forms
if (text.Contains(Environment.NewLine))
{
var arr = text.SplitToLines();
if (arr.Length == 2)
if (arr.Count == 2)
{
var minMsBtwnLnBy2 = Configuration.Settings.General.MinimumMillisecondsBetweenLines / 2;
int spacing1 = minMsBtwnLnBy2;

View File

@ -507,7 +507,7 @@ namespace Nikse.SubtitleEdit.Core
if (italicBeginTagCount == 2 && italicEndTagCount == 1)
{
var lines = text.SplitToLines();
if (lines.Length == 2 && lines[0].StartsWith(beginTag, StringComparison.Ordinal) && lines[0].EndsWith(endTag, StringComparison.Ordinal) &&
if (lines.Count == 2 && lines[0].StartsWith(beginTag, StringComparison.Ordinal) && lines[0].EndsWith(endTag, StringComparison.Ordinal) &&
lines[1].StartsWith(beginTag, StringComparison.Ordinal))
{
text = text.TrimEnd() + endTag;

View File

@ -26,7 +26,7 @@ namespace Nikse.SubtitleEdit.Core.NetflixQualityCheck
foreach (Paragraph p in subtitle.Paragraphs)
{
var arr = p.Text.SplitToLines();
if (arr.Length == 2 && p.Text.Contains("-"))
if (arr.Count == 2 && p.Text.Contains("-"))
{
string newText = p.Text;
if (arr[0].StartsWith("- ", StringComparison.Ordinal) && arr[1].StartsWith("- ", StringComparison.Ordinal))
@ -71,7 +71,7 @@ namespace Nikse.SubtitleEdit.Core.NetflixQualityCheck
{
Paragraph p = new Paragraph(sub.Paragraphs[i]);
var arr = p.Text.SplitToLines();
if (arr.Length == 2 && p.Text.Contains("-") && arr[0].Length > 3 && arr[1].Length > 3)
if (arr.Count == 2 && p.Text.Contains("-") && arr[0].Length > 3 && arr[1].Length > 3)
{
string newText = p.Text;
if (arr[0][0] == '-' && char.IsLetter(arr[0][1]) && (arr[1].StartsWith("-", StringComparison.Ordinal) || arr[1].StartsWith("<i>-", StringComparison.Ordinal)))

View File

@ -10,11 +10,11 @@
{
foreach (Paragraph p in subtitle.Paragraphs)
{
if (p.Text.SplitToLines().Length > 2)
if (p.Text.SplitToLines().Count > 2)
{
var fixedParagraph = new Paragraph(p, false);
fixedParagraph.Text = Utilities.AutoBreakLine(fixedParagraph.Text, controller.SingleLineMaxLength, controller.SingleLineMaxLength - 3, controller.Language);
if (fixedParagraph.Text.SplitToLines().Length > 2)
if (fixedParagraph.Text.SplitToLines().Count > 2)
{
fixedParagraph = null; // cannot fix text
}

View File

@ -22,7 +22,7 @@ namespace Nikse.SubtitleEdit.Core.NetflixQualityCheck
{
newText = "[" + newText.Substring(1, newText.Length - 2) + "]";
}
else if (arr.Length == 2 && arr[0].StartsWith("-", StringComparison.Ordinal) && arr[1].StartsWith("-", StringComparison.Ordinal))
else if (arr.Count == 2 && arr[0].StartsWith("-", StringComparison.Ordinal) && arr[1].StartsWith("-", StringComparison.Ordinal))
{
if ((arr[0].StartsWith("-(", StringComparison.Ordinal) && arr[0].EndsWith(")", StringComparison.Ordinal)) || (arr[0].StartsWith("-{", StringComparison.Ordinal) && arr[0].EndsWith("}", StringComparison.Ordinal)))
{

View File

@ -1,4 +1,5 @@
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Text;
@ -85,9 +86,49 @@ namespace Nikse.SubtitleEdit.Core
return source.IndexOf(value, comparisonType) >= 0;
}
public static string[] SplitToLines(this string source)
public static List<string> SplitToLines(this string s)
{
return source.Replace("\r\r\n", "\n").Replace("\r\n", "\n").Replace('\r', '\n').Replace('\u2028', '\n').Split('\n');
//original non-optimized version: return source.Replace("\r\r\n", "\n").Replace("\r\n", "\n").Replace('\r', '\n').Replace('\u2028', '\n').Split('\n');
var lines = new List<string>();
int start = 0;
int max = s.Length;
int i = 0;
while (i < max)
{
var ch = s[i];
if (ch == '\r')
{
if (i < s.Length - 2 && s[i + 1] == '\r' && s[i + 2] == '\n') // \r\r\n
{
lines.Add(start < i ? s.Substring(start, i - start) : string.Empty);
i += 3;
start = i;
continue;
}
if (i < s.Length - 1 && s[i + 1] == '\n') // \r\n
{
lines.Add(start < i ? s.Substring(start, i - start) : string.Empty);
i += 2;
start = i;
continue;
}
lines.Add(start < i ? s.Substring(start, i - start) : string.Empty);
i++;
start = i;
continue;
}
if (ch == '\n' || ch == '\u2028')
{
lines.Add(start < i ? s.Substring(start, i - start) : string.Empty);
i++;
start = i;
continue;
}
i++;
}
lines.Add(start < i ? s.Substring(start, i - start) : string.Empty);
return lines;
}
public static int CountWords(this string source)

View File

@ -177,7 +177,7 @@ namespace Nikse.SubtitleEdit.Core
}
encoding = sr.CurrentEncoding;
var lines = sr.ReadToEnd().SplitToLines().ToList();
var lines = sr.ReadToEnd().SplitToLines();
sr.Close();
foreach (SubtitleFormat subtitleFormat in SubtitleFormat.AllSubtitleFormats)

View File

@ -40,10 +40,7 @@ namespace Nikse.SubtitleEdit.Core.SubtitleFormats
SubtitleFormat format = new AdvancedSubStationAlpha();
var sub = new Subtitle();
string text = format.ToText(sub, string.Empty);
string[] lineArray = text.SplitToLines();
var lines = new List<string>();
foreach (string line in lineArray)
lines.Add(line);
var lines = text.SplitToLines();
format.LoadSubtitle(sub, lines, string.Empty);
return sub.Header;
}

View File

@ -436,14 +436,14 @@ namespace Nikse.SubtitleEdit.Core.SubtitleFormats
string line1 = string.Empty;
string line2 = string.Empty;
var lines = text.SplitToLines();
if (lines.Length > 2)
if (lines.Count > 2)
lines = Utilities.AutoBreakLine(text).SplitToLines();
if (lines.Length > 1)
if (lines.Count > 1)
{
line1 = lines[0];
line2 = lines[1];
}
else if (lines.Length == 1)
else if (lines.Count == 1)
{
line2 = lines[0];
}

View File

@ -56,16 +56,16 @@ namespace Nikse.SubtitleEdit.Core.SubtitleFormats
foreach (Paragraph p in subtitle.Paragraphs)
{
var arr = p.Text.Trim().SplitToLines();
if (arr.Length > 3)
if (arr.Count > 3)
{
string s = Utilities.AutoBreakLine(p.Text);
arr = s.Trim().SplitToLines();
}
string line1 = string.Empty;
string line2 = string.Empty;
if (arr.Length > 0)
if (arr.Count > 0)
line1 = arr[0];
if (arr.Length > 1)
if (arr.Count > 1)
line2 = arr[1];
line1 = line1.Replace("\"", "\"\"");
line2 = line2.Replace("\"", "\"\"");

View File

@ -185,11 +185,11 @@ namespace Nikse.SubtitleEdit.Core.SubtitleFormats
}
else if (alignVCenter)
{
vPos = (int)Math.Round((lines.Length * vPosFactor * -1) / 2.0);
vPos = (int)Math.Round((lines.Count * vPosFactor * -1) / 2.0);
}
else
{
vPos = (lines.Length * vPosFactor) - vPosFactor + Configuration.Settings.SubtitleSettings.DCinemaBottomMargin; // Bottom margin is normally 8
vPos = (lines.Count * vPosFactor) - vPosFactor + Configuration.Settings.SubtitleSettings.DCinemaBottomMargin; // Bottom margin is normally 8
}
bool isItalic = false;

View File

@ -194,7 +194,7 @@ namespace Nikse.SubtitleEdit.Core.SubtitleFormats
string text = Utilities.RemoveSsaTags(p.Text);
var lines = text.SplitToLines();
int vPos = 1 + lines.Length * 7;
int vPos = 1 + lines.Count * 7;
int vPosFactor = (int)Math.Round(fontSize / 7.4);
if (alignVTop)
{
@ -202,11 +202,11 @@ namespace Nikse.SubtitleEdit.Core.SubtitleFormats
}
else if (alignVCenter)
{
vPos = (int)Math.Round((lines.Length * vPosFactor * -1) / 2.0);
vPos = (int)Math.Round((lines.Count * vPosFactor * -1) / 2.0);
}
else
{
vPos = (lines.Length * vPosFactor) - vPosFactor + Configuration.Settings.SubtitleSettings.DCinemaBottomMargin; // Bottom margin is normally 8
vPos = (lines.Count * vPosFactor) - vPosFactor + Configuration.Settings.SubtitleSettings.DCinemaBottomMargin; // Bottom margin is normally 8
}
bool isItalic = false;

View File

@ -194,7 +194,7 @@ namespace Nikse.SubtitleEdit.Core.SubtitleFormats
string text = Utilities.RemoveSsaTags(p.Text);
var lines = text.SplitToLines();
int vPos = 1 + lines.Length * 7;
int vPos = 1 + lines.Count * 7;
int vPosFactor = (int)Math.Round(fontSize / 7.4);
if (alignVTop)
{
@ -202,11 +202,11 @@ namespace Nikse.SubtitleEdit.Core.SubtitleFormats
}
else if (alignVCenter)
{
vPos = (int)Math.Round((lines.Length * vPosFactor * -1) / 2.0);
vPos = (int)Math.Round((lines.Count * vPosFactor * -1) / 2.0);
}
else
{
vPos = (lines.Length * vPosFactor) - vPosFactor + Configuration.Settings.SubtitleSettings.DCinemaBottomMargin; // Bottom margin is normally 8
vPos = (lines.Count * vPosFactor) - vPosFactor + Configuration.Settings.SubtitleSettings.DCinemaBottomMargin; // Bottom margin is normally 8
}
bool isItalic = false;

View File

@ -54,7 +54,7 @@ namespace Nikse.SubtitleEdit.Core.SubtitleFormats
if (!rtf.StartsWith("{\\rtf", StringComparison.Ordinal))
return;
lines = rtf.FromRtf().SplitToLines().ToList();
lines = rtf.FromRtf().SplitToLines();
_errorCount = 0;
Paragraph p = null;
char[] splitChars = { ':', ';', ',' };

View File

@ -41,7 +41,7 @@ namespace Nikse.SubtitleEdit.Core.SubtitleFormats
{
var sub = new Subtitle();
var format = new TimedText();
sub.ReloadLoadSubtitle(xmlAsString.SplitToLines().ToList(), null, format);
sub.ReloadLoadSubtitle(xmlAsString.SplitToLines(), null, format);
if (sub.Paragraphs.Count == 0)
continue;

View File

@ -65,7 +65,7 @@ TimeCode Format: " + Configuration.Settings.General.CurrentFrameRate + @" frames
if (!rtf.StartsWith("{\\rtf", StringComparison.Ordinal))
return;
lines = rtf.FromRtf().SplitToLines().ToList();
lines = rtf.FromRtf().SplitToLines();
_errorCount = 0;
Paragraph p = null;
char[] splitChars = { ':', ';', ',' };

View File

@ -58,7 +58,7 @@ TimeCode Format: " + Configuration.Settings.General.CurrentFrameRate + @" frames
if (!rtf.StartsWith("{\\rtf", StringComparison.Ordinal))
return;
lines = rtf.FromRtf().SplitToLines().ToList();
lines = rtf.FromRtf().SplitToLines();
_errorCount = 0;
Paragraph p = null;
char[] splitChars = { ':', ';', ',' };

View File

@ -15,14 +15,14 @@ namespace Nikse.SubtitleEdit.Core.SubtitleFormats
{
var text = GetSamiFromAvDicPlayerText(lines);
var subtitle = new Subtitle();
base.LoadSubtitle(subtitle, text.SplitToLines().ToList(), fileName);
base.LoadSubtitle(subtitle, text.SplitToLines(), fileName);
return subtitle.Paragraphs.Count > _errorCount;
}
public override void LoadSubtitle(Subtitle subtitle, List<string> lines, string fileName)
{
var text = GetSamiFromAvDicPlayerText(lines);
base.LoadSubtitle(subtitle, text.SplitToLines().ToList(), fileName);
base.LoadSubtitle(subtitle, text.SplitToLines(), fileName);
}
public override string ToText(Subtitle subtitle, string title)

View File

@ -469,11 +469,11 @@ namespace Nikse.SubtitleEdit.Core.SubtitleFormats
return sb.ToString().Trim();
}
private static bool IsAllOkay(string[] lines)
private static bool IsAllOkay(List<string> lines)
{
if (lines.Length > 4)
if (lines.Count > 4)
return false;
for (int i = 0; i < lines.Length; i++)
for (int i = 0; i < lines.Count; i++)
{
if (lines[i].Length > 32)
return false;
@ -579,7 +579,7 @@ namespace Nikse.SubtitleEdit.Core.SubtitleFormats
text = line.Trim();
if (count > 0)
sb.Append(' ');
sb.Append(GetCenterCodes(text, count, lines.Length));
sb.Append(GetCenterCodes(text, count, lines.Count));
count++;
int i = 0;
string code = string.Empty;

View File

@ -52,10 +52,10 @@ namespace Nikse.SubtitleEdit.Core.SubtitleFormats
var lines = text.SplitToLines();
int textLengthFirstLine = 0;
int textLengthSecondLine = 0;
if (lines.Length > 0)
if (lines.Count > 0)
{
textLengthFirstLine = lines[0].Length;
if (lines.Length > 1)
if (lines.Count > 1)
textLengthSecondLine = lines[1].Length;
}
}

View File

@ -36,7 +36,7 @@ namespace Nikse.SubtitleEdit.Core.SubtitleFormats
sb.AppendLine($"{index + 1:0000} : {EncodeTimeCode(p.StartTime)},{EncodeTimeCode(p.EndTime)},{numberOfLinesCode}");
sb.AppendLine("80 80 80");
for (int i = 0; i < p.Text.SplitToLines().Length; i++)
for (int i = 0; i < p.Text.SplitToLines().Count; i++)
{
string line = p.Text.SplitToLines()[i];
sb.AppendLine(GetPositionCode(i, p.Extra) + " " + line.Trim());

View File

@ -109,9 +109,9 @@ namespace Nikse.SubtitleEdit.Core.SubtitleFormats
text = ItalicPrefix + text;
}
var arr = text.SplitToLines();
for (int rowNo = 0; rowNo < arr.Length; rowNo++)
for (int rowNo = 0; rowNo < arr.Count; rowNo++)
{
if (rowNo == arr.Length - 1)
if (rowNo == arr.Count - 1)
{
sb.AppendLine("# ROW " + rowNo);
}

View File

@ -599,7 +599,7 @@ namespace Nikse.SubtitleEdit.Core.SubtitleFormats
var sb = new StringBuilder();
bool italic = false;
bool bold = false;
for (int lineNumber = 0; lineNumber < lines.Length; lineNumber++)
for (int lineNumber = 0; lineNumber < lines.Count; lineNumber++)
{
string line = lines[lineNumber];
if (lineNumber > 0)

View File

@ -28,7 +28,7 @@ namespace Nikse.SubtitleEdit.Core.SubtitleFormats
foreach (string s in lines)
text.AppendLine(s);
var lines2 = text.ToString().FromRtf().SplitToLines().ToList();
var lines2 = text.ToString().FromRtf().SplitToLines();
var u52 = new UnknownSubtitle52();
u52.LoadSubtitle(subtitle, lines2, fileName);
_errorCount = u52.ErrorCount;

View File

@ -24,10 +24,10 @@ namespace Nikse.SubtitleEdit.Core.SubtitleFormats
{
string line1 = string.Empty;
string line2 = string.Empty;
string[] lines = p.Text.SplitToLines();
if (lines.Length > 2)
var lines = p.Text.SplitToLines();
if (lines.Count > 2)
lines = Utilities.AutoBreakLine(p.Text).SplitToLines();
if (lines.Length == 1)
if (lines.Count == 1)
{
line2 = lines[0];
}

View File

@ -54,7 +54,7 @@ namespace Nikse.SubtitleEdit.Core.SubtitleFormats
if (!rtf.StartsWith("{\\rtf", StringComparison.Ordinal))
return;
lines = rtf.FromRtf().SplitToLines().ToList();
lines = rtf.FromRtf().SplitToLines();
_errorCount = 0;
Paragraph p = null;
char[] splitChar = { ':', ';', ',' };

View File

@ -68,7 +68,7 @@ namespace Nikse.SubtitleEdit.Core.SubtitleFormats
if (!rtf.StartsWith("{\\rtf", StringComparison.Ordinal))
return;
lines = rtf.FromRtf().SplitToLines().ToList();
lines = rtf.FromRtf().SplitToLines();
_errorCount = 0;
Paragraph p = null;
sb.Clear();

View File

@ -35,7 +35,7 @@ namespace Nikse.SubtitleEdit.Core.SubtitleFormats
if (!rtf.StartsWith("{\\rtf", StringComparison.Ordinal))
return;
lines = rtf.FromRtf().SplitToLines().ToList();
lines = rtf.FromRtf().SplitToLines();
base.LoadSubtitle(subtitle, lines, fileName);
}

View File

@ -39,7 +39,7 @@ namespace Nikse.SubtitleEdit.Core.SubtitleFormats
paragraph.AppendChild(time);
var arr = p.Text.SplitToLines();
for (int i = 0; i < arr.Length; i++)
for (int i = 0; i < arr.Count; i++)
{
XmlNode text = xml.CreateElement("text" + (i + 1));
text.InnerText = arr[i];

View File

@ -32,10 +32,10 @@ namespace Nikse.SubtitleEdit.Core.SubtitleFormats
foreach (Paragraph p in subtitle.Paragraphs)
{
var lines = HtmlUtil.RemoveHtmlTags(p.Text).SplitToLines();
if (lines.Length > 0)
if (lines.Count > 0)
{
sb.AppendLine(string.Format(paragraphWriteFormat, EncodeTimeCode(p.StartTime), count.ToString(CultureInfo.InvariantCulture).PadLeft(2, ' '), lines[0]));
for (int i = 1; i < lines.Length; i++)
for (int i = 1; i < lines.Count; i++)
{
count++;
if (count > 26)

View File

@ -28,10 +28,10 @@ namespace Nikse.SubtitleEdit.Core.SubtitleFormats
foreach (Paragraph p in subtitle.Paragraphs)
{
var lines = HtmlUtil.RemoveHtmlTags(p.Text).SplitToLines();
if (lines.Length > 0)
if (lines.Count > 0)
{
sb.AppendLine(EncodeTimeCode(p.StartTime) + "\t" + lines[0]);
for (int i = 1; i < lines.Length; i++)
for (int i = 1; i < lines.Count; i++)
sb.AppendLine("\t" + lines[i]);
}
}

View File

@ -35,7 +35,7 @@ namespace Nikse.SubtitleEdit.Core.SubtitleFormats
if (!rtf.StartsWith("{\\rtf", StringComparison.Ordinal))
return;
var list = rtf.FromRtf().SplitToLines().ToList();
var list = rtf.FromRtf().SplitToLines();
base.LoadSubtitle(subtitle, list, fileName);
}

View File

@ -35,7 +35,7 @@ namespace Nikse.SubtitleEdit.Core.SubtitleFormats
if (!rtf.StartsWith("{\\rtf", StringComparison.Ordinal))
return;
var list = rtf.FromRtf().SplitToLines().ToList();
var list = rtf.FromRtf().SplitToLines();
base.LoadSubtitle(subtitle, list, fileName);
}

View File

@ -63,7 +63,7 @@ ST 0 EB 3.10
if (!rtf.StartsWith("{\\rtf", StringComparison.Ordinal))
return;
string[] arr = rtf.FromRtf().SplitToLines();
var arr = rtf.FromRtf().SplitToLines();
Paragraph p = null;
subtitle.Paragraphs.Clear();
char[] splitChar = { '.' };

View File

@ -47,7 +47,7 @@ namespace Nikse.SubtitleEdit.Core.SubtitleFormats
if (!rtf.StartsWith("{\\rtf", StringComparison.Ordinal))
return;
string[] arr = rtf.FromRtf().SplitToLines();
var arr = rtf.FromRtf().SplitToLines();
bool expectStartTime = true;
var p = new Paragraph();
subtitle.Paragraphs.Clear();

View File

@ -42,7 +42,7 @@ namespace Nikse.SubtitleEdit.Core.SubtitleFormats
if (!rtf.StartsWith("{\\rtf", StringComparison.Ordinal))
return;
string[] arr = rtf.FromRtf().SplitToLines();
var arr = rtf.FromRtf().SplitToLines();
var p = new Paragraph();
subtitle.Paragraphs.Clear();
foreach (string line in arr)

View File

@ -28,10 +28,10 @@ namespace Nikse.SubtitleEdit.Core.SubtitleFormats
foreach (Paragraph p in subtitle.Paragraphs)
{
var lines = HtmlUtil.RemoveHtmlTags(p.Text).SplitToLines();
if (lines.Length > 0)
if (lines.Count > 0)
{
sb.AppendLine(EncodeTimeCode(p.StartTime) + "\t" + lines[0]);
for (int i = 1; i < lines.Length; i++)
for (int i = 1; i < lines.Count; i++)
sb.AppendLine("\t" + lines[i]);
}
}

View File

@ -41,13 +41,13 @@ SRPSKI
string firstLine = string.Empty;
string secondLine = string.Empty;
var lines = p.Text.SplitToLines();
if (lines.Length > 2)
if (lines.Count > 2)
{
lines = Utilities.AutoBreakLine(p.Text).SplitToLines();
}
if (lines.Length > 0)
if (lines.Count > 0)
firstLine = lines[0];
if (lines.Length > 1)
if (lines.Count > 1)
secondLine = lines[1];
sb.AppendLine(string.Format(" {0} {1} " + Environment.NewLine +

View File

@ -47,7 +47,7 @@ namespace Nikse.SubtitleEdit.Core.SubtitleFormats
if (!rtf.StartsWith("{\\rtf", StringComparison.Ordinal))
return;
lines = rtf.FromRtf().SplitToLines().ToList();
lines = rtf.FromRtf().SplitToLines();
Paragraph p = null;
foreach (var line in lines)
{

View File

@ -111,7 +111,7 @@ namespace Nikse.SubtitleEdit.Core.SubtitleFormats
var paragraphNode = content.SelectSingleNode("ContentBlock/ThreadedObject/Content/SubtitleText/Paragraph");
var lines = HtmlUtil.RemoveHtmlTags(p.Text, true).SplitToLines();
for (int i = 1; i < lines.Length + 1; i++)
for (int i = 1; i < lines.Count + 1; i++)
{
var rowNode = xml.CreateElement("Row");
@ -129,7 +129,7 @@ namespace Nikse.SubtitleEdit.Core.SubtitleFormats
paragraphNode.AppendChild(rowNode);
}
for (int index = 0; index < lines.Length; index++)
for (int index = 0; index < lines.Count; index++)
{
var line = lines[index];

View File

@ -1,5 +1,6 @@
using Nikse.SubtitleEdit.Core.SubtitleFormats;
using System;
using System.Collections.Generic;
using System.Text;
using System.Text.RegularExpressions;
@ -13,7 +14,7 @@ namespace Nikse.SubtitleEdit.Core
private static readonly char[] ExpectedSplitChars = { '.', ',', ';', ':' };
public bool UseFrames { get; set; }
public Subtitle AutoGuessImport(string[] lines)
public Subtitle AutoGuessImport(List<string> lines)
{
var subtitle = ImportTimeCodesOnSameSeperateLine(lines);
if (subtitle.Paragraphs.Count < 2)
@ -48,7 +49,7 @@ namespace Nikse.SubtitleEdit.Core
subtitle = jsonSubtitle;
}
if (subtitle.Paragraphs.Count == 0 && lines.Length == 1 && lines[0].Contains(" --> "))
if (subtitle.Paragraphs.Count == 0 && lines.Count == 1 && lines[0].Contains(" --> "))
{
subtitle = ImportSubtitleWithNoLineBreaks(lines[0]);
}
@ -89,13 +90,13 @@ namespace Nikse.SubtitleEdit.Core
subtitle.RemoveEmptyLines();
}
private Subtitle ImportTimeCodesInFramesAndTextOnSameLine(string[] lines)
private Subtitle ImportTimeCodesInFramesAndTextOnSameLine(List<string> lines)
{
var regexTimeCodes1 = new Regex(@"\d+", RegexOptions.Compiled);
Paragraph p = null;
var subtitle = new Subtitle();
var sb = new StringBuilder();
for (int idx = 0; idx < lines.Length; idx++)
for (int idx = 0; idx < lines.Count; idx++)
{
string line = lines[idx];
@ -156,12 +157,12 @@ namespace Nikse.SubtitleEdit.Core
return subtitle;
}
private Subtitle ImportTimeCodesInFramesOnSameSeperateLine(string[] lines)
private Subtitle ImportTimeCodesInFramesOnSameSeperateLine(List<string> lines)
{
Paragraph p = null;
var subtitle = new Subtitle();
var sb = new StringBuilder();
for (int idx = 0; idx < lines.Length; idx++)
for (int idx = 0; idx < lines.Count; idx++)
{
string line = lines[idx];
string lineWithPerhapsOnlyNumbers = GetLineWithPerhapsOnlyNumbers(line);
@ -267,13 +268,13 @@ namespace Nikse.SubtitleEdit.Core
return subtitle;
}
private static Subtitle ImportTimeCodesOnAloneLines(string[] lines)
private static Subtitle ImportTimeCodesOnAloneLines(List<string> lines)
{
Paragraph p = null;
var subtitle = new Subtitle();
var sb = new StringBuilder();
char[] splitChars = { ' ', '\t', '-', '>', '<', '{', '}', '[', ']' };
for (int idx = 0; idx < lines.Length; idx++)
for (int idx = 0; idx < lines.Count; idx++)
{
string line = lines[idx];
string lineWithPerhapsOnlyNumbers = GetLineWithPerhapsOnlyNumbers(line);
@ -325,7 +326,7 @@ namespace Nikse.SubtitleEdit.Core
return subtitle;
}
private static Subtitle ImportTimeCodesAndTextOnSameLine(string[] lines)
private static Subtitle ImportTimeCodesAndTextOnSameLine(List<string> lines)
{
var regexTimeCodes1 = new Regex(@"\d+[:.,;]{1}\d\d[:.,;]{1}\d\d[:.,;]{1}\d+", RegexOptions.Compiled);
var regexTimeCodes2 = new Regex(@"\d+[:.,;]{1}\d\d[:.,;]{1}\d+", RegexOptions.Compiled);
@ -336,7 +337,7 @@ namespace Nikse.SubtitleEdit.Core
bool isFirstLineNumber = false;
int count = -1;
for (int idx = 0; idx < lines.Length; idx++)
for (int idx = 0; idx < lines.Count; idx++)
{
string line = lines[idx];
var matches = regexTimeCodes1.Matches(line);
@ -362,7 +363,7 @@ namespace Nikse.SubtitleEdit.Core
isFirstLineNumber = true;
}
for (int idx = 0; idx < lines.Length; idx++)
for (int idx = 0; idx < lines.Count; idx++)
{
string line = lines[idx];
@ -446,7 +447,7 @@ namespace Nikse.SubtitleEdit.Core
return subtitle;
}
private static Subtitle ImportTimeCodesAndTextOnSameLineOnlySpaceAsSeparator(string[] lines)
private static Subtitle ImportTimeCodesAndTextOnSameLineOnlySpaceAsSeparator(List<string> lines)
{
var regexTimeCodes1 = new Regex(@"\d+ {1}\d\d {1}\d\d {1}\d+", RegexOptions.Compiled);
var regexTimeCodes2 = new Regex(@"\d+ {1}\d\d {1}\d+", RegexOptions.Compiled);
@ -454,7 +455,7 @@ namespace Nikse.SubtitleEdit.Core
var subtitle = new Subtitle();
var sb = new StringBuilder();
char[] splitChar = { ' ' };
for (int idx = 0; idx < lines.Length; idx++)
for (int idx = 0; idx < lines.Count; idx++)
{
string line = lines[idx];
@ -498,13 +499,13 @@ namespace Nikse.SubtitleEdit.Core
return subtitle;
}
private static Subtitle ImportTimeCodesOnSameSeperateLine(string[] lines)
private static Subtitle ImportTimeCodesOnSameSeperateLine(List<string> lines)
{
Paragraph p = null;
var subtitle = new Subtitle();
var sb = new StringBuilder();
char[] splitChars = { ' ', '\t' };
for (int idx = 0; idx < lines.Length; idx++)
for (int idx = 0; idx < lines.Count; idx++)
{
string line = lines[idx];
string lineWithPerhapsOnlyNumbers = GetLineWithPerhapsOnlyNumbers(line);
@ -608,13 +609,13 @@ namespace Nikse.SubtitleEdit.Core
return subtitle;
}
private static Subtitle ImportTimeCodesOnSameSeperateLineNoMilliseconds(string[] lines)
private static Subtitle ImportTimeCodesOnSameSeperateLineNoMilliseconds(List<string> lines)
{
Paragraph p = null;
var subtitle = new Subtitle();
var sb = new StringBuilder();
char[] splitChar = { ' ' };
for (int idx = 0; idx < lines.Length; idx++)
for (int idx = 0; idx < lines.Count; idx++)
{
string line = lines[idx];
string lineWithPerhapsOnlyNumbers = GetLineWithPerhapsOnlyNumbers(line);

View File

@ -1,5 +1,6 @@
using Nikse.SubtitleEdit.Core.SubtitleFormats;
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Text;
@ -8,7 +9,7 @@ namespace Nikse.SubtitleEdit.Core
public class UknownFormatImporterJson
{
public Subtitle AutoGuessImport(string[] lines)
public Subtitle AutoGuessImport(List<string> lines)
{
var sb = new StringBuilder();

View File

@ -302,7 +302,7 @@ namespace Nikse.SubtitleEdit.Core
string s = AutoBreakLine(text, 0, 0, language);
var arr = s.SplitToLines();
if ((arr.Length < 2 && arr[0].Length <= maximumLineLength) || (arr[0].Length <= maximumLineLength && arr[1].Length <= maximumLineLength))
if ((arr.Count < 2 && arr[0].Length <= maximumLineLength) || (arr[0].Length <= maximumLineLength && arr[1].Length <= maximumLineLength))
return s;
s = RemoveLineBreaks(s);
@ -409,7 +409,7 @@ namespace Nikse.SubtitleEdit.Core
if (text.Contains(Environment.NewLine) && (text.Contains('-') || text.Contains('♪')))
{
var noTagLines = HtmlUtil.RemoveHtmlTags(text, true).SplitToLines();
if (noTagLines.Length == 2)
if (noTagLines.Count == 2)
{
var arr0 = noTagLines[0].Trim().TrimEnd('"', '\'').TrimEnd();
if (language == "ar")
@ -679,7 +679,7 @@ namespace Nikse.SubtitleEdit.Core
public static string UnbreakLine(string text)
{
var lines = text.SplitToLines();
if (lines.Length == 1)
if (lines.Count == 1)
return text;
var singleLine = string.Join(" ", lines);

View File

@ -2,6 +2,7 @@
using System.Collections.Generic;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Text.RegularExpressions;
namespace Nikse.SubtitleEdit.Core.VobSub
@ -15,11 +16,11 @@ namespace Nikse.SubtitleEdit.Core.VobSub
private static readonly Regex _timeCodeLinePattern = new Regex(@"^timestamp: \d+:\d+:\d+:\d+, filepos: [\dabcdefABCDEF]+$", RegexOptions.Compiled);
public Idx(string fileName)
: this(File.ReadAllLines(fileName))
: this(File.ReadAllLines(fileName).ToList())
{
}
public Idx(string[] lines)
public Idx(List<string> lines)
{
int languageIndex = 0;
foreach (string line in lines)

View File

@ -363,7 +363,7 @@ namespace Nikse.SubtitleEdit.Forms
var lines = new List<string>();
if (format == null)
{
lines = File.ReadAllText(fileName).SplitToLines().ToList();
lines = File.ReadAllText(fileName).SplitToLines();
var f = new DlDd();
if (f.IsMine(lines, fileName)) // not binary, so text lines are needed
{
@ -812,7 +812,7 @@ namespace Nikse.SubtitleEdit.Forms
List<string> lines = new List<string>();
if (format == null)
{
lines = File.ReadAllText(fileName).SplitToLines().ToList();
lines = File.ReadAllText(fileName).SplitToLines();
var timedTextImage = new TimedTextImage();
if (timedTextImage.IsMine(lines, fileName))
{
@ -1634,7 +1634,7 @@ namespace Nikse.SubtitleEdit.Forms
var lines = new List<string>();
if (format == null)
{
lines = File.ReadAllText(fileName).SplitToLines().ToList();
lines = File.ReadAllText(fileName).SplitToLines();
var timedTextImage = new TimedTextImage();
if (timedTextImage.IsMine(lines, fileName))
format = timedTextImage;

View File

@ -291,9 +291,9 @@ namespace Nikse.SubtitleEdit.Forms
var lines = text.SplitToLines();
var line1 = string.Empty;
var line2 = string.Empty;
if (lines.Length > 0)
if (lines.Count > 0)
line1 = lines[0];
if (lines.Length > 1)
if (lines.Count > 1)
line2 = lines[1];
string s = template;

View File

@ -2534,9 +2534,9 @@ $DROP=[DROPVALUE]" + Environment.NewLine + Environment.NewLine +
// align lines with "gjpqy,ýęçÇ/()[]" a bit lower
var lines = text.SplitToLines();
if (lines.Length > 0)
if (lines.Count > 0)
{
var lastLine = lines[lines.Length - 1];
var lastLine = lines[lines.Count - 1];
if (lastLine.Contains(new[] { 'g', 'j', 'p', 'q', 'y', ',', 'ý', 'ę', 'ç', 'Ç', '/', '(', ')', '[', ']' }))
{
var textNoBelow = lastLine.Replace('g', 'a').Replace('j', 'a').Replace('p', 'a').Replace('q', 'a').Replace('y', 'a').Replace(',', 'a').Replace('ý', 'a').Replace('ę', 'a').Replace('ç', 'a').Replace('Ç', 'a').Replace('/', 'a').Replace('(', 'a').Replace(')', 'a').Replace('[', 'a').Replace(']', 'a');

View File

@ -1537,7 +1537,7 @@ namespace Nikse.SubtitleEdit.Forms
string oldText = currentParagraph.Text;
var lines = currentParagraph.Text.SplitToLines();
if (lines.Length == 2 && (lines[0].EndsWith('.') || lines[0].EndsWith('!') || lines[0].EndsWith('?')))
if (lines.Count == 2 && (lines[0].EndsWith('.') || lines[0].EndsWith('!') || lines[0].EndsWith('?')))
{
currentParagraph.Text = Utilities.AutoBreakLine(lines[0], Language);
newParagraph.Text = Utilities.AutoBreakLine(lines[1], Language);
@ -1546,7 +1546,7 @@ namespace Nikse.SubtitleEdit.Forms
{
string s = Utilities.AutoBreakLine(currentParagraph.Text, 5, Configuration.Settings.Tools.MergeLinesShorterThan, Language);
lines = s.SplitToLines();
if (lines.Length == 2)
if (lines.Count == 2)
{
currentParagraph.Text = Utilities.AutoBreakLine(lines[0], Language);
newParagraph.Text = Utilities.AutoBreakLine(lines[1], Language);

View File

@ -312,7 +312,7 @@ namespace Nikse.SubtitleEdit.Forms
}
var lines = text.SplitToLines();
if (Configuration.Settings.Tools.TranslateAutoSplit && lines.Length == 2 && !string.IsNullOrEmpty(lines[0]) && (Utilities.AllLettersAndNumbers + ",").Contains(lines[0].Substring(lines[0].Length-1)))
if (Configuration.Settings.Tools.TranslateAutoSplit && lines.Count == 2 && !string.IsNullOrEmpty(lines[0]) && (Utilities.AllLettersAndNumbers + ",").Contains(lines[0].Substring(lines[0].Length-1)))
{
_autoSplit[i] = true;
text = Utilities.RemoveLineBreaks(text);

View File

@ -417,7 +417,7 @@ namespace Nikse.SubtitleEdit.Forms
if (input.Length < Configuration.Settings.General.SubtitleLineMaximumLength * 3 && input.Length > Configuration.Settings.General.SubtitleLineMaximumLength * 1.5)
{
var breaked = Utilities.AutoBreakLine(input).SplitToLines();
if (breaked.Length == 2 && (breaked[0].Length > Configuration.Settings.General.SubtitleLineMaximumLength || breaked[1].Length > Configuration.Settings.General.SubtitleLineMaximumLength))
if (breaked.Count == 2 && (breaked[0].Length > Configuration.Settings.General.SubtitleLineMaximumLength || breaked[1].Length > Configuration.Settings.General.SubtitleLineMaximumLength))
{
var first = new StringBuilder();
var second = new StringBuilder();
@ -472,8 +472,8 @@ namespace Nikse.SubtitleEdit.Forms
private void SplitSingle(StringBuilder sb)
{
string t = sb.ToString().Trim();
string[] tarr = t.SplitToLines();
if (checkBoxMergeShortLines.Checked == false && tarr.Length == 3 &&
var tarr = t.SplitToLines();
if (checkBoxMergeShortLines.Checked == false && tarr.Count == 3 &&
tarr[0].Length < Configuration.Settings.General.SubtitleLineMaximumLength &&
tarr[1].Length < Configuration.Settings.General.SubtitleLineMaximumLength &&
tarr[2].Length < Configuration.Settings.General.SubtitleLineMaximumLength)
@ -481,14 +481,14 @@ namespace Nikse.SubtitleEdit.Forms
_subtitle.Paragraphs.Add(new Paragraph { Text = tarr[0] + Environment.NewLine + tarr[1] });
return;
}
if (checkBoxMergeShortLines.Checked == false && tarr.Length == 2 &&
if (checkBoxMergeShortLines.Checked == false && tarr.Count == 2 &&
tarr[0].Length < Configuration.Settings.General.SubtitleLineMaximumLength &&
tarr[1].Length < Configuration.Settings.General.SubtitleLineMaximumLength)
{
_subtitle.Paragraphs.Add(new Paragraph { Text = tarr[0] + Environment.NewLine + tarr[1] });
return;
}
if (checkBoxMergeShortLines.Checked == false && tarr.Length == 1 && tarr[0].Length < Configuration.Settings.General.SubtitleLineMaximumLength)
if (checkBoxMergeShortLines.Checked == false && tarr.Count == 1 && tarr[0].Length < Configuration.Settings.General.SubtitleLineMaximumLength)
{
_subtitle.Paragraphs.Add(new Paragraph { Text = tarr[0].Trim() });
return;
@ -769,7 +769,7 @@ namespace Nikse.SubtitleEdit.Forms
{
var fd = new FinalDraftTemplate2();
var sub = new Subtitle();
fd.LoadSubtitle(sub, Encoding.UTF8.GetString(FileUtil.ReadAllBytesShared(fileName)).SplitToLines().ToList(), fileName);
fd.LoadSubtitle(sub, Encoding.UTF8.GetString(FileUtil.ReadAllBytesShared(fileName)).SplitToLines(), fileName);
textBoxText.Text = sub.ToText(fd);
_videoFileName = null;
Text = Configuration.Settings.Language.ImportText.Title + " - " + fileName;

View File

@ -2,6 +2,7 @@
using Nikse.SubtitleEdit.Logic;
using System;
using System.IO;
using System.Linq;
using System.Text;
using System.Windows.Forms;
@ -45,7 +46,7 @@ namespace Nikse.SubtitleEdit.Forms
{
var uknownFormatImporter = new UknownFormatImporter();
uknownFormatImporter.UseFrames = radioButtonTimeCodeFrames.Checked;
ImportedSubitle = uknownFormatImporter.AutoGuessImport(textBoxText.Lines);
ImportedSubitle = uknownFormatImporter.AutoGuessImport(textBoxText.Lines.ToList());
groupBoxImportResult.Text = string.Format(Configuration.Settings.Language.ImportText.PreviewLinesModifiedX, ImportedSubitle.Paragraphs.Count);
SubtitleListview1.Fill(ImportedSubitle);
if (ImportedSubitle.Paragraphs.Count > 0)

View File

@ -7614,7 +7614,7 @@ namespace Nikse.SubtitleEdit.Forms
if (numberOfLines <= maxLines)
{
if (s.Length <= Configuration.Settings.General.SubtitleLineMaximumLength * Math.Max(numberOfLines, 2) &&
splitLines.Length == 2 && splitLines[0].StartsWith('-') && splitLines[1].StartsWith('-') &&
splitLines.Count == 2 && splitLines[0].StartsWith('-') && splitLines[1].StartsWith('-') &&
(splitLines[0].Length > Configuration.Settings.General.SubtitleLineMaximumLength || splitLines[1].Length > Configuration.Settings.General.SubtitleLineMaximumLength))
{
if (buttonUnBreak.Visible)
@ -8320,9 +8320,9 @@ namespace Nikse.SubtitleEdit.Forms
else
{
var l0 = string.Empty;
if (lines.Length > 0)
if (lines.Count > 0)
l0 = lines[0].Trim().TrimEnd('"', '\'').TrimEnd();
if (lines.Length == 2 && (l0.EndsWith('.') || l0.EndsWith('!') || l0.EndsWith('?')))
if (lines.Count == 2 && (l0.EndsWith('.') || l0.EndsWith('!') || l0.EndsWith('?')))
{
currentParagraph.Text = Utilities.AutoBreakLine(lines[0], language);
newParagraph.Text = Utilities.AutoBreakLine(lines[1], language);
@ -8357,7 +8357,7 @@ namespace Nikse.SubtitleEdit.Forms
newParagraph.Text = lines[1].Remove(3, 1).Replace(" ", " ").Trim();
}
}
else if (lines.Length == 2 && (lines[0].EndsWith(".</i>", StringComparison.Ordinal) || lines[0].EndsWith("!</i>", StringComparison.Ordinal) || lines[0].EndsWith("?</i>", StringComparison.Ordinal)))
else if (lines.Count == 2 && (lines[0].EndsWith(".</i>", StringComparison.Ordinal) || lines[0].EndsWith("!</i>", StringComparison.Ordinal) || lines[0].EndsWith("?</i>", StringComparison.Ordinal)))
{
currentParagraph.Text = Utilities.AutoBreakLine(lines[0], language);
newParagraph.Text = Utilities.AutoBreakLine(lines[1], language);
@ -8389,9 +8389,9 @@ namespace Nikse.SubtitleEdit.Forms
{
string s = currentParagraph.Text;
var arr = HtmlUtil.RemoveHtmlTags(s, true).SplitToLines();
if (arr.Length != 2 || arr[0].Length > Configuration.Settings.General.SubtitleLineMaximumLength || arr[1].Length > Configuration.Settings.General.SubtitleLineMaximumLength)
if (arr.Count != 2 || arr[0].Length > Configuration.Settings.General.SubtitleLineMaximumLength || arr[1].Length > Configuration.Settings.General.SubtitleLineMaximumLength)
{
if (arr.Length == 2 && arr[0].StartsWith('-') && arr[1].StartsWith('-'))
if (arr.Count == 2 && arr[0].StartsWith('-') && arr[1].StartsWith('-'))
{
if (lines[0].StartsWith("<i>-", StringComparison.Ordinal))
{
@ -8408,23 +8408,23 @@ namespace Nikse.SubtitleEdit.Forms
}
lines = s.SplitToLines();
if (lines.Length == 1)
if (lines.Count == 1)
{
s = Utilities.AutoBreakLine(currentParagraph.Text, 3, 20, language);
lines = s.SplitToLines();
}
if (lines.Length == 1)
if (lines.Count == 1)
{
s = Utilities.AutoBreakLine(currentParagraph.Text, 3, 18, language);
lines = s.SplitToLines();
}
if (lines.Length == 1)
if (lines.Count == 1)
{
s = Utilities.AutoBreakLine(currentParagraph.Text, 3, 15, language);
lines = s.SplitToLines();
}
if (lines.Length == 2)
if (lines.Count == 2)
{
if (Utilities.CountTagInText(s, "<i>") == 1 && lines[0].StartsWith("<i>", StringComparison.Ordinal) && lines[1].EndsWith("</i>", StringComparison.Ordinal))
{
@ -8434,7 +8434,7 @@ namespace Nikse.SubtitleEdit.Forms
currentParagraph.Text = Utilities.AutoBreakLine(lines[0], language);
newParagraph.Text = Utilities.AutoBreakLine(lines[1], language);
}
else if (lines.Length == 1)
else if (lines.Count == 1)
{
currentParagraph.Text = Utilities.AutoBreakLine(lines[0], language);
newParagraph.Text = string.Empty;
@ -8551,9 +8551,9 @@ namespace Nikse.SubtitleEdit.Forms
originalCurrent.Text = originalCurrent.Text.Remove(3, 1);
originalNew.Text = originalNew.Text.Remove(3, 1);
}
lines = new string[0];
lines.Clear();
}
else if (lines.Length == 2 && (lines[0].EndsWith('.') || lines[0].EndsWith('!') || lines[0].EndsWith('?')))
else if (lines.Count == 2 && (lines[0].EndsWith('.') || lines[0].EndsWith('!') || lines[0].EndsWith('?')))
{
string a = lines[0].Trim();
string b = lines[1].Trim();
@ -8593,22 +8593,22 @@ namespace Nikse.SubtitleEdit.Forms
lines = s.SplitToLines();
}
if (lines.Length == 1)
if (lines.Count == 1)
{
string s = Utilities.AutoBreakLine(lines[0], 3, 20, languageOriginal);
lines = s.SplitToLines();
}
if (lines.Length == 1)
if (lines.Count == 1)
{
string s = Utilities.AutoBreakLine(lines[0], 3, 18, languageOriginal);
lines = s.SplitToLines();
}
if (lines.Length == 1)
if (lines.Count == 1)
{
string s = Utilities.AutoBreakLine(lines[0], 3, 15, languageOriginal);
lines = s.SplitToLines();
}
if (lines.Length == 2)
if (lines.Count == 2)
{
string a = lines[0].Trim();
string b = lines[1].Trim();
@ -8643,7 +8643,7 @@ namespace Nikse.SubtitleEdit.Forms
originalCurrent.Text = Utilities.AutoBreakLine(lines[0]);
originalNew.Text = Utilities.AutoBreakLine(lines[1]);
}
else if (lines.Length == 1)
else if (lines.Count == 1)
{
originalNew.Text = string.Empty;
}

View File

@ -177,7 +177,7 @@ namespace Nikse.SubtitleEdit.Forms
}
var arr = dialogText.SplitToLines();
if (arr.Length == 2 && (arr[0].StartsWith('-') || arr[0].StartsWith("<i>-", StringComparison.Ordinal)) && (arr[1].StartsWith('-') || arr[1].StartsWith("<i>-", StringComparison.Ordinal)))
if (arr.Count == 2 && (arr[0].StartsWith('-') || arr[0].StartsWith("<i>-", StringComparison.Ordinal)) && (arr[1].StartsWith('-') || arr[1].StartsWith("<i>-", StringComparison.Ordinal)))
isDialog = true;
}
@ -199,7 +199,7 @@ namespace Nikse.SubtitleEdit.Forms
if (isDialog || text.Contains(Environment.NewLine))
{
var arr = text.SplitToLines();
if (arr.Length == 2)
if (arr.Count == 2)
{
int spacing1 = Configuration.Settings.General.MinimumMillisecondsBetweenLines / 2;
int spacing2 = Configuration.Settings.General.MinimumMillisecondsBetweenLines / 2;

View File

@ -544,7 +544,7 @@ namespace Nikse.SubtitleEdit.Logic
var lines = new List<string>();
if (format == null)
{
lines = File.ReadAllText(fileName).SplitToLines().ToList();
lines = File.ReadAllText(fileName).SplitToLines();
var timedTextImage = new TimedTextImage();
if (timedTextImage.IsMine(lines, fileName))
{
@ -605,7 +605,7 @@ namespace Nikse.SubtitleEdit.Logic
{
WriteLine("Found image based subtitle format: " + format.FriendlyName);
var subtitle = new Subtitle();
format.LoadSubtitle(subtitle, File.ReadAllText(fileName).SplitToLines().ToList(), fileName);
format.LoadSubtitle(subtitle, File.ReadAllText(fileName).SplitToLines(), fileName);
if (subtitle != null)
{
subtitle.FileName = fileName;

View File

@ -654,7 +654,7 @@ namespace Nikse.SubtitleEdit.Logic.Ocr
{
var sb = new StringBuilder();
var lines = input.SplitToLines();
for (int i = 0; i < lines.Length; i++)
for (int i = 0; i < lines.Count; i++)
{
string l = lines[i];

View File

@ -444,7 +444,7 @@ namespace Nikse.SubtitleEdit.Logic
const int max = 3;
var sb = new StringBuilder();
for (int i = 0; i < lines.Length; i++)
for (int i = 0; i < lines.Count; i++)
{
string line = lines[i];
if (i > 0)

View File

@ -86,5 +86,53 @@ namespace Test.Core
Assert.IsFalse(test.LineBreakStartsWithHtmlTag(true, true));
}
[TestMethod]
public void SplitToLines1()
{
string input = "Line1" + Environment.NewLine + "Line2";
Assert.AreEqual(2, input.SplitToLines().Count);
}
[TestMethod]
public void SplitToLines2()
{
string input = "Line1\r\r\nLine2\r\nLine3\rLine4\u2028Line5\nLine6";
var res = input.SplitToLines();
Assert.AreEqual(6, res.Count);
Assert.AreEqual("Line1", res[0]);
Assert.AreEqual("Line2", res[1]);
Assert.AreEqual("Line3", res[2]);
Assert.AreEqual("Line4", res[3]);
Assert.AreEqual("Line5", res[4]);
Assert.AreEqual("Line6", res[5]);
}
[TestMethod]
public void SplitToLinesEmptyLines1()
{
string input = "\n\nLine3\r\n\r\nLine5\r";
var res = input.SplitToLines();
Assert.AreEqual(6, res.Count);
Assert.AreEqual(string.Empty, res[0]);
Assert.AreEqual(string.Empty, res[1]);
Assert.AreEqual("Line3", res[2]);
Assert.AreEqual(string.Empty, res[3]);
Assert.AreEqual("Line5", res[4]);
Assert.AreEqual(string.Empty, res[5]);
}
[TestMethod]
public void SplitToLinesEmptyLines2()
{
string input = "\r\n\r\nLine3\u2028\rLine5\r\r\n";
var res = input.SplitToLines();
Assert.AreEqual(6, res.Count);
Assert.AreEqual(string.Empty, res[0]);
Assert.AreEqual(string.Empty, res[1]);
Assert.AreEqual("Line3", res[2]);
Assert.AreEqual(string.Empty, res[3]);
Assert.AreEqual("Line5", res[4]);
Assert.AreEqual(string.Empty, res[5]);
}
}
}

View File

@ -1581,7 +1581,7 @@ namespace Test
var lines3 = input3.SplitToLines();
var lines4 = input4.SplitToLines();
for (int i = 0; i < lines1.Length; i++)
for (int i = 0; i < lines1.Count; i++)
{
lines1[i] = Helper.FixDoubleGreaterThanHelper(lines1[i]);
lines2[i] = Helper.FixDoubleGreaterThanHelper(lines2[i]);

View File

@ -146,7 +146,7 @@ Line 3";
var text = target.ToText(subtitle, "title");
var outSubtitle = new Subtitle();
target.LoadSubtitle(outSubtitle, text.SplitToLines().ToList(), null);
target.LoadSubtitle(outSubtitle, text.SplitToLines(), null);
Assert.IsTrue(outSubtitle.Paragraphs[0].Text == subText);
}
@ -398,7 +398,7 @@ Dialogue: 0,0:00:01.80,0:00:04.93,Segoe Script Red shadow alpha 160,,0,0,0,,Die
Dialogue: 0,0:00:05.02,0:00:07.94,Segoe Script Red shadow alpha 160,,0,0,0,,Dit wordt de trip van ons leven.";
var target = new AdvancedSubStationAlpha();
var subtitle = new Subtitle();
target.LoadSubtitle(subtitle, text.SplitToLines().ToList(), null);
target.LoadSubtitle(subtitle, text.SplitToLines(), null);
var output = new AdvancedSubStationAlpha().ToText(subtitle, string.Empty);
Assert.IsTrue(output.Contains("[Events]"));
Assert.AreEqual(2, subtitle.Paragraphs.Count);
@ -635,7 +635,7 @@ Dialogue: Marked=0,0:00:01.00,0:00:03.00,Default,NTP,0000,0000,0000,!Effect," +
var text = target.ToText(subtitle, "title");
var outSubtitle = new Subtitle();
target.LoadSubtitle(outSubtitle, text.SplitToLines().ToList(), null);
target.LoadSubtitle(outSubtitle, text.SplitToLines(), null);
Assert.IsTrue(outSubtitle.Paragraphs[0].Text == subText);
}
@ -650,7 +650,7 @@ Dialogue: Marked=0,0:00:01.00,0:00:03.00,Default,NTP,0000,0000,0000,!Effect," +
var text = target.ToText(subtitle, "title");
var outSubtitle = new Subtitle();
target.LoadSubtitle(outSubtitle, text.SplitToLines().ToList(), null);
target.LoadSubtitle(outSubtitle, text.SplitToLines(), null);
Assert.IsTrue(outSubtitle.Paragraphs[0].Text == subText);
Assert.IsTrue(outSubtitle.Paragraphs[1].Text == subText);
}
@ -666,7 +666,7 @@ Dialogue: Marked=0,0:00:01.00,0:00:03.00,Default,NTP,0000,0000,0000,!Effect," +
var text = target.ToText(subtitle, "title");
var outSubtitle = new Subtitle();
target.LoadSubtitle(outSubtitle, text.SplitToLines().ToList(), null);
target.LoadSubtitle(outSubtitle, text.SplitToLines(), null);
Assert.IsTrue(outSubtitle.Paragraphs[0].Text == subText);
Assert.IsTrue(outSubtitle.Paragraphs[1].Text == subText);
}
@ -882,7 +882,7 @@ Dialogue: Marked=0,0:00:01.00,0:00:03.00,Default,NTP,0000,0000,0000,!Effect," +
string s = "#Every satellite...#\r\n#0:02:06.14,0:02:08.08";
var target = new Utx();
var subtitle = new Subtitle();
target.LoadSubtitle(subtitle, s.SplitToLines().ToList(), string.Empty);
target.LoadSubtitle(subtitle, s.SplitToLines(), string.Empty);
string actual = subtitle.Paragraphs[0].Text;
Assert.AreEqual("#Every satellite...#", actual);
}
@ -899,7 +899,7 @@ Dialogue: Marked=0,0:00:01.00,0:00:03.00,Default,NTP,0000,0000,0000,!Effect," +
sb.AppendLine(Utilities.LowercaseLetters);
sb.AppendLine();
}
var lines = sb.ToString().SplitToLines().ToList();
var lines = sb.ToString().SplitToLines();
Configuration.Settings.General.CurrentFrameRate = 27;
foreach (var format in SubtitleFormat.AllSubtitleFormats)
{
@ -999,7 +999,7 @@ and astronauts.“...""
</tt:div>
</tt:body>
</tt:tt>".Replace("'", "\"");
target.LoadSubtitle(subtitle, raw.SplitToLines().ToList(), null);
target.LoadSubtitle(subtitle, raw.SplitToLines(), null);
string actual = subtitle.Paragraphs[0].Text;
const string expected = "Hallo world.";
Assert.AreEqual(expected, actual);
@ -1098,7 +1098,7 @@ Hi, I'm Keith Lemon.
00:00:58.960 --> 00:01:03.280 align:middle line:-3
<c.yellow>AUDIENCE: Aww!</c>";
target.LoadSubtitle(subtitle, raw.SplitToLines().ToList(), null);
target.LoadSubtitle(subtitle, raw.SplitToLines(), null);
string actual = subtitle.Paragraphs[1].Text;
const string expected = "<font color=\"yellow\">AUDIENCE: Aww!</font>";
Assert.AreEqual(expected, actual);