Fix bug in "Remove text for HI" - thx Chamallow :)

This commit is contained in:
niksedk 2023-09-18 22:18:21 +02:00
parent c3dd5a3504
commit 820ad1f4ff
2 changed files with 36 additions and 14 deletions

View File

@ -2217,5 +2217,22 @@ namespace Test.Logic.Forms
var actual = target.RemoveTextFromHearImpaired(text);
Assert.AreEqual(expected, actual);
}
[TestMethod]
public void Line2Speaker()
{
var target = GetRemoveTextForHiLib();
target.Settings.RemoveIfAllUppercase = false;
target.Settings.RemoveTextBeforeColon = true;
target.Settings.OnlyIfInSeparateLine = false;
target.Settings.OnlyIfInSeparateLine = false;
target.Settings.ColonSeparateLine = false;
target.Settings.RemoveInterjections = true;
target.Settings.RemoveTextBeforeColonOnlyUppercase = false;
var text = "and that is gonna take..." + Environment.NewLine + "[STAMMERS] ... real deep pockets.";
var expected = "and that is gonna take..." + Environment.NewLine + "... real deep pockets.";
var actual = target.RemoveTextFromHearImpaired(text);
Assert.AreEqual(expected, actual);
}
}
}

View File

@ -1059,27 +1059,29 @@ namespace Nikse.SubtitleEdit.Core.Forms
if (!text.StartsWith('-') && noOfNamesRemoved >= 1 && Utilities.GetNumberOfLines(text) == 2)
{
var lines = text.SplitToLines();
var part0 = lines[0].Trim().Replace("</i>", string.Empty).Trim();
if (!part0.EndsWith(',') && (!part0.EndsWith('-') || noOfNamesRemovedNotInLineOne > 0))
if (input.Contains("-") || noOfNamesRemoved > 1)
{
if (part0.Length > 0 && ".?!".Contains(part0[part0.Length - 1]))
var lines = text.SplitToLines();
var part0 = lines[0].Trim().Replace("</i>", string.Empty).Trim();
if (!part0.EndsWith(',') && (!part0.EndsWith('-') || noOfNamesRemovedNotInLineOne > 0))
{
if (noOfNamesRemovedNotInLineOne > 0)
if (part0.Length > 0 && ".?!".Contains(part0[part0.Length - 1]))
{
if (!st.Pre.Contains('-') && !text.Contains(Environment.NewLine + "-"))
if (noOfNamesRemovedNotInLineOne > 0)
{
text = "- " + text;
if (!text.Contains(Environment.NewLine + "<i>- "))
if (!st.Pre.Contains('-') && !text.Contains(Environment.NewLine + "-"))
{
text = "- " + text;
if (!text.Contains(Environment.NewLine + "<i>- "))
{
text = text.Replace(Environment.NewLine, Environment.NewLine + "- ");
}
}
if (!text.Contains(Environment.NewLine + "-") && !text.Contains(Environment.NewLine + "<i>-"))
{
text = text.Replace(Environment.NewLine, Environment.NewLine + "- ");
}
}
if (!text.Contains(Environment.NewLine + "-") && !text.Contains(Environment.NewLine + "<i>-"))
{
text = text.Replace(Environment.NewLine, Environment.NewLine + "- ");
}
}
}
}
@ -1245,6 +1247,8 @@ namespace Nikse.SubtitleEdit.Core.Forms
private static readonly HashSet<string> HiDescriptionWords = new HashSet<string>(new[]
{
"breathes",
"breathes deeply",
"cackles",
"cheers",
"chitters",
@ -1267,12 +1271,13 @@ namespace Nikse.SubtitleEdit.Core.Forms
"sigh",
"sighs",
"snores",
"stammers",
"stutters",
"thuds",
"trumpets",
"whisper",
"whispers",
"whistles"
"whistles",
});
private bool IsHIDescription(string text)