Refactor extra space removal in Utilities

This commit refactors the process of removing extra spaces in Utilities.cs for improved code efficiency and readability. Instead of using a loop to remove consecutive spaces, a new method `FixExtraSpaces()` is now used. This method is more clear and efficient. Additionally, the process of replacing tags with a single whitespace has been simplified by using a constant `singleWhiteSpace`. This not only improves readability but also ensures a uniform definition of single whitespace replacement throughout the code.
This commit is contained in:
Ivandro Jao 2023-07-29 04:19:17 +01:00
parent 08766944f1
commit 05487e8f66

View File

@ -715,23 +715,21 @@ namespace Nikse.SubtitleEdit.Core.Common
return lines[0];
}
var singleLine = string.Join(" ", lines);
while (singleLine.Contains(" "))
{
singleLine = singleLine.Replace(" ", " ");
}
var singleLine = string.Join(" ", lines).FixExtraSpaces();
if (singleLine.Contains("</")) // Fix tag
{
singleLine = singleLine.Replace("</i> <i>", " ");
singleLine = singleLine.Replace("</i><i>", " ");
const string singleWhiteSpace = " ";
singleLine = singleLine.Replace("</i> <i>", singleWhiteSpace);
singleLine = singleLine.Replace("</i><i>", singleWhiteSpace);
singleLine = singleLine.Replace("</b> <b>", " ");
singleLine = singleLine.Replace("</b><b>", " ");
singleLine = singleLine.Replace("</b> <b>", singleWhiteSpace);
singleLine = singleLine.Replace("</b><b>", singleWhiteSpace);
singleLine = singleLine.Replace("</u> <u>", " ");
singleLine = singleLine.Replace("</u><u>", " ");
singleLine = singleLine.Replace("</u> <u>", singleWhiteSpace);
singleLine = singleLine.Replace("</u><u>", singleWhiteSpace);
}
return singleLine;
}