From d5190e44b96597ab3595cbf37d698925c3f9dbee Mon Sep 17 00:00:00 2001 From: Ivandro Jao Date: Sat, 24 Feb 2024 20:30:27 +0000 Subject: [PATCH] Refactor quotes replacement in FixCommonErrors Changed the structure and logic of AddMissingQuotes.cs to improve readability and performance. Instead of multiple utility function calls with hardcoded quotes, a constant "doubleQuote" is implemented, and the nested conditions are reorganized for better flow. --- .../Forms/FixCommonErrors/AddMissingQuotes.cs | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/src/libse/Forms/FixCommonErrors/AddMissingQuotes.cs b/src/libse/Forms/FixCommonErrors/AddMissingQuotes.cs index 1c513fa6c..102980530 100644 --- a/src/libse/Forms/FixCommonErrors/AddMissingQuotes.cs +++ b/src/libse/Forms/FixCommonErrors/AddMissingQuotes.cs @@ -243,14 +243,20 @@ namespace Nikse.SubtitleEdit.Core.Forms.FixCommonErrors return text; } - if (Utilities.CountTagInText(text, "\"") == 1 && Utilities.CountTagInText(text, "”") == 1) + const string doubleQuote = "\""; + if (Utilities.CountTagInText(text, doubleQuote) == 1) { - return text.Replace("”", "\""); - } - if (Utilities.CountTagInText(text, "\"") == 1 && Utilities.CountTagInText(text, "“") == 1) - { - return text.Replace("“", "\""); + if (Utilities.CountTagInText(text, "”") == 1) + { + return text.Replace("”", doubleQuote); + } + + if (Utilities.CountTagInText(text, "“") == 1) + { + return text.Replace("“", doubleQuote); + } } + return text; } }