Fixed "Remove text for HI" issue - thx cipry15 :)

Even if only uppercase then "Number 9:" was removed in the sentence below:
GIOVANNI: <i>Number 9: I never look for a scapegoat.</i>


git-svn-id: https://subtitleedit.googlecode.com/svn/trunk@2294 99eadd0c-20b8-1223-b5c4-2a2b2df33de2
This commit is contained in:
niksedk 2013-12-08 08:44:38 +00:00
parent f78229e9a7
commit 279e3686fa
2 changed files with 63 additions and 15 deletions

View File

@ -446,23 +446,31 @@ namespace Nikse.SubtitleEdit.Forms
{
int colonIndex = s2.IndexOf(":");
string start = s2.Substring(0, colonIndex);
int periodIndex = start.LastIndexOf(". ");
int questIndex = start.LastIndexOf("? ");
int exclaIndex = start.LastIndexOf("! ");
int endIndex = periodIndex;
if (endIndex == -1 || questIndex > endIndex)
endIndex = questIndex;
if (endIndex == -1 || exclaIndex > endIndex)
endIndex = exclaIndex;
if (colonIndex > 0 && colonIndex < s2.Length - 1)
bool doContinue = true;
if (checkBoxRemoveTextBeforeColonOnlyUppercase.Checked && start != start.ToUpper())
doContinue = false;
if (doContinue)
{
if ("1234567890".Contains(s2.Substring(colonIndex - 1, 1)) && "1234567890".Contains(s2.Substring(colonIndex + 1, 1)))
endIndex = -10;
int periodIndex = start.LastIndexOf(". ");
int questIndex = start.LastIndexOf("? ");
int exclaIndex = start.LastIndexOf("! ");
int endIndex = periodIndex;
if (endIndex == -1 || questIndex > endIndex)
endIndex = questIndex;
if (endIndex == -1 || exclaIndex > endIndex)
endIndex = exclaIndex;
if (colonIndex > 0 && colonIndex < s2.Length - 1)
{
if ("1234567890".Contains(s2.Substring(colonIndex - 1, 1)) && "1234567890".Contains(s2.Substring(colonIndex + 1, 1)))
endIndex = -10;
}
if (endIndex == -1)
s2 = s2.Remove(0, colonIndex - endIndex);
else if (endIndex > 0)
s2 = s2.Remove(endIndex + 1, colonIndex - endIndex);
}
if (endIndex == -1)
s2 = s2.Remove(0, colonIndex - endIndex);
else if (endIndex > 0)
s2 = s2.Remove(endIndex + 1, colonIndex - endIndex);
if (count == 0)
removedInFirstLine = true;
@ -558,6 +566,8 @@ namespace Nikse.SubtitleEdit.Forms
newText = newText.Replace(Environment.NewLine, Environment.NewLine + "- ");
}
}
if (text.Contains("<i>") && !newText.Contains("<i>") && newText.EndsWith("</i>"))
newText = "<i>" + newText;
return newText;
}

View File

@ -83,6 +83,44 @@ namespace Test
Assert.AreEqual(expected, actual);
}
[TestMethod()]
[DeploymentItem("SubtitleEdit.exe")]
public void RemoveColonTest2a()
{
var target = new FormRemoveTextForHearImpaired_Accessor();
target.checkBoxRemoveIfAllUppercase.Checked = false;
target.checkBoxRemoveTextBeforeColon.Checked = true;
target.checkBoxOnlyIfInSeparateLine.Checked = false;
target.checkBoxOnlyIfInSeparateLine.Checked = false;
target.checkBoxColonSeparateLine.Checked = false;
target.checkBoxRemoveTextBeforeColonOnlyUppercase.Checked = false;
string text = "GIOVANNI: <i>Number 9: I never look for a scapegoat.</i>";
string expected = "<i>I never look for a scapegoat.</i>";
string actual = target.RemoveColon(text, string.Empty);
Assert.AreEqual(expected, actual);
}
[TestMethod()]
[DeploymentItem("SubtitleEdit.exe")]
public void RemoveColonTest2b()
{
var target = new FormRemoveTextForHearImpaired_Accessor();
target.checkBoxRemoveIfAllUppercase.Checked = false;
target.checkBoxRemoveTextBeforeColon.Checked = true;
target.checkBoxOnlyIfInSeparateLine.Checked = false;
target.checkBoxOnlyIfInSeparateLine.Checked = false;
target.checkBoxColonSeparateLine.Checked = false;
target.checkBoxRemoveTextBeforeColonOnlyUppercase.Checked = true;
string text = "GIOVANNI: <i>Number 9: I never look for a scapegoat.</i>";
string expected = "<i>Number 9: I never look for a scapegoat.</i>";
string actual = target.RemoveColon(text, string.Empty);
Assert.AreEqual(expected, actual);
}
/// <summary>
///A test for RemoveHIInsideLine
///</summary>