mirror of
https://github.com/SubtitleEdit/subtitleedit.git
synced 2024-11-22 19:22:53 +01:00
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:
parent
08766944f1
commit
05487e8f66
@ -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;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user