more minor performance fixes

This commit is contained in:
niksedk 2014-09-07 10:27:16 +02:00
parent fa5b9e4980
commit cdf2b712e3
23 changed files with 177 additions and 177 deletions

View File

@ -189,13 +189,13 @@ namespace Nikse.SubtitleEdit.Controls
} }
// fix end spaces // fix end spaces
if (endIndex < Text.Length && !newText.EndsWith(" ") && Text[endIndex] != ' ') if (endIndex < Text.Length && !newText.EndsWith(" ", StringComparison.Ordinal) && Text[endIndex] != ' ')
{ {
bool lastWord = ";:]<.!?".Contains(Text[endIndex].ToString()); bool lastWord = ";:]<.!?".Contains(Text[endIndex].ToString());
if (!lastWord) if (!lastWord)
Text = Text.Insert(endIndex, " "); Text = Text.Insert(endIndex, " ");
} }
else if (endIndex < Text.Length && newText.EndsWith(" ") && Text[endIndex] == ' ') else if (endIndex < Text.Length && newText.EndsWith(" ", StringComparison.Ordinal) && Text[endIndex] == ' ')
{ {
Text = Text.Remove(endIndex, 1); Text = Text.Remove(endIndex, 1);
} }

View File

@ -98,8 +98,8 @@ namespace Nikse.SubtitleEdit.Forms
if (list.Count > 0) if (list.Count > 0)
{ {
string name = list[0]; string name = list[0];
int start = name.LastIndexOf("[", StringComparison.Ordinal); int start = name.LastIndexOf('[');
int end = name.LastIndexOf("]", StringComparison.Ordinal); int end = name.LastIndexOf(']');
if (start > 0 && end > start) if (start > 0 && end > start)
{ {
start++; start++;
@ -118,8 +118,8 @@ namespace Nikse.SubtitleEdit.Forms
if (comboBoxDictionaries.Items.Count > 0) if (comboBoxDictionaries.Items.Count > 0)
{ {
string name = comboBoxDictionaries.SelectedItem.ToString(); string name = comboBoxDictionaries.SelectedItem.ToString();
int start = name.LastIndexOf("[", StringComparison.Ordinal); int start = name.LastIndexOf('[');
int end = name.LastIndexOf("]", StringComparison.Ordinal); int end = name.LastIndexOf(']');
if (start >= 0 && end > start) if (start >= 0 && end > start)
{ {
start++; start++;

View File

@ -152,8 +152,8 @@ namespace Nikse.SubtitleEdit.Forms
get get
{ {
string name = comboBoxDictionaries.SelectedItem.ToString(); string name = comboBoxDictionaries.SelectedItem.ToString();
int start = name.LastIndexOf("["); int start = name.LastIndexOf('[');
int end = name.LastIndexOf("]"); int end = name.LastIndexOf(']');
if (start >= 0 && end > start) if (start >= 0 && end > start)
{ {
start++; start++;

View File

@ -831,7 +831,7 @@ $DROP=[DROPVALUE]" + Environment.NewLine + Environment.NewLine +
} }
if (text.Contains("(")) if (text.Contains("("))
text = text.Remove(0, text.IndexOf("(")).Trim(); text = text.Remove(0, text.IndexOf('(')).Trim();
text = text.TrimStart('(').TrimEnd(')').Trim(); text = text.TrimStart('(').TrimEnd(')').Trim();
string[] arr = text.Split('x'); string[] arr = text.Split('x');
width = int.Parse(arr[0]); width = int.Parse(arr[0]);
@ -1475,7 +1475,7 @@ $DROP=[DROPVALUE]" + Environment.NewLine + Environment.NewLine +
var lineHeight = parameter.LineHeight; // (textSize.Height * 0.64f); var lineHeight = parameter.LineHeight; // (textSize.Height * 0.64f);
while (i < text.Length) while (i < text.Length)
{ {
if (text.Substring(i).ToLower().StartsWith("<font ")) if (text.Substring(i).ToLower().StartsWith("<font ", StringComparison.Ordinal))
{ {
float addLeft = 0; float addLeft = 0;
int oldPathPointIndex = path.PointCount; int oldPathPointIndex = path.PointCount;
@ -1520,7 +1520,7 @@ $DROP=[DROPVALUE]" + Environment.NewLine + Environment.NewLine +
string fontContent = text.Substring(i, endIndex); string fontContent = text.Substring(i, endIndex);
if (fontContent.Contains(" color=")) if (fontContent.Contains(" color="))
{ {
string[] arr = fontContent.Substring(fontContent.IndexOf(" color=") + 7).Trim().Split(" ".ToCharArray(), StringSplitOptions.RemoveEmptyEntries); string[] arr = fontContent.Substring(fontContent.IndexOf(" color=", StringComparison.Ordinal) + 7).Trim().Split(" ".ToCharArray(), StringSplitOptions.RemoveEmptyEntries);
if (arr.Length > 0) if (arr.Length > 0)
{ {
string fontColor = arr[0].Trim('\'').Trim('"').Trim('\''); string fontColor = arr[0].Trim('\'').Trim('"').Trim('\'');
@ -1546,7 +1546,7 @@ $DROP=[DROPVALUE]" + Environment.NewLine + Environment.NewLine +
i += endIndex; i += endIndex;
} }
} }
else if (text.Substring(i).ToLower().StartsWith("</font>")) else if (text.Substring(i).ToLower().StartsWith("</font>", StringComparison.Ordinal))
{ {
if (text.Substring(i).ToLower().Replace("</font>", string.Empty).Length > 0) if (text.Substring(i).ToLower().Replace("</font>", string.Empty).Length > 0)
{ {
@ -1594,7 +1594,7 @@ $DROP=[DROPVALUE]" + Environment.NewLine + Environment.NewLine +
} }
i += 6; i += 6;
} }
else if (text.Substring(i).ToLower().StartsWith("<i>")) else if (text.Substring(i).ToLower().StartsWith("<i>", StringComparison.Ordinal))
{ {
if (sb.Length > 0) if (sb.Length > 0)
{ {
@ -1604,7 +1604,7 @@ $DROP=[DROPVALUE]" + Environment.NewLine + Environment.NewLine +
isItalic = true; isItalic = true;
i += 2; i += 2;
} }
else if (text.Substring(i).ToLower().StartsWith("</i>") && isItalic) else if (text.Substring(i).ToLower().StartsWith("</i>", StringComparison.Ordinal) && isItalic)
{ {
if (lastText.ToString().EndsWith(" ") && !sb.ToString().StartsWith(" ")) if (lastText.ToString().EndsWith(" ") && !sb.ToString().StartsWith(" "))
{ {
@ -1617,7 +1617,7 @@ $DROP=[DROPVALUE]" + Environment.NewLine + Environment.NewLine +
isItalic = false; isItalic = false;
i += 3; i += 3;
} }
else if (text.Substring(i).ToLower().StartsWith("<b>")) else if (text.Substring(i).ToLower().StartsWith("<b>", StringComparison.Ordinal))
{ {
if (sb.Length > 0) if (sb.Length > 0)
{ {
@ -1627,7 +1627,7 @@ $DROP=[DROPVALUE]" + Environment.NewLine + Environment.NewLine +
isBold = true; isBold = true;
i += 2; i += 2;
} }
else if (text.Substring(i).ToLower().StartsWith("</b>") && isBold) else if (text.Substring(i).ToLower().StartsWith("</b>", StringComparison.Ordinal) && isBold)
{ {
if (lastText.ToString().EndsWith(" ") && !sb.ToString().StartsWith(" ")) if (lastText.ToString().EndsWith(" ") && !sb.ToString().StartsWith(" "))
{ {
@ -1695,8 +1695,8 @@ $DROP=[DROPVALUE]" + Environment.NewLine + Environment.NewLine +
parameter.P.Text = fontTag + parameter.P.Text; parameter.P.Text = fontTag + parameter.P.Text;
if (parameter.P.Text.Contains("<font ") && !parameter.P.Text.Contains("</font>")) if (parameter.P.Text.Contains("<font ") && !parameter.P.Text.Contains("</font>"))
{ {
int start = parameter.P.Text.LastIndexOf("<font "); int start = parameter.P.Text.LastIndexOf("<font ", StringComparison.Ordinal);
int end = parameter.P.Text.IndexOf(">", start); int end = parameter.P.Text.IndexOf('>', start);
fontTag = parameter.P.Text.Substring(start, end - start + 1); fontTag = parameter.P.Text.Substring(start, end - start + 1);
} }
@ -1895,7 +1895,7 @@ $DROP=[DROPVALUE]" + Environment.NewLine + Environment.NewLine +
if (parameter.SimpleRendering) if (parameter.SimpleRendering)
{ {
if (text.StartsWith("<font ") && Utilities.CountTagInText(text, "<font") == 1) if (text.StartsWith("<font ", StringComparison.Ordinal) && Utilities.CountTagInText(text, "<font") == 1)
{ {
parameter.SubtitleColor = Utilities.GetColorFromFontString(text, parameter.SubtitleColor); parameter.SubtitleColor = Utilities.GetColorFromFontString(text, parameter.SubtitleColor);
} }
@ -2019,7 +2019,7 @@ $DROP=[DROPVALUE]" + Environment.NewLine + Environment.NewLine +
var lastText = new StringBuilder(); var lastText = new StringBuilder();
while (i < text.Length) while (i < text.Length)
{ {
if (text.Substring(i).ToLower().StartsWith("<font ")) if (text.Substring(i).ToLower().StartsWith("<font ", StringComparison.Ordinal))
{ {
float addLeft = 0; float addLeft = 0;
int oldPathPointIndex = path.PointCount; int oldPathPointIndex = path.PointCount;
@ -2054,7 +2054,7 @@ $DROP=[DROPVALUE]" + Environment.NewLine + Environment.NewLine +
path = new GraphicsPath(); path = new GraphicsPath();
sb = new StringBuilder(); sb = new StringBuilder();
int endIndex = text.Substring(i).IndexOf(">", StringComparison.Ordinal); int endIndex = text.Substring(i).IndexOf('>');
if (endIndex == -1) if (endIndex == -1)
{ {
i += 9999; i += 9999;
@ -2071,7 +2071,7 @@ $DROP=[DROPVALUE]" + Environment.NewLine + Environment.NewLine +
try try
{ {
colorStack.Push(c); // save old color colorStack.Push(c); // save old color
if (fontColor.StartsWith("rgb(")) if (fontColor.StartsWith("rgb(", StringComparison.Ordinal))
{ {
arr = fontColor.Remove(0, 4).TrimEnd(')').Split(",".ToCharArray(), StringSplitOptions.RemoveEmptyEntries); arr = fontColor.Remove(0, 4).TrimEnd(')').Split(",".ToCharArray(), StringSplitOptions.RemoveEmptyEntries);
c = Color.FromArgb(int.Parse(arr[0]), int.Parse(arr[1]), int.Parse(arr[2])); c = Color.FromArgb(int.Parse(arr[0]), int.Parse(arr[1]), int.Parse(arr[2]));
@ -2090,7 +2090,7 @@ $DROP=[DROPVALUE]" + Environment.NewLine + Environment.NewLine +
i += endIndex; i += endIndex;
} }
} }
else if (text.Substring(i).ToLower().StartsWith("</font>")) else if (text.Substring(i).ToLower().StartsWith("</font>", StringComparison.Ordinal))
{ {
if (text.Substring(i).ToLower().Replace("</font>", string.Empty).Length > 0) if (text.Substring(i).ToLower().Replace("</font>", string.Empty).Length > 0)
{ {
@ -2138,7 +2138,7 @@ $DROP=[DROPVALUE]" + Environment.NewLine + Environment.NewLine +
} }
i += 6; i += 6;
} }
else if (text.Substring(i).ToLower().StartsWith("<i>")) else if (text.Substring(i).ToLower().StartsWith("<i>", StringComparison.Ordinal))
{ {
if (sb.ToString().Trim().Length > 0) if (sb.ToString().Trim().Length > 0)
{ {
@ -2148,7 +2148,7 @@ $DROP=[DROPVALUE]" + Environment.NewLine + Environment.NewLine +
isItalic = true; isItalic = true;
i += 2; i += 2;
} }
else if (text.Substring(i).ToLower().StartsWith("</i>") && isItalic) else if (text.Substring(i).ToLower().StartsWith("</i>", StringComparison.Ordinal) && isItalic)
{ {
if (lastText.ToString().EndsWith(" ") && !sb.ToString().StartsWith(" ")) if (lastText.ToString().EndsWith(" ") && !sb.ToString().StartsWith(" "))
{ {
@ -2161,7 +2161,7 @@ $DROP=[DROPVALUE]" + Environment.NewLine + Environment.NewLine +
isItalic = false; isItalic = false;
i += 3; i += 3;
} }
else if (text.Substring(i).ToLower().StartsWith("<b>")) else if (text.Substring(i).ToLower().StartsWith("<b>", StringComparison.Ordinal))
{ {
if (sb.ToString().Trim().Length > 0) if (sb.ToString().Trim().Length > 0)
{ {
@ -2171,7 +2171,7 @@ $DROP=[DROPVALUE]" + Environment.NewLine + Environment.NewLine +
isBold = true; isBold = true;
i += 2; i += 2;
} }
else if (text.Substring(i).ToLower().StartsWith("</b>") && isBold) else if (text.Substring(i).ToLower().StartsWith("</b>", StringComparison.Ordinal) && isBold)
{ {
if (lastText.ToString().EndsWith(" ") && !sb.ToString().StartsWith(" ")) if (lastText.ToString().EndsWith(" ") && !sb.ToString().StartsWith(" "))
{ {
@ -2184,7 +2184,7 @@ $DROP=[DROPVALUE]" + Environment.NewLine + Environment.NewLine +
isBold = false; isBold = false;
i += 3; i += 3;
} }
else if (text.Substring(i).StartsWith(Environment.NewLine)) else if (text.Substring(i).StartsWith(Environment.NewLine, StringComparison.Ordinal))
{ {
lastText.Append(sb); lastText.Append(sb);
TextDraw.DrawText(font, sf, path, sb, isItalic, isBold, false, left, top, ref newLine, leftMargin, ref newLinePathPoint); TextDraw.DrawText(font, sf, path, sb, isItalic, isBold, false, left, top, ref newLine, leftMargin, ref newLinePathPoint);
@ -2346,11 +2346,11 @@ $DROP=[DROPVALUE]" + Environment.NewLine + Environment.NewLine +
private static string RemoveSubStationAlphaFormatting(string s) private static string RemoveSubStationAlphaFormatting(string s)
{ {
int indexOfBegin = s.IndexOf("{", StringComparison.Ordinal); int indexOfBegin = s.IndexOf("{", StringComparison.Ordinal);
while (indexOfBegin >= 0 && s.IndexOf("}") > indexOfBegin) while (indexOfBegin >= 0 && s.IndexOf('}') > indexOfBegin)
{ {
int indexOfEnd = s.IndexOf("}"); int indexOfEnd = s.IndexOf('}');
s = s.Remove(indexOfBegin, (indexOfEnd - indexOfBegin) + 1); s = s.Remove(indexOfBegin, (indexOfEnd - indexOfBegin) + 1);
indexOfBegin = s.IndexOf("{"); indexOfBegin = s.IndexOf('{');
} }
return s; return s;
} }
@ -2758,8 +2758,8 @@ $DROP=[DROPVALUE]" + Environment.NewLine + Environment.NewLine +
//set language //set language
if (!string.IsNullOrEmpty(languageString)) if (!string.IsNullOrEmpty(languageString))
{ {
if (languageString.Contains("(") && !languageString.StartsWith("(")) if (languageString.Contains("(") && languageString[0] != '(')
languageString = languageString.Substring(0, languageString.IndexOf("(", StringComparison.Ordinal) - 1).Trim(); languageString = languageString.Substring(0, languageString.IndexOf('(') - 1).Trim();
for (int i = 0; i < comboBoxLanguage.Items.Count; i++) for (int i = 0; i < comboBoxLanguage.Items.Count; i++)
{ {
string l = comboBoxLanguage.Items[i].ToString(); string l = comboBoxLanguage.Items[i].ToString();
@ -3188,7 +3188,7 @@ $DROP=[DROPVALUE]" + Environment.NewLine + Environment.NewLine +
} }
else else
{ {
int indexOfEndBracket = _subtitle.Paragraphs[i].Text.IndexOf("}"); int indexOfEndBracket = _subtitle.Paragraphs[i].Text.IndexOf('}');
if (_subtitle.Paragraphs[i].Text.StartsWith("{\\") && indexOfEndBracket > 1 && indexOfEndBracket < 6) if (_subtitle.Paragraphs[i].Text.StartsWith("{\\") && indexOfEndBracket > 1 && indexOfEndBracket < 6)
_subtitle.Paragraphs[i].Text = string.Format("{2}<{0}>{1}</{0}>", tag, _subtitle.Paragraphs[i].Text.Remove(0, indexOfEndBracket + 1), _subtitle.Paragraphs[i].Text.Substring(0, indexOfEndBracket + 1)); _subtitle.Paragraphs[i].Text = string.Format("{2}<{0}>{1}</{0}>", tag, _subtitle.Paragraphs[i].Text.Remove(0, indexOfEndBracket + 1), _subtitle.Paragraphs[i].Text.Substring(0, indexOfEndBracket + 1));
else else
@ -3230,7 +3230,7 @@ $DROP=[DROPVALUE]" + Environment.NewLine + Environment.NewLine +
Paragraph p = _subtitle.GetParagraphOrDefault(item.Index); Paragraph p = _subtitle.GetParagraphOrDefault(item.Index);
if (p != null) if (p != null)
{ {
int indexOfEndBracket = p.Text.IndexOf("}"); int indexOfEndBracket = p.Text.IndexOf('}');
if (p.Text.StartsWith("{\\") && indexOfEndBracket > 1 && indexOfEndBracket < 6) if (p.Text.StartsWith("{\\") && indexOfEndBracket > 1 && indexOfEndBracket < 6)
p.Text = p.Text.Remove(0, indexOfEndBracket + 1); p.Text = p.Text.Remove(0, indexOfEndBracket + 1);
p.Text = Utilities.RemoveHtmlTags(p.Text); p.Text = Utilities.RemoveHtmlTags(p.Text);
@ -3248,12 +3248,12 @@ $DROP=[DROPVALUE]" + Environment.NewLine + Environment.NewLine +
private static string RemoveSsaStyle(string text) private static string RemoveSsaStyle(string text)
{ {
int indexOfBegin = text.IndexOf("{"); int indexOfBegin = text.IndexOf('{');
while (indexOfBegin >= 0 && text.IndexOf("}") > indexOfBegin) while (indexOfBegin >= 0 && text.IndexOf('}') > indexOfBegin)
{ {
int indexOfEnd = text.IndexOf("}"); int indexOfEnd = text.IndexOf('}');
text = text.Remove(indexOfBegin, (indexOfEnd - indexOfBegin) + 1); text = text.Remove(indexOfBegin, (indexOfEnd - indexOfBegin) + 1);
indexOfBegin = text.IndexOf("{"); indexOfBegin = text.IndexOf('{');
} }
return text; return text;
} }

View File

@ -570,7 +570,7 @@ namespace Nikse.SubtitleEdit.Forms
AddFixToListView(p, fixAction1, text, p.Text); AddFixToListView(p, fixAction1, text, p.Text);
} }
} }
if (text.EndsWith(Environment.NewLine)) if (text.EndsWith(Environment.NewLine, StringComparison.Ordinal))
{ {
if (AllowFix(p, fixAction2)) if (AllowFix(p, fixAction2))
{ {
@ -1274,7 +1274,7 @@ namespace Nikse.SubtitleEdit.Forms
AddFixToListView(p, fixAction, oldText, p.Text); AddFixToListView(p, fixAction, oldText, p.Text);
} }
} }
if (p.Text.EndsWith("!.")) if (p.Text.EndsWith("!.", StringComparison.Ordinal))
{ {
if (AllowFix(p, fixAction)) if (AllowFix(p, fixAction))
{ {
@ -1285,7 +1285,7 @@ namespace Nikse.SubtitleEdit.Forms
AddFixToListView(p, fixAction, oldText, p.Text); AddFixToListView(p, fixAction, oldText, p.Text);
} }
} }
if (p.Text.EndsWith("?.")) if (p.Text.EndsWith("?.", StringComparison.Ordinal))
{ {
if (AllowFix(p, fixAction)) if (AllowFix(p, fixAction))
{ {
@ -1538,8 +1538,8 @@ namespace Nikse.SubtitleEdit.Forms
!newText.Substring(1).StartsWith("♪") && !newText.Substring(1).StartsWith("♫")) !newText.Substring(1).StartsWith("♪") && !newText.Substring(1).StartsWith("♫"))
newText = newText.Insert(1, " "); newText = newText.Insert(1, " ");
if ("#♪♫".Contains(newText[newText.Length - 1].ToString()) && !" >".Contains(newText[newText.Length - 2].ToString()) && if ("#♪♫".Contains(newText[newText.Length - 1].ToString()) && !" >".Contains(newText[newText.Length - 2].ToString()) &&
!newText.Substring(0, newText.Length - 1).EndsWith(Environment.NewLine) && !newText.Substring(0, newText.Length - 1).EndsWith("♪") && !newText.Substring(0, newText.Length - 1).EndsWith(Environment.NewLine, StringComparison.Ordinal) && !newText.Substring(0, newText.Length - 1).EndsWith("♪") &&
!newText.Substring(0, newText.Length - 1).EndsWith("♫")) !newText.Substring(0, newText.Length - 1).EndsWith("♫", StringComparison.Ordinal))
newText = newText.Insert(newText.Length - 1, " "); newText = newText.Insert(newText.Length - 1, " ");
if (newText != p.Text && AllowFix(p, fixAction)) if (newText != p.Text && AllowFix(p, fixAction))
{ {
@ -1716,7 +1716,7 @@ namespace Nikse.SubtitleEdit.Forms
if (betweenMilliseconds > 1500) if (betweenMilliseconds > 1500)
next = null; // cannot be quote spanning several lines of more than 1.5 seconds between lines! next = null; // cannot be quote spanning several lines of more than 1.5 seconds between lines!
else if (next.Text.Replace("<i>", string.Empty).TrimStart().TrimStart('-').TrimStart().StartsWith("\"") && else if (next.Text.Replace("<i>", string.Empty).TrimStart().TrimStart('-').TrimStart().StartsWith("\"") &&
next.Text.Replace("</i>", string.Empty).TrimEnd().EndsWith("\"") && next.Text.Replace("</i>", string.Empty).TrimEnd().EndsWith("\"", StringComparison.Ordinal) &&
Utilities.CountTagInText(next.Text, "\"") == 2) Utilities.CountTagInText(next.Text, "\"") == 2)
next = null; // seems to have valid quotes, so no spanning next = null; // seems to have valid quotes, so no spanning
} }
@ -1728,7 +1728,7 @@ namespace Nikse.SubtitleEdit.Forms
if (betweenMilliseconds > 1500) if (betweenMilliseconds > 1500)
prev = null; // cannot be quote spanning several lines of more than 1.5 seconds between lines! prev = null; // cannot be quote spanning several lines of more than 1.5 seconds between lines!
else if (prev.Text.Replace("<i>", string.Empty).TrimStart().TrimStart('-').TrimStart().StartsWith("\"") && else if (prev.Text.Replace("<i>", string.Empty).TrimStart().TrimStart('-').TrimStart().StartsWith("\"") &&
prev.Text.Replace("</i>", string.Empty).TrimEnd().EndsWith("\"") && prev.Text.Replace("</i>", string.Empty).TrimEnd().EndsWith("\"", StringComparison.Ordinal) &&
Utilities.CountTagInText(prev.Text, "\"") == 2) Utilities.CountTagInText(prev.Text, "\"") == 2)
prev = null; // seems to have valid quotes, so no spanning prev = null; // seems to have valid quotes, so no spanning
} }
@ -1740,12 +1740,12 @@ namespace Nikse.SubtitleEdit.Forms
lines = p.Text.Split(Environment.NewLine.ToCharArray(), StringSplitOptions.RemoveEmptyEntries); lines = p.Text.Split(Environment.NewLine.ToCharArray(), StringSplitOptions.RemoveEmptyEntries);
string line = lines[0].Trim(); string line = lines[0].Trim();
if (line.Length > 5 && line.TrimStart().StartsWith("- \"") && (line.EndsWith(".") || line.EndsWith("!") || line.EndsWith("?"))) if (line.Length > 5 && line.TrimStart().StartsWith("- \"") && (line.EndsWith(".", StringComparison.Ordinal) || line.EndsWith("!", StringComparison.Ordinal) || line.EndsWith("?", StringComparison.Ordinal)))
{ {
p.Text = p.Text.Trim().Replace(" " + Environment.NewLine, Environment.NewLine); p.Text = p.Text.Trim().Replace(" " + Environment.NewLine, Environment.NewLine);
p.Text = p.Text.Replace(Environment.NewLine, "\"" + Environment.NewLine); p.Text = p.Text.Replace(Environment.NewLine, "\"" + Environment.NewLine);
} }
else if (line.Length > 5 && line.EndsWith("\"") && line.IndexOf("- ", StringComparison.Ordinal) >= 0 && line.IndexOf("- ", StringComparison.Ordinal) < 4) else if (line.Length > 5 && line.EndsWith("\"", StringComparison.Ordinal) && line.IndexOf("- ", StringComparison.Ordinal) >= 0 && line.IndexOf("- ", StringComparison.Ordinal) < 4)
{ {
p.Text = p.Text.Insert(line.IndexOf("- ", StringComparison.Ordinal) + 2, "\""); p.Text = p.Text.Insert(line.IndexOf("- ", StringComparison.Ordinal) + 2, "\"");
} }
@ -1766,11 +1766,11 @@ namespace Nikse.SubtitleEdit.Forms
else if (lines[1].Contains("\"")) else if (lines[1].Contains("\""))
{ {
line = lines[1].Trim(); line = lines[1].Trim();
if (line.Length > 5 && line.TrimStart().StartsWith("- \"") && (line.EndsWith(".") || line.EndsWith("!") || line.EndsWith("?"))) if (line.Length > 5 && line.TrimStart().StartsWith("- \"") && (line.EndsWith(".", StringComparison.Ordinal) || line.EndsWith("!", StringComparison.Ordinal) || line.EndsWith("?", StringComparison.Ordinal)))
{ {
p.Text = p.Text.Trim() + "\""; p.Text = p.Text.Trim() + "\"";
} }
else if (line.Length > 5 && line.EndsWith("\"") && p.Text.IndexOf(Environment.NewLine + "- ", StringComparison.Ordinal) >= 0) else if (line.Length > 5 && line.EndsWith("\"", StringComparison.Ordinal) && p.Text.IndexOf(Environment.NewLine + "- ", StringComparison.Ordinal) >= 0)
{ {
p.Text = p.Text.Insert(p.Text.IndexOf(Environment.NewLine + "- ", StringComparison.Ordinal) + Environment.NewLine.Length + 2, "\""); p.Text = p.Text.Insert(p.Text.IndexOf(Environment.NewLine + "- ", StringComparison.Ordinal) + Environment.NewLine.Length + 2, "\"");
} }
@ -1796,12 +1796,12 @@ namespace Nikse.SubtitleEdit.Forms
if (next == null || !next.Text.Contains("\"")) if (next == null || !next.Text.Contains("\""))
p.Text += "\""; p.Text += "\"";
} }
else if (p.Text.StartsWith("<i>\"") && p.Text.EndsWith("</i>") && Utilities.CountTagInText(p.Text, "</i>") == 1) else if (p.Text.StartsWith("<i>\"") && p.Text.EndsWith("</i>", StringComparison.Ordinal) && Utilities.CountTagInText(p.Text, "</i>") == 1)
{ {
if (next == null || !next.Text.Contains("\"")) if (next == null || !next.Text.Contains("\""))
p.Text = p.Text.Replace("</i>", "\"</i>"); p.Text = p.Text.Replace("</i>", "\"</i>");
} }
else if (p.Text.EndsWith("\"")) else if (p.Text.EndsWith("\"", StringComparison.Ordinal))
{ {
if (prev == null || !prev.Text.Contains("\"")) if (prev == null || !prev.Text.Contains("\""))
p.Text = "\"" + p.Text; p.Text = "\"" + p.Text;
@ -1816,13 +1816,13 @@ namespace Nikse.SubtitleEdit.Forms
{ {
if (next == null || !next.Text.Contains("\"")) if (next == null || !next.Text.Contains("\""))
{ {
if (p.Text.StartsWith("<i>") && p.Text.EndsWith("</i>") && Utilities.CountTagInText(p.Text, "</i>") == 1) if (p.Text.StartsWith("<i>") && p.Text.EndsWith("</i>", StringComparison.Ordinal) && Utilities.CountTagInText(p.Text, "</i>") == 1)
p.Text = p.Text.Replace("</i>", "\"</i>"); p.Text = p.Text.Replace("</i>", "\"</i>");
else else
p.Text = p.Text + "\""; p.Text = p.Text + "\"";
} }
} }
else if (p.Text.StartsWith("<i>") && p.Text.EndsWith("</i>") && Utilities.CountTagInText(p.Text, "<i>") == 1) else if (p.Text.StartsWith("<i>") && p.Text.EndsWith("</i>", StringComparison.Ordinal) && Utilities.CountTagInText(p.Text, "<i>") == 1)
{ {
if (prev == null || !prev.Text.Contains("\"")) if (prev == null || !prev.Text.Contains("\""))
p.Text = p.Text.Replace("<i>", "<i>\""); p.Text = p.Text.Replace("<i>", "<i>\"");
@ -1836,7 +1836,7 @@ namespace Nikse.SubtitleEdit.Forms
int index = text.IndexOf('"'); int index = text.IndexOf('"');
if (text[index - 1] == ' ') if (text[index - 1] == ' ')
{ {
if (p.Text.EndsWith(",")) if (p.Text.EndsWith(",", StringComparison.Ordinal))
p.Text = p.Text.Insert(p.Text.Length - 1, "\"").Trim(); p.Text = p.Text.Insert(p.Text.Length - 1, "\"").Trim();
else else
p.Text = p.Text.Trim() + "\""; p.Text = p.Text.Trim() + "\"";
@ -2063,7 +2063,7 @@ namespace Nikse.SubtitleEdit.Forms
string tempNoHtml = Utilities.RemoveHtmlTags(p.Text).TrimEnd(); string tempNoHtml = Utilities.RemoveHtmlTags(p.Text).TrimEnd();
if (IsOneLineUrl(p.Text) || p.Text.Contains("♪") || p.Text.Contains("♫") || p.Text.EndsWith("'")) if (IsOneLineUrl(p.Text) || p.Text.Contains("♪") || p.Text.Contains("♫") || p.Text.EndsWith("'", StringComparison.Ordinal))
{ {
; // ignore urls ; // ignore urls
} }
@ -2087,17 +2087,17 @@ namespace Nikse.SubtitleEdit.Forms
if (AllowFix(p, fixAction)) if (AllowFix(p, fixAction))
{ {
string oldText = p.Text; string oldText = p.Text;
if (p.Text.EndsWith(">")) if (p.Text.EndsWith(">", StringComparison.Ordinal))
{ {
int lastLT = p.Text.LastIndexOf("<"); int lastLT = p.Text.LastIndexOf('<');
if (lastLT > 0) if (lastLT > 0)
p.Text = p.Text.Insert(lastLT, "."); p.Text = p.Text.Insert(lastLT, ".");
} }
else else
{ {
if (p.Text.EndsWith("“") && tempNoHtml.StartsWith("„")) if (p.Text.EndsWith("“", StringComparison.Ordinal) && tempNoHtml.StartsWith("„", StringComparison.Ordinal))
p.Text = p.Text.TrimEnd('“') + ".“"; p.Text = p.Text.TrimEnd('“') + ".“";
else if (p.Text.EndsWith("\"") && tempNoHtml.StartsWith("\"")) else if (p.Text.EndsWith("\"", StringComparison.Ordinal) && tempNoHtml.StartsWith("\"", StringComparison.Ordinal))
p.Text = p.Text.TrimEnd('"') + ".\""; p.Text = p.Text.TrimEnd('"') + ".\"";
else else
p.Text += "."; p.Text += ".";
@ -2162,9 +2162,9 @@ namespace Nikse.SubtitleEdit.Forms
string text = p.Text.Substring(0, indexOfNewLine); string text = p.Text.Substring(0, indexOfNewLine);
StripableText st = new StripableText(text); StripableText st = new StripableText(text);
if (st.Pre.TrimEnd().EndsWith("¿")) // Spanish ¿ if (st.Pre.TrimEnd().EndsWith("¿", StringComparison.Ordinal)) // Spanish ¿
p.Text = p.Text.Insert(indexOfNewLine, "?"); p.Text = p.Text.Insert(indexOfNewLine, "?");
else if (st.Pre.TrimEnd().EndsWith("¡")) // Spanish ¡ else if (st.Pre.TrimEnd().EndsWith("¡", StringComparison.Ordinal)) // Spanish ¡
p.Text = p.Text.Insert(indexOfNewLine, "!"); p.Text = p.Text.Insert(indexOfNewLine, "!");
else else
p.Text = p.Text.Insert(indexOfNewLine, "."); p.Text = p.Text.Insert(indexOfNewLine, ".");
@ -2331,9 +2331,9 @@ namespace Nikse.SubtitleEdit.Forms
isPrevEndOfLine) isPrevEndOfLine)
{ {
bool isMatchInKnowAbbreviations = language == "en" && bool isMatchInKnowAbbreviations = language == "en" &&
(prevText.EndsWith(" o.r.") || (prevText.EndsWith(" o.r.", StringComparison.Ordinal) ||
prevText.EndsWith(" a.m.") || prevText.EndsWith(" a.m.", StringComparison.Ordinal) ||
prevText.EndsWith(" p.m.")); prevText.EndsWith(" p.m.", StringComparison.Ordinal));
if (!isMatchInKnowAbbreviations) if (!isMatchInKnowAbbreviations)
{ {
@ -2403,13 +2403,13 @@ namespace Nikse.SubtitleEdit.Forms
bool isPrevEndOfLine = IsPrevoiusTextEndOfParagraph(prevText); bool isPrevEndOfLine = IsPrevoiusTextEndOfParagraph(prevText);
if ((!text.StartsWith("www.") && !text.StartsWith("http:") && !text.StartsWith("https:")) && if ((!text.StartsWith("www.") && !text.StartsWith("http:") && !text.StartsWith("https:")) &&
(firstLetter != firstLetter.ToUpper() || IsTurkishLittleI(firstLetter, encoding, language)) && (firstLetter != firstLetter.ToUpper() || IsTurkishLittleI(firstLetter, encoding, language)) &&
!prevText.EndsWith("...") && !prevText.EndsWith("...", StringComparison.Ordinal) &&
isPrevEndOfLine) isPrevEndOfLine)
{ {
bool isMatchInKnowAbbreviations = language == "en" && bool isMatchInKnowAbbreviations = language == "en" &&
(prevText.EndsWith(" o.r.") || (prevText.EndsWith(" o.r.", StringComparison.Ordinal) ||
prevText.EndsWith(" a.m.") || prevText.EndsWith(" a.m.", StringComparison.Ordinal) ||
prevText.EndsWith(" p.m.")); prevText.EndsWith(" p.m.", StringComparison.Ordinal));
if (!isMatchInKnowAbbreviations) if (!isMatchInKnowAbbreviations)
{ {
@ -2506,12 +2506,12 @@ namespace Nikse.SubtitleEdit.Forms
string text = p.Text.Substring(indexOfNewLine + len); string text = p.Text.Substring(indexOfNewLine + len);
StripableText st = new StripableText(text); StripableText st = new StripableText(text);
if (st.StrippedText.Length > 0 && IsTurkishLittleI(st.StrippedText, encoding, language) && !st.Pre.EndsWith("[") && !st.Pre.Contains("...")) if (st.StrippedText.Length > 0 && IsTurkishLittleI(st.StrippedText, encoding, language) && !st.Pre.EndsWith("[", StringComparison.Ordinal) && !st.Pre.Contains("..."))
{ {
text = st.Pre + st.StrippedText.Remove(0, 1).Insert(0, GetTurkishUppercaseLetter(st.StrippedText, encoding)) + st.Post; text = st.Pre + st.StrippedText.Remove(0, 1).Insert(0, GetTurkishUppercaseLetter(st.StrippedText, encoding)) + st.Post;
p.Text = p.Text.Remove(indexOfNewLine + len).Insert(indexOfNewLine + len, text); p.Text = p.Text.Remove(indexOfNewLine + len).Insert(indexOfNewLine + len, text);
} }
else if (st.StrippedText.Length > 0 && st.StrippedText[0] != char.ToUpper(st.StrippedText[0]) && !st.Pre.EndsWith("[") && !st.Pre.Contains("...")) else if (st.StrippedText.Length > 0 && st.StrippedText[0] != char.ToUpper(st.StrippedText[0]) && !st.Pre.EndsWith("[", StringComparison.Ordinal) && !st.Pre.Contains("..."))
{ {
text = st.Pre + st.StrippedText.Remove(0, 1).Insert(0, st.StrippedText[0].ToString().ToUpper()) + st.Post; text = st.Pre + st.StrippedText.Remove(0, 1).Insert(0, st.StrippedText[0].ToString().ToUpper()) + st.Post;
p.Text = p.Text.Remove(indexOfNewLine + len).Insert(indexOfNewLine + len, text); p.Text = p.Text.Remove(indexOfNewLine + len).Insert(indexOfNewLine + len, text);
@ -2555,12 +2555,12 @@ namespace Nikse.SubtitleEdit.Forms
prevText = prevText.Replace("♪", string.Empty).Replace("♫", string.Empty).Trim(); prevText = prevText.Replace("♪", string.Empty).Replace("♫", string.Empty).Trim();
bool isPrevEndOfLine = prevText.Length > 1 && bool isPrevEndOfLine = prevText.Length > 1 &&
!prevText.EndsWith("...") && !prevText.EndsWith("...", StringComparison.Ordinal) &&
(prevText.EndsWith(".") || (prevText.EndsWith(".", StringComparison.Ordinal) ||
prevText.EndsWith("!") || prevText.EndsWith("!", StringComparison.Ordinal) ||
prevText.EndsWith("?")); prevText.EndsWith("?", StringComparison.Ordinal));
if (isPrevEndOfLine && prevText.Length > 5 && prevText.EndsWith(".") && if (isPrevEndOfLine && prevText.Length > 5 && prevText.EndsWith(".", StringComparison.Ordinal) &&
prevText[prevText.Length - 3] == '.' && prevText[prevText.Length - 3] == '.' &&
Utilities.AllLetters.Contains(prevText[prevText.Length - 2].ToString())) Utilities.AllLetters.Contains(prevText[prevText.Length - 2].ToString()))
isPrevEndOfLine = false; isPrevEndOfLine = false;
@ -2647,7 +2647,7 @@ namespace Nikse.SubtitleEdit.Forms
if (last != null) if (last != null)
{ {
string lastText = Utilities.RemoveHtmlTags(last.Text); string lastText = Utilities.RemoveHtmlTags(last.Text);
if (lastText.EndsWith(":") || lastText.EndsWith(";")) if (lastText.EndsWith(":", StringComparison.Ordinal) || lastText.EndsWith(";", StringComparison.Ordinal))
{ {
var st = new StripableText(p.Text); var st = new StripableText(p.Text);
if (st.StrippedText.Length > 0 && st.StrippedText[0] != char.ToUpper(st.StrippedText[0])) if (st.StrippedText.Length > 0 && st.StrippedText[0] != char.ToUpper(st.StrippedText[0]))
@ -2964,7 +2964,7 @@ namespace Nikse.SubtitleEdit.Forms
if (match.Index > 1) if (match.Index > 1)
wholePrev = s.Substring(0, match.Index - 1); wholePrev = s.Substring(0, match.Index - 1);
if (prev != ">" && next != ">" && next != "}" && !wholePrev.Trim().EndsWith("...")) if (prev != ">" && next != ">" && next != "}" && !wholePrev.Trim().EndsWith("...", StringComparison.Ordinal))
{ {
bool fix = true; bool fix = true;
@ -3018,7 +3018,7 @@ namespace Nikse.SubtitleEdit.Forms
{ {
Paragraph prev = _subtitle.GetParagraphOrDefault(i - 1); Paragraph prev = _subtitle.GetParagraphOrDefault(i - 1);
if (prev == null || !Utilities.RemoveHtmlTags(prev.Text).Trim().EndsWith("-")) if (prev == null || !Utilities.RemoveHtmlTags(prev.Text).Trim().EndsWith("-", StringComparison.Ordinal))
{ {
var lines = Utilities.RemoveHtmlTags(p.Text).Split(Environment.NewLine.ToCharArray(), StringSplitOptions.RemoveEmptyEntries); var lines = Utilities.RemoveHtmlTags(p.Text).Split(Environment.NewLine.ToCharArray(), StringSplitOptions.RemoveEmptyEntries);
int startHyphenCount = 0; int startHyphenCount = 0;
@ -3105,11 +3105,11 @@ namespace Nikse.SubtitleEdit.Forms
else if (text.StartsWith("<font ")) else if (text.StartsWith("<font "))
{ {
Paragraph prev = _subtitle.GetParagraphOrDefault(i - 1); Paragraph prev = _subtitle.GetParagraphOrDefault(i - 1);
if (prev == null || !Utilities.RemoveHtmlTags(prev.Text).Trim().EndsWith("-")) if (prev == null || !Utilities.RemoveHtmlTags(prev.Text).Trim().EndsWith("-", StringComparison.Ordinal))
{ {
string oldText = p.Text; string oldText = p.Text;
var st = new StripableText(text); var st = new StripableText(text);
if (st.Pre.EndsWith("-") || st.Pre.EndsWith("- ")) if (st.Pre.EndsWith("-", StringComparison.Ordinal) || st.Pre.EndsWith("- ", StringComparison.Ordinal))
{ {
text = st.Pre.TrimEnd().TrimEnd('-').TrimEnd() + st.StrippedText + st.Post; text = st.Pre.TrimEnd().TrimEnd('-').TrimEnd() + st.StrippedText + st.Post;
} }
@ -3153,7 +3153,7 @@ namespace Nikse.SubtitleEdit.Forms
{ {
Paragraph prev = _subtitle.GetParagraphOrDefault(i - 1); Paragraph prev = _subtitle.GetParagraphOrDefault(i - 1);
if (prev == null || !Utilities.RemoveHtmlTags(prev.Text).Trim().EndsWith("-")) if (prev == null || !Utilities.RemoveHtmlTags(prev.Text).Trim().EndsWith("-", StringComparison.Ordinal))
{ {
var lines = Utilities.RemoveHtmlTags(p.Text).Split(Environment.NewLine.ToCharArray(), StringSplitOptions.RemoveEmptyEntries); var lines = Utilities.RemoveHtmlTags(p.Text).Split(Environment.NewLine.ToCharArray(), StringSplitOptions.RemoveEmptyEntries);
int startHyphenCount = 0; int startHyphenCount = 0;
@ -3169,11 +3169,11 @@ namespace Nikse.SubtitleEdit.Forms
string[] parts = Utilities.RemoveHtmlTags(text).Split(Environment.NewLine.ToCharArray(), StringSplitOptions.RemoveEmptyEntries); string[] parts = Utilities.RemoveHtmlTags(text).Split(Environment.NewLine.ToCharArray(), StringSplitOptions.RemoveEmptyEntries);
if (parts.Length == 2) if (parts.Length == 2)
{ {
bool doAdd = parts[0].Trim().EndsWith(".") || parts[0].Trim().EndsWith("!") || parts[0].Trim().EndsWith("?") || Language == "ko"; bool doAdd = parts[0].Trim().EndsWith(".", StringComparison.Ordinal) || parts[0].Trim().EndsWith("!", StringComparison.Ordinal) || parts[0].Trim().EndsWith("?", StringComparison.Ordinal) || Language == "ko";
if (parts[0].Trim().StartsWith("-") && parts[1].Contains(":")) if (parts[0].Trim().StartsWith("-", StringComparison.Ordinal) && parts[1].Contains(":"))
doAdd = false; doAdd = false;
if (parts[1].Trim().StartsWith("-") && parts[0].Contains(":")) if (parts[1].Trim().StartsWith("-", StringComparison.Ordinal) && parts[0].Contains(":"))
doAdd = false; doAdd = false;
if (doAdd) if (doAdd)
@ -3332,7 +3332,7 @@ namespace Nikse.SubtitleEdit.Forms
text = text.Remove(0, 1); text = text.Remove(0, 1);
text = text.Insert(0, "..."); text = text.Insert(0, "...");
} }
if (p.Text.EndsWith("—")) if (p.Text.EndsWith("—", StringComparison.Ordinal))
{ {
text = text.Substring(0, text.Length - 1) + "..."; text = text.Substring(0, text.Length - 1) + "...";
text = text.Replace(" ...", "..."); text = text.Replace(" ...", "...");
@ -4214,10 +4214,10 @@ namespace Nikse.SubtitleEdit.Forms
Paragraph p = _subtitle.Paragraphs[i]; Paragraph p = _subtitle.Paragraphs[i];
Paragraph last = _subtitle.GetParagraphOrDefault(i - 1); Paragraph last = _subtitle.GetParagraphOrDefault(i - 1);
bool wasLastLineClosed = last == null || last.Text.EndsWith("?") || last.Text.EndsWith("!") || last.Text.EndsWith(".") || bool wasLastLineClosed = last == null || last.Text.EndsWith("?", StringComparison.Ordinal) || last.Text.EndsWith("!", StringComparison.Ordinal) || last.Text.EndsWith(".", StringComparison.Ordinal) ||
last.Text.EndsWith(":") || last.Text.EndsWith(")") || last.Text.EndsWith("]"); last.Text.EndsWith(":", StringComparison.Ordinal) || last.Text.EndsWith(")", StringComparison.Ordinal) || last.Text.EndsWith("]", StringComparison.Ordinal);
string trimmedStart = p.Text.TrimStart(("- ").ToCharArray()); string trimmedStart = p.Text.TrimStart(("- ").ToCharArray());
if (last != null && last.Text.EndsWith("...") && trimmedStart.Length > 0 && trimmedStart[0].ToString() == trimmedStart[0].ToString().ToLower()) if (last != null && last.Text.EndsWith("...", StringComparison.Ordinal) && trimmedStart.Length > 0 && trimmedStart[0].ToString() == trimmedStart[0].ToString().ToLower())
wasLastLineClosed = false; wasLastLineClosed = false;
if (!wasLastLineClosed && last != null && last.Text == last.Text.ToUpper()) if (!wasLastLineClosed && last != null && last.Text == last.Text.ToUpper())
wasLastLineClosed = true; wasLastLineClosed = true;
@ -4319,11 +4319,11 @@ namespace Nikse.SubtitleEdit.Forms
} }
var st = new StripableText(part); var st = new StripableText(part);
if (j == 0 && mark == "!" && st.Pre == "¿" && Utilities.CountTagInText(p.Text, mark) == 1 && Utilities.RemoveHtmlTags(p.Text).EndsWith(mark)) if (j == 0 && mark == "!" && st.Pre == "¿" && Utilities.CountTagInText(p.Text, mark) == 1 && Utilities.RemoveHtmlTags(p.Text).EndsWith(mark, StringComparison.Ordinal))
{ {
p.Text = inverseMark + p.Text; p.Text = inverseMark + p.Text;
} }
else if (j == 0 && mark == "?" && st.Pre == "¡" && Utilities.CountTagInText(p.Text, mark) == 1 && Utilities.RemoveHtmlTags(p.Text).EndsWith(mark)) else if (j == 0 && mark == "?" && st.Pre == "¡" && Utilities.CountTagInText(p.Text, mark) == 1 && Utilities.RemoveHtmlTags(p.Text).EndsWith(mark, StringComparison.Ordinal))
{ {
p.Text = inverseMark + p.Text; p.Text = inverseMark + p.Text;
} }
@ -4368,7 +4368,7 @@ namespace Nikse.SubtitleEdit.Forms
wasLastLineClosed = true; wasLastLineClosed = true;
} }
} }
if (p.Text.EndsWith(mark + "...") && p.Text.Length > 4) if (p.Text.EndsWith(mark + "...", StringComparison.Ordinal) && p.Text.Length > 4)
{ {
p.Text = p.Text.Remove(p.Text.Length - 4, 4) + "..." + mark; p.Text = p.Text.Remove(p.Text.Length - 4, 4) + "..." + mark;
} }
@ -5377,7 +5377,7 @@ namespace Nikse.SubtitleEdit.Forms
string oldText = currentParagraph.Text; string oldText = currentParagraph.Text;
string[] lines = currentParagraph.Text.Split(Environment.NewLine.ToCharArray(), StringSplitOptions.RemoveEmptyEntries); string[] lines = currentParagraph.Text.Split(Environment.NewLine.ToCharArray(), StringSplitOptions.RemoveEmptyEntries);
if (lines.Length == 2 && (lines[0].EndsWith(".") || lines[0].EndsWith("!") || lines[0].EndsWith("?"))) if (lines.Length == 2 && (lines[0].EndsWith(".", StringComparison.Ordinal) || lines[0].EndsWith("!", StringComparison.Ordinal) || lines[0].EndsWith("?", StringComparison.Ordinal)))
{ {
currentParagraph.Text = Utilities.AutoBreakLine(lines[0], Language); currentParagraph.Text = Utilities.AutoBreakLine(lines[0], Language);
newParagraph.Text = Utilities.AutoBreakLine(lines[1], Language); newParagraph.Text = Utilities.AutoBreakLine(lines[1], Language);

View File

@ -188,7 +188,7 @@ namespace Nikse.SubtitleEdit.Forms
{ {
foreach (ZipExtractor.ZipFileEntry entry in dir) foreach (ZipExtractor.ZipFileEntry entry in dir)
{ {
if (entry.FilenameInZip.ToLower().EndsWith(".zip")) if (entry.FilenameInZip.ToLower().EndsWith(".zip", StringComparison.Ordinal))
{ {
var innerMs = new MemoryStream(); var innerMs = new MemoryStream();
zip.ExtractFile(entry, innerMs); zip.ExtractFile(entry, innerMs);

View File

@ -446,7 +446,7 @@ namespace Nikse.SubtitleEdit.Forms
res = res.Replace(Environment.NewLine + " ", Environment.NewLine).Trim(); res = res.Replace(Environment.NewLine + " ", Environment.NewLine).Trim();
res = res.Replace(" " + Environment.NewLine, Environment.NewLine).Trim(); res = res.Replace(" " + Environment.NewLine, Environment.NewLine).Trim();
res = res.Replace(" " + Environment.NewLine, Environment.NewLine).Trim(); res = res.Replace(" " + Environment.NewLine, Environment.NewLine).Trim();
int end = res.LastIndexOf("<p>"); int end = res.LastIndexOf("<p>", StringComparison.Ordinal);
if (end > 0) if (end > 0)
res = res.Substring(0, end); res = res.Substring(0, end);
return res; return res;

View File

@ -380,11 +380,11 @@ namespace Nikse.SubtitleEdit.Forms
if (pos + 35 < textBoxSource.TextLength) if (pos + 35 < textBoxSource.TextLength)
pos += 35; pos += 35;
string s = textBoxSource.Text.Substring(0, pos); string s = textBoxSource.Text.Substring(0, pos);
int lastTimeCode = s.LastIndexOf(" --> "); // 00:02:26,407 --> 00:02:31,356 int lastTimeCode = s.LastIndexOf(" --> ", StringComparison.Ordinal); // 00:02:26,407 --> 00:02:31,356
if (lastTimeCode > 14 && lastTimeCode + 16 >= s.Length) if (lastTimeCode > 14 && lastTimeCode + 16 >= s.Length)
{ {
s = s.Substring(0, lastTimeCode - 5); s = s.Substring(0, lastTimeCode - 5);
lastTimeCode = s.LastIndexOf(" --> "); lastTimeCode = s.LastIndexOf(" --> ", StringComparison.Ordinal);
} }
if (lastTimeCode > 14 && lastTimeCode + 16 < s.Length) if (lastTimeCode > 14 && lastTimeCode + 16 < s.Length)
@ -710,7 +710,7 @@ namespace Nikse.SubtitleEdit.Forms
} }
else else
{ {
int indexOfDirectorySeparatorChar = pattern.LastIndexOf(Path.DirectorySeparatorChar.ToString()); int indexOfDirectorySeparatorChar = pattern.LastIndexOf(Path.DirectorySeparatorChar);
if (indexOfDirectorySeparatorChar > 0 && indexOfDirectorySeparatorChar < pattern.Length) if (indexOfDirectorySeparatorChar > 0 && indexOfDirectorySeparatorChar < pattern.Length)
{ {
pattern = pattern.Substring(indexOfDirectorySeparatorChar + 1); pattern = pattern.Substring(indexOfDirectorySeparatorChar + 1);
@ -2622,7 +2622,7 @@ namespace Nikse.SubtitleEdit.Forms
} }
} }
if (fileName.ToLower().EndsWith(".dost")) if (fileName.ToLower().EndsWith(".dost", StringComparison.Ordinal))
{ {
try try
{ {
@ -2674,7 +2674,7 @@ namespace Nikse.SubtitleEdit.Forms
foreach (Paragraph p in _subtitle.Paragraphs) foreach (Paragraph p in _subtitle.Paragraphs)
{ {
string s = p.Text.ToLower(); string s = p.Text.ToLower();
if (s.EndsWith(".bmp") || s.EndsWith(".png") || s.EndsWith(".jpg") || s.EndsWith(".tif")) if (s.EndsWith(".bmp", StringComparison.Ordinal) || s.EndsWith(".png", StringComparison.Ordinal) || s.EndsWith(".jpg", StringComparison.Ordinal) || s.EndsWith(".tif", StringComparison.Ordinal))
{ {
imageCount++; imageCount++;
} }
@ -2830,7 +2830,7 @@ namespace Nikse.SubtitleEdit.Forms
string s = File.ReadAllText(fileName, enc); string s = File.ReadAllText(fileName, enc);
// check for RTF file // check for RTF file
if (fileName.ToLower().EndsWith(".rtf") && !s.Trim().StartsWith("{\\rtf")) if (fileName.ToLower().EndsWith(".rtf", StringComparison.Ordinal) && !s.Trim().StartsWith("{\\rtf", StringComparison.Ordinal))
{ {
var rtBox = new RichTextBox(); var rtBox = new RichTextBox();
rtBox.Rtf = s; rtBox.Rtf = s;
@ -3033,7 +3033,7 @@ namespace Nikse.SubtitleEdit.Forms
} }
else else
{ {
if (!string.IsNullOrEmpty(fileName) && fileName.ToLower().EndsWith(".xml")) if (!string.IsNullOrEmpty(fileName) && fileName.ToLower().EndsWith(".xml", StringComparison.Ordinal))
{ {
string[] arr = File.ReadAllLines(fileName, Utilities.GetEncodingFromFile(fileName)); string[] arr = File.ReadAllLines(fileName, Utilities.GetEncodingFromFile(fileName));
var sb = new StringBuilder(); var sb = new StringBuilder();
@ -3478,7 +3478,7 @@ namespace Nikse.SubtitleEdit.Forms
bool extOk = ext == format.Extension.ToLower() || format.AlternateExtensions.Contains(ext) || ext == ".txt"; bool extOk = ext == format.Extension.ToLower() || format.AlternateExtensions.Contains(ext) || ext == ".txt";
if (!extOk) if (!extOk)
{ {
if (_fileName.EndsWith(".")) if (_fileName.EndsWith(".", StringComparison.Ordinal))
_fileName = _fileName.Substring(0, _fileName.Length - 1); _fileName = _fileName.Substring(0, _fileName.Length - 1);
_fileName += format.Extension; _fileName += format.Extension;
} }
@ -7272,12 +7272,12 @@ namespace Nikse.SubtitleEdit.Forms
// If the first subtitle ends with a tag (</i>): // If the first subtitle ends with a tag (</i>):
String endTag = ""; String endTag = "";
if (p.Text.EndsWith(">") && p.Text.Contains("<")) if (p.Text.EndsWith(">", StringComparison.Ordinal) && p.Text.Contains("<"))
{ {
// Save the end tag. // Save the end tag.
endTag = p.Text.Substring(p.Text.LastIndexOf("<"), p.Text.Length - p.Text.LastIndexOf("<")); endTag = p.Text.Substring(p.Text.LastIndexOf('<'), p.Text.Length - p.Text.LastIndexOf('<'));
// Remove the endTag from first subtitle. // Remove the endTag from first subtitle.
p.Text = p.Text.Remove(p.Text.LastIndexOf("<")); p.Text = p.Text.Remove(p.Text.LastIndexOf('<'));
} }
// If the first subtitle ends with "...": // If the first subtitle ends with "...":
@ -7365,7 +7365,7 @@ namespace Nikse.SubtitleEdit.Forms
if (p != null && next != null) if (p != null && next != null)
{ {
string s = p.Text.Trim(); string s = p.Text.Trim();
int idx = s.LastIndexOf(" "); int idx = s.LastIndexOf(' ');
if (idx > 0 || s.Length > 0) if (idx > 0 || s.Length > 0)
// A last word was found or the first subtitle is not empty (has one word). // A last word was found or the first subtitle is not empty (has one word).
{ {
@ -7392,9 +7392,9 @@ namespace Nikse.SubtitleEdit.Forms
if (lastWord.EndsWith(">") && lastWord.Contains("<")) if (lastWord.EndsWith(">") && lastWord.Contains("<"))
{ {
// Save the end tag. // Save the end tag.
endTag = lastWord.Substring(lastWord.LastIndexOf("<"), lastWord.Length - lastWord.LastIndexOf("<")); endTag = lastWord.Substring(lastWord.LastIndexOf('<'), lastWord.Length - lastWord.LastIndexOf("<"));
// Remove the end tag from the last word. // Remove the end tag from the last word.
lastWord = lastWord.Remove(lastWord.LastIndexOf("<")); lastWord = lastWord.Remove(lastWord.LastIndexOf('<'));
} }
// If the first subtitle ends with "...": // If the first subtitle ends with "...":
@ -8691,7 +8691,7 @@ namespace Nikse.SubtitleEdit.Forms
int start = textBoxSource.Text.IndexOf(tc); int start = textBoxSource.Text.IndexOf(tc);
if (start > 0) if (start > 0)
{ {
int start2 = textBoxSource.Text.LastIndexOf("Dialogue:", start); int start2 = textBoxSource.Text.LastIndexOf("Dialogue:", start, StringComparison.Ordinal);
if (start2 > 0) if (start2 > 0)
start2 = (textBoxSource.Text + Environment.NewLine).IndexOf(Environment.NewLine, start2); start2 = (textBoxSource.Text + Environment.NewLine).IndexOf(Environment.NewLine, start2);
if (start2 > 0) if (start2 > 0)
@ -8720,11 +8720,11 @@ namespace Nikse.SubtitleEdit.Forms
if (pos + 35 < textBoxSource.TextLength) if (pos + 35 < textBoxSource.TextLength)
pos += 35; pos += 35;
string s = textBoxSource.Text.Substring(0, pos); string s = textBoxSource.Text.Substring(0, pos);
int lastTimeCode = s.LastIndexOf(" --> "); // 00:02:26,407 --> 00:02:31,356 int lastTimeCode = s.LastIndexOf(" --> ", StringComparison.Ordinal); // 00:02:26,407 --> 00:02:31,356
if (lastTimeCode > 14 && lastTimeCode + 16 >= s.Length) if (lastTimeCode > 14 && lastTimeCode + 16 >= s.Length)
{ {
s = s.Substring(0, lastTimeCode - 5); s = s.Substring(0, lastTimeCode - 5);
lastTimeCode = s.LastIndexOf(" --> "); lastTimeCode = s.LastIndexOf(" --> ", StringComparison.Ordinal);
} }
if (lastTimeCode > 14 && lastTimeCode + 16 < s.Length) if (lastTimeCode > 14 && lastTimeCode + 16 < s.Length)
@ -13302,7 +13302,7 @@ namespace Nikse.SubtitleEdit.Forms
} }
else if (fileNameNoExtension.Contains(".")) else if (fileNameNoExtension.Contains("."))
{ {
fileNameNoExtension = fileNameNoExtension.Substring(0, fileNameNoExtension.LastIndexOf(".")); fileNameNoExtension = fileNameNoExtension.Substring(0, fileNameNoExtension.LastIndexOf('.'));
TryToFindAndOpenVideoFile(fileNameNoExtension); TryToFindAndOpenVideoFile(fileNameNoExtension);
} }
} }

View File

@ -205,7 +205,7 @@ namespace Nikse.SubtitleEdit.Forms
return string.Empty; return string.Empty;
string endTag = string.Empty; string endTag = string.Empty;
int start = text.LastIndexOf("</"); int start = text.LastIndexOf("</", StringComparison.Ordinal);
if (start > 0 && start >= text.Length - 8) if (start > 0 && start >= text.Length - 8)
{ {
endTag = text.Substring(start); endTag = text.Substring(start);

View File

@ -93,7 +93,7 @@ namespace Nikse.SubtitleEdit.Forms
} }
else if (fileNameNoExtension.Contains(".")) else if (fileNameNoExtension.Contains("."))
{ {
fileNameNoExtension = fileNameNoExtension.Substring(0, fileNameNoExtension.LastIndexOf(".")); fileNameNoExtension = fileNameNoExtension.Substring(0, fileNameNoExtension.LastIndexOf('.'));
TryToFindAndOpenVideoFile(fileNameNoExtension); TryToFindAndOpenVideoFile(fileNameNoExtension);
} }
} }

View File

@ -1032,8 +1032,8 @@ namespace Nikse.SubtitleEdit.Forms
else else
{ {
string name = Utilities.GetDictionaryLanguages()[0]; string name = Utilities.GetDictionaryLanguages()[0];
int start = name.LastIndexOf("["); int start = name.LastIndexOf('[');
int end = name.LastIndexOf("]"); int end = name.LastIndexOf(']');
if (start > 0 && end > start) if (start > 0 && end > start)
{ {
start++; start++;

View File

@ -379,7 +379,7 @@ namespace Nikse.SubtitleEdit.Forms
} }
else if (fileNameNoExtension.Contains(".")) else if (fileNameNoExtension.Contains("."))
{ {
fileNameNoExtension = fileNameNoExtension.Substring(0, fileNameNoExtension.LastIndexOf(".")); fileNameNoExtension = fileNameNoExtension.Substring(0, fileNameNoExtension.LastIndexOf('.'));
TryToFindAndOpenMovieFile(fileNameNoExtension); TryToFindAndOpenMovieFile(fileNameNoExtension);
} }
} }

View File

@ -7296,8 +7296,8 @@ namespace Nikse.SubtitleEdit.Forms
return null; return null;
string name = comboBoxDictionaries.SelectedItem.ToString(); string name = comboBoxDictionaries.SelectedItem.ToString();
int start = name.LastIndexOf("["); int start = name.LastIndexOf('[');
int end = name.LastIndexOf("]"); int end = name.LastIndexOf(']');
if (start >= 0 && end > start) if (start >= 0 && end > start)
{ {
start++; start++;

View File

@ -422,11 +422,11 @@ namespace Nikse.SubtitleEdit.Logic.Forms
{ {
StripableText temp = new StripableText(text); StripableText temp = new StripableText(text);
temp.StrippedText = temp.StrippedText.Replace(Environment.NewLine, " "); temp.StrippedText = temp.StrippedText.Replace(Environment.NewLine, " ");
int splitIndex = temp.StrippedText.LastIndexOf("!", StringComparison.Ordinal); int splitIndex = temp.StrippedText.LastIndexOf('!');
if (splitIndex == -1) if (splitIndex == -1)
splitIndex = temp.StrippedText.LastIndexOf("?", StringComparison.Ordinal); splitIndex = temp.StrippedText.LastIndexOf('?');
if (splitIndex == -1) if (splitIndex == -1)
splitIndex = temp.StrippedText.LastIndexOf(".", StringComparison.Ordinal); splitIndex = temp.StrippedText.LastIndexOf('.');
if (splitIndex > 0) if (splitIndex > 0)
{ {
text = temp.Pre + temp.StrippedText.Insert(splitIndex + 1, Environment.NewLine) + temp.Post; text = temp.Pre + temp.StrippedText.Insert(splitIndex + 1, Environment.NewLine) + temp.Post;

View File

@ -955,7 +955,7 @@ namespace Nikse.SubtitleEdit.Logic.Ocr
if (HexNumber.IsMatch(word)) if (HexNumber.IsMatch(word))
return word; return word;
if (word.LastIndexOf("0", StringComparison.Ordinal) > 0) if (word.LastIndexOf('0') > 0)
{ {
Match match = RegExTime1.Match(word); Match match = RegExTime1.Match(word);
if (match.Success) if (match.Success)

View File

@ -75,21 +75,21 @@ namespace Nikse.SubtitleEdit.Logic
text = text.Substring(0, text.Length - 1); text = text.Substring(0, text.Length - 1);
} }
if (text.EndsWith(">")) if (text.EndsWith(">", StringComparison.Ordinal))
{ {
string lower = text.ToLower(); string lower = text.ToLower();
// tags </i> </b> </u> // tags </i> </b> </u>
if (lower.EndsWith("</i>") || if (lower.EndsWith("</i>", StringComparison.Ordinal) ||
lower.EndsWith("</b>") || lower.EndsWith("</b>", StringComparison.Ordinal) ||
lower.EndsWith("</u>")) lower.EndsWith("</u>", StringComparison.Ordinal))
{ {
Post = text.Substring(text.Length - 4, 4) + Post; Post = text.Substring(text.Length - 4, 4) + Post;
text = text.Substring(0, text.Length - 4); text = text.Substring(0, text.Length - 4);
} }
// tag </font> // tag </font>
if (lower.EndsWith("</font>")) if (lower.EndsWith("</font>", StringComparison.Ordinal))
{ {
Post = text.Substring(text.Length - 7, 7) + Post; Post = text.Substring(text.Length - 7, 7) + Post;
text = text.Substring(0, text.Length - 7); text = text.Substring(0, text.Length - 7);
@ -132,7 +132,7 @@ namespace Nikse.SubtitleEdit.Logic
{ {
bool startOk = (start == 0) || (lower[start - 1] == ' ') || (lower[start - 1] == '-') || bool startOk = (start == 0) || (lower[start - 1] == ' ') || (lower[start - 1] == '-') ||
(lower[start - 1] == '"') || (lower[start - 1] == '\'') || (lower[start - 1] == '>') || (lower[start - 1] == '"') || (lower[start - 1] == '\'') || (lower[start - 1] == '>') ||
(Environment.NewLine.EndsWith(lower[start - 1].ToString())); (Environment.NewLine.EndsWith(lower[start - 1].ToString(), StringComparison.Ordinal));
if (startOk) if (startOk)
{ {
@ -157,7 +157,7 @@ namespace Nikse.SubtitleEdit.Logic
} }
} }
if (StrippedText.EndsWith(".")) if (StrippedText.EndsWith(".", StringComparison.Ordinal))
{ {
Post = "." + Post; Post = "." + Post;
StrippedText = StrippedText.TrimEnd('.'); StrippedText = StrippedText.TrimEnd('.');
@ -185,18 +185,18 @@ namespace Nikse.SubtitleEdit.Logic
bool startWithUppercase = string.IsNullOrEmpty(s) || bool startWithUppercase = string.IsNullOrEmpty(s) ||
s.EndsWith(".") || s.EndsWith(".", StringComparison.Ordinal) ||
s.EndsWith("!") || s.EndsWith("!", StringComparison.Ordinal) ||
s.EndsWith("?") || s.EndsWith("?", StringComparison.Ordinal) ||
s.EndsWith(". ♪") || s.EndsWith(". ♪", StringComparison.Ordinal) ||
s.EndsWith("! ♪") || s.EndsWith("! ♪", StringComparison.Ordinal) ||
s.EndsWith("? ♪") || s.EndsWith("? ♪", StringComparison.Ordinal) ||
s.EndsWith("]") || s.EndsWith("]", StringComparison.Ordinal) ||
s.EndsWith(")") || s.EndsWith(")", StringComparison.Ordinal) ||
s.EndsWith(":"); s.EndsWith(":", StringComparison.Ordinal);
// start with uppercase after music symbol - but only if next line not starts with music symbol // start with uppercase after music symbol - but only if next line not starts with music symbol
if (!startWithUppercase && (s.EndsWith("♪") || s.EndsWith("♫"))) if (!startWithUppercase && (s.EndsWith("♪", StringComparison.Ordinal) || s.EndsWith("♫", StringComparison.Ordinal)))
{ {
if (!Pre.Contains("♪") && !Pre.Contains("♫")) if (!Pre.Contains("♪") && !Pre.Contains("♫"))
startWithUppercase = true; startWithUppercase = true;
@ -232,15 +232,15 @@ namespace Nikse.SubtitleEdit.Logic
{ {
sb.Append(s); sb.Append(s);
} }
else if ((sb.ToString().EndsWith("<") || sb.ToString().EndsWith("</")) && i + 1 < StrippedText.Length && StrippedText[i + 1] == '>') else if ((sb.ToString().EndsWith("<", StringComparison.Ordinal) || sb.ToString().EndsWith("</", StringComparison.Ordinal)) && i + 1 < StrippedText.Length && StrippedText[i + 1] == '>')
{ // tags { // tags
sb.Append(s); sb.Append(s);
} }
else if (sb.ToString().EndsWith("<") && s == "/" && i + 2 < StrippedText.Length && StrippedText[i + 2] == '>') else if (sb.ToString().EndsWith("<", StringComparison.Ordinal) && s == "/" && i + 2 < StrippedText.Length && StrippedText[i + 2] == '>')
{ // tags { // tags
sb.Append(s); sb.Append(s);
} }
else if (sb.ToString().EndsWith("... ")) else if (sb.ToString().EndsWith("... ", StringComparison.Ordinal))
{ {
sb.Append(s); sb.Append(s);
lastWasBreak = false; lastWasBreak = false;

View File

@ -67,7 +67,7 @@ namespace Nikse.SubtitleEdit.Logic.SubtitleFormats
var sb = new StringBuilder(); var sb = new StringBuilder();
lines.ForEach(line => sb.AppendLine(line)); lines.ForEach(line => sb.AppendLine(line));
string all = sb.ToString(); string all = sb.ToString();
if (!string.IsNullOrEmpty(fileName) && fileName.ToLower().EndsWith(".ass") && !all.Contains("[V4 Styles]")) if (!string.IsNullOrEmpty(fileName) && fileName.ToLower().EndsWith(".ass", StringComparison.Ordinal) && !all.Contains("[V4 Styles]"))
{ {
} }
else if (!all.ToLower().Contains("dialogue:")) else if (!all.ToLower().Contains("dialogue:"))

View File

@ -120,7 +120,7 @@ namespace Nikse.SubtitleEdit.Logic.SubtitleFormats
try try
{ {
int textIndex = s.LastIndexOf("]") + 1; int textIndex = s.LastIndexOf(']') + 1;
if (textIndex < s.Length) if (textIndex < s.Length)
{ {
string text = s.Substring(textIndex); string text = s.Substring(textIndex);

View File

@ -85,7 +85,7 @@ namespace Nikse.SubtitleEdit.Logic.SubtitleFormats
string[] endParts = end.Split(":.\"".ToCharArray(), StringSplitOptions.RemoveEmptyEntries); string[] endParts = end.Split(":.\"".ToCharArray(), StringSplitOptions.RemoveEmptyEntries);
if (startParts.Length == 4 && endParts.Length == 4) if (startParts.Length == 4 && endParts.Length == 4)
{ {
string text = line.Substring(line.LastIndexOf("/>") + 2); string text = line.Substring(line.LastIndexOf("/>", StringComparison.Ordinal) + 2);
p = new Paragraph(DecodeTimeCode(startParts), DecodeTimeCode(endParts), text); p = new Paragraph(DecodeTimeCode(startParts), DecodeTimeCode(endParts), text);
subtitle.Paragraphs.Add(p); subtitle.Paragraphs.Add(p);
} }

View File

@ -72,7 +72,7 @@ namespace Nikse.SubtitleEdit.Logic.SubtitleFormats
string[] endParts = end.Split(":".ToCharArray(), StringSplitOptions.RemoveEmptyEntries); string[] endParts = end.Split(":".ToCharArray(), StringSplitOptions.RemoveEmptyEntries);
if (startParts.Length == 4 && endParts.Length == 4) if (startParts.Length == 4 && endParts.Length == 4)
{ {
int lastIndexOfTab = line.LastIndexOf("\t"); int lastIndexOfTab = line.LastIndexOf('\t');
string text = line.Remove(0, lastIndexOfTab+1).Trim(); string text = line.Remove(0, lastIndexOfTab+1).Trim();
if (!text.Contains(Environment.NewLine)) if (!text.Contains(Environment.NewLine))
text = text.Replace("\t", Environment.NewLine); text = text.Replace("\t", Environment.NewLine);

View File

@ -235,9 +235,9 @@ namespace Nikse.SubtitleEdit.Logic.SubtitleFormats
// Fix a few more cases of wrong time codes, seen this: 00.00.02,000 --> 00.00.04,000 // Fix a few more cases of wrong time codes, seen this: 00.00.02,000 --> 00.00.04,000
line = line.Replace('.', ':'); line = line.Replace('.', ':');
if (line.Length >= 29 && ":;".Contains(line[8].ToString())) if (line.Length >= 29 && (line[8] == ':' || line[8] == ';'))
line = line.Substring(0, 8) + ',' + line.Substring(8 + 1); line = line.Substring(0, 8) + ',' + line.Substring(8 + 1);
if (line.Length >= 29 && line.Length <= 30 && ":;".Contains(line[25].ToString())) if (line.Length >= 29 && line.Length <= 30 && (line[25] == ':' || line[25] == ';'))
line = line.Substring(0, 25) + ',' + line.Substring(25 + 1); line = line.Substring(0, 25) + ',' + line.Substring(25 + 1);
if (_regexTimeCodes.IsMatch(line) || _regexTimeCodes2.IsMatch(line)) if (_regexTimeCodes.IsMatch(line) || _regexTimeCodes2.IsMatch(line))

View File

@ -378,7 +378,7 @@ namespace Nikse.SubtitleEdit.Logic
} }
} }
if (s2.EndsWith("? -") || s2.EndsWith("! -") || s2.EndsWith(". -")) if (s2.EndsWith("? -", StringComparison.Ordinal) || s2.EndsWith("! -", StringComparison.Ordinal) || s2.EndsWith(". -", StringComparison.Ordinal))
return false; return false;
return true; return true;
@ -553,7 +553,7 @@ namespace Nikse.SubtitleEdit.Logic
if (arr.Length == 2) if (arr.Length == 2)
{ {
string arr0 = arr[0].Trim().TrimEnd('"').TrimEnd('\'').TrimEnd(); string arr0 = arr[0].Trim().TrimEnd('"').TrimEnd('\'').TrimEnd();
if (arr0.StartsWith("-") && arr[1].Trim().StartsWith("-") && (arr0.EndsWith(".") || arr0.EndsWith("!") || arr0.EndsWith("?"))) if (arr0.StartsWith("-", StringComparison.Ordinal) && arr[1].Trim().StartsWith("-", StringComparison.Ordinal) && (arr0.EndsWith(".", StringComparison.Ordinal) || arr0.EndsWith("!", StringComparison.Ordinal) || arr0.EndsWith("?", StringComparison.Ordinal)))
return text; return text;
} }
} }
@ -963,7 +963,7 @@ namespace Nikse.SubtitleEdit.Logic
{ // keep utf-8 encoding if it's default { // keep utf-8 encoding if it's default
encoding = Encoding.UTF8; encoding = Encoding.UTF8;
} }
else if (couldBeUtf8 && fileName.ToLower().EndsWith(".xml") && Encoding.Default.GetString(buffer).ToLower().Replace("'", "\"").Contains("encoding=\"utf-8\"")) else if (couldBeUtf8 && fileName.ToLower().EndsWith(".xml", StringComparison.Ordinal) && Encoding.Default.GetString(buffer).ToLower().Replace("'", "\"").Contains("encoding=\"utf-8\""))
{ // keep utf-8 encoding for xml files with utf-8 in header (without any utf-8 encoded characters, but with only allowed utf-8 characters) { // keep utf-8 encoding for xml files with utf-8 in header (without any utf-8 encoded characters, but with only allowed utf-8 characters)
encoding = Encoding.UTF8; encoding = Encoding.UTF8;
} }
@ -2299,7 +2299,7 @@ namespace Nikse.SubtitleEdit.Logic
{ {
if (s.IndexOf(word, StringComparison.Ordinal) >= 0 && text.IndexOf(s, StringComparison.Ordinal) >= 0) if (s.IndexOf(word, StringComparison.Ordinal) >= 0 && text.IndexOf(s, StringComparison.Ordinal) >= 0)
{ {
if (s.StartsWith(word + " ") || s.EndsWith(" " + word) || s.Contains(" " + word + " ")) if (s.StartsWith(word + " ", StringComparison.Ordinal) || s.EndsWith(" " + word, StringComparison.Ordinal) || s.Contains(" " + word + " "))
return true; return true;
if (word == s) if (word == s)
return true; return true;
@ -2317,7 +2317,7 @@ namespace Nikse.SubtitleEdit.Logic
{ {
if (s.Contains(word) && text.Contains(s)) if (s.Contains(word) && text.Contains(s))
{ {
if (s.StartsWith(word + " ") || s.EndsWith(" " + word) || s.Contains(" " + word + " ")) if (s.StartsWith(word + " ", StringComparison.Ordinal) || s.EndsWith(" " + word, StringComparison.Ordinal) || s.Contains(" " + word + " "))
return true; return true;
if (word == s) if (word == s)
return true; return true;
@ -2576,8 +2576,8 @@ namespace Nikse.SubtitleEdit.Logic
if (italicBeginTagCount == 2 && italicEndTagCount == 1) if (italicBeginTagCount == 2 && italicEndTagCount == 1)
{ {
var lines = text.Replace(Environment.NewLine, "\n").Split('\n'); var lines = text.Replace(Environment.NewLine, "\n").Split('\n');
if (lines.Length == 2 && lines[0].StartsWith("<i>") && lines[0].EndsWith("</i>") && if (lines.Length == 2 && lines[0].StartsWith("<i>") && lines[0].EndsWith("</i>", StringComparison.Ordinal) &&
lines[1].StartsWith("<i>")) lines[1].StartsWith("<i>", StringComparison.Ordinal))
{ {
text = text.TrimEnd() + "</i>"; text = text.TrimEnd() + "</i>";
} }
@ -2589,7 +2589,7 @@ namespace Nikse.SubtitleEdit.Logic
else else
text = text.Substring(0, lastIndex - 1) + endTag; text = text.Substring(0, lastIndex - 1) + endTag;
} }
if (text.StartsWith("<i>") && text.EndsWith("</i>") && text.Contains("</i>" + Environment.NewLine + "<i>")) if (text.StartsWith("<i>", StringComparison.Ordinal) && text.EndsWith("</i>", StringComparison.Ordinal) && text.Contains("</i>" + Environment.NewLine + "<i>"))
{ {
text = text.Replace("</i>" + Environment.NewLine + "<i>", Environment.NewLine); text = text.Replace("</i>" + Environment.NewLine + "<i>", Environment.NewLine);
} }
@ -2614,7 +2614,7 @@ namespace Nikse.SubtitleEdit.Logic
bool isFixed= false; bool isFixed= false;
// Foo.</i> // Foo.</i>
if (text.EndsWith(endTag) && !cleanText.StartsWith("-") && !cleanText.Contains(Environment.NewLine + "-")) if (text.EndsWith(endTag, StringComparison.Ordinal) && !cleanText.StartsWith("-", StringComparison.Ordinal) && !cleanText.Contains(Environment.NewLine + "-"))
{ {
text = beginTag + text; text = beginTag + text;
isFixed = true; isFixed = true;
@ -2629,12 +2629,12 @@ namespace Nikse.SubtitleEdit.Logic
{ {
var firstLine = text.Substring(0, newLineIndex).Trim(); var firstLine = text.Substring(0, newLineIndex).Trim();
var secondLine = text.Substring(newLineIndex + 2).Trim(); var secondLine = text.Substring(newLineIndex + 2).Trim();
if (firstLine.EndsWith(endTag)) if (firstLine.EndsWith(endTag, StringComparison.Ordinal))
{ {
firstLine = beginTag + firstLine; firstLine = beginTag + firstLine;
isFixed = true; isFixed = true;
} }
if (secondLine.EndsWith(endTag)) if (secondLine.EndsWith(endTag, StringComparison.Ordinal))
{ {
secondLine = beginTag + secondLine; secondLine = beginTag + secondLine;
isFixed = true; isFixed = true;
@ -2648,13 +2648,13 @@ namespace Nikse.SubtitleEdit.Logic
// - foo.</i> // - foo.</i>
// - bar.</i> // - bar.</i>
if (italicBeginTagCount == 0 && italicEndTagCount == 2 && text.Contains(endTag + Environment.NewLine) && text.EndsWith(endTag)) if (italicBeginTagCount == 0 && italicEndTagCount == 2 && text.Contains(endTag + Environment.NewLine) && text.EndsWith(endTag, StringComparison.Ordinal))
{ {
text = text.Replace(endTag, string.Empty); text = text.Replace(endTag, string.Empty);
text = beginTag + text + endTag; text = beginTag + text + endTag;
} }
if (italicBeginTagCount == 0 && italicEndTagCount == 2 && text.StartsWith("</i>") && text.EndsWith("</i>")) if (italicBeginTagCount == 0 && italicEndTagCount == 2 && text.StartsWith("</i>", StringComparison.Ordinal) && text.EndsWith("</i>", StringComparison.Ordinal))
{ {
int firstIndex = text.IndexOf(endTag, StringComparison.Ordinal); int firstIndex = text.IndexOf(endTag, StringComparison.Ordinal);
text = text.Remove(firstIndex, endTag.Length).Insert(firstIndex, "<i>"); text = text.Remove(firstIndex, endTag.Length).Insert(firstIndex, "<i>");
@ -2709,9 +2709,9 @@ namespace Nikse.SubtitleEdit.Logic
bool isStart = false; bool isStart = false;
bool isEnd = false; bool isEnd = false;
if(text.StartsWith(startTag) || text.StartsWith(s1) || text.StartsWith(s2) || text.StartsWith(s3) || text.StartsWith(s4)) if (text.StartsWith(startTag, StringComparison.Ordinal) || text.StartsWith(s1, StringComparison.Ordinal) || text.StartsWith(s2, StringComparison.Ordinal) || text.StartsWith(s3, StringComparison.Ordinal) || text.StartsWith(s4, StringComparison.Ordinal))
isStart = true; isStart = true;
if (text.EndsWith(endTag) || text.EndsWith(e1) || text.EndsWith(e2) || text.EndsWith(e3) || text.EndsWith(e4) || text.EndsWith(e5)) if (text.EndsWith(endTag, StringComparison.Ordinal) || text.EndsWith(e1, StringComparison.Ordinal) || text.EndsWith(e2, StringComparison.Ordinal) || text.EndsWith(e3, StringComparison.Ordinal) || text.EndsWith(e4, StringComparison.Ordinal) || text.EndsWith(e5, StringComparison.Ordinal))
isEnd = true; isEnd = true;
return isStart && isEnd; return isStart && isEnd;
} }
@ -3995,10 +3995,10 @@ namespace Nikse.SubtitleEdit.Logic
if (string.IsNullOrEmpty(text)) if (string.IsNullOrEmpty(text))
return text; return text;
if (text.StartsWith("\"") && text.Length > 1) if (text.StartsWith("\"", StringComparison.Ordinal) && text.Length > 1)
text = text.Substring(1); text = text.Substring(1);
if (text.EndsWith("\"") && text.Length >= 1) if (text.EndsWith("\"", StringComparison.Ordinal) && text.Length >= 1)
text = text.Substring(0, text.Length - 1); text = text.Substring(0, text.Length - 1);
return text.Replace("\"\"", "\""); return text.Replace("\"\"", "\"");
@ -4214,7 +4214,7 @@ namespace Nikse.SubtitleEdit.Logic
if (text.Contains(" " + Environment.NewLine)) if (text.Contains(" " + Environment.NewLine))
text = text.Replace(" " + Environment.NewLine, Environment.NewLine); text = text.Replace(" " + Environment.NewLine, Environment.NewLine);
if (text.EndsWith(" ")) if (text.EndsWith(" ", StringComparison.Ordinal))
text = text.TrimEnd(' '); text = text.TrimEnd(' ');
text = text.Replace(". . ..", "..."); text = text.Replace(". . ..", "...");
@ -4232,11 +4232,11 @@ namespace Nikse.SubtitleEdit.Logic
text = text.Replace(Environment.NewLine + "- ... ", Environment.NewLine + "- ..."); text = text.Replace(Environment.NewLine + "- ... ", Environment.NewLine + "- ...");
text = text.Replace(Environment.NewLine + "<i>- ... ", Environment.NewLine + "<i>- ..."); text = text.Replace(Environment.NewLine + "<i>- ... ", Environment.NewLine + "<i>- ...");
if (text.StartsWith("... ")) if (text.StartsWith("... ", StringComparison.Ordinal))
text = text.Remove(3, 1); text = text.Remove(3, 1);
if (text.EndsWith(" ...")) if (text.EndsWith(" ...", StringComparison.Ordinal))
text = text.Remove(text.Length - 4, 1); text = text.Remove(text.Length - 4, 1);
if (text.EndsWith(" ...</i>")) if (text.EndsWith(" ...</i>", StringComparison.Ordinal))
text = text.Remove(text.Length - 8, 1); text = text.Remove(text.Length - 8, 1);
if (language != "fr") // special rules for French if (language != "fr") // special rules for French
@ -4254,10 +4254,10 @@ namespace Nikse.SubtitleEdit.Logic
while (text.Contains(" ,")) while (text.Contains(" ,"))
text = text.Replace(" ,", ","); text = text.Replace(" ,", ",");
if (text.EndsWith(" .")) if (text.EndsWith(" .", StringComparison.Ordinal))
text = text.Substring(0, text.Length - " .".Length) + "."; text = text.Substring(0, text.Length - " .".Length) + ".";
if (text.EndsWith(" \"")) if (text.EndsWith(" \"", StringComparison.Ordinal))
text = text.Remove(text.Length - 2, 1); text = text.Remove(text.Length - 2, 1);
if (text.Contains(" \"" + Environment.NewLine)) if (text.Contains(" \"" + Environment.NewLine))
@ -4288,13 +4288,13 @@ namespace Nikse.SubtitleEdit.Logic
if (text.Contains("? </i>" + Environment.NewLine)) if (text.Contains("? </i>" + Environment.NewLine))
text = text.Replace("? </i>" + Environment.NewLine, "?</i>" + Environment.NewLine); text = text.Replace("? </i>" + Environment.NewLine, "?</i>" + Environment.NewLine);
if (text.EndsWith(" </i>")) if (text.EndsWith(" </i>", StringComparison.Ordinal))
text = text.Substring(0, text.Length - " </i>".Length) + "</i>"; text = text.Substring(0, text.Length - " </i>".Length) + "</i>";
if (text.Contains(" </i>" + Environment.NewLine)) if (text.Contains(" </i>" + Environment.NewLine))
text = text.Replace(" </i>" + Environment.NewLine, "</i>" + Environment.NewLine); text = text.Replace(" </i>" + Environment.NewLine, "</i>" + Environment.NewLine);
if (text.EndsWith(" </I>")) if (text.EndsWith(" </I>", StringComparison.Ordinal))
text = text.Substring(0, text.Length - " </I>".Length) + "</I>"; text = text.Substring(0, text.Length - " </I>".Length) + "</I>";
if (text.Contains(" </I>" + Environment.NewLine)) if (text.Contains(" </I>" + Environment.NewLine))

View File

@ -493,7 +493,7 @@ namespace Nikse.SubtitleEdit.Logic.VideoPlayers
if (!string.IsNullOrEmpty(Configuration.Settings.General.VlcLocation)) if (!string.IsNullOrEmpty(Configuration.Settings.General.VlcLocation))
{ {
if (Configuration.Settings.General.VlcLocation.ToUpper().EndsWith(".exe")) if (Configuration.Settings.General.VlcLocation.ToUpper().EndsWith(".exe", StringComparison.Ordinal))
Configuration.Settings.General.VlcLocation = Path.GetDirectoryName(Configuration.Settings.General.VlcLocation); Configuration.Settings.General.VlcLocation = Path.GetDirectoryName(Configuration.Settings.General.VlcLocation);
path = Path.Combine(Configuration.Settings.General.VlcLocation, fileName); path = Path.Combine(Configuration.Settings.General.VlcLocation, fileName);
@ -506,7 +506,7 @@ namespace Nikse.SubtitleEdit.Logic.VideoPlayers
try try
{ {
path = Configuration.Settings.General.VlcLocationRelative; path = Configuration.Settings.General.VlcLocationRelative;
if (path.ToUpper().EndsWith(".exe")) if (path.ToUpper().EndsWith(".exe", StringComparison.Ordinal))
path = Path.GetDirectoryName(path); path = Path.GetDirectoryName(path);
path = Path.Combine(path, fileName); path = Path.Combine(path, fileName);