From c02f3287ab3d2ba6aa73b60cb1f84a9760bc834c Mon Sep 17 00:00:00 2001 From: Nikolaj Olsson Date: Mon, 7 Aug 2017 17:42:48 +0200 Subject: [PATCH] Minor refact --- libse/Dictionaries/OcrFixReplaceList.cs | 14 ++-- .../Forms/FixCommonErrors/FixMissingSpaces.cs | 74 +++++++++---------- libse/SubtitleFormats/Csv3.cs | 4 +- .../ScenaristClosedCaptions.cs | 10 +-- src/Forms/Beamer.cs | 2 +- src/Forms/Main.cs | 6 +- 6 files changed, 55 insertions(+), 55 deletions(-) diff --git a/libse/Dictionaries/OcrFixReplaceList.cs b/libse/Dictionaries/OcrFixReplaceList.cs index 87a0e1a47..c77a10efd 100644 --- a/libse/Dictionaries/OcrFixReplaceList.cs +++ b/libse/Dictionaries/OcrFixReplaceList.cs @@ -295,7 +295,7 @@ namespace Nikse.SubtitleEdit.Core.Dictionaries word = word.Replace('´', '\''); word = word.Replace('‘', '\''); word = word.Replace('—', '-'); - while(word.Contains("--")) + while (word.Contains("--")) word = word.Replace("--", "-"); word = word.Replace('|', 'l'); word = word.Replace("vx/", "w"); @@ -349,7 +349,7 @@ namespace Nikse.SubtitleEdit.Core.Dictionaries pre += ""; word = word.Remove(0, 3); } - while (word.Length > 2 && word.EndsWith(Environment.NewLine)) + while (word.Length > 2 && word.EndsWith(Environment.NewLine, StringComparison.Ordinal)) { post += Environment.NewLine; word = word.Substring(0, word.Length - 2); @@ -484,8 +484,8 @@ namespace Nikse.SubtitleEdit.Core.Dictionaries { if (word[match.Index + 1] == 'I' || word[match.Index + 1] == '1') { - bool doFix = word[match.Index + 1] != 'I' && match.Index >= 1 && word.Substring(match.Index - 1).StartsWith("Mc"); - if (word[match.Index + 1] == 'I' && match.Index >= 2 && word.Substring(match.Index - 2).StartsWith("Mac")) + bool doFix = word[match.Index + 1] != 'I' && match.Index >= 1 && word.Substring(match.Index - 1).StartsWith("Mc", StringComparison.Ordinal); + if (word[match.Index + 1] == 'I' && match.Index >= 2 && word.Substring(match.Index - 2).StartsWith("Mac", StringComparison.Ordinal)) doFix = false; if (doFix) @@ -566,7 +566,7 @@ namespace Nikse.SubtitleEdit.Core.Dictionaries pre += ""; word = word.Remove(0, 3); } - while (word.StartsWith(Environment.NewLine) && word.Length > 2) + while (word.StartsWith(Environment.NewLine, StringComparison.Ordinal) && word.Length > 2) { pre += Environment.NewLine; word = word.Substring(2); @@ -597,7 +597,7 @@ namespace Nikse.SubtitleEdit.Core.Dictionaries pre += ""; word = word.Remove(0, 3); } - while (word.EndsWith(Environment.NewLine) && word.Length > 2) + while (word.EndsWith(Environment.NewLine, StringComparison.Ordinal) && word.Length > 2) { post += Environment.NewLine; word = word.Substring(0, word.Length - 2); @@ -911,7 +911,7 @@ namespace Nikse.SubtitleEdit.Core.Dictionaries int appendFrom = 0; for (int i = 0; i < text.Length; i++) { - if (text.Substring(i).StartsWith(word) && i >= appendFrom) + if (text.Substring(i).StartsWith(word, StringComparison.Ordinal) && i >= appendFrom) { bool startOk = i == 0; if (!startOk) diff --git a/libse/Forms/FixCommonErrors/FixMissingSpaces.cs b/libse/Forms/FixCommonErrors/FixMissingSpaces.cs index 7d4137c15..0d61be234 100644 --- a/libse/Forms/FixCommonErrors/FixMissingSpaces.cs +++ b/libse/Forms/FixCommonErrors/FixMissingSpaces.cs @@ -202,7 +202,7 @@ namespace Nikse.SubtitleEdit.Core.Forms.FixCommonErrors if (p.Text.Length > 5 && p.Text.Contains(new[] { '#', '♪', '♫' })) { string newText = p.Text; - if (@"#♪♫".Contains(newText[0]) && !@" <".Contains(newText[1]) && !newText.Substring(1).StartsWith(Environment.NewLine) && + if (@"#♪♫".Contains(newText[0]) && !@" <".Contains(newText[1]) && !newText.Substring(1).StartsWith(Environment.NewLine, StringComparison.Ordinal) && !newText.Substring(1).StartsWith('♪') && !newText.Substring(1).StartsWith('♫')) newText = newText.Insert(1, " "); if (@"#♪♫".Contains(newText[newText.Length - 1]) && !@" >".Contains(newText[newText.Length - 2]) && @@ -316,45 +316,45 @@ namespace Nikse.SubtitleEdit.Core.Forms.FixCommonErrors private static bool IsSwedishSkipValue(string languageCode, Match match) { - return languageCode == "sv" && (match.Value.EndsWith(":e") || - match.Value.EndsWith(":a") || - match.Value.EndsWith(":et") || - match.Value.EndsWith(":en") || - match.Value.EndsWith(":n") || - match.Value.EndsWith(":s")); + return languageCode == "sv" && (match.Value.EndsWith(":e", StringComparison.Ordinal) || + match.Value.EndsWith(":a", StringComparison.Ordinal) || + match.Value.EndsWith(":et", StringComparison.Ordinal) || + match.Value.EndsWith(":en", StringComparison.Ordinal) || + match.Value.EndsWith(":n", StringComparison.Ordinal) || + match.Value.EndsWith(":s", StringComparison.Ordinal)); } private static bool IsFinnishSkipValue(string languageCode, Match match) { - return languageCode == "fi" && (match.Value.EndsWith(":aa") || - match.Value.EndsWith(":aan") || - match.Value.EndsWith(":een") || - match.Value.EndsWith(":ia") || - match.Value.EndsWith(":ien") || - match.Value.EndsWith(":iksi") || - match.Value.EndsWith(":ille") || - match.Value.EndsWith(":een") || - match.Value.EndsWith(":in") || - match.Value.EndsWith(":ina") || - match.Value.EndsWith(":inä") || - match.Value.EndsWith(":itta") || - match.Value.EndsWith(":ittä") || - match.Value.EndsWith(":iä") || - match.Value.EndsWith(":ksi") || - match.Value.EndsWith(":lta") || - match.Value.EndsWith(":ltä") || - match.Value.EndsWith(":n") || - match.Value.EndsWith(":nä") || - match.Value.EndsWith(":ssa") || - match.Value.EndsWith(":ssä") || - match.Value.EndsWith(":sta") || - match.Value.EndsWith(":stä") || - match.Value.EndsWith(":t") || - match.Value.EndsWith(":ta") || - match.Value.EndsWith(":tta") || - match.Value.EndsWith(":ttä") || - match.Value.EndsWith(":tä") || - match.Value.EndsWith(":ää") || - match.Value.EndsWith(":ään")); + return languageCode == "fi" && (match.Value.EndsWith(":aa", StringComparison.Ordinal) || + match.Value.EndsWith(":aan", StringComparison.Ordinal) || + match.Value.EndsWith(":een", StringComparison.Ordinal) || + match.Value.EndsWith(":ia", StringComparison.Ordinal) || + match.Value.EndsWith(":ien", StringComparison.Ordinal) || + match.Value.EndsWith(":iksi", StringComparison.Ordinal) || + match.Value.EndsWith(":ille", StringComparison.Ordinal) || + match.Value.EndsWith(":een", StringComparison.Ordinal) || + match.Value.EndsWith(":in", StringComparison.Ordinal) || + match.Value.EndsWith(":ina", StringComparison.Ordinal) || + match.Value.EndsWith(":inä", StringComparison.Ordinal) || + match.Value.EndsWith(":itta", StringComparison.Ordinal) || + match.Value.EndsWith(":ittä", StringComparison.Ordinal) || + match.Value.EndsWith(":iä", StringComparison.Ordinal) || + match.Value.EndsWith(":ksi", StringComparison.Ordinal) || + match.Value.EndsWith(":lta", StringComparison.Ordinal) || + match.Value.EndsWith(":ltä", StringComparison.Ordinal) || + match.Value.EndsWith(":n", StringComparison.Ordinal) || + match.Value.EndsWith(":nä", StringComparison.Ordinal) || + match.Value.EndsWith(":ssa", StringComparison.Ordinal) || + match.Value.EndsWith(":ssä", StringComparison.Ordinal) || + match.Value.EndsWith(":sta", StringComparison.Ordinal) || + match.Value.EndsWith(":stä", StringComparison.Ordinal) || + match.Value.EndsWith(":t", StringComparison.Ordinal) || + match.Value.EndsWith(":ta", StringComparison.Ordinal) || + match.Value.EndsWith(":tta", StringComparison.Ordinal) || + match.Value.EndsWith(":ttä", StringComparison.Ordinal) || + match.Value.EndsWith(":tä", StringComparison.Ordinal) || + match.Value.EndsWith(":ää", StringComparison.Ordinal) || + match.Value.EndsWith(":ään", StringComparison.Ordinal)); } private static string GetWordFromIndex(string text, int index) diff --git a/libse/SubtitleFormats/Csv3.cs b/libse/SubtitleFormats/Csv3.cs index 3d43b6721..af862bb5b 100644 --- a/libse/SubtitleFormats/Csv3.cs +++ b/libse/SubtitleFormats/Csv3.cs @@ -128,7 +128,7 @@ namespace Nikse.SubtitleEdit.Core.SubtitleFormats for (int i = 0; i < csv.Length; i++) { var s = csv[i]; - if (s == '"' && csv.Substring(i).StartsWith("\"\"")) + if (s == '"' && csv.Substring(i).StartsWith("\"\"", StringComparison.Ordinal)) { sb.Append('"'); } @@ -138,7 +138,7 @@ namespace Nikse.SubtitleEdit.Core.SubtitleFormats { isBreak = false; } - else if (i == 0 || i == csv.Length - 1 || sb.ToString().EndsWith(Environment.NewLine)) + else if (i == 0 || i == csv.Length - 1 || sb.ToString().EndsWith(Environment.NewLine, StringComparison.Ordinal)) { sb.Append('"'); } diff --git a/libse/SubtitleFormats/ScenaristClosedCaptions.cs b/libse/SubtitleFormats/ScenaristClosedCaptions.cs index bb4919658..45ae66a14 100644 --- a/libse/SubtitleFormats/ScenaristClosedCaptions.cs +++ b/libse/SubtitleFormats/ScenaristClosedCaptions.cs @@ -710,19 +710,19 @@ namespace Nikse.SubtitleEdit.Core.SubtitleFormats string s = text.Substring(i, 1); int index = Letters.IndexOf(s); string newCode; - if (text.Substring(i).StartsWith("")) + if (text.Substring(i).StartsWith("", StringComparison.Ordinal)) { newCode = "91ae"; i += 2; italic++; } - else if (text.Substring(i).StartsWith("") && italic > 0) + else if (text.Substring(i).StartsWith("", StringComparison.Ordinal) && italic > 0) { newCode = "9120"; i += 3; italic--; } - else if (text.Substring(i).StartsWith("’")) + else if (text[i] == '’') { if (code.Length == 4) { @@ -1691,7 +1691,7 @@ namespace Nikse.SubtitleEdit.Core.SubtitleFormats var cp = GetColorAndPosition(part); if (cp != null) { - if (cp.Y > 0 && y >= 0 && cp.Y > y && !sb.ToString().EndsWith(Environment.NewLine) && !string.IsNullOrWhiteSpace(sb.ToString())) + if (cp.Y > 0 && y >= 0 && cp.Y > y && !sb.ToString().EndsWith(Environment.NewLine, StringComparison.Ordinal) && !string.IsNullOrWhiteSpace(sb.ToString())) sb.AppendLine(); if (cp.Y > 0) y = cp.Y; @@ -1712,7 +1712,7 @@ namespace Nikse.SubtitleEdit.Core.SubtitleFormats { case "9440": case "94e0": - if (!sb.ToString().EndsWith(Environment.NewLine)) + if (!sb.ToString().EndsWith(Environment.NewLine, StringComparison.Ordinal)) sb.AppendLine(); break; case "2c75": diff --git a/src/Forms/Beamer.cs b/src/Forms/Beamer.cs index b3f3c53c2..e10b117ce 100644 --- a/src/Forms/Beamer.cs +++ b/src/Forms/Beamer.cs @@ -394,7 +394,7 @@ namespace Nikse.SubtitleEdit.Forms isItalic = false; i += 3; } - else if (text.Substring(i).StartsWith(Environment.NewLine)) + else if (text.Substring(i).StartsWith(Environment.NewLine, StringComparison.Ordinal)) { TextDraw.DrawText(font, sf, path, sb, isItalic, subtitleFontBold, false, left, top, ref newLine, leftMargin, ref newLinePathPoint); diff --git a/src/Forms/Main.cs b/src/Forms/Main.cs index e17a9c319..e3cbeb359 100644 --- a/src/Forms/Main.cs +++ b/src/Forms/Main.cs @@ -16909,14 +16909,14 @@ namespace Nikse.SubtitleEdit.Forms string pre = string.Empty; // There is text selected text = tb.SelectedText; - while (text.EndsWith(' ') || text.EndsWith(Environment.NewLine) || text.StartsWith(' ') || text.StartsWith(Environment.NewLine)) + while (text.EndsWith(' ') || text.EndsWith(Environment.NewLine, StringComparison.Ordinal) || text.StartsWith(' ') || text.StartsWith(Environment.NewLine, StringComparison.Ordinal)) { if (text.EndsWith(' ')) { post += " "; text = text.Remove(text.Length - 1); } - if (text.EndsWith(Environment.NewLine)) + if (text.EndsWith(Environment.NewLine, StringComparison.Ordinal)) { post += Environment.NewLine; text = text.Remove(text.Length - 2); @@ -16926,7 +16926,7 @@ namespace Nikse.SubtitleEdit.Forms pre += " "; text = text.Remove(0, 1); } - if (text.StartsWith(Environment.NewLine)) + if (text.StartsWith(Environment.NewLine, StringComparison.Ordinal)) { pre += Environment.NewLine; text = text.Remove(0, 2);