Refactored "Remove text for HI" for better unit testing

This commit is contained in:
niksedk 2014-03-22 19:33:27 +01:00
parent a7eb372631
commit d1a5ceee1c
6 changed files with 1183 additions and 1081 deletions

View File

@ -50,7 +50,7 @@ namespace Nikse.SubtitleEdit.Forms
string _assStyle;
string _ssaStyle;
FormRemoveTextForHearImpaired _removeForHI = new FormRemoveTextForHearImpaired();
Nikse.SubtitleEdit.Logic.Forms.RemoveTextForHI _removeForHI;
ChangeCasing _changeCasing = new ChangeCasing();
ChangeCasingNames _changeCasingNames = new ChangeCasingNames();
bool _converting = false;
@ -198,6 +198,10 @@ namespace Nikse.SubtitleEdit.Forms
checkBoxOverwriteOriginalFiles.Checked = false;
checkBoxOverwriteOriginalFiles.Visible = false;
}
var hiSettings = new Nikse.SubtitleEdit.Logic.Forms.RemoveTextForHISettings();
hiSettings.LoadFromConfiguration();
_removeForHI = new Nikse.SubtitleEdit.Logic.Forms.RemoveTextForHI(hiSettings);
}
private void FixLargeFonts()

View File

@ -1,10 +1,9 @@
using System;
using Nikse.SubtitleEdit.Logic;
using Nikse.SubtitleEdit.Logic.Forms;
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Text;
using System.Text.RegularExpressions;
using System.Windows.Forms;
using Nikse.SubtitleEdit.Logic;
namespace Nikse.SubtitleEdit.Forms
{
@ -12,14 +11,14 @@ namespace Nikse.SubtitleEdit.Forms
{
Subtitle _subtitle;
readonly LanguageStructure.RemoveTextFromHearImpaired _language;
private List<string> _interjectionList;
private List<int> _warnings;
private int _warningIndex;
private RemoveTextForHI _removeTextForHILib;
public FormRemoveTextForHearImpaired()
{
InitializeComponent();
_removeTextForHILib = new RemoveTextForHI(GetSettings());
checkBoxRemoveTextBetweenSquares.Checked = Configuration.Settings.RemoveTextForHearingImpaired.RemoveTextBetweenBrackets;
checkBoxRemoveTextBetweenParentheses.Checked = Configuration.Settings.RemoveTextForHearingImpaired.RemoveTextBetweenParentheses;
checkBoxRemoveTextBetweenBrackets.Checked = Configuration.Settings.RemoveTextForHearingImpaired.RemoveTextBetweenCurlyBrackets;
@ -109,103 +108,6 @@ namespace Nikse.SubtitleEdit.Forms
return s.Trim();
}
private string RemoveTextBetweenTags(string startTag, string endTag, string text)
{
text = text.Trim();
if (startTag == "?" || endTag == "?")
{
if (text.StartsWith(startTag) && text.EndsWith(endTag))
return string.Empty;
return text;
}
int start = text.IndexOf(startTag);
if (start == -1 || start == text.Length - 1)
return text;
int end = text.IndexOf(endTag, start + 1);
while (start >= 0 && end > start)
{
text = text.Remove(start, (end - start)+1);
start = text.IndexOf(startTag);
if (start >= 0 && start < text.Length - 1)
end = text.IndexOf(endTag, start);
else
end = -1;
}
return text.Replace(" " + Environment.NewLine, Environment.NewLine).TrimEnd();
}
private string RemoveHearImpairedTags(string text)
{
if (checkBoxRemoveTextBetweenSquares.Checked)
{
text = RemoveTextBetweenTags("[", "]:", text);
text = RemoveTextBetweenTags("[", "]", text);
}
if (checkBoxRemoveTextBetweenBrackets.Checked)
{
text = RemoveTextBetweenTags("{", "}:", text);
text = RemoveTextBetweenTags("{", "}", text);
}
if (checkBoxRemoveTextBetweenQuestionMarks.Checked)
{
text = RemoveTextBetweenTags("?", "?:", text);
text = RemoveTextBetweenTags("?", "?", text);
}
if (checkBoxRemoveTextBetweenParentheses.Checked)
{
text = RemoveTextBetweenTags("(", "):", text);
text = RemoveTextBetweenTags("(", ")", text);
}
if (checkBoxRemoveTextBetweenCustomTags.Checked && comboBoxCustomStart.Text.Length > 0 && comboBoxCustomEnd.Text.Length > 0)
{
text = RemoveTextBetweenTags(comboBoxCustomStart.Text, comboBoxCustomEnd.Text, text);
}
return text;
}
private bool HasHearImpairedText(string text)
{
return RemoveHearImpairedTags(text) != text;
}
public bool HasHearImpariedTagsAtStart(string text)
{
if (checkBoxOnlyIfInSeparateLine.Checked)
return StartAndEndsWithHearImpariedTags(text);
return HasHearImpairedText(text);
}
public bool HasHearImpariedTagsAtEnd(string text)
{
if (checkBoxOnlyIfInSeparateLine.Checked)
return StartAndEndsWithHearImpariedTags(text);
return HasHearImpairedText(text);
}
private bool StartAndEndsWithHearImpariedTags(string text)
{
return (text.StartsWith("[") && text.EndsWith("]") && !text.Trim('[').Contains("[") && checkBoxRemoveTextBetweenSquares.Checked) ||
(text.StartsWith("{") && text.EndsWith("}") && !text.Trim('{').Contains("{") && checkBoxRemoveTextBetweenBrackets.Checked) ||
(text.StartsWith("?") && text.EndsWith("?") && !text.Trim('?').Contains("?") && checkBoxRemoveTextBetweenQuestionMarks.Checked) ||
(text.StartsWith("(") && text.EndsWith(")") && !text.Trim('(').Contains("(") && checkBoxRemoveTextBetweenParentheses.Checked) ||
(text.StartsWith("[") && text.EndsWith("]:") && !text.Trim('[').Contains("[") && checkBoxRemoveTextBetweenSquares.Checked) ||
(text.StartsWith("{") && text.EndsWith("}:") && !text.Trim('{').Contains("{") && checkBoxRemoveTextBetweenBrackets.Checked) ||
(text.StartsWith("?") && text.EndsWith("?:") && !text.Trim('?').Contains("?") && checkBoxRemoveTextBetweenQuestionMarks.Checked) ||
(text.StartsWith("(") && text.EndsWith("):") && !text.Trim('(').Contains("(") && checkBoxRemoveTextBetweenParentheses.Checked) ||
(checkBoxRemoveTextBetweenCustomTags.Checked &&
comboBoxCustomStart.Text.Length > 0 && comboBoxCustomEnd.Text.Length > 0 &&
text.StartsWith(comboBoxCustomStart.Text) && text.EndsWith(comboBoxCustomEnd.Text));
}
public void Initialize(Subtitle subtitle)
{
if (Environment.OSVersion.Version.Major < 6) // 6 == Vista/Win2008Server/Win7
@ -231,24 +133,18 @@ namespace Nikse.SubtitleEdit.Forms
this.Height = h;
}
private void AddWarning()
{
if (_warnings == null || _warningIndex < 0)
return;
_warnings.Add(_warningIndex);
}
private void GeneratePreview()
{
if (_subtitle == null)
return;
_warnings = new List<int>();
_removeTextForHILib.settings = GetSettings();
_removeTextForHILib._warnings = new List<int>();
listViewFixes.BeginUpdate();
listViewFixes.Items.Clear();
int count = 0;
int prevIndex = -1;
var settings = GetSettings();
foreach (Paragraph p in _subtitle.Paragraphs)
{
string prevText = string.Empty;
@ -257,8 +153,8 @@ namespace Nikse.SubtitleEdit.Forms
prevText = prev.Text;
prevIndex++;
_warningIndex = prevIndex;
string newText = RemoveTextFromHearImpaired(p.Text, prevText);
_removeTextForHILib._warningIndex = prevIndex;
string newText = _removeTextForHILib.RemoveTextFromHearImpaired(p.Text, prevText);
bool hit = p.Text.Replace(" ", string.Empty) != newText.Replace(" ", string.Empty);
if (hit)
{
@ -270,730 +166,12 @@ namespace Nikse.SubtitleEdit.Forms
groupBoxLinesFound.Text = string.Format(_language.LinesFoundX, count);
}
private string RemoveHearImpairedtagsInsideLine(string newText)
{
int i = 5;
while (i < newText.Length)
{
string s = newText.Substring(i);
if (i > 5 && s.Length > 2 && (s.StartsWith(".") || s.StartsWith("!") || s.StartsWith("?")))
{
if (s[1] == ' ' || s.Substring(1).StartsWith("<i>") || s.Substring(1).StartsWith("</i>"))
{
string pre = " ";
if (s.Substring(1).StartsWith("<i>"))
pre = "<i>";
else if (s.Substring(1).StartsWith(" <i>"))
pre = " <i>";
else if (s.Substring(1).StartsWith("</i>"))
pre = "</i>";
s = s.Remove(0, 1 + pre.Length);
if (s.StartsWith(" ") && s.Length > 1)
{
pre += " ";
s = s.Remove(0, 1);
}
if (HasHearImpariedTagsAtStart(s))
{
s = RemoveStartEndTags(s);
newText = newText.Substring(0, i+1) + pre + " " + s;
newText = newText.Replace("<i></i>", string.Empty);
newText = newText.Replace("<i> </i>", " ");
newText = newText.Replace(" ", " ");
newText = newText.Replace(" ", " ");
newText = newText.Replace(" " + Environment.NewLine, Environment.NewLine);
}
}
}
i++;
}
return newText;
}
private string RemoveColon(string text, string prevText)
{
if (!checkBoxRemoveTextBeforeColon.Checked)
return text;
if (text.IndexOf(":") < 0)
return text;
// House 7x01 line 52: and she would like you to do three things:
// Okay or remove???
if (text.IndexOf(':') > 0 && text.IndexOf(':') == text.Length - 1 && text != text.ToUpper())
return text;
string newText = string.Empty;
string[] parts = text.Trim().Split(Environment.NewLine.ToCharArray(), StringSplitOptions.RemoveEmptyEntries);
int noOfNames = 0;
int count = 0;
bool removedInFirstLine = false;
bool removedInSecondLine = false;
foreach (string s in parts)
{
int indexOfColon = s.IndexOf(":");
if (indexOfColon > 0)
{
string pre = s.Substring(0, indexOfColon);
if (checkBoxRemoveTextBeforeColonOnlyUppercase.Checked && pre.Replace("<i>", string.Empty) != pre.Replace("<i>", string.Empty).ToUpper())
{
newText = newText + Environment.NewLine + s;
newText = newText.Trim();
}
else
{
StripableText st = new StripableText(pre);
if (count == 1 && Utilities.CountTagInText(text, Environment.NewLine) == 1 && removedInFirstLine && Utilities.CountTagInText(s, ":") == 1 &&
!newText.EndsWith(".") && !newText.EndsWith("!") && !newText.EndsWith("?") && !newText.EndsWith(".</i>") && !newText.EndsWith("!</i>") && !newText.EndsWith("?</i>") &&
s != s.ToUpper())
{
if (pre.Contains("<i>") && s.Contains("</i>"))
newText = newText + Environment.NewLine + "<i>" + s;
else if (pre.Contains("<b>") && s.Contains("</b>"))
newText = newText + Environment.NewLine + "<b>" + s;
else if (pre.Contains("[") && s.Contains("]"))
newText = newText + Environment.NewLine + "[" + s;
else if (pre.Contains("(") && s.EndsWith(")"))
newText = newText + Environment.NewLine + "(" + s;
else
newText = newText + Environment.NewLine + s;
}
else if (count == 1 && Utilities.CountTagInText(text, Environment.NewLine) == 1 && indexOfColon > 15 && s.Substring(0, indexOfColon).Contains(" ") && Utilities.CountTagInText(s, ":") == 1 &&
!newText.EndsWith(".") && !newText.EndsWith("!") && !newText.EndsWith("?") && !newText.EndsWith(".</i>") && !newText.EndsWith("!</i>") && !newText.EndsWith("?</i>") &&
s != s.ToUpper())
{
if (pre.Contains("<i>") && s.Contains("</i>"))
newText = newText + Environment.NewLine + "<i>" + s;
else if (pre.Contains("<b>") && s.Contains("</b>"))
newText = newText + Environment.NewLine + "<b>" + s;
else if (pre.Contains("[") && s.Contains("]"))
newText = newText + Environment.NewLine + "[" + s;
else if (pre.Contains("(") && s.EndsWith(")"))
newText = newText + Environment.NewLine + "(" + s;
else
newText = newText + Environment.NewLine + s;
}
else if (Utilities.CountTagInText(s, ":") == 1)
{
bool remove = true;
if (indexOfColon > 0 && indexOfColon < s.Length - 1)
{
if ("1234567890".Contains(s.Substring(indexOfColon - 1, 1)) && "1234567890".Contains(s.Substring(indexOfColon + 1, 1)))
remove = false;
}
if (s.StartsWith("Previously on") || s.StartsWith("<i>Previously on"))
remove = false;
if (remove && checkBoxColonSeparateLine.Checked)
{
if (indexOfColon == s.Length - 1 || s.Substring(indexOfColon + 1).StartsWith(Environment.NewLine))
remove = true;
else
remove = false;
}
if (remove)
{
string content = s.Substring(indexOfColon + 1).Trim();
if (content.Length > 0)
{
if (pre.Contains("<i>") && content.Contains("</i>"))
newText = newText + Environment.NewLine + "<i>" + content;
else if (pre.Contains("<b>") && content.Contains("</b>"))
newText = newText + Environment.NewLine + "<b>" + content;
else if (pre.Contains("[") && content.Contains("]"))
newText = newText + Environment.NewLine + "[" + content;
else if (pre.Contains("(") && content.EndsWith(")"))
newText = newText + Environment.NewLine + "(" + content;
else
newText = newText + Environment.NewLine + content;
if (count == 0)
removedInFirstLine = true;
else if (count == 1)
removedInSecondLine = true;
}
newText = newText.Trim();
if (text.StartsWith("(") && newText.EndsWith(")") && !newText.Contains("("))
newText = newText.TrimEnd(')');
else if (newText.EndsWith("</i>") && text.StartsWith("<i>") && !newText.StartsWith("<i>"))
newText = "<i>" + newText;
else if (newText.EndsWith("</b>") && text.StartsWith("<b>") && !newText.StartsWith("<b>"))
newText = "<b>" + newText;
if (!IsHIDescription(st.StrippedText))
noOfNames++;
}
else
{
newText = newText + Environment.NewLine + s;
newText = newText.Trim();
if (newText.EndsWith("</i>") && text.StartsWith("<i>") && !newText.StartsWith("<i>"))
newText = "<i>" + newText;
else if (newText.EndsWith("</b>") && text.StartsWith("<b>") && !newText.StartsWith("<b>"))
newText = "<b>" + newText;
}
}
else
{
string s2 = s;
for (int k = 0; k < 2; k++)
{
if (s2.Contains(":"))
{
int colonIndex = s2.IndexOf(":");
string start = s2.Substring(0, colonIndex);
bool doContinue = true;
if (checkBoxRemoveTextBeforeColonOnlyUppercase.Checked && start != start.ToUpper())
doContinue = false;
if (doContinue)
{
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 (count == 0)
removedInFirstLine = true;
else if (count == 1)
removedInSecondLine = true;
}
}
newText = newText + Environment.NewLine + s2;
newText = newText.Trim();
}
}
}
else
{
newText = newText + Environment.NewLine + s;
newText = newText.Trim();
if (newText.EndsWith("</i>") && text.StartsWith("<i>") && !newText.StartsWith("<i>"))
newText = "<i>" + newText;
else if (newText.EndsWith("</b>") && text.StartsWith("<b>") && !newText.StartsWith("<b>"))
newText = "<b>" + newText;
}
count++;
}
newText = newText.Trim();
if (noOfNames > 0 && Utilities.CountTagInText(newText, Environment.NewLine) == 1)
{
int indexOfDialogChar = newText.IndexOf('-');
bool insertDash = true;
string[] arr = newText.Split(Environment.NewLine.ToCharArray(), StringSplitOptions.RemoveEmptyEntries);
if (arr.Length == 2 && arr[0].Length > 1 && arr[1].Length > 1)
{
string arr0 = new StripableText(arr[0]).StrippedText;
string arr1 = new StripableText(arr[1]).StrippedText;
//line continuation?
if (arr0.Length > 0 && arr1.Length > 1 && (Utilities.LowercaseLetters + ",").Contains(arr0.Substring(arr0.Length - 1)) &&
Utilities.LowercaseLetters.Contains(arr1.Substring(0, 1)))
{
if (new StripableText(arr[1]).Pre.Contains("...") == false)
insertDash = false;
}
if (arr0.Length > 0 && arr1.Length > 1 && !(arr[0].EndsWith(".") || arr[0].EndsWith("!") || arr[0].EndsWith("?") || arr[0].EndsWith("</i>")) &&
!(new StripableText(arr[1]).Pre.Contains("-")))
{
insertDash = false;
}
if (removedInFirstLine && !removedInSecondLine && !text.StartsWith("-") && !text.StartsWith("<i>-"))
{
if (insertDash && removedInFirstLine && (arr[1].StartsWith("-") || arr[1].StartsWith("<i>-")))
insertDash = true;
else
insertDash = false;
}
}
if (insertDash)
{
if (indexOfDialogChar < 0 || indexOfDialogChar > 4)
{
StripableText st = new StripableText(newText, "", "");
newText = st.Pre + "- " + st.StrippedText + st.Post;
}
int indexOfNewLine = newText.IndexOf(Environment.NewLine);
string second = newText.Substring(indexOfNewLine).Trim();
indexOfDialogChar = second.IndexOf('-');
if (indexOfDialogChar < 0 || indexOfDialogChar > 6)
{
StripableText st = new StripableText(second, "", "");
second = st.Pre + "- " + st.StrippedText + st.Post;
newText = newText.Remove(indexOfNewLine) + Environment.NewLine + second;
}
}
}
else if (!newText.Contains(Environment.NewLine) && newText.Contains("-"))
{
StripableText st = new StripableText(newText);
if (st.Pre.Contains("-"))
newText = st.Pre.Replace("-", string.Empty) + st.StrippedText + st.Post;
}
else if (Utilities.CountTagInText(newText, Environment.NewLine) == 1 && removedInFirstLine == false && removedInSecondLine == true)
{
string noTags = Utilities.RemoveHtmlTags(newText, true).Trim();
bool insertDash = noTags.StartsWith("-") && Utilities.CountTagInText(noTags, "-") == 1;
if (insertDash)
{
if (newText.Contains(Environment.NewLine + "<i>"))
newText = newText.Replace(Environment.NewLine + "<i>", Environment.NewLine + "<i>- ");
else
newText = newText.Replace(Environment.NewLine, Environment.NewLine + "- ");
}
}
if (text.Contains("<i>") && !newText.Contains("<i>") && newText.EndsWith("</i>"))
newText = "<i>" + newText;
return newText;
}
internal string RemoveTextFromHearImpaired(string text, string prevText)
{
if (checkBoxRemoveWhereContains.Checked && comboBoxRemoveIfTextContains.Text.Length > 0 && text.Contains(comboBoxRemoveIfTextContains.Text))
{
return string.Empty;
}
string oldText = text;
text = RemoveColon(text, prevText);
string pre = " >-\"'`´♪¿¡.…—";
string post = " -\"'`´♪.!?:…—";
if (checkBoxRemoveTextBetweenCustomTags.Checked)
{
pre = pre.Replace(comboBoxCustomStart.Text, string.Empty);
post = post.Replace(comboBoxCustomEnd.Text, string.Empty);
}
var st = new StripableText(text, pre, post);
var sb = new StringBuilder();
string[] parts = st.StrippedText.Trim().Split(Environment.NewLine.ToCharArray(), StringSplitOptions.RemoveEmptyEntries);
int lineNumber = 0;
bool removedDialogInFirstLine = false;
int noOfNamesRemoved = 0;
int noOfNamesRemovedNotInLineOne = 0;
foreach (string s in parts)
{
StripableText stSub = new StripableText(s, pre, post);
if (!StartAndEndsWithHearImpariedTags(stSub.StrippedText))
{
if (removedDialogInFirstLine && stSub.Pre.Contains("- "))
stSub.Pre = stSub.Pre.Replace("- ", string.Empty);
string newText = stSub.StrippedText;
newText = RemoveHearImpairedTags(newText);
if (stSub.StrippedText.Length - newText.Length > 2)
{
string removedText = GetRemovedString(stSub.StrippedText, newText);
if (!IsHIDescription(removedText))
{
noOfNamesRemoved++;
if (lineNumber > 0)
noOfNamesRemovedNotInLineOne++;
}
}
sb.AppendLine(stSub.Pre + newText + stSub.Post);
}
else
{
if (!IsHIDescription(stSub.StrippedText))
{
noOfNamesRemoved++;
if (lineNumber > 0)
noOfNamesRemovedNotInLineOne++;
}
if (st.Pre.Contains("- ") && lineNumber == 0)
{
st.Pre = st.Pre.Replace("- ", string.Empty);
removedDialogInFirstLine = true;
}
if (st.Pre.Contains("<i>") && stSub.Post.Contains("</i>"))
st.Pre = st.Pre.Replace("<i>", string.Empty);
if (s.Contains("<i>") && !s.Contains("</i>") && st.Post.Contains("</i>"))
st.Post = st.Post.Replace("</i>", string.Empty);
}
lineNumber++;
}
text = st.Pre + sb.ToString().Trim() + st.Post;
text = text.Replace("<i></i>", string.Empty).Trim();
text = RemoveColon(text, prevText);
text = RemoveLineIfAllUppercase(text);
text = RemoveHearImpairedtagsInsideLine(text);
if (checkBoxRemoveInterjections.Checked)
text = RemoveInterjections(text);
st = new StripableText(text, " >-\"'`´♪¿¡.…—", " -\"'`´♪.!?:…—");
text = st.StrippedText;
if (StartAndEndsWithHearImpariedTags(text))
{
text = RemoveStartEndTags(text);
}
text = RemoveHearImpairedTags(text);
// fix 3 lines to two liners - if only two lines
if (noOfNamesRemoved >= 1 && Utilities.CountTagInText(text, Environment.NewLine) == 2)
{
string[] a = Utilities.RemoveHtmlTags(text).Replace(" ", string.Empty).Split("!?.".ToCharArray(), StringSplitOptions.RemoveEmptyEntries);
if (a.Length == 2)
{
StripableText temp = new StripableText(text);
temp.StrippedText = temp.StrippedText.Replace(Environment.NewLine, " ");
int splitIndex = temp.StrippedText.LastIndexOf("!");
if (splitIndex == -1)
splitIndex = temp.StrippedText.LastIndexOf("?");
if (splitIndex == -1)
splitIndex = temp.StrippedText.LastIndexOf(".");
if (splitIndex > 0)
{
text = temp.Pre + temp.StrippedText.Insert(splitIndex + 1, Environment.NewLine) + temp.Post;
}
}
}
if (!text.StartsWith("-") && noOfNamesRemoved >= 1 && Utilities.CountTagInText(text, Environment.NewLine) == 1)
{
string[] arr = text.Split(Environment.NewLine.ToCharArray());
string part0 = arr[0].Trim().Replace("</i>", string.Empty).Trim();
if (!part0.EndsWith(",") && (!part0.EndsWith("-") || noOfNamesRemovedNotInLineOne > 0))
{
if (part0.Length > 0 && ".!?".Contains(part0.Substring(part0.Length - 1)))
{
if (noOfNamesRemovedNotInLineOne > 0)
{
if (!st.Pre.Contains("-"))
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 (!string.IsNullOrEmpty(text))
text = st.Pre + text + st.Post;
if (oldText.Trim().StartsWith("- ") &&
(oldText.Contains(Environment.NewLine + "- ") || oldText.Contains(Environment.NewLine + " - ")) &&
text != null && !text.Contains(Environment.NewLine))
{
text = text.TrimStart().TrimStart('-').TrimStart();
}
if (oldText != text)
{
// insert spaces before "-"
text = text.Replace(Environment.NewLine + "- <i>", Environment.NewLine + "<i>- ");
text = text.Replace(Environment.NewLine + "-<i>", Environment.NewLine + "<i>- ");
if (text.StartsWith("-") && text.Length > 2 && text[1] != ' ' && text[1] != '-')
text = text.Insert(1, " ");
if (text.StartsWith("<i>-") && text.Length > 5 && text[4] != ' ' && text[4] != '-')
text = text.Insert(4, " ");
if (text.Contains(Environment.NewLine + "-"))
{
int index = text.IndexOf(Environment.NewLine + "-");
if (index + 4 < text.Length && text[index + Environment.NewLine.Length + 1] != ' ' && text[index + Environment.NewLine.Length + 1] != '-')
text = text.Insert(index + Environment.NewLine.Length + 1, " ");
}
if (text.Contains(Environment.NewLine + "<i>-"))
{
int index = text.IndexOf(Environment.NewLine + "<i>-");
if (index + 5 < text.Length && text[index + Environment.NewLine.Length + 4] != ' ' && text[index + Environment.NewLine.Length + 4] != '-')
text = text.Insert(index + Environment.NewLine.Length + 4, " ");
}
}
return text.Trim();
}
private bool IsHIDescription(string text)
{
text = text.ToLower();
text = text.TrimEnd(" ()[]?{}".ToCharArray());
text = text.TrimStart(" ()[]?{}".ToCharArray());
if (text.Trim().Replace("mr. ", string.Empty).Replace("mrs. ", string.Empty).Replace("dr. ", string.Empty).Contains(" "))
AddWarning();
if (text == "sighing" ||
text == "cackles" ||
text == "cheers" ||
text == "chitters" ||
text == "chuckles" ||
text == "exclaims" ||
text == "gasps" ||
text == "grunts" ||
text == "groans" ||
text == "growls" ||
text == "explosion" ||
text == "laughs" ||
text == "noise" ||
text.StartsWith("engine ") ||
text == "roars" ||
text == "scoff" ||
text == "screeches" ||
text == "shouts" ||
text == "shrieks" ||
text == "sigh" ||
text == "sighs" ||
text == "singing" ||
text == "snores" ||
text == "stutters" ||
text == "thuds" ||
text == "trumpets" ||
text == "whispers" ||
text == "whisper" ||
text == "whistles" ||
text.EndsWith("ing"))
return true;
return false;
}
private string GetRemovedString(string oldText, string newText)
{
oldText = oldText.ToLower();
newText = newText.ToLower();
int start = oldText.IndexOf(newText);
string result;
if (start > 0)
result = oldText.Substring(0, oldText.Length - newText.Length);
else
result = oldText.Substring(newText.Length);
result = result.TrimEnd(" ()[]?{}".ToCharArray());
result = result.TrimStart(" ()[]?{}".ToCharArray());
return result;
}
static int CompareLength(string a, string b)
{
return b.Length.CompareTo(a.Length);
}
private string RemoveInterjections(string text)
{
string oldText = text;
if (_interjectionList == null)
{
string[] arr = Configuration.Settings.Tools.Interjections.Split(";".ToCharArray(), StringSplitOptions.RemoveEmptyEntries);
_interjectionList = new List<string>();
foreach (string s in arr)
{
if (!_interjectionList.Contains(s))
_interjectionList.Add(s);
string lower = s.ToLower();
if (!_interjectionList.Contains(lower))
_interjectionList.Add(lower);
}
_interjectionList.Sort(new Comparison<string>(CompareLength));
}
bool doRepeat = true;
while (doRepeat)
{
doRepeat = false;
foreach (string s in _interjectionList)
{
if (text.Contains(s))
{
var regex = new Regex("\\b" + s + "\\b");
Match match = regex.Match(text);
if (match.Success)
{
int index = match.Index;
string temp = text.Remove(index, s.Length);
string pre = string.Empty;
if (index > 0)
doRepeat = true;
bool removeAfter = true;
if (temp.Length > index - s.Length + 3 && index > s.Length)
{
if (temp.Substring(index - s.Length + 1, 3) == ", !")
{
temp = temp.Remove(index - s.Length + 1, 2);
removeAfter = false;
}
else if (temp.Substring(index - s.Length + 1, 3) == ", ?")
{
temp = temp.Remove(index - s.Length + 1, 2);
removeAfter = false;
}
else if (temp.Substring(index - s.Length + 1, 3) == ", .")
{
temp = temp.Remove(index - s.Length + 1, 2);
removeAfter = false;
}
}
if (removeAfter && temp.Length > index - s.Length + 2 && index > s.Length)
{
if (temp.Substring(index - s.Length, 3) == ", !")
{
temp = temp.Remove(index - s.Length, 2);
removeAfter = false;
}
else if (temp.Substring(index - s.Length, 3) == ", ?")
{
temp = temp.Remove(index - s.Length, 2);
removeAfter = false;
}
else if (temp.Substring(index - s.Length, 3) == ", .")
{
temp = temp.Remove(index - s.Length, 2);
removeAfter = false;
}
}
if (removeAfter && temp.Length > index - s.Length + 2 && index > s.Length)
{
if (temp.Substring(index - s.Length + 1, 2) == "-!")
{
temp = temp.Remove(index - s.Length + 1, 1);
removeAfter = false;
}
else if (temp.Substring(index - s.Length + 1, 2) == "-?")
{
temp = temp.Remove(index - s.Length + 1, 1);
removeAfter = false;
}
else if (temp.Substring(index - s.Length + 1, 2) == "-.")
{
temp = temp.Remove(index - s.Length + 1, 1);
removeAfter = false;
}
}
if (removeAfter)
{
if (index == 0)
{
if (!string.IsNullOrEmpty(temp) && temp.StartsWith("-"))
temp = temp.Remove(0, 1).Trim();
}
else if (index == 3 && !string.IsNullOrEmpty(temp) && temp.StartsWith("<i>-"))
{
temp = temp.Remove(3, 1);
}
else if (index > 0)
{
pre = text.Substring(0, index);
temp = temp.Remove(0, index);
if (pre.EndsWith("-") && temp.StartsWith("-"))
temp = temp.Remove(0, 1);
if (pre.EndsWith("- ") && temp.StartsWith("-"))
temp = temp.Remove(0, 1);
}
while (temp.Length > 0 && (temp.StartsWith(" ") || temp.StartsWith(",") || temp.StartsWith(".") || temp.StartsWith("!") || temp.StartsWith("?")))
{
temp = temp.Remove(0, 1);
doRepeat = true;
}
if (temp.Length > 0 && s[0].ToString() != s[0].ToString().ToLower())
{
temp = temp.Remove(0, 1).Insert(0, temp[0].ToString().ToUpper());
doRepeat = true;
}
temp = pre + temp;
}
if (temp.EndsWith(Environment.NewLine + "- "))
temp = temp.Remove(temp.Length - 4, 4);
var st = new StripableText(temp);
if (st.StrippedText.Length == 0)
return string.Empty;
if (!temp.Contains(Environment.NewLine) && text.Contains(Environment.NewLine) && temp.StartsWith("-"))
temp = temp.Remove(0,1).Trim();
text = temp;
}
}
}
}
string[] lines = text.Split(Environment.NewLine.ToCharArray(), StringSplitOptions.RemoveEmptyEntries);
if (text != oldText && lines.Length == 2)
{
if (lines[0] == "-" && lines[1] == "-")
return string.Empty;
if (lines[0].StartsWith("-") && lines[0].Length > 1 && lines[1].Trim() == "-")
return lines[0].Remove(0, 1).Trim();
if (lines[1].StartsWith("-") && lines[1].Length > 1 && lines[0].Trim() == "-")
return lines[1].Remove(0, 1).Trim();
if (lines[0].Length > 1 && (lines[1] == "-") || lines[1] == "." || lines[1] == "!" || lines[1] == "?")
{
if (oldText.Contains(Environment.NewLine + "-") && lines[0].StartsWith("-"))
lines[0] = lines[0].Remove(0, 1);
return lines[0].Trim();
}
}
return text;
}
private string RemoveStartEndTags(string text)
{
string newText = text;
string s = text;
if (s.StartsWith("[") && s.IndexOf("]") > 0 && checkBoxRemoveTextBetweenSquares.Checked)
newText = s.Remove(0, s.IndexOf("]") + 1);
else if (s.StartsWith("{") && s.IndexOf("}") > 0 && checkBoxRemoveTextBetweenBrackets.Checked)
newText = s.Remove(0, s.IndexOf("}") + 1);
else if (s.StartsWith("?") && s.IndexOf("?", 1) > 0 && checkBoxRemoveTextBetweenQuestionMarks.Checked)
newText = s.Remove(0, s.IndexOf("?", 1) + 1);
else if (s.StartsWith("(") && s.IndexOf(")") > 0 && checkBoxRemoveTextBetweenParentheses.Checked)
newText = s.Remove(0, s.IndexOf(")") + 1);
else if (s.StartsWith("[") && s.IndexOf("]:") > 0 && checkBoxRemoveTextBetweenSquares.Checked)
newText = s.Remove(0, s.IndexOf("]:") + 2);
else if (s.StartsWith("{") && s.IndexOf("}:") > 0 && checkBoxRemoveTextBetweenBrackets.Checked)
newText = s.Remove(0, s.IndexOf("}:") + 2);
else if (s.StartsWith("?") && s.IndexOf("?:", 1) > 0 && checkBoxRemoveTextBetweenQuestionMarks.Checked)
newText = s.Remove(0, s.IndexOf("?:") + 2);
else if (s.StartsWith("(") && s.IndexOf("):") > 0 && checkBoxRemoveTextBetweenParentheses.Checked)
newText = s.Remove(0, s.IndexOf("):") + 2);
else if (checkBoxRemoveTextBetweenCustomTags.Checked &&
s.Length > 0 && comboBoxCustomEnd.Text.Length > 0 && comboBoxCustomStart.Text.Length > 0 &&
s.StartsWith(comboBoxCustomStart.Text) && s.LastIndexOf(comboBoxCustomEnd.Text) > 0)
newText = s.Remove(0, s.LastIndexOf(comboBoxCustomEnd.Text) + comboBoxCustomEnd.Text.Length);
if (newText != text)
newText = newText.TrimStart(' ');
return newText;
}
private void AddToListView(Paragraph p, string newText)
{
var item = new ListViewItem(string.Empty) {Tag = p, Checked = true};
if (_warnings != null && _warnings.Contains(_warningIndex))
if (_removeTextForHILib._warnings != null && _removeTextForHILib._warnings.Contains(_removeTextForHILib._warningIndex))
{
item.UseItemStyleForSubItems = true;
item.BackColor = Color.PeachPuff;
@ -1022,6 +200,7 @@ namespace Nikse.SubtitleEdit.Forms
public int RemoveTextFromHearImpaired()
{
int count = 0;
var settings = GetSettings();
for (int i = _subtitle.Paragraphs.Count - 1; i >= 0; i--)
{
Paragraph p = _subtitle.Paragraphs[i];
@ -1032,7 +211,8 @@ namespace Nikse.SubtitleEdit.Forms
if (prev != null)
prevText = prev.Text;
string newText = RemoveTextFromHearImpaired(p.Text, prevText);
_removeTextForHILib.settings = GetSettings();
string newText = _removeTextForHILib.RemoveTextFromHearImpaired(p.Text, prevText);
if (string.IsNullOrEmpty(newText))
{
_subtitle.Paragraphs.RemoveAt(i);
@ -1122,31 +302,6 @@ namespace Nikse.SubtitleEdit.Forms
Cursor = Cursors.Default;
}
private string RemoveLineIfAllUppercase(string text)
{
if (!checkBoxRemoveIfAllUppercase.Checked)
return text;
string[] lines = text.Replace(Environment.NewLine, "\n").Replace("\r", "\n").Split('\n');
var sb = new StringBuilder();
foreach (string line in lines)
{
string lineNoHtml = Utilities.RemoveHtmlTags(line);
string tmp = lineNoHtml.TrimEnd(new char[] { '.', '!', '?', ':', }).Trim();
if (lineNoHtml != lineNoHtml.ToLower() && lineNoHtml == lineNoHtml.ToUpper())
{
if (tmp == "YES" || tmp == "NO" || tmp == "WHY" || tmp == "HI" || tmp.Length == 1)
{
sb.AppendLine(line);
}
}
else
{
sb.AppendLine(line);
}
}
return sb.ToString().Trim();
}
private void checkBoxRemoveIfAllUppercase_CheckedChanged(object sender, EventArgs e)
{
@ -1155,5 +310,26 @@ namespace Nikse.SubtitleEdit.Forms
Cursor = Cursors.Default;
}
public RemoveTextForHISettings GetSettings()
{
var settings = new RemoveTextForHISettings();
settings.OnlyIfInSeparateLine = checkBoxOnlyIfInSeparateLine.Checked;
settings.RemoveIfAllUppercase = checkBoxRemoveIfAllUppercase.Checked;
settings.RemoveTextBeforeColon = checkBoxRemoveTextBeforeColon.Checked;
settings.RemoveTextBeforeColonOnlyUppercase = checkBoxRemoveTextBeforeColonOnlyUppercase.Checked;
settings.ColonSeparateLine = checkBoxColonSeparateLine.Checked;
settings.RemoveWhereContains = checkBoxRemoveWhereContains.Checked;
settings.RemoveIfTextContains = comboBoxRemoveIfTextContains.Text;
settings.RemoveTextBetweenCustomTags = checkBoxRemoveTextBetweenCustomTags.Checked;
settings.RemoveInterjections = checkBoxRemoveInterjections.Checked;
settings.RemoveTextBetweenSquares = checkBoxRemoveTextBetweenSquares.Checked;
settings.RemoveTextBetweenBrackets = checkBoxRemoveTextBetweenBrackets.Checked;
settings.RemoveTextBetweenQuestionMarks = checkBoxRemoveTextBetweenQuestionMarks.Checked;
settings.RemoveTextBetweenParentheses = checkBoxRemoveTextBetweenParentheses.Checked;
settings.CustomStart = comboBoxCustomStart.Text;
settings.CustomEnd = comboBoxCustomEnd.Text;
return settings;
}
}
}

View File

@ -0,0 +1,873 @@
using System;
using System.Collections.Generic;
using System.Text;
using System.Text.RegularExpressions;
namespace Nikse.SubtitleEdit.Logic.Forms
{
public class RemoveTextForHI
{
public RemoveTextForHISettings settings { get; set; }
private List<string> _interjectionList;
public List<int> _warnings;
public int _warningIndex;
public RemoveTextForHI(RemoveTextForHISettings removeTextForHISettings)
{
settings = removeTextForHISettings;
}
public string RemoveHearImpairedtagsInsideLine(string newText)
{
int i = 5;
while (i < newText.Length)
{
string s = newText.Substring(i);
if (i > 5 && s.Length > 2 && (s.StartsWith(".") || s.StartsWith("!") || s.StartsWith("?")))
{
if (s[1] == ' ' || s.Substring(1).StartsWith("<i>") || s.Substring(1).StartsWith("</i>"))
{
string pre = " ";
if (s.Substring(1).StartsWith("<i>"))
pre = "<i>";
else if (s.Substring(1).StartsWith(" <i>"))
pre = " <i>";
else if (s.Substring(1).StartsWith("</i>"))
pre = "</i>";
s = s.Remove(0, 1 + pre.Length);
if (s.StartsWith(" ") && s.Length > 1)
{
pre += " ";
s = s.Remove(0, 1);
}
if (HasHearImpariedTagsAtStart(s))
{
s = RemoveStartEndTags(s);
newText = newText.Substring(0, i + 1) + pre + " " + s;
newText = newText.Replace("<i></i>", string.Empty);
newText = newText.Replace("<i> </i>", " ");
newText = newText.Replace(" ", " ");
newText = newText.Replace(" ", " ");
newText = newText.Replace(" " + Environment.NewLine, Environment.NewLine);
}
}
}
i++;
}
return newText;
}
public string RemoveColon(string text, string prevText)
{
if (!settings.RemoveTextBeforeColon)
return text;
if (text.IndexOf(":") < 0)
return text;
// House 7x01 line 52: and she would like you to do three things:
// Okay or remove???
if (text.IndexOf(':') > 0 && text.IndexOf(':') == text.Length - 1 && text != text.ToUpper())
return text;
string newText = string.Empty;
string[] parts = text.Trim().Split(Environment.NewLine.ToCharArray(), StringSplitOptions.RemoveEmptyEntries);
int noOfNames = 0;
int count = 0;
bool removedInFirstLine = false;
bool removedInSecondLine = false;
foreach (string s in parts)
{
int indexOfColon = s.IndexOf(":");
if (indexOfColon > 0)
{
string pre = s.Substring(0, indexOfColon);
if (settings.RemoveTextBeforeColonOnlyUppercase && pre.Replace("<i>", string.Empty) != pre.Replace("<i>", string.Empty).ToUpper())
{
newText = newText + Environment.NewLine + s;
newText = newText.Trim();
}
else
{
StripableText st = new StripableText(pre);
if (count == 1 && Utilities.CountTagInText(text, Environment.NewLine) == 1 && removedInFirstLine && Utilities.CountTagInText(s, ":") == 1 &&
!newText.EndsWith(".") && !newText.EndsWith("!") && !newText.EndsWith("?") && !newText.EndsWith(".</i>") && !newText.EndsWith("!</i>") && !newText.EndsWith("?</i>") &&
s != s.ToUpper())
{
if (pre.Contains("<i>") && s.Contains("</i>"))
newText = newText + Environment.NewLine + "<i>" + s;
else if (pre.Contains("<b>") && s.Contains("</b>"))
newText = newText + Environment.NewLine + "<b>" + s;
else if (pre.Contains("[") && s.Contains("]"))
newText = newText + Environment.NewLine + "[" + s;
else if (pre.Contains("(") && s.EndsWith(")"))
newText = newText + Environment.NewLine + "(" + s;
else
newText = newText + Environment.NewLine + s;
}
else if (count == 1 && Utilities.CountTagInText(text, Environment.NewLine) == 1 && indexOfColon > 15 && s.Substring(0, indexOfColon).Contains(" ") && Utilities.CountTagInText(s, ":") == 1 &&
!newText.EndsWith(".") && !newText.EndsWith("!") && !newText.EndsWith("?") && !newText.EndsWith(".</i>") && !newText.EndsWith("!</i>") && !newText.EndsWith("?</i>") &&
s != s.ToUpper())
{
if (pre.Contains("<i>") && s.Contains("</i>"))
newText = newText + Environment.NewLine + "<i>" + s;
else if (pre.Contains("<b>") && s.Contains("</b>"))
newText = newText + Environment.NewLine + "<b>" + s;
else if (pre.Contains("[") && s.Contains("]"))
newText = newText + Environment.NewLine + "[" + s;
else if (pre.Contains("(") && s.EndsWith(")"))
newText = newText + Environment.NewLine + "(" + s;
else
newText = newText + Environment.NewLine + s;
}
else if (Utilities.CountTagInText(s, ":") == 1)
{
bool remove = true;
if (indexOfColon > 0 && indexOfColon < s.Length - 1)
{
if ("1234567890".Contains(s.Substring(indexOfColon - 1, 1)) && "1234567890".Contains(s.Substring(indexOfColon + 1, 1)))
remove = false;
}
if (s.StartsWith("Previously on") || s.StartsWith("<i>Previously on"))
remove = false;
if (remove && settings.ColonSeparateLine)
{
if (indexOfColon == s.Length - 1 || s.Substring(indexOfColon + 1).StartsWith(Environment.NewLine))
remove = true;
else
remove = false;
}
if (remove)
{
string content = s.Substring(indexOfColon + 1).Trim();
if (content.Length > 0)
{
if (pre.Contains("<i>") && content.Contains("</i>"))
newText = newText + Environment.NewLine + "<i>" + content;
else if (pre.Contains("<b>") && content.Contains("</b>"))
newText = newText + Environment.NewLine + "<b>" + content;
else if (pre.Contains("[") && content.Contains("]"))
newText = newText + Environment.NewLine + "[" + content;
else if (pre.Contains("(") && content.EndsWith(")"))
newText = newText + Environment.NewLine + "(" + content;
else
newText = newText + Environment.NewLine + content;
if (count == 0)
removedInFirstLine = true;
else if (count == 1)
removedInSecondLine = true;
}
newText = newText.Trim();
if (text.StartsWith("(") && newText.EndsWith(")") && !newText.Contains("("))
newText = newText.TrimEnd(')');
else if (newText.EndsWith("</i>") && text.StartsWith("<i>") && !newText.StartsWith("<i>"))
newText = "<i>" + newText;
else if (newText.EndsWith("</b>") && text.StartsWith("<b>") && !newText.StartsWith("<b>"))
newText = "<b>" + newText;
if (!IsHIDescription(st.StrippedText))
noOfNames++;
}
else
{
newText = newText + Environment.NewLine + s;
newText = newText.Trim();
if (newText.EndsWith("</i>") && text.StartsWith("<i>") && !newText.StartsWith("<i>"))
newText = "<i>" + newText;
else if (newText.EndsWith("</b>") && text.StartsWith("<b>") && !newText.StartsWith("<b>"))
newText = "<b>" + newText;
}
}
else
{
string s2 = s;
for (int k = 0; k < 2; k++)
{
if (s2.Contains(":"))
{
int colonIndex = s2.IndexOf(":");
string start = s2.Substring(0, colonIndex);
bool doContinue = true;
if (settings.RemoveTextBeforeColonOnlyUppercase && start != start.ToUpper())
doContinue = false;
if (doContinue)
{
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 (count == 0)
removedInFirstLine = true;
else if (count == 1)
removedInSecondLine = true;
}
}
newText = newText + Environment.NewLine + s2;
newText = newText.Trim();
}
}
}
else
{
newText = newText + Environment.NewLine + s;
newText = newText.Trim();
if (newText.EndsWith("</i>") && text.StartsWith("<i>") && !newText.StartsWith("<i>"))
newText = "<i>" + newText;
else if (newText.EndsWith("</b>") && text.StartsWith("<b>") && !newText.StartsWith("<b>"))
newText = "<b>" + newText;
}
count++;
}
newText = newText.Trim();
if (noOfNames > 0 && Utilities.CountTagInText(newText, Environment.NewLine) == 1)
{
int indexOfDialogChar = newText.IndexOf('-');
bool insertDash = true;
string[] arr = newText.Split(Environment.NewLine.ToCharArray(), StringSplitOptions.RemoveEmptyEntries);
if (arr.Length == 2 && arr[0].Length > 1 && arr[1].Length > 1)
{
string arr0 = new StripableText(arr[0]).StrippedText;
string arr1 = new StripableText(arr[1]).StrippedText;
//line continuation?
if (arr0.Length > 0 && arr1.Length > 1 && (Utilities.LowercaseLetters + ",").Contains(arr0.Substring(arr0.Length - 1)) &&
Utilities.LowercaseLetters.Contains(arr1.Substring(0, 1)))
{
if (new StripableText(arr[1]).Pre.Contains("...") == false)
insertDash = false;
}
if (arr0.Length > 0 && arr1.Length > 1 && !(arr[0].EndsWith(".") || arr[0].EndsWith("!") || arr[0].EndsWith("?") || arr[0].EndsWith("</i>")) &&
!(new StripableText(arr[1]).Pre.Contains("-")))
{
insertDash = false;
}
if (removedInFirstLine && !removedInSecondLine && !text.StartsWith("-") && !text.StartsWith("<i>-"))
{
if (insertDash && removedInFirstLine && (arr[1].StartsWith("-") || arr[1].StartsWith("<i>-")))
insertDash = true;
else
insertDash = false;
}
}
if (insertDash)
{
if (indexOfDialogChar < 0 || indexOfDialogChar > 4)
{
StripableText st = new StripableText(newText, "", "");
newText = st.Pre + "- " + st.StrippedText + st.Post;
}
int indexOfNewLine = newText.IndexOf(Environment.NewLine);
string second = newText.Substring(indexOfNewLine).Trim();
indexOfDialogChar = second.IndexOf('-');
if (indexOfDialogChar < 0 || indexOfDialogChar > 6)
{
StripableText st = new StripableText(second, "", "");
second = st.Pre + "- " + st.StrippedText + st.Post;
newText = newText.Remove(indexOfNewLine) + Environment.NewLine + second;
}
}
}
else if (!newText.Contains(Environment.NewLine) && newText.Contains("-"))
{
StripableText st = new StripableText(newText);
if (st.Pre.Contains("-"))
newText = st.Pre.Replace("-", string.Empty) + st.StrippedText + st.Post;
}
else if (Utilities.CountTagInText(newText, Environment.NewLine) == 1 && removedInFirstLine == false && removedInSecondLine == true)
{
string noTags = Utilities.RemoveHtmlTags(newText, true).Trim();
bool insertDash = noTags.StartsWith("-") && Utilities.CountTagInText(noTags, "-") == 1;
if (insertDash)
{
if (newText.Contains(Environment.NewLine + "<i>"))
newText = newText.Replace(Environment.NewLine + "<i>", Environment.NewLine + "<i>- ");
else
newText = newText.Replace(Environment.NewLine, Environment.NewLine + "- ");
}
}
if (text.Contains("<i>") && !newText.Contains("<i>") && newText.EndsWith("</i>"))
newText = "<i>" + newText;
return newText;
}
public string RemoveTextFromHearImpaired(string text, string prevText)
{
if (settings.RemoveWhereContains && settings.RemoveIfTextContains.Length > 0 && text.Contains(settings.RemoveIfTextContains))
{
return string.Empty;
}
string oldText = text;
text = RemoveColon(text, prevText);
string pre = " >-\"'`´♪¿¡.…—";
string post = " -\"'`´♪.!?:…—";
if (settings.RemoveTextBetweenCustomTags)
{
pre = pre.Replace(settings.CustomStart, string.Empty);
post = post.Replace(settings.CustomEnd, string.Empty);
}
var st = new StripableText(text, pre, post);
var sb = new StringBuilder();
string[] parts = st.StrippedText.Trim().Split(Environment.NewLine.ToCharArray(), StringSplitOptions.RemoveEmptyEntries);
int lineNumber = 0;
bool removedDialogInFirstLine = false;
int noOfNamesRemoved = 0;
int noOfNamesRemovedNotInLineOne = 0;
foreach (string s in parts)
{
StripableText stSub = new StripableText(s, pre, post);
if (!StartAndEndsWithHearImpariedTags(stSub.StrippedText))
{
if (removedDialogInFirstLine && stSub.Pre.Contains("- "))
stSub.Pre = stSub.Pre.Replace("- ", string.Empty);
string newText = stSub.StrippedText;
newText = RemoveHearImpairedTags(newText);
if (stSub.StrippedText.Length - newText.Length > 2)
{
string removedText = GetRemovedString(stSub.StrippedText, newText);
if (!IsHIDescription(removedText))
{
noOfNamesRemoved++;
if (lineNumber > 0)
noOfNamesRemovedNotInLineOne++;
}
}
sb.AppendLine(stSub.Pre + newText + stSub.Post);
}
else
{
if (!IsHIDescription(stSub.StrippedText))
{
noOfNamesRemoved++;
if (lineNumber > 0)
noOfNamesRemovedNotInLineOne++;
}
if (st.Pre.Contains("- ") && lineNumber == 0)
{
st.Pre = st.Pre.Replace("- ", string.Empty);
removedDialogInFirstLine = true;
}
if (st.Pre.Contains("<i>") && stSub.Post.Contains("</i>"))
st.Pre = st.Pre.Replace("<i>", string.Empty);
if (s.Contains("<i>") && !s.Contains("</i>") && st.Post.Contains("</i>"))
st.Post = st.Post.Replace("</i>", string.Empty);
}
lineNumber++;
}
text = st.Pre + sb.ToString().Trim() + st.Post;
text = text.Replace("<i></i>", string.Empty).Trim();
text = RemoveColon(text, prevText);
text = RemoveLineIfAllUppercase(text);
text = RemoveHearImpairedtagsInsideLine(text);
if (settings.RemoveInterjections)
text = RemoveInterjections(text);
st = new StripableText(text, " >-\"'`´♪¿¡.…—", " -\"'`´♪.!?:…—");
text = st.StrippedText;
if (StartAndEndsWithHearImpariedTags(text))
{
text = RemoveStartEndTags(text);
}
text = RemoveHearImpairedTags(text);
// fix 3 lines to two liners - if only two lines
if (noOfNamesRemoved >= 1 && Utilities.CountTagInText(text, Environment.NewLine) == 2)
{
string[] a = Utilities.RemoveHtmlTags(text).Replace(" ", string.Empty).Split("!?.".ToCharArray(), StringSplitOptions.RemoveEmptyEntries);
if (a.Length == 2)
{
StripableText temp = new StripableText(text);
temp.StrippedText = temp.StrippedText.Replace(Environment.NewLine, " ");
int splitIndex = temp.StrippedText.LastIndexOf("!");
if (splitIndex == -1)
splitIndex = temp.StrippedText.LastIndexOf("?");
if (splitIndex == -1)
splitIndex = temp.StrippedText.LastIndexOf(".");
if (splitIndex > 0)
{
text = temp.Pre + temp.StrippedText.Insert(splitIndex + 1, Environment.NewLine) + temp.Post;
}
}
}
if (!text.StartsWith("-") && noOfNamesRemoved >= 1 && Utilities.CountTagInText(text, Environment.NewLine) == 1)
{
string[] arr = text.Split(Environment.NewLine.ToCharArray());
string part0 = arr[0].Trim().Replace("</i>", string.Empty).Trim();
if (!part0.EndsWith(",") && (!part0.EndsWith("-") || noOfNamesRemovedNotInLineOne > 0))
{
if (part0.Length > 0 && ".!?".Contains(part0.Substring(part0.Length - 1)))
{
if (noOfNamesRemovedNotInLineOne > 0)
{
if (!st.Pre.Contains("-"))
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 (!string.IsNullOrEmpty(text))
text = st.Pre + text + st.Post;
if (oldText.Trim().StartsWith("- ") &&
(oldText.Contains(Environment.NewLine + "- ") || oldText.Contains(Environment.NewLine + " - ")) &&
text != null && !text.Contains(Environment.NewLine))
{
text = text.TrimStart().TrimStart('-').TrimStart();
}
if (oldText != text)
{
// insert spaces before "-"
text = text.Replace(Environment.NewLine + "- <i>", Environment.NewLine + "<i>- ");
text = text.Replace(Environment.NewLine + "-<i>", Environment.NewLine + "<i>- ");
if (text.StartsWith("-") && text.Length > 2 && text[1] != ' ' && text[1] != '-')
text = text.Insert(1, " ");
if (text.StartsWith("<i>-") && text.Length > 5 && text[4] != ' ' && text[4] != '-')
text = text.Insert(4, " ");
if (text.Contains(Environment.NewLine + "-"))
{
int index = text.IndexOf(Environment.NewLine + "-");
if (index + 4 < text.Length && text[index + Environment.NewLine.Length + 1] != ' ' && text[index + Environment.NewLine.Length + 1] != '-')
text = text.Insert(index + Environment.NewLine.Length + 1, " ");
}
if (text.Contains(Environment.NewLine + "<i>-"))
{
int index = text.IndexOf(Environment.NewLine + "<i>-");
if (index + 5 < text.Length && text[index + Environment.NewLine.Length + 4] != ' ' && text[index + Environment.NewLine.Length + 4] != '-')
text = text.Insert(index + Environment.NewLine.Length + 4, " ");
}
}
return text.Trim();
}
private void AddWarning()
{
if (_warnings == null || _warningIndex < 0)
return;
_warnings.Add(_warningIndex);
}
private bool IsHIDescription(string text)
{
text = text.ToLower();
text = text.TrimEnd(" ()[]?{}".ToCharArray());
text = text.TrimStart(" ()[]?{}".ToCharArray());
if (text.Trim().Replace("mr. ", string.Empty).Replace("mrs. ", string.Empty).Replace("dr. ", string.Empty).Contains(" "))
AddWarning();
if (text == "sighing" ||
text == "cackles" ||
text == "cheers" ||
text == "chitters" ||
text == "chuckles" ||
text == "exclaims" ||
text == "gasps" ||
text == "grunts" ||
text == "groans" ||
text == "growls" ||
text == "explosion" ||
text == "laughs" ||
text == "noise" ||
text.StartsWith("engine ") ||
text == "roars" ||
text == "scoff" ||
text == "screeches" ||
text == "shouts" ||
text == "shrieks" ||
text == "sigh" ||
text == "sighs" ||
text == "singing" ||
text == "snores" ||
text == "stutters" ||
text == "thuds" ||
text == "trumpets" ||
text == "whispers" ||
text == "whisper" ||
text == "whistles" ||
text.EndsWith("ing"))
return true;
return false;
}
private static string GetRemovedString(string oldText, string newText)
{
oldText = oldText.ToLower();
newText = newText.ToLower();
int start = oldText.IndexOf(newText);
string result;
if (start > 0)
result = oldText.Substring(0, oldText.Length - newText.Length);
else
result = oldText.Substring(newText.Length);
result = result.TrimEnd(" ()[]?{}".ToCharArray());
result = result.TrimStart(" ()[]?{}".ToCharArray());
return result;
}
private static int CompareLength(string a, string b)
{
return b.Length.CompareTo(a.Length);
}
public string RemoveInterjections(string text)
{
string oldText = text;
if (_interjectionList == null)
{
string[] arr = Configuration.Settings.Tools.Interjections.Split(";".ToCharArray(), StringSplitOptions.RemoveEmptyEntries);
_interjectionList = new List<string>();
foreach (string s in arr)
{
if (!_interjectionList.Contains(s))
_interjectionList.Add(s);
string lower = s.ToLower();
if (!_interjectionList.Contains(lower))
_interjectionList.Add(lower);
}
_interjectionList.Sort(new Comparison<string>(CompareLength));
}
bool doRepeat = true;
while (doRepeat)
{
doRepeat = false;
foreach (string s in _interjectionList)
{
if (text.Contains(s))
{
var regex = new Regex("\\b" + s + "\\b");
Match match = regex.Match(text);
if (match.Success)
{
int index = match.Index;
string temp = text.Remove(index, s.Length);
string pre = string.Empty;
if (index > 0)
doRepeat = true;
bool removeAfter = true;
if (temp.Length > index - s.Length + 3 && index > s.Length)
{
if (temp.Substring(index - s.Length + 1, 3) == ", !")
{
temp = temp.Remove(index - s.Length + 1, 2);
removeAfter = false;
}
else if (temp.Substring(index - s.Length + 1, 3) == ", ?")
{
temp = temp.Remove(index - s.Length + 1, 2);
removeAfter = false;
}
else if (temp.Substring(index - s.Length + 1, 3) == ", .")
{
temp = temp.Remove(index - s.Length + 1, 2);
removeAfter = false;
}
}
if (removeAfter && temp.Length > index - s.Length + 2 && index > s.Length)
{
if (temp.Substring(index - s.Length, 3) == ", !")
{
temp = temp.Remove(index - s.Length, 2);
removeAfter = false;
}
else if (temp.Substring(index - s.Length, 3) == ", ?")
{
temp = temp.Remove(index - s.Length, 2);
removeAfter = false;
}
else if (temp.Substring(index - s.Length, 3) == ", .")
{
temp = temp.Remove(index - s.Length, 2);
removeAfter = false;
}
}
if (removeAfter && temp.Length > index - s.Length + 2 && index > s.Length)
{
if (temp.Substring(index - s.Length + 1, 2) == "-!")
{
temp = temp.Remove(index - s.Length + 1, 1);
removeAfter = false;
}
else if (temp.Substring(index - s.Length + 1, 2) == "-?")
{
temp = temp.Remove(index - s.Length + 1, 1);
removeAfter = false;
}
else if (temp.Substring(index - s.Length + 1, 2) == "-.")
{
temp = temp.Remove(index - s.Length + 1, 1);
removeAfter = false;
}
}
if (removeAfter)
{
if (index == 0)
{
if (!string.IsNullOrEmpty(temp) && temp.StartsWith("-"))
temp = temp.Remove(0, 1).Trim();
}
else if (index == 3 && !string.IsNullOrEmpty(temp) && temp.StartsWith("<i>-"))
{
temp = temp.Remove(3, 1);
}
else if (index > 0)
{
pre = text.Substring(0, index);
temp = temp.Remove(0, index);
if (pre.EndsWith("-") && temp.StartsWith("-"))
temp = temp.Remove(0, 1);
if (pre.EndsWith("- ") && temp.StartsWith("-"))
temp = temp.Remove(0, 1);
}
while (temp.Length > 0 && (temp.StartsWith(" ") || temp.StartsWith(",") || temp.StartsWith(".") || temp.StartsWith("!") || temp.StartsWith("?")))
{
temp = temp.Remove(0, 1);
doRepeat = true;
}
if (temp.Length > 0 && s[0].ToString() != s[0].ToString().ToLower())
{
temp = temp.Remove(0, 1).Insert(0, temp[0].ToString().ToUpper());
doRepeat = true;
}
temp = pre + temp;
}
if (temp.EndsWith(Environment.NewLine + "- "))
temp = temp.Remove(temp.Length - 4, 4);
var st = new StripableText(temp);
if (st.StrippedText.Length == 0)
return string.Empty;
if (!temp.Contains(Environment.NewLine) && text.Contains(Environment.NewLine) && temp.StartsWith("-"))
temp = temp.Remove(0, 1).Trim();
text = temp;
}
}
}
}
string[] lines = text.Split(Environment.NewLine.ToCharArray(), StringSplitOptions.RemoveEmptyEntries);
if (text != oldText && lines.Length == 2)
{
if (lines[0] == "-" && lines[1] == "-")
return string.Empty;
if (lines[0].StartsWith("-") && lines[0].Length > 1 && lines[1].Trim() == "-")
return lines[0].Remove(0, 1).Trim();
if (lines[1].StartsWith("-") && lines[1].Length > 1 && lines[0].Trim() == "-")
return lines[1].Remove(0, 1).Trim();
if (lines[0].Length > 1 && (lines[1] == "-") || lines[1] == "." || lines[1] == "!" || lines[1] == "?")
{
if (oldText.Contains(Environment.NewLine + "-") && lines[0].StartsWith("-"))
lines[0] = lines[0].Remove(0, 1);
return lines[0].Trim();
}
}
return text;
}
private string RemoveStartEndTags(string text)
{
string newText = text;
string s = text;
if (s.StartsWith("[") && s.IndexOf("]") > 0 && settings.RemoveTextBetweenSquares)
newText = s.Remove(0, s.IndexOf("]") + 1);
else if (s.StartsWith("{") && s.IndexOf("}") > 0 && settings.RemoveTextBetweenBrackets)
newText = s.Remove(0, s.IndexOf("}") + 1);
else if (s.StartsWith("?") && s.IndexOf("?", 1) > 0 && settings.RemoveTextBetweenQuestionMarks)
newText = s.Remove(0, s.IndexOf("?", 1) + 1);
else if (s.StartsWith("(") && s.IndexOf(")") > 0 && settings.RemoveTextBetweenParentheses)
newText = s.Remove(0, s.IndexOf(")") + 1);
else if (s.StartsWith("[") && s.IndexOf("]:") > 0 && settings.RemoveTextBetweenSquares)
newText = s.Remove(0, s.IndexOf("]:") + 2);
else if (s.StartsWith("{") && s.IndexOf("}:") > 0 && settings.RemoveTextBetweenBrackets)
newText = s.Remove(0, s.IndexOf("}:") + 2);
else if (s.StartsWith("?") && s.IndexOf("?:", 1) > 0 && settings.RemoveTextBetweenQuestionMarks)
newText = s.Remove(0, s.IndexOf("?:") + 2);
else if (s.StartsWith("(") && s.IndexOf("):") > 0 && settings.RemoveTextBetweenParentheses)
newText = s.Remove(0, s.IndexOf("):") + 2);
else if (settings.RemoveTextBetweenCustomTags &&
s.Length > 0 && settings.CustomEnd.Length > 0 && settings.CustomStart.Length > 0 &&
s.StartsWith(settings.CustomStart) && s.LastIndexOf(settings.CustomEnd) > 0)
newText = s.Remove(0, s.LastIndexOf(settings.CustomEnd) + settings.CustomEnd.Length);
if (newText != text)
newText = newText.TrimStart(' ');
return newText;
}
public string RemoveHearImpairedTags(string text)
{
if (settings.RemoveTextBetweenSquares)
{
text = RemoveTextBetweenTags("[", "]:", text);
text = RemoveTextBetweenTags("[", "]", text);
}
if (settings.RemoveTextBetweenBrackets)
{
text = RemoveTextBetweenTags("{", "}:", text);
text = RemoveTextBetweenTags("{", "}", text);
}
if (settings.RemoveTextBetweenQuestionMarks)
{
text = RemoveTextBetweenTags("?", "?:", text);
text = RemoveTextBetweenTags("?", "?", text);
}
if (settings.RemoveTextBetweenParentheses)
{
text = RemoveTextBetweenTags("(", "):", text);
text = RemoveTextBetweenTags("(", ")", text);
}
if (settings.RemoveTextBetweenCustomTags && settings.CustomStart.Length > 0 && settings.CustomEnd.Length > 0)
{
text = RemoveTextBetweenTags(settings.CustomStart, settings.CustomEnd, text);
}
return text;
}
private bool HasHearImpairedText(string text)
{
return RemoveHearImpairedTags(text) != text;
}
public bool HasHearImpariedTagsAtStart(string text)
{
if (settings.OnlyIfInSeparateLine)
return StartAndEndsWithHearImpariedTags(text);
return HasHearImpairedText(text);
}
public bool HasHearImpariedTagsAtEnd(string text)
{
if (settings.OnlyIfInSeparateLine)
return StartAndEndsWithHearImpariedTags(text);
return HasHearImpairedText(text);
}
private bool StartAndEndsWithHearImpariedTags(string text)
{
return (text.StartsWith("[") && text.EndsWith("]") && !text.Trim('[').Contains("[") && settings.RemoveTextBetweenSquares) ||
(text.StartsWith("{") && text.EndsWith("}") && !text.Trim('{').Contains("{") && settings.RemoveTextBetweenBrackets) ||
(text.StartsWith("?") && text.EndsWith("?") && !text.Trim('?').Contains("?") && settings.RemoveTextBetweenQuestionMarks) ||
(text.StartsWith("(") && text.EndsWith(")") && !text.Trim('(').Contains("(") && settings.RemoveTextBetweenParentheses) ||
(text.StartsWith("[") && text.EndsWith("]:") && !text.Trim('[').Contains("[") && settings.RemoveTextBetweenSquares) ||
(text.StartsWith("{") && text.EndsWith("}:") && !text.Trim('{').Contains("{") && settings.RemoveTextBetweenBrackets) ||
(text.StartsWith("?") && text.EndsWith("?:") && !text.Trim('?').Contains("?") && settings.RemoveTextBetweenQuestionMarks) ||
(text.StartsWith("(") && text.EndsWith("):") && !text.Trim('(').Contains("(") && settings.RemoveTextBetweenParentheses) ||
(settings.RemoveTextBetweenCustomTags &&
settings.CustomStart.Length > 0 && settings.CustomEnd.Length > 0 &&
text.StartsWith(settings.CustomStart) && text.EndsWith(settings.CustomEnd));
}
private static string RemoveTextBetweenTags(string startTag, string endTag, string text)
{
text = text.Trim();
if (startTag == "?" || endTag == "?")
{
if (text.StartsWith(startTag) && text.EndsWith(endTag))
return string.Empty;
return text;
}
int start = text.IndexOf(startTag);
if (start == -1 || start == text.Length - 1)
return text;
int end = text.IndexOf(endTag, start + 1);
while (start >= 0 && end > start)
{
text = text.Remove(start, (end - start) + 1);
start = text.IndexOf(startTag);
if (start >= 0 && start < text.Length - 1)
end = text.IndexOf(endTag, start);
else
end = -1;
}
return text.Replace(" " + Environment.NewLine, Environment.NewLine).TrimEnd();
}
public string RemoveLineIfAllUppercase(string text)
{
if (!settings.RemoveIfAllUppercase)
return text;
string[] lines = text.Replace(Environment.NewLine, "\n").Replace("\r", "\n").Split('\n');
var sb = new StringBuilder();
foreach (string line in lines)
{
string lineNoHtml = Utilities.RemoveHtmlTags(line);
string tmp = lineNoHtml.TrimEnd(new char[] { '.', '!', '?', ':', }).Trim();
if (lineNoHtml != lineNoHtml.ToLower() && lineNoHtml == lineNoHtml.ToUpper())
{
if (tmp == "YES" || tmp == "NO" || tmp == "WHY" || tmp == "HI" || tmp.Length == 1)
{
sb.AppendLine(line);
}
}
else
{
sb.AppendLine(line);
}
}
return sb.ToString().Trim();
}
}
}

View File

@ -0,0 +1,42 @@

namespace Nikse.SubtitleEdit.Logic.Forms
{
public class RemoveTextForHISettings
{
public bool OnlyIfInSeparateLine { get; set; }
public bool RemoveIfAllUppercase { get; set; }
public bool RemoveTextBeforeColon { get; set; }
public bool RemoveTextBeforeColonOnlyUppercase { get; set; }
public bool ColonSeparateLine { get; set; }
public bool RemoveWhereContains { get; set; }
public string RemoveIfTextContains { get; set; }
public bool RemoveTextBetweenCustomTags { get; set; }
public bool RemoveInterjections { get; set; }
public bool RemoveTextBetweenSquares { get; set; }
public bool RemoveTextBetweenBrackets { get; set; }
public bool RemoveTextBetweenQuestionMarks { get; set; }
public bool RemoveTextBetweenParentheses { get; set; }
public string CustomStart { get; set; }
public string CustomEnd { get; set; }
public void LoadFromConfiguration()
{
OnlyIfInSeparateLine = Configuration.Settings.RemoveTextForHearingImpaired.RemoveTextBetweenOnlySeperateLines;
RemoveIfAllUppercase = Configuration.Settings.RemoveTextForHearingImpaired.RemoveIfAllUppercase;
RemoveTextBeforeColon = Configuration.Settings.RemoveTextForHearingImpaired.RemoveTextBeforeColon;
RemoveTextBeforeColonOnlyUppercase = Configuration.Settings.RemoveTextForHearingImpaired.RemoveTextBeforeColonOnlyIfUppercase;
ColonSeparateLine = Configuration.Settings.RemoveTextForHearingImpaired.RemoveTextBeforeColonOnlyOnSeparateLine;
RemoveWhereContains = Configuration.Settings.RemoveTextForHearingImpaired.RemoveIfContains;
RemoveIfTextContains = Configuration.Settings.RemoveTextForHearingImpaired.RemoveIfContainsText;
RemoveTextBetweenCustomTags = Configuration.Settings.RemoveTextForHearingImpaired.RemoveTextBetweenCustom;
RemoveInterjections = Configuration.Settings.RemoveTextForHearingImpaired.RemoveInterjections;
RemoveTextBetweenSquares = Configuration.Settings.RemoveTextForHearingImpaired.RemoveTextBetweenBrackets;
RemoveTextBetweenBrackets = Configuration.Settings.RemoveTextForHearingImpaired.RemoveTextBetweenCurlyBrackets;
RemoveTextBetweenQuestionMarks = Configuration.Settings.RemoveTextForHearingImpaired.RemoveTextBetweenQuestionMarks;
RemoveTextBetweenParentheses = Configuration.Settings.RemoveTextForHearingImpaired.RemoveTextBetweenParentheses;
CustomStart = Configuration.Settings.RemoveTextForHearingImpaired.RemoveTextBetweenCustomBefore;
CustomEnd = Configuration.Settings.RemoveTextForHearingImpaired.RemoveTextBetweenCustomAfter;
}
}
}

View File

@ -762,6 +762,8 @@
<Compile Include="Logic\BluRaySup\PaletteInfo.cs" />
<Compile Include="Logic\BluRaySup\ToolBox.cs" />
<Compile Include="Logic\BmpReader.cs" />
<Compile Include="Logic\Forms\RemoveTextForHISettings.cs" />
<Compile Include="Logic\Forms\RemoveTextForHI.cs" />
<Compile Include="Logic\Forms\SplitLongLinesHelper.cs" />
<Compile Include="Logic\MurMurHash3.cs" />
<Compile Include="Logic\NikseBitmapImageSplitter.cs" />

View File

@ -1,5 +1,4 @@
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Nikse.SubtitleEdit.Forms;
using System;
namespace Test
@ -14,7 +13,6 @@ namespace Test
public class RemoveTextForHearImpairedTest
{
private TestContext testContextInstance;
/// <summary>
@ -33,6 +31,13 @@ namespace Test
}
}
private Nikse.SubtitleEdit.Logic.Forms.RemoveTextForHI GetRemoveTextForHiLib()
{
var hiSettings = new Nikse.SubtitleEdit.Logic.Forms.RemoveTextForHISettings();
hiSettings.LoadFromConfiguration();
return new Nikse.SubtitleEdit.Logic.Forms.RemoveTextForHI(hiSettings);
}
#region Additional test attributes
//
//You can use the following additional attributes as you write your tests:
@ -70,13 +75,13 @@ namespace Test
[DeploymentItem("SubtitleEdit.exe")]
public void RemoveColonTest()
{
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;
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.RemoveTextBeforeColonOnlyUppercase = false;
string text = "Man over P.A.:\r\nGive back our homes.";
string expected = "Give back our homes.";
string actual = target.RemoveColon(text, string.Empty);
@ -88,13 +93,13 @@ namespace Test
[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;
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.RemoveTextBeforeColonOnlyUppercase = 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);
@ -106,13 +111,13 @@ namespace Test
[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;
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.RemoveTextBeforeColonOnlyUppercase = 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);
@ -128,13 +133,13 @@ namespace Test
[DeploymentItem("SubtitleEdit.exe")]
public void RemoveHIInsideLine()
{
FormRemoveTextForHearImpaired_Accessor target = new FormRemoveTextForHearImpaired_Accessor();
target.checkBoxRemoveIfAllUppercase.Checked = false;
target.checkBoxRemoveTextBeforeColon.Checked = true;
target.checkBoxOnlyIfInSeparateLine.Checked = false;
target.checkBoxRemoveTextBetweenParentheses.Checked = true;
target.checkBoxRemoveTextBeforeColonOnlyUppercase.Checked = false;
target.checkBoxColonSeparateLine.Checked = false;
var target = GetRemoveTextForHiLib();
target.settings.RemoveIfAllUppercase = false;
target.settings.RemoveTextBeforeColon = true;
target.settings.OnlyIfInSeparateLine = false;
target.settings.RemoveTextBetweenParentheses = true;
target.settings.RemoveTextBeforeColonOnlyUppercase = false;
target.settings.ColonSeparateLine = false;
string text = "Be quiet. (SHUSHING) It's okay.";
string expected = "Be quiet. It's okay.";
string actual = target.RemoveHearImpairedtagsInsideLine(text);
@ -148,12 +153,12 @@ namespace Test
[DeploymentItem("SubtitleEdit.exe")]
public void RemoveHI1()
{
FormRemoveTextForHearImpaired_Accessor target = new FormRemoveTextForHearImpaired_Accessor();
target.checkBoxRemoveIfAllUppercase.Checked = false;
target.checkBoxOnlyIfInSeparateLine.Checked = false;
target.checkBoxRemoveTextBetweenSquares.Checked = true;
target.checkBoxRemoveTextBeforeColonOnlyUppercase.Checked = false;
target.checkBoxColonSeparateLine.Checked = false;
var target = GetRemoveTextForHiLib();
target.settings.RemoveIfAllUppercase = false;
target.settings.OnlyIfInSeparateLine = false;
target.settings.RemoveTextBetweenSquares = true;
target.settings.RemoveTextBeforeColonOnlyUppercase = false;
target.settings.ColonSeparateLine = false;
string text = "- Aw, save it. Storm?\r\n- [Storm]\r\nWe're outta here.";
string expected = "- Aw, save it. Storm?\r\n- We're outta here.";
string actual = target.RemoveTextFromHearImpaired(text, string.Empty);
@ -167,12 +172,12 @@ namespace Test
[DeploymentItem("SubtitleEdit.exe")]
public void RemoveHI2()
{
FormRemoveTextForHearImpaired_Accessor target = new FormRemoveTextForHearImpaired_Accessor();
target.checkBoxRemoveIfAllUppercase.Checked = false;
target.checkBoxOnlyIfInSeparateLine.Checked = false;
target.checkBoxRemoveTextBetweenSquares.Checked = true;
target.checkBoxRemoveTextBeforeColonOnlyUppercase.Checked = false;
target.checkBoxColonSeparateLine.Checked = false;
var target = GetRemoveTextForHiLib();
target.settings.RemoveIfAllUppercase = false;
target.settings.OnlyIfInSeparateLine = false;
target.settings.RemoveTextBetweenSquares = true;
target.settings.RemoveTextBeforeColonOnlyUppercase = false;
target.settings.ColonSeparateLine = false;
string text = "[Chuckles,\r\nCoughing]\r\nBut we lived through it.";
string expected = "But we lived through it.";
string actual = target.RemoveTextFromHearImpaired(text, string.Empty);
@ -186,11 +191,11 @@ namespace Test
[DeploymentItem("SubtitleEdit.exe")]
public void RemoveHINot()
{
FormRemoveTextForHearImpaired_Accessor target = new FormRemoveTextForHearImpaired_Accessor();
target.checkBoxRemoveIfAllUppercase.Checked = false;
target.checkBoxOnlyIfInSeparateLine.Checked = false;
target.checkBoxRemoveTextBeforeColonOnlyUppercase.Checked = false;
target.checkBoxColonSeparateLine.Checked = false;
var target = GetRemoveTextForHiLib();
target.settings.RemoveIfAllUppercase = false;
target.settings.OnlyIfInSeparateLine = false;
target.settings.RemoveTextBeforeColonOnlyUppercase = false;
target.settings.ColonSeparateLine = false;
string text = "is the body of a mutant kid\r\non the 6:00 news.";
string expected = "is the body of a mutant kid\r\non the 6:00 news.";
string actual = target.RemoveTextFromHearImpaired(text, string.Empty);
@ -205,12 +210,12 @@ namespace Test
[DeploymentItem("SubtitleEdit.exe")]
public void RemoveHIMultilineItalic()
{
FormRemoveTextForHearImpaired_Accessor target = new FormRemoveTextForHearImpaired_Accessor();
target.checkBoxRemoveIfAllUppercase.Checked = false;
target.checkBoxRemoveTextBeforeColon.Checked = true;
target.checkBoxOnlyIfInSeparateLine.Checked = false;
target.checkBoxRemoveTextBeforeColonOnlyUppercase.Checked = false;
target.checkBoxColonSeparateLine.Checked = false;
var target = GetRemoveTextForHiLib();
target.settings.RemoveIfAllUppercase = false;
target.settings.RemoveTextBeforeColon = true;
target.settings.OnlyIfInSeparateLine = false;
target.settings.RemoveTextBeforeColonOnlyUppercase = false;
target.settings.ColonSeparateLine = false;
string text = "<i>NARRATOR:" + Environment.NewLine +
"Previously on NCIS</i>";
string expected = "<i>Previously on NCIS</i>";
@ -225,12 +230,12 @@ namespace Test
[DeploymentItem("SubtitleEdit.exe")]
public void RemoveHIMultilineBold()
{
FormRemoveTextForHearImpaired_Accessor target = new FormRemoveTextForHearImpaired_Accessor();
target.checkBoxRemoveIfAllUppercase.Checked = false;
target.checkBoxRemoveTextBeforeColon.Checked = true;
target.checkBoxOnlyIfInSeparateLine.Checked = false;
target.checkBoxRemoveTextBeforeColonOnlyUppercase.Checked = false;
target.checkBoxColonSeparateLine.Checked = false;
var target = GetRemoveTextForHiLib();
target.settings.RemoveIfAllUppercase = false;
target.settings.RemoveTextBeforeColon = true;
target.settings.OnlyIfInSeparateLine = false;
target.settings.RemoveTextBeforeColonOnlyUppercase = false;
target.settings.ColonSeparateLine = false;
string text = "<b>NARRATOR:" + Environment.NewLine +
"Previously on NCIS</b>";
string expected = "<b>Previously on NCIS</b>";
@ -245,12 +250,12 @@ namespace Test
[DeploymentItem("SubtitleEdit.exe")]
public void RemoveHISecondLineDelay()
{
FormRemoveTextForHearImpaired_Accessor target = new FormRemoveTextForHearImpaired_Accessor();
target.checkBoxRemoveIfAllUppercase.Checked = false;
target.checkBoxRemoveTextBeforeColon.Checked = true;
target.checkBoxOnlyIfInSeparateLine.Checked = false;
target.checkBoxRemoveTextBeforeColonOnlyUppercase.Checked = false;
target.checkBoxColonSeparateLine.Checked = false;
var target = GetRemoveTextForHiLib();
target.settings.RemoveIfAllUppercase = false;
target.settings.RemoveTextBeforeColon = true;
target.settings.OnlyIfInSeparateLine = false;
target.settings.RemoveTextBeforeColonOnlyUppercase = false;
target.settings.ColonSeparateLine = false;
string text = "- JOHN: Hey." + Environment.NewLine +
"- ...hey.";
string expected = "- Hey."+ Environment.NewLine +"- ...hey.";
@ -262,11 +267,11 @@ namespace Test
[DeploymentItem("SubtitleEdit.exe")]
public void RemoveHIQuotes()
{
FormRemoveTextForHearImpaired_Accessor target = new FormRemoveTextForHearImpaired_Accessor();
target.checkBoxRemoveIfAllUppercase.Checked = false;
target.checkBoxOnlyIfInSeparateLine.Checked = false;
target.checkBoxRemoveTextBeforeColonOnlyUppercase.Checked = false;
target.checkBoxColonSeparateLine.Checked = false;
var target = GetRemoveTextForHiLib();
target.settings.RemoveIfAllUppercase = false;
target.settings.OnlyIfInSeparateLine = false;
target.settings.RemoveTextBeforeColonOnlyUppercase = false;
target.settings.ColonSeparateLine = false;
string text = "- Where?!" + Environment.NewLine + "- Ow!";
string expected = "Where?!";
string actual = target.RemoveInterjections(text);
@ -277,12 +282,12 @@ namespace Test
[DeploymentItem("SubtitleEdit.exe")]
public void RemoveHIDouble()
{
FormRemoveTextForHearImpaired_Accessor target = new FormRemoveTextForHearImpaired_Accessor();
target.checkBoxRemoveIfAllUppercase.Checked = false;
target.checkBoxOnlyIfInSeparateLine.Checked = false;
target.checkBoxRemoveTextBetweenSquares.Checked = true;
target.checkBoxRemoveTextBeforeColonOnlyUppercase.Checked = false;
target.checkBoxColonSeparateLine.Checked = false;
var target = GetRemoveTextForHiLib();
target.settings.RemoveIfAllUppercase = false;
target.settings.OnlyIfInSeparateLine = false;
target.settings.RemoveTextBetweenSquares = true;
target.settings.RemoveTextBeforeColonOnlyUppercase = false;
target.settings.ColonSeparateLine = false;
string text = "[MAN]Where?![MAN]";
string expected = "Where?!";
string actual = target.RemoveTextFromHearImpaired(text, string.Empty);
@ -293,13 +298,13 @@ namespace Test
[DeploymentItem("SubtitleEdit.exe")]
public void RemoveRemoveNameOfFirstLine()
{
FormRemoveTextForHearImpaired_Accessor target = new FormRemoveTextForHearImpaired_Accessor();
target.checkBoxRemoveIfAllUppercase.Checked = false;
target.checkBoxRemoveInterjections.Checked = false;
target.checkBoxRemoveTextBeforeColon.Checked = true;
target.checkBoxOnlyIfInSeparateLine.Checked = false;
target.checkBoxRemoveTextBeforeColonOnlyUppercase.Checked = false;
target.checkBoxColonSeparateLine.Checked = false;
var target = GetRemoveTextForHiLib();
target.settings.RemoveIfAllUppercase = false;
target.settings.RemoveInterjections = false;
target.settings.RemoveTextBeforeColon = true;
target.settings.OnlyIfInSeparateLine = false;
target.settings.RemoveTextBeforeColonOnlyUppercase = false;
target.settings.ColonSeparateLine = false;
string text = "HECTOR: Hi." + Environment.NewLine + "-Oh, hey, Hector.";
string expected = "- Hi." + Environment.NewLine + "- Oh, hey, Hector.";
string actual = target.RemoveTextFromHearImpaired(text, string.Empty);
@ -310,13 +315,13 @@ namespace Test
[DeploymentItem("SubtitleEdit.exe")]
public void RemoveRemoveNameOfFirstLineBold()
{
FormRemoveTextForHearImpaired_Accessor target = new FormRemoveTextForHearImpaired_Accessor();
target.checkBoxRemoveIfAllUppercase.Checked = false;
target.checkBoxRemoveInterjections.Checked = false;
target.checkBoxRemoveTextBeforeColon.Checked = true;
target.checkBoxOnlyIfInSeparateLine.Checked = false;
target.checkBoxRemoveTextBeforeColonOnlyUppercase.Checked = false;
target.checkBoxColonSeparateLine.Checked = false;
var target = GetRemoveTextForHiLib();
target.settings.RemoveIfAllUppercase = false;
target.settings.RemoveInterjections = false;
target.settings.RemoveTextBeforeColon = true;
target.settings.OnlyIfInSeparateLine = false;
target.settings.RemoveTextBeforeColonOnlyUppercase = false;
target.settings.ColonSeparateLine = false;
string text = "<b>HECTOR: Hi.</b>";
string expected = "<b>Hi.</b>";
string actual = target.RemoveTextFromHearImpaired(text, string.Empty);
@ -327,12 +332,12 @@ namespace Test
[DeploymentItem("SubtitleEdit.exe")]
public void RemoveInterjections()
{
FormRemoveTextForHearImpaired_Accessor target = new FormRemoveTextForHearImpaired_Accessor();
target.checkBoxRemoveIfAllUppercase.Checked = false;
target.checkBoxRemoveInterjections.Checked = true;
target.checkBoxOnlyIfInSeparateLine.Checked = false;
target.checkBoxRemoveTextBeforeColonOnlyUppercase.Checked = false;
target.checkBoxColonSeparateLine.Checked = false;
var target = GetRemoveTextForHiLib();
target.settings.RemoveIfAllUppercase = false;
target.settings.RemoveInterjections = true;
target.settings.OnlyIfInSeparateLine = false;
target.settings.RemoveTextBeforeColonOnlyUppercase = false;
target.settings.ColonSeparateLine = false;
string text = "-Ballpark." + Environment.NewLine + "-Hmm.";
string expected = "Ballpark.";
string actual = target.RemoveInterjections(text);
@ -343,12 +348,12 @@ namespace Test
[DeploymentItem("SubtitleEdit.exe")]
public void RemoveInterjections2()
{
FormRemoveTextForHearImpaired_Accessor target = new FormRemoveTextForHearImpaired_Accessor();
target.checkBoxRemoveIfAllUppercase.Checked = false;
target.checkBoxRemoveInterjections.Checked = true;
target.checkBoxOnlyIfInSeparateLine.Checked = false;
target.checkBoxRemoveTextBeforeColonOnlyUppercase.Checked = false;
target.checkBoxColonSeparateLine.Checked = false;
var target = GetRemoveTextForHiLib();
target.settings.RemoveIfAllUppercase = false;
target.settings.RemoveInterjections = true;
target.settings.OnlyIfInSeparateLine = false;
target.settings.RemoveTextBeforeColonOnlyUppercase = false;
target.settings.ColonSeparateLine = false;
string text = "-Ballpark." + Environment.NewLine + "-Mm-hm.";
string expected = "Ballpark.";
string actual = target.RemoveInterjections(text);
@ -359,12 +364,12 @@ namespace Test
[DeploymentItem("SubtitleEdit.exe")]
public void RemoveInterjections3()
{
FormRemoveTextForHearImpaired_Accessor target = new FormRemoveTextForHearImpaired_Accessor();
target.checkBoxRemoveIfAllUppercase.Checked = false;
target.checkBoxRemoveInterjections.Checked = true;
target.checkBoxOnlyIfInSeparateLine.Checked = false;
target.checkBoxRemoveTextBeforeColonOnlyUppercase.Checked = false;
target.checkBoxColonSeparateLine.Checked = false;
var target = GetRemoveTextForHiLib();
target.settings.RemoveIfAllUppercase = false;
target.settings.RemoveInterjections = true;
target.settings.OnlyIfInSeparateLine = false;
target.settings.RemoveTextBeforeColonOnlyUppercase = false;
target.settings.ColonSeparateLine = false;
string text = "-Mm-hm." + Environment.NewLine + "-Ballpark.";
string expected = "Ballpark.";
string actual = target.RemoveInterjections(text);
@ -375,12 +380,12 @@ namespace Test
[DeploymentItem("SubtitleEdit.exe")]
public void RemoveInterjections4()
{
FormRemoveTextForHearImpaired_Accessor target = new FormRemoveTextForHearImpaired_Accessor();
target.checkBoxRemoveIfAllUppercase.Checked = false;
target.checkBoxRemoveInterjections.Checked = true;
target.checkBoxOnlyIfInSeparateLine.Checked = false;
target.checkBoxRemoveTextBeforeColonOnlyUppercase.Checked = false;
target.checkBoxColonSeparateLine.Checked = false;
var target = GetRemoveTextForHiLib();
target.settings.RemoveIfAllUppercase = false;
target.settings.RemoveInterjections = true;
target.settings.OnlyIfInSeparateLine = false;
target.settings.RemoveTextBeforeColonOnlyUppercase = false;
target.settings.ColonSeparateLine = false;
string text = "- Mm-hm." + Environment.NewLine + "- Ballpark.";
string expected = "Ballpark.";
string actual = target.RemoveInterjections(text);
@ -391,12 +396,12 @@ namespace Test
[DeploymentItem("SubtitleEdit.exe")]
public void RemoveInterjections5()
{
FormRemoveTextForHearImpaired_Accessor target = new FormRemoveTextForHearImpaired_Accessor();
target.checkBoxRemoveIfAllUppercase.Checked = false;
target.checkBoxRemoveInterjections.Checked = true;
target.checkBoxOnlyIfInSeparateLine.Checked = false;
target.checkBoxRemoveTextBeforeColonOnlyUppercase.Checked = false;
target.checkBoxColonSeparateLine.Checked = false;
var target = GetRemoveTextForHiLib();
target.settings.RemoveIfAllUppercase = false;
target.settings.RemoveInterjections = true;
target.settings.OnlyIfInSeparateLine = false;
target.settings.RemoveTextBeforeColonOnlyUppercase = false;
target.settings.ColonSeparateLine = false;
string text = "- Ballpark." + Environment.NewLine + "- Hmm.";
string expected = "Ballpark.";
string actual = target.RemoveInterjections(text);
@ -407,12 +412,12 @@ namespace Test
[DeploymentItem("SubtitleEdit.exe")]
public void RemoveInterjections6a()
{
FormRemoveTextForHearImpaired_Accessor target = new FormRemoveTextForHearImpaired_Accessor();
target.checkBoxRemoveIfAllUppercase.Checked = false;
target.checkBoxRemoveInterjections.Checked = true;
target.checkBoxOnlyIfInSeparateLine.Checked = false;
target.checkBoxRemoveTextBeforeColonOnlyUppercase.Checked = false;
target.checkBoxColonSeparateLine.Checked = false;
var target = GetRemoveTextForHiLib();
target.settings.RemoveIfAllUppercase = false;
target.settings.RemoveInterjections = true;
target.settings.OnlyIfInSeparateLine = false;
target.settings.RemoveTextBeforeColonOnlyUppercase = false;
target.settings.ColonSeparateLine = false;
string text = "Ballpark, mm-hm.";
string expected = "Ballpark.";
string actual = target.RemoveInterjections(text);
@ -423,12 +428,12 @@ namespace Test
[DeploymentItem("SubtitleEdit.exe")]
public void RemoveInterjections6b()
{
FormRemoveTextForHearImpaired_Accessor target = new FormRemoveTextForHearImpaired_Accessor();
target.checkBoxRemoveIfAllUppercase.Checked = false;
target.checkBoxRemoveInterjections.Checked = true;
target.checkBoxOnlyIfInSeparateLine.Checked = false;
target.checkBoxRemoveTextBeforeColonOnlyUppercase.Checked = false;
target.checkBoxColonSeparateLine.Checked = false;
var target = GetRemoveTextForHiLib();
target.settings.RemoveIfAllUppercase = false;
target.settings.RemoveInterjections = true;
target.settings.OnlyIfInSeparateLine = false;
target.settings.RemoveTextBeforeColonOnlyUppercase = false;
target.settings.ColonSeparateLine = false;
string text = "Mm-hm, Ballpark.";
string expected = "Ballpark.";
string actual = target.RemoveInterjections(text);
@ -439,12 +444,12 @@ namespace Test
[DeploymentItem("SubtitleEdit.exe")]
public void RemoveInterjections6bItalic()
{
FormRemoveTextForHearImpaired_Accessor target = new FormRemoveTextForHearImpaired_Accessor();
target.checkBoxRemoveIfAllUppercase.Checked = false;
target.checkBoxRemoveInterjections.Checked = true;
target.checkBoxOnlyIfInSeparateLine.Checked = false;
target.checkBoxRemoveTextBeforeColonOnlyUppercase.Checked = false;
target.checkBoxColonSeparateLine.Checked = false;
var target = GetRemoveTextForHiLib();
target.settings.RemoveIfAllUppercase = false;
target.settings.RemoveInterjections = true;
target.settings.OnlyIfInSeparateLine = false;
target.settings.RemoveTextBeforeColonOnlyUppercase = false;
target.settings.ColonSeparateLine = false;
string text = "<i>Mm-hm, Ballpark.</i>";
string expected = "<i>Ballpark.</i>";
string actual = target.RemoveInterjections(text);
@ -455,12 +460,12 @@ namespace Test
[DeploymentItem("SubtitleEdit.exe")]
public void RemoveInterjections7()
{
FormRemoveTextForHearImpaired_Accessor target = new FormRemoveTextForHearImpaired_Accessor();
target.checkBoxRemoveIfAllUppercase.Checked = false;
target.checkBoxRemoveInterjections.Checked = true;
target.checkBoxOnlyIfInSeparateLine.Checked = false;
target.checkBoxRemoveTextBeforeColonOnlyUppercase.Checked = false;
target.checkBoxColonSeparateLine.Checked = false;
var target = GetRemoveTextForHiLib();
target.settings.RemoveIfAllUppercase = false;
target.settings.RemoveInterjections = true;
target.settings.OnlyIfInSeparateLine = false;
target.settings.RemoveTextBeforeColonOnlyUppercase = false;
target.settings.ColonSeparateLine = false;
string text = "You like her, huh?";
string expected = "You like her?";
string actual = target.RemoveInterjections(text);
@ -471,12 +476,12 @@ namespace Test
[DeploymentItem("SubtitleEdit.exe")]
public void RemoveInterjections8()
{
FormRemoveTextForHearImpaired_Accessor target = new FormRemoveTextForHearImpaired_Accessor();
target.checkBoxRemoveIfAllUppercase.Checked = false;
target.checkBoxRemoveInterjections.Checked = true;
target.checkBoxOnlyIfInSeparateLine.Checked = false;
target.checkBoxRemoveTextBeforeColonOnlyUppercase.Checked = false;
target.checkBoxColonSeparateLine.Checked = false;
var target = GetRemoveTextForHiLib();
target.settings.RemoveIfAllUppercase = false;
target.settings.RemoveInterjections = true;
target.settings.OnlyIfInSeparateLine = false;
target.settings.RemoveTextBeforeColonOnlyUppercase = false;
target.settings.ColonSeparateLine = false;
string text = "You like her, huh!";
string expected = "You like her!";
string actual = target.RemoveInterjections(text);
@ -487,12 +492,12 @@ namespace Test
[DeploymentItem("SubtitleEdit.exe")]
public void RemoveInterjections9()
{
FormRemoveTextForHearImpaired_Accessor target = new FormRemoveTextForHearImpaired_Accessor();
target.checkBoxRemoveIfAllUppercase.Checked = false;
target.checkBoxRemoveInterjections.Checked = true;
target.checkBoxOnlyIfInSeparateLine.Checked = false;
target.checkBoxRemoveTextBeforeColonOnlyUppercase.Checked = false;
target.checkBoxColonSeparateLine.Checked = false;
var target = GetRemoveTextForHiLib();
target.settings.RemoveIfAllUppercase = false;
target.settings.RemoveInterjections = true;
target.settings.OnlyIfInSeparateLine = false;
target.settings.RemoveTextBeforeColonOnlyUppercase = false;
target.settings.ColonSeparateLine = false;
string text = "You like her, huh.";
string expected = "You like her.";
string actual = target.RemoveInterjections(text);
@ -503,12 +508,12 @@ namespace Test
[DeploymentItem("SubtitleEdit.exe")]
public void RemoveInterjections10()
{
FormRemoveTextForHearImpaired_Accessor target = new FormRemoveTextForHearImpaired_Accessor();
target.checkBoxRemoveIfAllUppercase.Checked = false;
target.checkBoxRemoveInterjections.Checked = true;
target.checkBoxOnlyIfInSeparateLine.Checked = false;
target.checkBoxRemoveTextBeforeColonOnlyUppercase.Checked = false;
target.checkBoxColonSeparateLine.Checked = false;
var target = GetRemoveTextForHiLib();
target.settings.RemoveIfAllUppercase = false;
target.settings.RemoveInterjections = true;
target.settings.OnlyIfInSeparateLine = false;
target.settings.RemoveTextBeforeColonOnlyUppercase = false;
target.settings.ColonSeparateLine = false;
string text = "- You like her, huh." + Environment.NewLine + "- I do";
string expected = "- You like her." + Environment.NewLine + "- I do";
string actual = target.RemoveInterjections(text);
@ -519,12 +524,12 @@ namespace Test
[DeploymentItem("SubtitleEdit.exe")]
public void RemoveInterjections10Italic()
{
FormRemoveTextForHearImpaired_Accessor target = new FormRemoveTextForHearImpaired_Accessor();
target.checkBoxRemoveIfAllUppercase.Checked = false;
target.checkBoxRemoveInterjections.Checked = true;
target.checkBoxOnlyIfInSeparateLine.Checked = false;
target.checkBoxRemoveTextBeforeColonOnlyUppercase.Checked = false;
target.checkBoxColonSeparateLine.Checked = false;
var target = GetRemoveTextForHiLib();
target.settings.RemoveIfAllUppercase = false;
target.settings.RemoveInterjections = true;
target.settings.OnlyIfInSeparateLine = false;
target.settings.RemoveTextBeforeColonOnlyUppercase = false;
target.settings.ColonSeparateLine = false;
string text = "<i>- You like her, huh." + Environment.NewLine + "- I do</i>";
string expected = "<i>- You like her." + Environment.NewLine + "- I do</i>";
string actual = target.RemoveInterjections(text);
@ -536,12 +541,12 @@ namespace Test
[DeploymentItem("SubtitleEdit.exe")]
public void RemoveInterjections11()
{
FormRemoveTextForHearImpaired_Accessor target = new FormRemoveTextForHearImpaired_Accessor();
target.checkBoxRemoveIfAllUppercase.Checked = false;
target.checkBoxRemoveInterjections.Checked = true;
target.checkBoxOnlyIfInSeparateLine.Checked = false;
target.checkBoxRemoveTextBeforeColonOnlyUppercase.Checked = false;
target.checkBoxColonSeparateLine.Checked = false;
var target = GetRemoveTextForHiLib();
target.settings.RemoveIfAllUppercase = false;
target.settings.RemoveInterjections = true;
target.settings.OnlyIfInSeparateLine = false;
target.settings.RemoveTextBeforeColonOnlyUppercase = false;
target.settings.ColonSeparateLine = false;
string text = "- Ballpark, mm-hm." + Environment.NewLine + "- Oh yes!";
string expected = "- Ballpark." + Environment.NewLine + "- Yes!";
string actual = target.RemoveInterjections(text);
@ -552,13 +557,13 @@ namespace Test
[DeploymentItem("SubtitleEdit.exe")]
public void RemoveColonOnlyOnSeparateLine()
{
FormRemoveTextForHearImpaired_Accessor target = new FormRemoveTextForHearImpaired_Accessor();
target.checkBoxRemoveIfAllUppercase.Checked = false;
target.checkBoxRemoveInterjections.Checked = false;
target.checkBoxRemoveTextBeforeColon.Checked = true;
target.checkBoxOnlyIfInSeparateLine.Checked = false;
target.checkBoxRemoveTextBeforeColonOnlyUppercase.Checked = false;
target.checkBoxColonSeparateLine.Checked = true;
var target = GetRemoveTextForHiLib();
target.settings.RemoveIfAllUppercase = false;
target.settings.RemoveInterjections = false;
target.settings.RemoveTextBeforeColon = true;
target.settings.OnlyIfInSeparateLine = false;
target.settings.RemoveTextBeforeColonOnlyUppercase = false;
target.settings.ColonSeparateLine = true;
string text = "HECTOR: Hi.";
string expected = "HECTOR: Hi.";
string actual = target.RemoveColon(text, string.Empty);
@ -569,13 +574,13 @@ namespace Test
[DeploymentItem("SubtitleEdit.exe")]
public void RemoveLineIfAllUppercase1()
{
FormRemoveTextForHearImpaired_Accessor target = new FormRemoveTextForHearImpaired_Accessor();
target.checkBoxRemoveIfAllUppercase.Checked = true;
target.checkBoxRemoveInterjections.Checked = false;
target.checkBoxRemoveTextBeforeColon.Checked = false;
target.checkBoxOnlyIfInSeparateLine.Checked = false;
target.checkBoxRemoveTextBeforeColonOnlyUppercase.Checked = false;
target.checkBoxColonSeparateLine.Checked = false;
var target = GetRemoveTextForHiLib();
target.settings.RemoveIfAllUppercase = true;
target.settings.RemoveInterjections = false;
target.settings.RemoveTextBeforeColon = false;
target.settings.OnlyIfInSeparateLine = false;
target.settings.RemoveTextBeforeColonOnlyUppercase = false;
target.settings.ColonSeparateLine = false;
string text = "HECTOR " + Environment.NewLine + "Hi.";
string expected = "Hi.";
string actual = target.RemoveLineIfAllUppercase(text);
@ -586,13 +591,13 @@ namespace Test
[DeploymentItem("SubtitleEdit.exe")]
public void RemoveLineIfAllUppercase2()
{
FormRemoveTextForHearImpaired_Accessor target = new FormRemoveTextForHearImpaired_Accessor();
target.checkBoxRemoveIfAllUppercase.Checked = true;
target.checkBoxRemoveInterjections.Checked = false;
target.checkBoxRemoveTextBeforeColon.Checked = false;
target.checkBoxOnlyIfInSeparateLine.Checked = false;
target.checkBoxRemoveTextBeforeColonOnlyUppercase.Checked = false;
target.checkBoxColonSeparateLine.Checked = false;
var target = GetRemoveTextForHiLib();
target.settings.RemoveIfAllUppercase = true;
target.settings.RemoveInterjections = false;
target.settings.RemoveTextBeforeColon = false;
target.settings.OnlyIfInSeparateLine = false;
target.settings.RemoveTextBeforeColonOnlyUppercase = false;
target.settings.ColonSeparateLine = false;
string text = "Please, Mr Krook." + Environment.NewLine + "SHOP DOOR BELL CLANGS";
string expected = "Please, Mr Krook.";
string actual = target.RemoveLineIfAllUppercase(text);
@ -603,14 +608,14 @@ namespace Test
[DeploymentItem("SubtitleEdit.exe")]
public void RemoveLineIfAllUppercase3()
{
FormRemoveTextForHearImpaired_Accessor target = new FormRemoveTextForHearImpaired_Accessor();
target.checkBoxRemoveIfAllUppercase.Checked = true;
target.checkBoxRemoveInterjections.Checked = false;
target.checkBoxRemoveTextBeforeColon.Checked = false;
target.checkBoxOnlyIfInSeparateLine.Checked = false;
target.checkBoxRemoveTextBeforeColonOnlyUppercase.Checked = false;
target.checkBoxColonSeparateLine.Checked = false;
target.checkBoxRemoveTextBetweenParentheses.Checked = true;
var target = GetRemoveTextForHiLib();
target.settings.RemoveIfAllUppercase = true;
target.settings.RemoveInterjections = false;
target.settings.RemoveTextBeforeColon = false;
target.settings.OnlyIfInSeparateLine = false;
target.settings.RemoveTextBeforeColonOnlyUppercase = false;
target.settings.ColonSeparateLine = false;
target.settings.RemoveTextBetweenParentheses = true;
string text = "(<i>GOIN' BACK TO INDIANA</i>" + Environment.NewLine + "CONTINUES PLAYING)";
string expected = "";
string actual = target.RemoveLineIfAllUppercase(text);
@ -621,14 +626,14 @@ namespace Test
[DeploymentItem("SubtitleEdit.exe")]
public void RemoveLineIfParentheses3()
{
FormRemoveTextForHearImpaired_Accessor target = new FormRemoveTextForHearImpaired_Accessor();
target.checkBoxRemoveIfAllUppercase.Checked = false;
target.checkBoxRemoveInterjections.Checked = false;
target.checkBoxRemoveTextBeforeColon.Checked = false;
target.checkBoxOnlyIfInSeparateLine.Checked = false;
target.checkBoxRemoveTextBeforeColonOnlyUppercase.Checked = false;
target.checkBoxColonSeparateLine.Checked = false;
target.checkBoxRemoveTextBetweenParentheses.Checked = true;
var target = GetRemoveTextForHiLib();
target.settings.RemoveIfAllUppercase = false;
target.settings.RemoveInterjections = false;
target.settings.RemoveTextBeforeColon = false;
target.settings.OnlyIfInSeparateLine = false;
target.settings.RemoveTextBeforeColonOnlyUppercase = false;
target.settings.ColonSeparateLine = false;
target.settings.RemoveTextBetweenParentheses = true;
string text = "(<i>GOIN' BACK TO INDIANA</i>" + Environment.NewLine + "CONTINUES PLAYING)";
string expected = "";
string actual = target.RemoveHearImpairedTags(text);
@ -640,13 +645,13 @@ namespace Test
[DeploymentItem("SubtitleEdit.exe")]
public void RemoveTextBeforeColonSecondLine()
{
FormRemoveTextForHearImpaired_Accessor target = new FormRemoveTextForHearImpaired_Accessor();
target.checkBoxRemoveIfAllUppercase.Checked = false;
target.checkBoxRemoveInterjections.Checked = false;
target.checkBoxRemoveTextBeforeColon.Checked = true;
target.checkBoxOnlyIfInSeparateLine.Checked = false;
target.checkBoxRemoveTextBeforeColonOnlyUppercase.Checked = false;
target.checkBoxColonSeparateLine.Checked = false;
var target = GetRemoveTextForHiLib();
target.settings.RemoveIfAllUppercase = false;
target.settings.RemoveInterjections = false;
target.settings.RemoveTextBeforeColon = true;
target.settings.OnlyIfInSeparateLine = false;
target.settings.RemoveTextBeforeColonOnlyUppercase = false;
target.settings.ColonSeparateLine = false;
string text = "- even if it was one week." + Environment.NewLine + "CANNING: Objection.";
string expected = "- even if it was one week." + Environment.NewLine + "- Objection.";
string actual = target.RemoveColon(text, string.Empty);