Fix common errors - "Add missing period at end of line" now works better with italics

git-svn-id: https://subtitleedit.googlecode.com/svn/trunk@272 99eadd0c-20b8-1223-b5c4-2a2b2df33de2
This commit is contained in:
niksedk 2011-01-21 14:02:05 +00:00
parent 69be8e1365
commit 90d4cd3d80
3 changed files with 162 additions and 26 deletions

View File

@ -1373,6 +1373,11 @@ namespace Nikse.SubtitleEdit.Forms
{
Paragraph p = _subtitle.Paragraphs[i];
Paragraph next = _subtitle.GetParagraphOrDefault(i + 1);
string nextText = string.Empty;
if (next != null)
nextText = Utilities.RemoveHtmlTags(next.Text).TrimStart('-').TrimStart();
string tempNoHtml = Utilities.RemoveHtmlTags(p.Text).TrimEnd();
if (IsOneLineUrl(p.Text))
{
@ -1380,11 +1385,11 @@ namespace Nikse.SubtitleEdit.Forms
}
else if (next != null &&
next.Text.Length > 0 &&
Utilities.GetLetters(true, false, false).Contains(next.Text[0].ToString()) &&
p.Text.Length > 0 &&
(!"\",.!?:;>-])♪♫".Contains(p.Text[p.Text.Length - 1].ToString())))
Utilities.GetLetters(true, false, false).Contains(nextText[0].ToString()) &&
tempNoHtml.Length > 0 &&
(!"\",.!?:;>-])♪♫".Contains(tempNoHtml[tempNoHtml.Length - 1].ToString())))
{
if (!p.Text.EndsWith(")") && !p.Text.EndsWith("]") && !p.Text.EndsWith("*") && !p.Text.EndsWith("¶")) // hear impaired
if (!tempNoHtml.EndsWith(")") && !tempNoHtml.EndsWith("]") && !tempNoHtml.EndsWith("*") && !tempNoHtml.EndsWith("¶")) // hear impaired
{
if (p.Text != p.Text.ToUpper())
{
@ -1397,10 +1402,22 @@ namespace Nikse.SubtitleEdit.Forms
if (AllowFix(i + 1, fixAction))
{
string oldText = p.Text;
_totalFixes++;
missigPeriodsAtEndOfLine++;
p.Text += ".";
AddFixToListView(p, i + 1, fixAction, oldText, p.Text);
if (p.Text.EndsWith(">"))
{
int lastLT = p.Text.LastIndexOf("<");
if (lastLT > 0)
p.Text = p.Text.Insert(lastLT, ".");
}
else
{
p.Text += ".";
}
if (p.Text != oldText)
{
_totalFixes++;
missigPeriodsAtEndOfLine++;
AddFixToListView(p, i + 1, fixAction, oldText, p.Text);
}
}
}
}

View File

@ -112,6 +112,8 @@ namespace Nikse.SubtitleEdit.Logic
Instance._baseDir = Path.GetDirectoryName(a.Location);
else
Instance._baseDir = Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location);
if (Instance._baseDir.EndsWith("Test\\bin\\Release"))
Instance._baseDir = Instance._baseDir.Replace("Test\\bin\\Release", "bin\\Release");
if (!Instance._baseDir.EndsWith(Path.DirectorySeparatorChar.ToString()))
Instance._baseDir += Path.DirectorySeparatorChar;
}

View File

