Remove text for HI now removes empty font tags - fix #882 - thx invandrofly :)

This commit is contained in:
niksedk 2015-06-20 14:48:37 +02:00
parent 845650e959
commit db78d33a58
2 changed files with 59 additions and 1 deletions

View File

@ -447,7 +447,13 @@ namespace Nikse.SubtitleEdit.Logic.Forms
}
text = st.Pre + sb.ToString().Trim() + st.Post;
text = text.Replace("<i></i>", string.Empty).Trim();
text = text.Replace(" ", " ").Trim();
text = text.Replace("<i></i>", string.Empty);
text = text.Replace("<i> </i>", " ");
text = text.Replace("<b></b>", string.Empty);
text = text.Replace("<b> </b>", " ");
text = RemoveEmptyFontTag(text);
text = text.Replace(" ", " ").Trim();
text = RemoveColon(text);
text = RemoveLineIfAllUppercase(text);
text = RemoveHearImpairedtagsInsideLine(text);
@ -572,6 +578,25 @@ namespace Nikse.SubtitleEdit.Logic.Forms
return text.Trim();
}
private string RemoveEmptyFontTag(string text)
{
int indexOfStartFont = text.IndexOf("<font ", StringComparison.OrdinalIgnoreCase);
int indexOfEndFont = text.IndexOf("</font>", StringComparison.OrdinalIgnoreCase);
if (indexOfEndFont > 0 && indexOfStartFont >= 0 && indexOfStartFont < indexOfEndFont)
{
int startTagBefore = text.Substring(0, indexOfEndFont).LastIndexOf('<');
string lastTwo = text.Substring(indexOfEndFont - 2, 2);
if (startTagBefore == indexOfStartFont && lastTwo.Trim().EndsWith(">"))
{
text = text.Remove(indexOfStartFont, indexOfEndFont + "</font>".Length - indexOfStartFont);
if (lastTwo.EndsWith(" "))
text = text.Insert(indexOfStartFont, " ");
text = text.Replace(" ", " ");
}
}
return text;
}
private void AddWarning()
{
if (Warnings == null || WarningIndex < 0)

View File

@ -1226,6 +1226,39 @@ namespace Test.Logic.Forms
Assert.AreEqual(expected, actual);
}
[TestMethod]
public void RemoveTextForHiRemoveFontTag()
{
RemoveTextForHI target = GetRemoveTextForHiLib();
target.Settings.RemoveTextBetweenBrackets = true;
const string text = "<font color=\"#808080\">[Whistling]</font> Hallo everybody!";
const string expected = "Hallo everybody!";
string actual = target.RemoveTextFromHearImpaired(text);
Assert.AreEqual(expected, actual);
}
[TestMethod]
public void RemoveTextForHiRemoveFontTag2()
{
RemoveTextForHI target = GetRemoveTextForHiLib();
target.Settings.RemoveTextBetweenBrackets = true;
const string text = "♪ <font color=\"#000000\">[LIGHT SWITCH CLICKS]</font>";
const string expected = "♪";
string actual = target.RemoveTextFromHearImpaired(text);
Assert.AreEqual(expected, actual);
}
[TestMethod]
public void RemoveTextForHiRemoveFontTag3()
{
RemoveTextForHI target = GetRemoveTextForHiLib();
target.Settings.RemoveTextBetweenBrackets = true;
const string text = "Foobar <font color=\"#808080\">[CHAINS RATTLING]</font> Foobar";
const string expected = "Foobar Foobar";
string actual = target.RemoveTextFromHearImpaired(text);
Assert.AreEqual(expected, actual);
}
#region Additional test attributes
//