diff --git a/libse/FixCasing.cs b/libse/FixCasing.cs index 162abbcd9..749ac58dd 100644 --- a/libse/FixCasing.cs +++ b/libse/FixCasing.cs @@ -66,11 +66,12 @@ namespace Nikse.SubtitleEdit.Core } } - private static string FixEnglishAloneILowerToUpper(string text) + private static string FixEnglishAloneILowerToUpper(string input) { const string pre = " >¡¿♪♫(["; const string post = " nameList, CultureInfo subtitleCulture, double millisecondsFromLast) + private string Fix(string original, string lastLine, List nameList, CultureInfo subtitleCulture, double millisecondsFromLast) { - string original = text; + var text = original; if (FixNormal) { if (FixNormalOnlyAllUppercase && text != text.ToUpper(subtitleCulture)) diff --git a/libse/Forms/FixCommonErrors/Helper.cs b/libse/Forms/FixCommonErrors/Helper.cs index 4187db353..2801c7b9d 100644 --- a/libse/Forms/FixCommonErrors/Helper.cs +++ b/libse/Forms/FixCommonErrors/Helper.cs @@ -47,8 +47,9 @@ namespace Nikse.SubtitleEdit.Core.Forms.FixCommonErrors return letter; } - public static string FixEllipsesStartHelper(string text) + public static string FixEllipsesStartHelper(string input) { + var text = input; if (string.IsNullOrEmpty(text) || text.Trim().Length < 4 || !(text.Contains("..", StringComparison.Ordinal) || text.Contains(". .", StringComparison.Ordinal))) { return text; diff --git a/libse/Forms/RemoveTextForHI.cs b/libse/Forms/RemoveTextForHI.cs index 31a5ae2e9..9e0c9fff6 100644 --- a/libse/Forms/RemoveTextForHI.cs +++ b/libse/Forms/RemoveTextForHI.cs @@ -8,8 +8,8 @@ namespace Nikse.SubtitleEdit.Core.Forms { public RemoveTextForHISettings Settings { get; set; } - public List Warnings; - public int WarningIndex; + public List Warnings { get; set; } + public int WarningIndex { get; set; } // interjection private readonly InterjectionRemoveContext _interjectionRemoveContext; @@ -648,9 +648,9 @@ namespace Nikse.SubtitleEdit.Core.Forms private static readonly char[] TrimStartNoiseChar = { '-', ' ' }; - public string RemoveTextFromHearImpaired(string text) + public string RemoveTextFromHearImpaired(string input) { - if (StartsAndEndsWithHearImpairedTags(HtmlUtil.RemoveHtmlTags(text, true).TrimStart(TrimStartNoiseChar))) + if (StartsAndEndsWithHearImpairedTags(HtmlUtil.RemoveHtmlTags(input, true).TrimStart(TrimStartNoiseChar))) { return string.Empty; } @@ -659,15 +659,14 @@ namespace Nikse.SubtitleEdit.Core.Forms { foreach (var removeIfTextContain in Settings.RemoveIfTextContains) { - if (text.Contains(removeIfTextContain)) + if (input.Contains(removeIfTextContain)) { return string.Empty; } } } - string oldText = text; - text = RemoveColon(text); + var text = RemoveColon(input); string pre = " >-\"'‘`´♪¿¡.…—"; string post = " -\"'`´♪.!?:…—"; if (Settings.RemoveTextBetweenCustomTags) @@ -852,12 +851,12 @@ namespace Nikse.SubtitleEdit.Core.Forms text = st.Pre + text + st.Post; } - if (oldText.TrimStart().StartsWith("- ", StringComparison.Ordinal) && + if (input.TrimStart().StartsWith("- ", StringComparison.Ordinal) && text != null && !text.Contains(Environment.NewLine) && - (oldText.Contains(Environment.NewLine + "- ") || - oldText.Contains(Environment.NewLine + " - ") || - oldText.Contains(Environment.NewLine + "- ") || - oldText.Contains(Environment.NewLine + " - "))) + (input.Contains(Environment.NewLine + "- ") || + input.Contains(Environment.NewLine + " - ") || + input.Contains(Environment.NewLine + "- ") || + input.Contains(Environment.NewLine + " - "))) { if (text.StartsWith("-", StringComparison.Ordinal)) { @@ -868,35 +867,35 @@ namespace Nikse.SubtitleEdit.Core.Forms text = text.TrimStart().TrimStart('-').TrimStart(); } } - if (oldText.TrimStart().StartsWith('-') && !oldText.TrimStart().StartsWith("--", StringComparison.Ordinal) && + if (input.TrimStart().StartsWith('-') && !input.TrimStart().StartsWith("--", StringComparison.Ordinal) && text != null && !text.Contains(Environment.NewLine) && - (oldText.Contains(Environment.NewLine + "-") && !oldText.Contains(Environment.NewLine + "--") || - oldText.Contains(Environment.NewLine + " - ") || - oldText.Contains(Environment.NewLine + "- ") || - oldText.Contains(Environment.NewLine + " - "))) + (input.Contains(Environment.NewLine + "-") && !input.Contains(Environment.NewLine + "--") || + input.Contains(Environment.NewLine + " - ") || + input.Contains(Environment.NewLine + "- ") || + input.Contains(Environment.NewLine + " - "))) { text = text.TrimStart().TrimStart('-').TrimStart(); } - if (oldText.TrimStart().StartsWith("- ", StringComparison.Ordinal) && + if (input.TrimStart().StartsWith("- ", StringComparison.Ordinal) && text != null && text.StartsWith("- ", StringComparison.Ordinal) && !text.Contains(Environment.NewLine) && - (oldText.Contains(Environment.NewLine + "- ") || - oldText.Contains(Environment.NewLine + " - ") || - oldText.Contains(Environment.NewLine + "- ") || - oldText.Contains(Environment.NewLine + " - "))) + (input.Contains(Environment.NewLine + "- ") || + input.Contains(Environment.NewLine + " - ") || + input.Contains(Environment.NewLine + "- ") || + input.Contains(Environment.NewLine + " - "))) { text = text.Remove(3, 2); } if (text != null && !text.Contains(Environment.NewLine) && - (oldText.Contains(':') && !text.Contains(':') || - oldText.Contains('[') && !text.Contains('[') || - oldText.Contains('(') && !text.Contains('(') || - oldText.Contains('{') && !text.Contains('{')) && - (oldText.Contains(Environment.NewLine + "- ") || - oldText.Contains(Environment.NewLine + " - ") || - oldText.Contains(Environment.NewLine + "- ") || - oldText.Contains(Environment.NewLine + " - "))) + (input.Contains(':') && !text.Contains(':') || + input.Contains('[') && !text.Contains('[') || + input.Contains('(') && !text.Contains('(') || + input.Contains('{') && !text.Contains('{')) && + (input.Contains(Environment.NewLine + "- ") || + input.Contains(Environment.NewLine + " - ") || + input.Contains(Environment.NewLine + "- ") || + input.Contains(Environment.NewLine + " - "))) { text = text.TrimStart().TrimStart('-').TrimStart(); } @@ -925,7 +924,7 @@ namespace Nikse.SubtitleEdit.Core.Forms text = "" + text.Remove(0, removeText.Length).TrimStart(' '); } - if (oldText != text) + if (input != text) { // insert spaces before "-" text = text.Replace(Environment.NewLine + "- ", Environment.NewLine + "- "); diff --git a/libse/NoBreakAfterItem.cs b/libse/NoBreakAfterItem.cs index 52e38d4f2..b3faed5aa 100644 --- a/libse/NoBreakAfterItem.cs +++ b/libse/NoBreakAfterItem.cs @@ -5,7 +5,7 @@ namespace Nikse.SubtitleEdit.Core { public class NoBreakAfterItem : IComparable { - public readonly Regex Regex; + public Regex Regex { get; } public readonly string Text; public NoBreakAfterItem(Regex regex, string text) diff --git a/libse/SpellCheck/SpellCheckWordLists.cs b/libse/SpellCheck/SpellCheckWordLists.cs index 8aca3a80a..8a677efa3 100644 --- a/libse/SpellCheck/SpellCheckWordLists.cs +++ b/libse/SpellCheck/SpellCheckWordLists.cs @@ -400,7 +400,7 @@ namespace Nikse.SubtitleEdit.Core.SpellCheck if (startOk && endOk) { i++; - string id = string.Format("_@{0}_", i); + string id = $"_@{i}_"; replaceIds.Add(id); replaceNames.Add(wordWithDashesOrPeriods); text = text.Remove(indexStart, wordWithDashesOrPeriods.Length).Insert(indexStart, id); diff --git a/libse/SubtitleFormats/Idx.cs b/libse/SubtitleFormats/Idx.cs index efb93e8c1..d8e64584c 100644 --- a/libse/SubtitleFormats/Idx.cs +++ b/libse/SubtitleFormats/Idx.cs @@ -12,7 +12,7 @@ namespace Nikse.SubtitleEdit.Core.SubtitleFormats // timestamp: 00:00:01:401, filepos: 000000000 private static readonly Regex RegexTimeCodes = new Regex(@"^timestamp: \d+:\d+:\d+:\d+, filepos: [\dabcdefABCDEF]+$", RegexOptions.Compiled); - public Hashtable NonTimeCodes = new Hashtable(); + private readonly Hashtable _nonTimeCodes = new Hashtable(); public override string Extension => ".idx"; @@ -41,9 +41,12 @@ namespace Nikse.SubtitleEdit.Core.SubtitleFormats const string paragraphWriteFormat = "timestamp: {0}, filepos: {1}"; var tempNonTimeCodes = new Hashtable(); - foreach (DictionaryEntry de in (subtitle.OriginalFormat as Idx).NonTimeCodes) + if (subtitle.OriginalFormat != null) { - tempNonTimeCodes.Add(de.Key, de.Value); + foreach (DictionaryEntry de in ((Idx)subtitle.OriginalFormat)._nonTimeCodes) + { + tempNonTimeCodes.Add(de.Key, de.Value); + } } var sb = new StringBuilder(); @@ -96,20 +99,19 @@ namespace Nikse.SubtitleEdit.Core.SubtitleFormats } else { - int place; if (subtitle.Paragraphs.Count == 0 || - !int.TryParse(subtitle.Paragraphs[subtitle.Paragraphs.Count - 1].Text, out place)) + !int.TryParse(subtitle.Paragraphs[subtitle.Paragraphs.Count - 1].Text, out var place)) { place = -1; } - if (NonTimeCodes.ContainsKey(place)) + if (_nonTimeCodes.ContainsKey(place)) { - NonTimeCodes[place] += Environment.NewLine + line; + _nonTimeCodes[place] += Environment.NewLine + line; } else { - NonTimeCodes.Add(place, line); + _nonTimeCodes.Add(place, line); } } } @@ -120,14 +122,10 @@ namespace Nikse.SubtitleEdit.Core.SubtitleFormats // timestamp: 00:00:01:401, filepos: 000000000 if (parts.Length == 7) { - int hours; - int minutes; - int seconds; - int milliseconds; - if (int.TryParse(parts[1], out hours) && - int.TryParse(parts[2], out minutes) && - int.TryParse(parts[3], out seconds) && - int.TryParse(parts[4], out milliseconds)) + if (int.TryParse(parts[1], out var hours) && + int.TryParse(parts[2], out var minutes) && + int.TryParse(parts[3], out var seconds) && + int.TryParse(parts[4], out var milliseconds)) { return new Paragraph { diff --git a/libse/SubtitleFormats/NciTimedRollUpCaptions.cs b/libse/SubtitleFormats/NciTimedRollUpCaptions.cs index 40bc1d49a..8a9320e80 100644 --- a/libse/SubtitleFormats/NciTimedRollUpCaptions.cs +++ b/libse/SubtitleFormats/NciTimedRollUpCaptions.cs @@ -129,9 +129,9 @@ namespace Nikse.SubtitleEdit.Core.SubtitleFormats subtitle.Renumber(); } - private static string FixText(string text) + private static string FixText(string input) { - text = text.Replace("\u0011P", Environment.NewLine); + var text = input.Replace("\u0011P", Environment.NewLine); text = text.Replace("\u00117", "♪"); text = text.Replace("\u0012\u0029", string.Empty); diff --git a/libse/SubtitleFormats/Spruce.cs b/libse/SubtitleFormats/Spruce.cs index 565ce57c1..508e6e554 100644 --- a/libse/SubtitleFormats/Spruce.cs +++ b/libse/SubtitleFormats/Spruce.cs @@ -70,9 +70,9 @@ $ColorIndex4 = 3 return sb.ToString(); } - private static string EncodeText(string text) + private static string EncodeText(string input) { - text = HtmlUtil.FixUpperTags(text); + var text = HtmlUtil.FixUpperTags(input); bool allItalic = text.StartsWith("", StringComparison.Ordinal) && text.EndsWith("", StringComparison.Ordinal) && Utilities.CountTagInText(text, "") == 1; text = text.Replace("", Bold); text = text.Replace("", Bold); diff --git a/src/Forms/DurationsBridgeGaps.cs b/src/Forms/DurationsBridgeGaps.cs index 592942a40..0b1620f97 100644 --- a/src/Forms/DurationsBridgeGaps.cs +++ b/src/Forms/DurationsBridgeGaps.cs @@ -22,11 +22,7 @@ namespace Nikse.SubtitleEdit.Forms set => numericUpDownMinMsBetweenLines.Value = value; } - public bool PreviousSubtitleTakesAllTime - { - get => radioButtonProlongEndTime.Checked; - set => radioButtonProlongEndTime.Checked = value; - } + public bool PreviousSubtitleTakesAllTime => radioButtonProlongEndTime.Checked; public DurationsBridgeGaps(Subtitle subtitle) { diff --git a/src/UpdateResourceScript/Program.cs b/src/UpdateResourceScript/Program.cs index 0d75d0ce3..b02767474 100644 --- a/src/UpdateResourceScript/Program.cs +++ b/src/UpdateResourceScript/Program.cs @@ -24,10 +24,10 @@ namespace UpdateResourceScript { private class VersionInfoResource { - public string StringFileInfo { get; private set; } - public string ProductVersion { get; private set; } - public string FileVersion { get; private set; } - public string FileFlags { get; private set; } + public string StringFileInfo { get; } + public string ProductVersion { get; } + public string FileVersion { get; } + public string FileFlags { get; } public VersionInfoResource(string assemblyFileName) { @@ -77,13 +77,6 @@ namespace UpdateResourceScript private const string WorkInProgress = "Updating win32 resource script..."; - private static void WriteWarning(string message) - { - Console.WriteLine(); - Console.WriteLine("WARNING: " + message); - Console.Write(WorkInProgress); - } - private static int Main(string[] args) { var myName = Environment.GetCommandLineArgs()[0];