Fix some issues found by PVS-Studio

Work on #2810
This commit is contained in:
Nikolaj Olsson 2018-03-07 08:10:26 +01:00
parent d8a790c8bd
commit d4b43edbb3
8 changed files with 19 additions and 15 deletions

View File

@ -80,7 +80,7 @@ namespace Nikse.SubtitleEdit.Core.Forms.FixCommonErrors
double currentWantedDisplayTime = Utilities.GetOptimalDisplayMilliseconds(p.Text, Configuration.Settings.General.SubtitleMaximumCharactersPerSeconds); double currentWantedDisplayTime = Utilities.GetOptimalDisplayMilliseconds(p.Text, Configuration.Settings.General.SubtitleMaximumCharactersPerSeconds);
double prevOptimalDisplayTime = Utilities.GetOptimalDisplayMilliseconds(prev.Text); double prevOptimalDisplayTime = Utilities.GetOptimalDisplayMilliseconds(prev.Text);
double currentOptimalDisplayTime = Utilities.GetOptimalDisplayMilliseconds(p.Text); double currentOptimalDisplayTime = Utilities.GetOptimalDisplayMilliseconds(p.Text);
bool canBeEqual = callbacks.Format != null && callbacks.Format.GetType() == typeof(AdvancedSubStationAlpha) || callbacks.Format.GetType() == typeof(SubStationAlpha); bool canBeEqual = callbacks != null && (callbacks.Format != null && callbacks.Format.GetType() == typeof(AdvancedSubStationAlpha) || callbacks.Format.GetType() == typeof(SubStationAlpha));
if (!canBeEqual) if (!canBeEqual)
canBeEqual = Configuration.Settings.Tools.FixCommonErrorsFixOverlapAllowEqualEndStart; canBeEqual = Configuration.Settings.Tools.FixCommonErrorsFixOverlapAllowEqualEndStart;

View File

@ -99,9 +99,7 @@ namespace Nikse.SubtitleEdit.Core.Forms.FixCommonErrors
{ {
if (Helper.IsTurkishLittleI(firstLetter, encoding, language)) if (Helper.IsTurkishLittleI(firstLetter, encoding, language))
p.Text = pre + Helper.GetTurkishUppercaseLetter(firstLetter, encoding) + text.Substring(1); p.Text = pre + Helper.GetTurkishUppercaseLetter(firstLetter, encoding) + text.Substring(1);
else if (language == "en" && (text.StartsWith("l ", StringComparison.Ordinal) || text.StartsWith("l-I", StringComparison.Ordinal) || text.StartsWith("ls ", StringComparison.Ordinal) || text.StartsWith("lnterested") || else if (IsEnglishCandidateForLowercaseLtoUppercaseI(language, text)) // l > I
text.StartsWith("lsn't ", StringComparison.Ordinal) || text.StartsWith("ldiot", StringComparison.Ordinal) || text.StartsWith("ln", StringComparison.Ordinal) || text.StartsWith("lm", StringComparison.Ordinal) ||
text.StartsWith("ls", StringComparison.Ordinal) || text.StartsWith("lt", StringComparison.Ordinal) || text.StartsWith("lf ", StringComparison.Ordinal) || text.StartsWith("lc", StringComparison.Ordinal) || text.StartsWith("l'm ", StringComparison.Ordinal)) || text.StartsWith("l am ", StringComparison.Ordinal)) // l > I
p.Text = pre + "I" + text.Substring(1); p.Text = pre + "I" + text.Substring(1);
else else
p.Text = pre + char.ToUpper(firstLetter) + text.Substring(1); p.Text = pre + char.ToUpper(firstLetter) + text.Substring(1);
@ -174,9 +172,7 @@ namespace Nikse.SubtitleEdit.Core.Forms.FixCommonErrors
{ {
if (Helper.IsTurkishLittleI(firstLetter, encoding, language)) if (Helper.IsTurkishLittleI(firstLetter, encoding, language))
text = pre + Helper.GetTurkishUppercaseLetter(firstLetter, encoding) + text.Substring(1); text = pre + Helper.GetTurkishUppercaseLetter(firstLetter, encoding) + text.Substring(1);
else if (language == "en" && (text.StartsWith("l ", StringComparison.Ordinal) || text.StartsWith("l-I", StringComparison.Ordinal) || text.StartsWith("ls ") || text.StartsWith("lnterested") || else if (IsEnglishCandidateForLowercaseLtoUppercaseI(language, text)) // l > I
text.StartsWith("lsn't ", StringComparison.Ordinal) || text.StartsWith("ldiot", StringComparison.Ordinal) || text.StartsWith("ln", StringComparison.Ordinal) || text.StartsWith("lm", StringComparison.Ordinal) ||
text.StartsWith("ls", StringComparison.Ordinal) || text.StartsWith("lt", StringComparison.Ordinal) || text.StartsWith("lf ", StringComparison.Ordinal) || text.StartsWith("lc", StringComparison.Ordinal) || text.StartsWith("l'm ", StringComparison.Ordinal)) || text.StartsWith("l am ", StringComparison.Ordinal)) // l > I
text = pre + "I" + text.Substring(1); text = pre + "I" + text.Substring(1);
else else
text = pre + char.ToUpper(firstLetter) + text.Substring(1); text = pre + char.ToUpper(firstLetter) + text.Substring(1);
@ -276,5 +272,13 @@ namespace Nikse.SubtitleEdit.Core.Forms.FixCommonErrors
return p.Text; return p.Text;
} }
private static bool IsEnglishCandidateForLowercaseLtoUppercaseI(string language, string text)
{
return language == "en" && (text.StartsWith("l ", StringComparison.Ordinal) || text.StartsWith("l-I", StringComparison.Ordinal) ||
text.StartsWith("ls") || text.StartsWith("ldiot", StringComparison.Ordinal) || text.StartsWith("ln", StringComparison.Ordinal) ||
text.StartsWith("lm", StringComparison.Ordinal) || text.StartsWith("lt", StringComparison.Ordinal) ||
text.StartsWith("lf ", StringComparison.Ordinal) || text.StartsWith("lc", StringComparison.Ordinal) ||
text.StartsWith("l'm ", StringComparison.Ordinal)) || text.StartsWith("l've ", StringComparison.Ordinal);
}
} }
} }