@ -1,6 +1,6 @@
using Nikse.SubtitleEdit.Forms;
using System;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System;
using Nikse.SubtitleEdit.Forms;
using Nikse.SubtitleEdit.Logic;
namespace Test
@ -36,7 +36,14 @@ namespace Test
Subtitle subtitle = new Subtitle();
subtitle.Paragraphs.Add(new Paragraph(line, 100, 10000));
target.Initialize(subtitle);
target.ButtonFixClick(null, null);
}
private static void InitializeFixCommonErrorsLine(FixCommonErrors_Accessor target, string line, string line2)
{
Subtitle subtitle = new Subtitle();
subtitle.Paragraphs.Add(new Paragraph(line, 100, 10000));
subtitle.Paragraphs.Add(new Paragraph(line2, 10001, 30000));
target.Initialize(subtitle);
}
#region Additional test attributes
@ -70,9 +77,6 @@ namespace Test
#endregion
#region Merge short lines
/// <summary>
///A test for Merge short lines
///</summary>
[TestMethod()]
[DeploymentItem("SubtitleEdit.exe")]
public void FixShortLinesNormal()
@ -83,9 +87,6 @@ namespace Test
Assert.AreEqual(target._subtitle.Paragraphs[0].Text, "This is short!");
}
/// <summary>
///A test for Merge short lines
///</summary>
[TestMethod()]
[DeploymentItem("SubtitleEdit.exe")]
public void FixShortLinesLong()
@ -96,9 +97,6 @@ namespace Test
Assert.AreEqual(target._subtitle.Paragraphs[0].Text, "This I'm pretty sure is not a" + Environment.NewLine + "short line, that should be merged!!!");
}
/// <summary>
///A test for Merge short lines
///</summary>
[TestMethod()]
[DeploymentItem("SubtitleEdit.exe")]
public void FixShortLinesNormalItalic()
@ -109,9 +107,6 @@ namespace Test
Assert.AreEqual(target._subtitle.Paragraphs[0].Text, "<i>This is short!</i>");
}
/// <summary>
///A test for Merge short lines
///</summary>
[TestMethod()]
[DeploymentItem("SubtitleEdit.exe")]
public void FixShortLinesDialogue()
@ -122,9 +117,6 @@ namespace Test
Assert.AreEqual(target._subtitle.Paragraphs[0].Text, "- Hallo!" + Environment.NewLine + "- Hi");
}
/// <summary>
///A test for Merge short lines
///</summary>
[TestMethod()]
[DeploymentItem("SubtitleEdit.exe")]
public void FixShortLinesDialogueItalic()
@ -149,5 +141,130 @@ namespace Test
Assert.AreEqual(target._subtitle.Paragraphs[0].Text, "<i>- Hallo!</i>" + Environment.NewLine + "<i>- Hi<i>");
}
#endregion
#region Fix Italics
[TestMethod()]
[DeploymentItem("SubtitleEdit.exe")]
public void FixItalicsBeginOnly()
{
FixCommonErrors_Accessor target = new FixCommonErrors_Accessor();
InitializeFixCommonErrorsLine(target, "<i>Hey!" + Environment.NewLine + "<i>Boy!");
target.FixInvalidItalicTags();
Assert.AreEqual(target._subtitle.Paragraphs[0].Text, "<i>Hey!</i>" + Environment.NewLine + "<i>Boy!</i>");
}
[TestMethod()]
[DeploymentItem("SubtitleEdit.exe")]
public void FixItalicsFirstLineEndMissing()
{
FixCommonErrors_Accessor target = new FixCommonErrors_Accessor();
InitializeFixCommonErrorsLine(target, "<i>(jones) seems their attackers headed north." + Environment.NewLine + "<i>Hi!</i>");
target.FixInvalidItalicTags();
Assert.AreEqual(target._subtitle.Paragraphs[0].Text, "<i>(jones) seems their attackers headed north." + Environment.NewLine + "Hi!</i>");
}
[TestMethod()]
[DeploymentItem("SubtitleEdit.exe")]
public void FixItalicsStartInMiddle()
{
FixCommonErrors_Accessor target = new FixCommonErrors_Accessor();
InitializeFixCommonErrorsLine(target, "Seems their <i>attackers headed north.");
target.FixInvalidItalicTags();
Assert.AreEqual(target._subtitle.Paragraphs[0].Text, "Seems their attackers headed north.");
}
[TestMethod()]
[DeploymentItem("SubtitleEdit.exe")]
public void FixItalicsEmptyStart()
{
FixCommonErrors_Accessor target = new FixCommonErrors_Accessor();
InitializeFixCommonErrorsLine(target, "<i></i>test");
target.FixInvalidItalicTags();
Assert.AreEqual(target._subtitle.Paragraphs[0].Text, "test");
}
[TestMethod()]
[DeploymentItem("SubtitleEdit.exe")]
public void FixItalicsSecondLineMissingEnd()
{
FixCommonErrors_Accessor target = new FixCommonErrors_Accessor();
InitializeFixCommonErrorsLine(target, "- And..." + Environment.NewLine + "<i>Awesome it is!");
target.FixInvalidItalicTags();
Assert.AreEqual(target._subtitle.Paragraphs[0].Text, "- And..." + Environment.NewLine + "<i>Awesome it is!</i>");
}
[TestMethod()]
[DeploymentItem("SubtitleEdit.exe")]
public void FixItalicsBadEnding()
{
FixCommonErrors_Accessor target = new FixCommonErrors_Accessor();
InitializeFixCommonErrorsLine(target, "Awesome it is!</i>");
target.FixInvalidItalicTags();
Assert.AreEqual(target._subtitle.Paragraphs[0].Text, "Awesome it is!");
}
[TestMethod()]
[DeploymentItem("SubtitleEdit.exe")]
public void FixItalicsBadEnding2()
{
FixCommonErrors_Accessor target = new FixCommonErrors_Accessor();
InitializeFixCommonErrorsLine(target, "Awesome it is!<i></i>");
target.FixInvalidItalicTags();
Assert.AreEqual(target._subtitle.Paragraphs[0].Text, "Awesome it is!");
}
[TestMethod()]
[DeploymentItem("SubtitleEdit.exe")]
public void FixItalicsBadEnding3()
{
FixCommonErrors_Accessor target = new FixCommonErrors_Accessor();
InitializeFixCommonErrorsLine(target, "Awesome it is!<i>");
target.FixInvalidItalicTags();
Assert.AreEqual(target._subtitle.Paragraphs[0].Text, "Awesome it is!");
}
[TestMethod()]
[DeploymentItem("SubtitleEdit.exe")]
public void FixItalicsBadEnding4()
{
FixCommonErrors_Accessor target = new FixCommonErrors_Accessor();
InitializeFixCommonErrorsLine(target, "Awesome it is!</i><i>");
target.FixInvalidItalicTags();
Assert.AreEqual(target._subtitle.Paragraphs[0].Text, "Awesome it is!");
}
#endregion
#region Fix Missing Periods At End Of Line
[TestMethod()]
[DeploymentItem("SubtitleEdit.exe")]
public void FixMissingPeriodsAtEndOfLineNone()
{
FixCommonErrors_Accessor target = new FixCommonErrors_Accessor();
InitializeFixCommonErrorsLine(target, "This is line one!" + Environment.NewLine + "<i>Boy!</i>", "This is line one!" + Environment.NewLine + "<i>Boy!</i>");
target.FixMissingPeriodsAtEndOfLine();
Assert.AreEqual(target._subtitle.Paragraphs[0].Text, "This is line one!" + Environment.NewLine + "<i>Boy!</i>");
}
[TestMethod()]
[DeploymentItem("SubtitleEdit.exe")]
public void FixMissingPeriodsAtEndOfLineItalicAndMissing()
{
FixCommonErrors_Accessor target = new FixCommonErrors_Accessor();
InitializeFixCommonErrorsLine(target, "This is line one!" + Environment.NewLine + "<i>Boy</i>", "This is line one!" + Environment.NewLine + "<i>Boy!</i>");
target.FixMissingPeriodsAtEndOfLine();
Assert.AreEqual(target._subtitle.Paragraphs[0].Text, "This is line one!" + Environment.NewLine + "<i>Boy.</i>");
}
[TestMethod()]
[DeploymentItem("SubtitleEdit.exe")]
public void FixMissingPeriodsAtEndOfLineItalicAndMissing2()
{
FixCommonErrors_Accessor target = new FixCommonErrors_Accessor();
InitializeFixCommonErrorsLine(target, "<i>This is line one!" + Environment.NewLine + "Boy</i>", "This is line one!" + Environment.NewLine + "<i>Boy!</i>");
target.FixMissingPeriodsAtEndOfLine();
Assert.AreEqual(target._subtitle.Paragraphs[0].Text, "<i>This is line one!" + Environment.NewLine + "Boy.</i>");
}
#endregion
}
}