mirror of
https://github.com/SubtitleEdit/subtitleedit.git
synced 2024-11-22 03:02:35 +01:00
Refactor - fix minor issues from codacy
This commit is contained in:
parent
720ba172d9
commit
877541314c
@ -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 = " <!?.:;,♪♫)]";
|
||||
|
||||
var text = input;
|
||||
if (text.StartsWith("I-i ", StringComparison.Ordinal))
|
||||
{
|
||||
text = text.Remove(0, 3).Insert(0, "I-I");
|
||||
@ -142,8 +143,9 @@ namespace Nikse.SubtitleEdit.Core
|
||||
return text;
|
||||
}
|
||||
|
||||
private string FixCasingAfterTitles(string text)
|
||||
private string FixCasingAfterTitles(string input)
|
||||
{
|
||||
var text = input;
|
||||
var titles = new[] { "Mrs.", "Miss.", "Mr.", "Ms.", "Dr." };
|
||||
var notChangeWords = new[] { "does", "has", "will", "is", "and", "for", "but", "or", "of" };
|
||||
for (int i = 0; i < text.Length - 4; i++)
|
||||
@ -171,9 +173,9 @@ namespace Nikse.SubtitleEdit.Core
|
||||
return text;
|
||||
}
|
||||
|
||||
private string Fix(string text, string lastLine, List<string> nameList, CultureInfo subtitleCulture, double millisecondsFromLast)
|
||||
private string Fix(string original, string lastLine, List<string> nameList, CultureInfo subtitleCulture, double millisecondsFromLast)
|
||||
{
|
||||
string original = text;
|
||||
var text = original;
|
||||
if (FixNormal)
|
||||
{
|
||||
if (FixNormalOnlyAllUppercase && text != text.ToUpper(subtitleCulture))
|
||||
|
@ -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;
|
||||
|
@ -8,8 +8,8 @@ namespace Nikse.SubtitleEdit.Core.Forms
|
||||
{
|
||||
public RemoveTextForHISettings Settings { get; set; }
|
||||
|
||||
public List<int> Warnings;
|
||||
public int WarningIndex;
|
||||
public List<int> 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 + "<i>- ") ||
|
||||
oldText.Contains(Environment.NewLine + "<i> - ")))
|
||||
(input.Contains(Environment.NewLine + "- ") ||
|
||||
input.Contains(Environment.NewLine + " - ") ||
|
||||
input.Contains(Environment.NewLine + "<i>- ") ||
|
||||
input.Contains(Environment.NewLine + "<i> - ")))
|
||||
{
|
||||
if (text.StartsWith("<i>-", 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 + "<i>- ") ||
|
||||
oldText.Contains(Environment.NewLine + "<i> - ")))
|
||||
(input.Contains(Environment.NewLine + "-") && !input.Contains(Environment.NewLine + "--") ||
|
||||
input.Contains(Environment.NewLine + " - ") ||
|
||||
input.Contains(Environment.NewLine + "<i>- ") ||
|
||||
input.Contains(Environment.NewLine + "<i> - ")))
|
||||
{
|
||||
text = text.TrimStart().TrimStart('-').TrimStart();
|
||||
}
|
||||
|
||||
if (oldText.TrimStart().StartsWith("<i>- ", StringComparison.Ordinal) &&
|
||||
if (input.TrimStart().StartsWith("<i>- ", StringComparison.Ordinal) &&
|
||||
text != null && text.StartsWith("<i>- ", StringComparison.Ordinal) && !text.Contains(Environment.NewLine) &&
|
||||
(oldText.Contains(Environment.NewLine + "- ") ||
|
||||
oldText.Contains(Environment.NewLine + " - ") ||
|
||||
oldText.Contains(Environment.NewLine + "<i>- ") ||
|
||||
oldText.Contains(Environment.NewLine + "<i> - ")))
|
||||
(input.Contains(Environment.NewLine + "- ") ||
|
||||
input.Contains(Environment.NewLine + " - ") ||
|
||||
input.Contains(Environment.NewLine + "<i>- ") ||
|
||||
input.Contains(Environment.NewLine + "<i> - ")))
|
||||
{
|
||||
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 + "<i>- ") ||
|
||||
oldText.Contains(Environment.NewLine + "<i> - ")))
|
||||
(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 + "<i>- ") ||
|
||||
input.Contains(Environment.NewLine + "<i> - ")))
|
||||
{
|
||||
text = text.TrimStart().TrimStart('-').TrimStart();
|
||||
}
|
||||
@ -925,7 +924,7 @@ namespace Nikse.SubtitleEdit.Core.Forms
|
||||
text = "<i>" + text.Remove(0, removeText.Length).TrimStart(' ');
|
||||
}
|
||||
|
||||
if (oldText != text)
|
||||
if (input != text)
|
||||
{
|
||||
// insert spaces before "-"
|
||||
text = text.Replace(Environment.NewLine + "- <i>", Environment.NewLine + "<i>- ");
|
||||
|
@ -5,7 +5,7 @@ namespace Nikse.SubtitleEdit.Core
|
||||
{
|
||||
public class NoBreakAfterItem : IComparable<NoBreakAfterItem>
|
||||
{
|
||||
public readonly Regex Regex;
|
||||
public Regex Regex { get; }
|
||||
public readonly string Text;
|
||||
|
||||
public NoBreakAfterItem(Regex regex, string text)
|
||||
|
@ -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);
|
||||
|
@ -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
|
||||
{
|
||||
|
@ -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);
|
||||
|
@ -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("<i>", StringComparison.Ordinal) && text.EndsWith("</i>", StringComparison.Ordinal) && Utilities.CountTagInText(text, "<i>") == 1;
|
||||
text = text.Replace("<b>", Bold);
|
||||
text = text.Replace("</b>", Bold);
|
||||
|
@ -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)
|
||||
{
|
||||
|
@ -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];
|
||||
|
Loading…
Reference in New Issue
Block a user