mirror of
https://github.com/SubtitleEdit/subtitleedit.git
synced 2024-11-22 03:02:35 +01:00
Remove text for HI now removes empty font tags - fix #882 - thx invandrofly :)
This commit is contained in:
parent
845650e959
commit
db78d33a58
@ -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)
|
||||
|
@ -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
|
||||
|
||||
//
|
||||
|
Loading…
Reference in New Issue
Block a user