Standardize hyphen character handling in RemoveDialogFirstLineInNonDialogs.

Replaced occurrences of literal hyphen characters with named constants to improve code readability and maintainability. This change ensures consistent handling of both hyphen-minus and standard hyphen characters throughout the function.

Signed-off-by: Ivandro Jao <Ivandrofly@gmail.com>
This commit is contained in:
Ivandro Jao 2024-10-25 23:49:22 +01:00
parent 0913c8d72a
commit 279f04c14d

View File

@ -14,6 +14,8 @@ namespace Nikse.SubtitleEdit.Core.Forms.FixCommonErrors
{ {
var fixAction = Language.RemoveDialogFirstInNonDialogs; var fixAction = Language.RemoveDialogFirstInNonDialogs;
var noOfFixes = 0; var noOfFixes = 0;
const char hyphenMinus = '-'; // Hyphen-Minus (-, U+002D)
const char hyphen = ''; // Hyphen (, U+2010)
for (int i = 0; i < subtitle.Paragraphs.Count; i++) for (int i = 0; i < subtitle.Paragraphs.Count; i++)
{ {
var p = subtitle.Paragraphs[i]; var p = subtitle.Paragraphs[i];
@ -22,15 +24,15 @@ namespace Nikse.SubtitleEdit.Core.Forms.FixCommonErrors
var noHtml = HtmlUtil.RemoveHtmlTags(text, true).TrimStart(); var noHtml = HtmlUtil.RemoveHtmlTags(text, true).TrimStart();
var count = Utilities.CountTagInText(text, '-') + Utilities.CountTagInText(text, ''); var count = Utilities.CountTagInText(text, hyphenMinus) + Utilities.CountTagInText(text, hyphen);
if (count == 0 || !noHtml.StartsWith('-') && !noHtml.StartsWith('')) if (count == 0 || !noHtml.StartsWith(hyphenMinus) && !noHtml.StartsWith(hyphen))
{ {
continue; continue;
} }
// test the two different dashes // test the two different dashes
text = RemoveDash(text, noHtml, '-'); text = RemoveDash(text, noHtml, hyphenMinus);
text = RemoveDash(text, noHtml, ''); text = RemoveDash(text, noHtml, hyphen);
if (oldText != text && callbacks.AllowFix(p, fixAction)) if (oldText != text && callbacks.AllowFix(p, fixAction))
{ {