Change/fix for "Remove text for HI" - thx pson :)

This commit is contained in:
Nikolaj Olsson 2017-05-04 21:00:44 +02:00
parent fef9ed619e
commit e5bb4d158c
2 changed files with 78 additions and 9 deletions

View File

@ -844,17 +844,21 @@ namespace Nikse.SubtitleEdit.Core.Forms
{
int index = match.Index;
string temp = text.Remove(index, s.Length);
while (index == 0 && temp.StartsWith("... ", StringComparison.Ordinal))
if (index == 0 && temp.StartsWith("... ", StringComparison.Ordinal))
{
temp = temp.Remove(3, 1);
temp = temp.Remove(0, 4);
}
while (index == 3 && temp.StartsWith("<i>... ", StringComparison.Ordinal))
if (index == 3 && temp.StartsWith("<i>... ", StringComparison.Ordinal))
{
temp = temp.Remove(6, 1);
temp = temp.Remove(3, 4);
}
while (index > 2 && (" \r\n".Contains(text.Substring(index - 1, 1))) && temp.Substring(index).StartsWith("... ", StringComparison.Ordinal))
if (index > 2 && (" \r\n".Contains(text.Substring(index - 1, 1))) && temp.Substring(index).StartsWith("... ", StringComparison.Ordinal))
{
temp = temp.Remove(index + 3, 1);
temp = temp.Remove(index, 4);
}
if (index > 4 && temp.Substring(index - 4).StartsWith("\n<i>... ", StringComparison.Ordinal))
{
temp = temp.Remove(index, 4);
}
if (temp.Remove(0, index) == " —" && temp.EndsWith("— —", StringComparison.Ordinal))
@ -906,6 +910,15 @@ namespace Nikse.SubtitleEdit.Core.Forms
temp = temp.Remove(subIndex, 2);
removeAfter = false;
}
else if (subIndex > 3 && ".!?".Contains(temp.Substring(subIndex -1, 1)))
{
subTemp = temp.Substring(subIndex);
if (subTemp == " ..." || subTemp.StartsWith(" ..." + Environment.NewLine, StringComparison.InvariantCulture))
{
temp = temp.Remove(subIndex, 4).Trim();
removeAfter = false;
}
}
}
if (removeAfter && temp.Length > index - s.Length + 2)
{

View File

@ -631,6 +631,62 @@ namespace Test.Logic.Forms
Assert.AreEqual(expected, actual);
}
[TestMethod]
public void RemoveInterjections14A()
{
var target = GetRemoveTextForHiLib();
target.Settings.RemoveIfAllUppercase = false;
target.Settings.OnlyIfInSeparateLine = false;
target.Settings.RemoveTextBeforeColonOnlyUppercase = false;
target.Settings.ColonSeparateLine = false;
string text = "Hey! Uh...";
const string expected = "Hey!";
string actual = target.RemoveInterjections(text);
Assert.AreEqual(expected, actual);
}
[TestMethod]
public void RemoveInterjections14B()
{
var target = GetRemoveTextForHiLib();
target.Settings.RemoveIfAllUppercase = false;
target.Settings.OnlyIfInSeparateLine = false;
target.Settings.RemoveTextBeforeColonOnlyUppercase = false;
target.Settings.ColonSeparateLine = false;
string text = "Hey! Uh..." + Environment.NewLine + "Bye.";
string expected = "Hey!" + Environment.NewLine + "Bye.";
string actual = target.RemoveInterjections(text);
Assert.AreEqual(expected, actual);
}
[TestMethod]
public void RemoveInterjections15A()
{
var target = GetRemoveTextForHiLib();
target.Settings.RemoveIfAllUppercase = false;
target.Settings.OnlyIfInSeparateLine = false;
target.Settings.RemoveTextBeforeColonOnlyUppercase = false;
target.Settings.ColonSeparateLine = false;
string text = "I think that..." + Environment.NewLine + "Uh... Hey!";
string expected = "I think that..." + Environment.NewLine + "Hey!";
string actual = target.RemoveInterjections(text);
Assert.AreEqual(expected, actual);
}
[TestMethod]
public void RemoveInterjections15B()
{
var target = GetRemoveTextForHiLib();
target.Settings.RemoveIfAllUppercase = false;
target.Settings.OnlyIfInSeparateLine = false;
target.Settings.RemoveTextBeforeColonOnlyUppercase = false;
target.Settings.ColonSeparateLine = false;
string text = "I think that..." + Environment.NewLine + "<i>Uh... Hey!</i>";
string expected = "I think that..." + Environment.NewLine + "<i>Hey!</i>";
string actual = target.RemoveInterjections(text);
Assert.AreEqual(expected, actual);
}
[TestMethod]
public void RemoveColonOnlyOnSeparateLine()
{
@ -1507,7 +1563,7 @@ namespace Test.Logic.Forms
public void RemoveInterjectionDotDotDot()
{
var target = GetRemoveTextForHiLib();
string expected = "...alright.";
string expected = "Alright.";
string actual = target.RemoveInterjections("Oh... alright.");
Assert.AreEqual(expected, actual);
}
@ -1516,7 +1572,7 @@ namespace Test.Logic.Forms
public void RemoveInterjectionDotDotDotItalic()
{
var target = GetRemoveTextForHiLib();
string expected = "<i>...alright.</i>";
string expected = "<i>Alright.</i>";
string actual = target.RemoveInterjections("<i>Oh... alright.</i>");
Assert.AreEqual(expected, actual);
}
@ -1525,7 +1581,7 @@ namespace Test.Logic.Forms
public void RemoveInterjectionDotDotDotSecondLineDialog()
{
var target = GetRemoveTextForHiLib();
string expected = "- OK." + Environment.NewLine + "- ...alright.";
string expected = "- OK." + Environment.NewLine + "- Alright.";
string actual = target.RemoveInterjections("- OK." + Environment.NewLine + "- Oh... alright.");
Assert.AreEqual(expected, actual);
}