Improve "Remove unneeded spaces" - thx uckthis :)

Related to comment https://github.com/SubtitleEdit/subtitleedit/issues/4131#issuecomment-619527038 in #4131
This commit is contained in:
Nikolaj Olsson 2020-04-26 13:49:32 +02:00
parent d699dbecd8
commit 571b0a958e
3 changed files with 29 additions and 4 deletions

View File

@ -2056,16 +2056,31 @@ namespace Nikse.SubtitleEdit.Core
text = text.Remove(3, 1); text = text.Remove(3, 1);
} }
if (text.EndsWith(" ...", StringComparison.Ordinal)) while (text.EndsWith(" ...", StringComparison.Ordinal))
{ {
text = text.Remove(text.Length - 4, 1); text = text.Remove(text.Length - 4, 1);
} }
if (text.EndsWith(" ...</i>", StringComparison.Ordinal)) while (text.EndsWith(" ...</i>", StringComparison.Ordinal))
{ {
text = text.Remove(text.Length - 8, 1); text = text.Remove(text.Length - 8, 1);
} }
while (text.EndsWith(" .</i>", StringComparison.Ordinal))
{
text = text.Remove(text.Length - 6, 1);
}
while (text.EndsWith(" !</i>", StringComparison.Ordinal))
{
text = text.Remove(text.Length - 6, 1);
}
while (text.EndsWith(" ?</i>", StringComparison.Ordinal))
{
text = text.Remove(text.Length - 6, 1);
}
if (text.StartsWith("- ... ", StringComparison.Ordinal)) if (text.StartsWith("- ... ", StringComparison.Ordinal))
{ {
text = text.Remove(5, 1); text = text.Remove(5, 1);

View File

@ -27062,10 +27062,9 @@ namespace Nikse.SubtitleEdit.Forms
} }
} }
// nothing changed
if (linesUpdated == 0) if (linesUpdated == 0)
{ {
return; return; // nothing changed
} }
var firstIdx = FirstSelectedIndex; var firstIdx = FirstSelectedIndex;

View File

@ -1155,6 +1155,17 @@ namespace Test.FixCommonErrors
} }
} }
[TestMethod]
public void FixUnneededSpacesBeforeEndTag()
{
using (var target = GetFixCommonErrorsLib())
{
InitializeFixCommonErrorsLine(target, "<i>I happen to have" + Environment.NewLine + " the blood of an ancient family .</i>");
new FixUnneededSpaces().Fix(_subtitle, new EmptyFixCallback());
Assert.AreEqual("<i>I happen to have" + Environment.NewLine + "the blood of an ancient family.</i>", _subtitle.Paragraphs[0].Text);
}
}
#endregion Fix unneeded spaces #endregion Fix unneeded spaces
#region Fix EmptyLines #region Fix EmptyLines