View File

@ -139,8 +139,7 @@ namespace Nikse.SubtitleEdit.Core.Forms.FixCommonErrors
text = text.Remove(0, index + 1).TrimStart(); text = text.Remove(0, index + 1).TrimStart();
text = FixEllipsesStartHelper(text); text = FixEllipsesStartHelper(text);
if (pre.Length > 0) pre += " ";
pre += " ";
} }
return pre + text; return pre + text;
} }

View File

@ -1824,7 +1824,8 @@ Format: Layer, Start, End, Style, Actor, MarginL, MarginR, MarginV, Effect, Text
} }
} }
if (styleName != null && style.Name != null && (styleName.Equals(style.Name, StringComparison.OrdinalIgnoreCase) || if (styleName != null && style.Name != null && (styleName.Equals(style.Name, StringComparison.OrdinalIgnoreCase) ||
styleName.Equals("*Default", StringComparison.OrdinalIgnoreCase) && style.Name.Equals("Default", StringComparison.OrdinalIgnoreCase))) styleName.Equals("*Default", StringComparison.OrdinalIgnoreCase) &&
style.Name.Equals("Default", StringComparison.OrdinalIgnoreCase)))
{ {
style.LoadedFromHeader = true; style.LoadedFromHeader = true;
return style; return style;

View File

@ -298,7 +298,7 @@ namespace Nikse.SubtitleEdit.Core.SubtitleFormats
c = c.TrimStart('#').ToUpper().PadLeft(8, 'F'); c = c.TrimStart('#').ToUpper().PadLeft(8, 'F');
fontColors.Push(c); fontColors.Push(c);
fontNo++; fontNo++;
i += endOfFont - i; i = endOfFont;
} }
else if (fontNo > 0 && line.Substring(i).StartsWith("</font>", StringComparison.Ordinal)) else if (fontNo > 0 && line.Substring(i).StartsWith("</font>", StringComparison.Ordinal))
{ {

View File

@ -300,7 +300,7 @@ namespace Nikse.SubtitleEdit.Core.SubtitleFormats
c = c.TrimStart('#').ToUpper().PadLeft(8, 'F'); c = c.TrimStart('#').ToUpper().PadLeft(8, 'F');
fontColors.Push(c); fontColors.Push(c);
fontNo++; fontNo++;
i += endOfFont - i; i = endOfFont;
} }
else if (fontNo > 0 && line.Substring(i).StartsWith("</font>")) else if (fontNo > 0 && line.Substring(i).StartsWith("</font>"))
{ {

View File

@ -300,7 +300,7 @@ namespace Nikse.SubtitleEdit.Core.SubtitleFormats
c = c.TrimStart('#').ToUpper().PadLeft(8, 'F'); c = c.TrimStart('#').ToUpper().PadLeft(8, 'F');
fontColors.Push(c); fontColors.Push(c);
fontNo++; fontNo++;
i += endOfFont - i; i = endOfFont;
} }
else if (fontNo > 0 && line.Substring(i).StartsWith("</font>", StringComparison.Ordinal)) else if (fontNo > 0 && line.Substring(i).StartsWith("</font>", StringComparison.Ordinal))
{ {

View File

@ -541,7 +541,7 @@ namespace Nikse.SubtitleEdit.Controls
int pos = SecondsToXPosition(time - _startPositionSeconds); int pos = SecondsToXPosition(time - _startPositionSeconds);
if (pos > 0 && pos < Width) if (pos > 0 && pos < Width)
{ {
if (Math.Abs(currentPositionPos - pos) < 0.01) if (currentPositionPos == pos)
{ // scene change and current pos are the same - draw 2 pixels + current pos dotted { // scene change and current pos are the same - draw 2 pixels + current pos dotted
currentPosDone = true; currentPosDone = true;
using (var p = new Pen(Color.AntiqueWhite, 2)) using (var p = new Pen(Color.AntiqueWhite, 2))
@ -616,7 +616,7 @@ namespace Nikse.SubtitleEdit.Controls
{ {
if (Width > 90) if (Width > 90)
{ {
graphics.DrawString(WaveformNotLoadedText, textFont, textBrush, new PointF(Width / 2 - 65, Height / 2 - 10)); graphics.DrawString(WaveformNotLoadedText, textFont, textBrush, new PointF(Width / 2.0f - 65, Height / 2.0f - 10));
} }
else else
{ {