mirror of
https://github.com/SubtitleEdit/subtitleedit.git
synced 2024-11-23 03:33:18 +01:00
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:
parent
f78229e9a7
commit
279e3686fa
@ -446,23 +446,31 @@ namespace Nikse.SubtitleEdit.Forms
|
|||||||
{
|
{
|
||||||
int colonIndex = s2.IndexOf(":");
|
int colonIndex = s2.IndexOf(":");
|
||||||
string start = s2.Substring(0, colonIndex);
|
string start = s2.Substring(0, colonIndex);
|
||||||
int periodIndex = start.LastIndexOf(". ");
|
|
||||||
int questIndex = start.LastIndexOf("? ");
|
bool doContinue = true;
|
||||||
int exclaIndex = start.LastIndexOf("! ");
|
if (checkBoxRemoveTextBeforeColonOnlyUppercase.Checked && start != start.ToUpper())
|
||||||
int endIndex = periodIndex;
|
doContinue = false;
|
||||||
if (endIndex == -1 || questIndex > endIndex)
|
if (doContinue)
|
||||||
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;
|
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)
|
if (count == 0)
|
||||||
removedInFirstLine = true;
|
removedInFirstLine = true;
|
||||||
@ -558,6 +566,8 @@ namespace Nikse.SubtitleEdit.Forms
|
|||||||
newText = newText.Replace(Environment.NewLine, Environment.NewLine + "- ");
|
newText = newText.Replace(Environment.NewLine, Environment.NewLine + "- ");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (text.Contains("<i>") && !newText.Contains("<i>") && newText.EndsWith("</i>"))
|
||||||
|
newText = "<i>" + newText;
|
||||||
return newText;
|
return newText;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -83,6 +83,44 @@ namespace Test
|
|||||||
Assert.AreEqual(expected, actual);
|
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>
|
/// <summary>
|
||||||
///A test for RemoveHIInsideLine
|
///A test for RemoveHIInsideLine
|
||||||
///</summary>
|
///</summary>
|
||||||
|
Loading…
Reference in New Issue
Block a user