Working on moving logic from FixCommonErrors form to libse

This commit is contained in:
niksedk 2015-09-18 22:18:42 +02:00
parent 97366246c2
commit 0450545022
19 changed files with 1395 additions and 1199 deletions

View File

@ -0,0 +1,50 @@
using Nikse.SubtitleEdit.Core.SubtitleFormats;
namespace Nikse.SubtitleEdit.Core.Forms.FixCommonErrors
{
public class EmptyFixCallback : IFixCallbacks
{
private string _language = "en";
public bool AllowFix(Paragraph p, string action)
{
return true;
}
public void AddFixToListView(Paragraph p, string action, string before, string after)
{
}
public void LogStatus(string sender, string message)
{
}
public void LogStatus(string sender, string message, bool isImportant)
{
}
public void AddToTotalFixes(int count)
{
}
public void AddtoTotalErrors(int count)
{
}
public void AddtoDeleteIndices(int index)
{
}
public SubtitleFormat Format
{
get { return new SubRip(); }
}
public string Language
{
get { return _language; }
set { _language = value; }
}
}
}

View File

@ -0,0 +1,127 @@
using System;
namespace Nikse.SubtitleEdit.Core.Forms.FixCommonErrors
{
public class FixEmptyLines : IFixCommonError
{
public void Fix(Subtitle subtitle, IFixCallbacks callbacks)
{
var language = Configuration.Settings.Language.FixCommonErrors;
string fixAction0 = language.RemovedEmptyLine;
string fixAction1 = language.RemovedEmptyLineAtTop;
string fixAction2 = language.RemovedEmptyLineAtBottom;
if (subtitle.Paragraphs.Count == 0)
return;
int emptyLinesRemoved = 0;
for (int i = subtitle.Paragraphs.Count - 1; i >= 0; i--)
{
Paragraph p = subtitle.Paragraphs[i];
if (!string.IsNullOrEmpty(p.Text))
{
string text = p.Text.Trim(' ');
var oldText = text;
var pre = string.Empty;
var post = string.Empty;
// Ssa Tags
if (text.StartsWith("{\\", StringComparison.Ordinal))
{
var endIDx = text.IndexOf('}', 2);
if (endIDx > 2)
{
pre = text.Substring(0, endIDx + 1);
text = text.Remove(0, endIDx + 1);
}
}
while (text.LineStartsWithHtmlTag(true, true))
{
// Three length tag
if (text[2] == '>')
{
pre += text.Substring(0, 3);
text = text.Remove(0, 3);
}
else // <font ...>
{
var closeIdx = text.IndexOf('>');
if (closeIdx <= 2)
break;
pre += text.Substring(0, closeIdx + 1);
text = text.Remove(0, closeIdx + 1);
}
}
while (text.LineEndsWithHtmlTag(true, true))
{
var len = text.Length;
// Three length tag
if (text[len - 4] == '<')
{
post = text.Substring(text.Length - 4) + post;
text = text.Remove(text.Length - 4);
}
else // </font>
{
post = text.Substring(text.Length - 7) + post;
text = text.Remove(text.Length - 7);
}
}
if (callbacks.AllowFix(p, fixAction1) && text.StartsWith(Environment.NewLine, StringComparison.Ordinal))
{
if (pre.Length > 0)
text = pre + text.TrimStart(Utilities.NewLineChars);
else
text = text.TrimStart(Utilities.NewLineChars);
p.Text = text;
emptyLinesRemoved++;
callbacks.AddFixToListView(p, fixAction1, oldText, p.Text);
}
else
{
text = pre + text;
}
if (callbacks.AllowFix(p, fixAction2) && text.EndsWith(Environment.NewLine, StringComparison.Ordinal))
{
if (post.Length > 0)
text = text.TrimEnd(Utilities.NewLineChars) + post;
else
text = text.TrimEnd(Utilities.NewLineChars);
p.Text = text;
emptyLinesRemoved++;
callbacks.AddFixToListView(p, fixAction2, oldText, p.Text);
}
}
}
// this must be the very last action done, or line numbers will be messed up!!!
for (int i = subtitle.Paragraphs.Count - 1; i >= 0; i--)
{
Paragraph p = subtitle.Paragraphs[i];
var text = HtmlUtil.RemoveHtmlTags(p.Text, true).Trim();
if (callbacks.AllowFix(p, fixAction0) && string.IsNullOrEmpty(text))
{
subtitle.Paragraphs.RemoveAt(i);
emptyLinesRemoved++;
callbacks.AddFixToListView(p, fixAction0, p.Text, string.Format("[{0}]", language.RemovedEmptyLine));
callbacks.AddtoDeleteIndices(i);
}
}
if (emptyLinesRemoved > 0)
{
callbacks.LogStatus(language.RemovedEmptyLinesUnsedLineBreaks, string.Format(language.EmptyLinesRemovedX, emptyLinesRemoved));
callbacks.AddToTotalFixes(emptyLinesRemoved);
subtitle.Renumber();
}
}
}
}

View File

@ -0,0 +1,42 @@
namespace Nikse.SubtitleEdit.Core.Forms.FixCommonErrors
{
public class FixInvalidItalicTags : IFixCommonError
{
public void Fix(Subtitle subtitle, IFixCallbacks callbacks)
{
var language = Configuration.Settings.Language.FixCommonErrors;
const string beginTagUpper = "<I>";
const string endTagUpper = "</I>";
const string beginTag = "<i>";
const string endTag = "</i>";
string fixAction = language.FixInvalidItalicTag;
int noOfInvalidHtmlTags = 0;
for (int i = 0; i < subtitle.Paragraphs.Count; i++)
{
if (callbacks.AllowFix(subtitle.Paragraphs[i], fixAction))
{
var text = subtitle.Paragraphs[i].Text;
if (text.Contains('<'))
{
text = text.Replace(beginTagUpper, beginTag).Replace(endTagUpper, endTag);
string oldText = text;
text = HtmlUtil.FixInvalidItalicTags(text);
if (text != oldText)
{
subtitle.Paragraphs[i].Text = text;
noOfInvalidHtmlTags++;
callbacks.AddFixToListView(subtitle.Paragraphs[i], fixAction, oldText, text);
}
}
}
}
if (noOfInvalidHtmlTags > 0)
{
callbacks.AddToTotalFixes(noOfInvalidHtmlTags);
callbacks.LogStatus(language.FixInvalidItalicTags, string.Format(language.XInvalidHtmlTagsFixed, noOfInvalidHtmlTags));
}
}
}
}

View File

@ -0,0 +1,43 @@
namespace Nikse.SubtitleEdit.Core.Forms.FixCommonErrors
{
public class FixLongDisplayTimes : IFixCommonError
{
public void Fix(Subtitle subtitle, IFixCallbacks callbacks)
{
var language = Configuration.Settings.Language.FixCommonErrors;
string fixAction = language.FixLongDisplayTime;
int noOfLongDisplayTimes = 0;
for (int i = 0; i < subtitle.Paragraphs.Count; i++)
{
Paragraph p = subtitle.Paragraphs[i];
double maxDisplayTime = Utilities.GetOptimalDisplayMilliseconds(p.Text) * 8.0;
if (maxDisplayTime > Configuration.Settings.General.SubtitleMaximumDisplayMilliseconds)
maxDisplayTime = Configuration.Settings.General.SubtitleMaximumDisplayMilliseconds;
double displayTime = p.Duration.TotalMilliseconds;
bool allowFix = callbacks.AllowFix(p, fixAction);
if (allowFix && displayTime > Configuration.Settings.General.SubtitleMaximumDisplayMilliseconds)
{
string oldCurrent = p.ToString();
p.EndTime.TotalMilliseconds = p.StartTime.TotalMilliseconds + Configuration.Settings.General.SubtitleMaximumDisplayMilliseconds;
noOfLongDisplayTimes++;
callbacks.AddFixToListView(p, fixAction, oldCurrent, p.ToString());
}
else if (allowFix && maxDisplayTime < displayTime)
{
string oldCurrent = p.ToString();
displayTime = Utilities.GetOptimalDisplayMilliseconds(p.Text);
p.EndTime.TotalMilliseconds = p.StartTime.TotalMilliseconds + displayTime;
noOfLongDisplayTimes++;
callbacks.AddFixToListView(p, fixAction, oldCurrent, p.ToString());
}
}
if (noOfLongDisplayTimes > 0)
{
callbacks.AddToTotalFixes(noOfLongDisplayTimes);
callbacks.LogStatus(language.FixLongDisplayTimes, string.Format(language.XDisplayTimesShortned, noOfLongDisplayTimes));
}
}
}
}

View File

@ -0,0 +1,43 @@
namespace Nikse.SubtitleEdit.Core.Forms.FixCommonErrors
{
public class FixLongLines : IFixCommonError
{
public void Fix(Subtitle subtitle, IFixCallbacks callbacks)
{
var language = Configuration.Settings.Language.FixCommonErrors;
string fixAction = language.BreakLongLine;
int noOfLongLines = 0;
for (int i = 0; i < subtitle.Paragraphs.Count; i++)
{
Paragraph p = subtitle.Paragraphs[i];
var lines = p.Text.SplitToLines();
bool tooLong = false;
foreach (string line in lines)
{
if (HtmlUtil.RemoveHtmlTags(line, true).Length > Configuration.Settings.General.SubtitleLineMaximumLength)
{
tooLong = true;
break;
}
}
if (callbacks.AllowFix(p, fixAction) && tooLong)
{
string oldText = p.Text;
p.Text = Utilities.AutoBreakLine(p.Text, callbacks.Language);
if (oldText != p.Text)
{
noOfLongLines++;
callbacks.AddFixToListView(p, fixAction, oldText, p.Text);
}
else
{
callbacks.LogStatus(fixAction, string.Format(language.UnableToFixTextXY, i + 1, p));
callbacks.AddtoTotalErrors(1);
}
}
}
if (noOfLongLines > 0)
callbacks.LogStatus(language.BreakLongLines, string.Format(language.XLineBreaksAdded, noOfLongLines));
}
}
}

View File

@ -0,0 +1,344 @@
using System;
using System.Text.RegularExpressions;
namespace Nikse.SubtitleEdit.Core.Forms.FixCommonErrors
{
public class FixMissingSpaces : IFixCommonError
{
private static readonly Regex FixMissingSpacesReComma = new Regex(@"[^\s\d],[^\s]", RegexOptions.Compiled);
private static readonly Regex FixMissingSpacesRePeriod = new Regex(@"[a-z][a-z][.][a-zA-Z]", RegexOptions.Compiled);
private static readonly Regex FixMissingSpacesReQuestionMark = new Regex(@"[^\s\d]\?[a-zA-Z]", RegexOptions.Compiled);
private static readonly Regex FixMissingSpacesReExclamation = new Regex(@"[^\s\d]\![a-zA-Z]", RegexOptions.Compiled);
private static readonly Regex FixMissingSpacesReColon = new Regex(@"[^\s\d]\:[a-zA-Z]", RegexOptions.Compiled);
private static readonly Regex UrlCom = new Regex(@"\w\.com\b", RegexOptions.Compiled);
private static readonly Regex UrlNet = new Regex(@"\w\.net\b", RegexOptions.Compiled);
private static readonly Regex UrlOrg = new Regex(@"\w\.org\b", RegexOptions.Compiled);
public void Fix(Subtitle subtitle, IFixCallbacks callbacks)
{
var language = Configuration.Settings.Language.FixCommonErrors;
string languageCode = callbacks.Language;
string fixAction = language.FixMissingSpace;
int missingSpaces = 0;
const string expectedChars = @"""”<.";
for (int i = 0; i < subtitle.Paragraphs.Count; i++)
{
Paragraph p = subtitle.Paragraphs[i];
// missing space after comma ","
Match match = FixMissingSpacesReComma.Match(p.Text);
while (match.Success)
{
bool doFix = !expectedChars.Contains(p.Text[match.Index + 2]);
if (doFix && languageCode == "el" && (p.Text.Substring(match.Index).StartsWith("ό,τι", StringComparison.Ordinal) || p.Text.Substring(match.Index).StartsWith("ο,τι", StringComparison.Ordinal)))
doFix = false;
if (doFix && callbacks.AllowFix(p, fixAction))
{
missingSpaces++;
string oldText = p.Text;
p.Text = p.Text.Replace(match.Value, match.Value[0] + ", " + match.Value[match.Value.Length - 1]);
callbacks.AddFixToListView(p, fixAction, oldText, p.Text);
}
match = match.NextMatch();
}
bool allowFix = callbacks.AllowFix(p, fixAction);
// missing space after "?"
match = FixMissingSpacesReQuestionMark.Match(p.Text);
while (match.Success)
{
if (allowFix && !@"""<".Contains(p.Text[match.Index + 2]))
{
missingSpaces++;
string oldText = p.Text;
p.Text = p.Text.Replace(match.Value, match.Value[0] + "? " + match.Value[match.Value.Length - 1]);
callbacks.AddFixToListView(p, fixAction, oldText, p.Text);
}
match = FixMissingSpacesReQuestionMark.Match(p.Text, match.Index + 1);
}
// missing space after "!"
match = FixMissingSpacesReExclamation.Match(p.Text);
while (match.Success)
{
if (allowFix && !@"""<".Contains(p.Text[match.Index + 2]))
{
missingSpaces++;
string oldText = p.Text;
p.Text = p.Text.Replace(match.Value, match.Value[0] + "! " + match.Value[match.Value.Length - 1]);
callbacks.AddFixToListView(p, fixAction, oldText, p.Text);
}
match = FixMissingSpacesReExclamation.Match(p.Text, match.Index + 1);
}
// missing space after ":"
match = FixMissingSpacesReColon.Match(p.Text);
while (match.Success)
{
int start = match.Index;
start -= 4;
if (start < 0)
start = 0;
int indexOfStartCodeTag = p.Text.IndexOf('{', start);
int indexOfEndCodeTag = p.Text.IndexOf('}', start);
if (indexOfStartCodeTag >= 0 && indexOfEndCodeTag >= 0 && indexOfStartCodeTag < match.Index)
{
// we are inside a tag: like indexOfEndCodeTag "{y:i}Is this italic?"
}
else if (allowFix && !@"""<".Contains(p.Text[match.Index + 2]))
{
missingSpaces++;
string oldText = p.Text;
p.Text = p.Text.Replace(match.Value, match.Value[0] + ": " + match.Value[match.Value.Length - 1]);
callbacks.AddFixToListView(p, fixAction, oldText, p.Text);
}
match = FixMissingSpacesReColon.Match(p.Text, match.Index + 1);
}
// missing space after period "."
match = FixMissingSpacesRePeriod.Match(p.Text);
while (match.Success)
{
if (!p.Text.Contains("www.", StringComparison.OrdinalIgnoreCase) &&
!p.Text.Contains("http://", StringComparison.OrdinalIgnoreCase) &&
!UrlCom.IsMatch(p.Text) &&
!UrlNet.IsMatch(p.Text) &&
!UrlOrg.IsMatch(p.Text)) // urls are skipped
{
bool isMatchAbbreviation = false;
string word = GetWordFromIndex(p.Text, match.Index);
if (Utilities.CountTagInText(word, '.') > 1)
isMatchAbbreviation = true;
if (!isMatchAbbreviation && word.Contains('@')) // skip emails
isMatchAbbreviation = true;
if (match.Value.Equals("h.d", StringComparison.OrdinalIgnoreCase) && match.Index > 0 && p.Text.Substring(match.Index - 1, 4).Equals("ph.d", StringComparison.OrdinalIgnoreCase))
isMatchAbbreviation = true;
if (!isMatchAbbreviation && callbacks.AllowFix(p, fixAction))
{
missingSpaces++;
string oldText = p.Text;
p.Text = p.Text.Replace(match.Value, match.Value.Replace(".", ". "));
callbacks.AddFixToListView(p, fixAction, oldText, p.Text);
}
}
match = match.NextMatch();
}
if (!p.Text.StartsWith("--", StringComparison.Ordinal))
{
var arr = p.Text.SplitToLines();
if (arr.Length == 2 && arr[0].Length > 1 && arr[1].Length > 1)
{
if (arr[0][0] == '-' && arr[0][1] != ' ')
arr[0] = arr[0].Insert(1, " ");
if (arr[0].Length > 6 && arr[0].StartsWith("<i>-", StringComparison.OrdinalIgnoreCase) && arr[0][4] != ' ')
arr[0] = arr[0].Insert(4, " ");
if (arr[1][0] == '-' && arr[1][1] != ' ' && arr[1][1] != '-')
arr[1] = arr[1].Insert(1, " ");
if (arr[1].Length > 6 && arr[1].StartsWith("<i>-", StringComparison.OrdinalIgnoreCase) && arr[1][4] != ' ')
arr[1] = arr[1].Insert(4, " ");
string newText = arr[0] + Environment.NewLine + arr[1];
if (newText != p.Text && callbacks.AllowFix(p, fixAction))
{
missingSpaces++;
string oldText = p.Text;
p.Text = newText;
callbacks.AddFixToListView(p, fixAction, oldText, p.Text);
}
}
}
//fix missing spaces before/after quotes - Get a"get out of jail free"card. -> Get a "get out of jail free" card.
if (Utilities.CountTagInText(p.Text, '"') == 2)
{
int start = p.Text.IndexOf('"');
int end = p.Text.LastIndexOf('"');
string quote = p.Text.Substring(start, end - start + 1);
if (!quote.Contains(Environment.NewLine))
{
string newText = p.Text;
int indexOfFontTag = newText.IndexOf("<font ", StringComparison.OrdinalIgnoreCase);
bool isAfterAssTag = newText.Contains("{\\") && start > 0 && newText[start - 1] == '}';
if (!isAfterAssTag && start > 0 && !(Environment.NewLine + @" >[(♪♫¿").Contains(p.Text[start - 1]))
{
if (indexOfFontTag < 0 || start > newText.IndexOf('>', indexOfFontTag)) // font tags can contain "
{
newText = newText.Insert(start, " ");
end++;
}
}
if (end < newText.Length - 2 && !(Environment.NewLine + @" <,.!?:;])♪♫¿").Contains(p.Text[end + 1]))
{
if (indexOfFontTag < 0 || end > newText.IndexOf('>', indexOfFontTag)) // font tags can contain "
{
newText = newText.Insert(end + 1, " ");
}
}
if (newText != p.Text && callbacks.AllowFix(p, fixAction))
{
missingSpaces++;
string oldText = p.Text;
p.Text = newText;
callbacks.AddFixToListView(p, fixAction, oldText, p.Text);
}
}
}
//fix missing spaces before/after music quotes - #He's so happy# -> #He's so happy#
if (p.Text.Length > 5 && p.Text.Contains(new[] { '#', '♪', '♫' }))
{
string newText = p.Text;
if (@"#♪♫".Contains(newText[0]) && !@" <".Contains(newText[1]) && !newText.Substring(1).StartsWith(Environment.NewLine) &&
!newText.Substring(1).StartsWith('♪') && !newText.Substring(1).StartsWith('♫'))
newText = newText.Insert(1, " ");
if (@"#♪♫".Contains(newText[newText.Length - 1]) && !@" >".Contains(newText[newText.Length - 2]) &&
!newText.Substring(0, newText.Length - 1).EndsWith(Environment.NewLine, StringComparison.Ordinal) && !newText.Substring(0, newText.Length - 1).EndsWith('♪') &&
!newText.Substring(0, newText.Length - 1).EndsWith('♫'))
newText = newText.Insert(newText.Length - 1, " ");
if (newText != p.Text && callbacks.AllowFix(p, fixAction))
{
missingSpaces++;
string oldText = p.Text;
p.Text = newText;
callbacks.AddFixToListView(p, fixAction, oldText, p.Text);
}
}
//fix missing spaces in "Hey...move it!" to "Hey... move it!"
int index = p.Text.IndexOf("...", StringComparison.Ordinal);
if (index >= 0 && p.Text.Length > 5)
{
string newText = p.Text;
while (index != -1)
{
if (newText.Length > index + 4 && index > 1)
{
if (Utilities.AllLettersAndNumbers.Contains(newText[index + 3]) &&
Utilities.AllLettersAndNumbers.Contains(newText[index - 1]))
newText = newText.Insert(index + 3, " ");
}
index = newText.IndexOf("...", index + 2, StringComparison.Ordinal);
}
if (newText != p.Text && callbacks.AllowFix(p, fixAction))
{
missingSpaces++;
string oldText = p.Text;
p.Text = newText;
callbacks.AddFixToListView(p, fixAction, oldText, p.Text);
}
}
//fix missing spaces in "The<i>Bombshell</i> will gone." to "The <i>Bombshell</i> will gone."
index = p.Text.IndexOf("<i>", StringComparison.OrdinalIgnoreCase);
if (index >= 0 && p.Text.Length > 5)
{
string newText = p.Text;
while (index != -1)
{
if (newText.Length > index + 6 && index > 1)
{
if (Utilities.AllLettersAndNumbers.Contains(newText[index + 3]) &&
Utilities.AllLettersAndNumbers.Contains(newText[index - 1]))
newText = newText.Insert(index, " ");
}
index = newText.IndexOf("<i>", index + 3, StringComparison.OrdinalIgnoreCase);
}
if (newText != p.Text && callbacks.AllowFix(p, fixAction))
{
missingSpaces++;
string oldText = p.Text;
p.Text = newText;
callbacks.AddFixToListView(p, fixAction, oldText, p.Text);
}
}
//fix missing spaces in "The <i>Bombshell</i>will gone." to "The <i>Bombshell</i> will gone."
index = p.Text.IndexOf("</i>", StringComparison.OrdinalIgnoreCase);
if (index > 3 && p.Text.Length > 5)
{
string newText = p.Text;
while (index != -1)
{
if (newText.Length > index + 6 && index > 1)
{
if (Utilities.AllLettersAndNumbers.Contains(newText[index + 4]) &&
Utilities.AllLettersAndNumbers.Contains(newText[index - 1]))
newText = newText.Insert(index + 4, " ");
}
index = newText.IndexOf("</i>", index + 4, StringComparison.OrdinalIgnoreCase);
}
if (newText != p.Text && callbacks.AllowFix(p, fixAction))
{
missingSpaces++;
string oldText = p.Text;
p.Text = newText;
callbacks.AddFixToListView(p, fixAction, oldText, p.Text);
}
}
if (callbacks.Language == "fr") // special rules for French
{
string newText = p.Text;
int j = 1;
while (j < newText.Length)
{
if (@"!?:;".Contains(newText[j]))
{
if (Utilities.AllLetters.Contains(newText[j - 1]))
{
newText = newText.Insert(j, " ");
j++;
}
}
j++;
}
if (newText != p.Text && callbacks.AllowFix(p, fixAction))
{
missingSpaces++;
string oldText = p.Text;
p.Text = newText;
callbacks.AddFixToListView(p, fixAction, oldText, p.Text);
}
}
}
if (missingSpaces > 0)
{
callbacks.AddToTotalFixes(missingSpaces);
callbacks.LogStatus(language.FixMissingSpaces, string.Format(language.XMissingSpacesAdded, missingSpaces));
}
}
private static string GetWordFromIndex(string text, int index)
{
if (string.IsNullOrEmpty(text) || index < 0 || index >= text.Length)
return string.Empty;
int endIndex = index;
for (int i = index; i < text.Length; i++)
{
if ((@" " + Environment.NewLine).Contains(text[i]))
break;
endIndex = i;
}
int startIndex = index;
for (int i = index; i >= 0; i--)
{
if ((@" " + Environment.NewLine).Contains(text[i]))
break;
startIndex = i;
}
return text.Substring(startIndex, endIndex - startIndex + 1);
}
}
}

View File

@ -0,0 +1,240 @@
using Nikse.SubtitleEdit.Core.SubtitleFormats;
using System;
namespace Nikse.SubtitleEdit.Core.Forms.FixCommonErrors
{
public class FixOverlappingDisplayTimes : IFixCommonError
{
public void Fix(Subtitle subtitle, IFixCallbacks callbacks)
{
var language = Configuration.Settings.Language.FixCommonErrors;
// negative display time
string fixAction = language.FixOverlappingDisplayTime;
int noOfOverlappingDisplayTimesFixed = 0;
for (int i = 0; i < subtitle.Paragraphs.Count; i++)
{
var p = subtitle.Paragraphs[i];
var oldP = new Paragraph(p);
if (p.Duration.TotalMilliseconds < 0) // negative display time...
{
bool isFixed = false;
string status = string.Format(language.StartTimeLaterThanEndTime,
i + 1, p.StartTime, p.EndTime, p.Text, Environment.NewLine);
var prev = subtitle.GetParagraphOrDefault(i - 1);
var next = subtitle.GetParagraphOrDefault(i + 1);
double wantedDisplayTime = Utilities.GetOptimalDisplayMilliseconds(p.Text) * 0.9;
if (next == null || next.StartTime.TotalMilliseconds > p.StartTime.TotalMilliseconds + wantedDisplayTime)
{
if (callbacks.AllowFix(p, fixAction))
{
p.EndTime.TotalMilliseconds = p.StartTime.TotalMilliseconds + wantedDisplayTime;
isFixed = true;
}
}
else if (next.StartTime.TotalMilliseconds > p.StartTime.TotalMilliseconds + 500.0)
{
if (callbacks.AllowFix(p, fixAction))
{
p.EndTime.TotalMilliseconds = p.StartTime.TotalMilliseconds + 500.0;
isFixed = true;
}
}
else if (prev == null || next.StartTime.TotalMilliseconds - wantedDisplayTime > prev.EndTime.TotalMilliseconds)
{
if (callbacks.AllowFix(p, fixAction))
{
p.StartTime.TotalMilliseconds = next.StartTime.TotalMilliseconds - wantedDisplayTime;
p.EndTime.TotalMilliseconds = next.StartTime.TotalMilliseconds - 1;
isFixed = true;
}
}
else
{
callbacks.LogStatus(language.FixOverlappingDisplayTimes, string.Format(language.UnableToFixStartTimeLaterThanEndTime, i + 1, p), true);
callbacks.AddtoTotalErrors(1);
}
if (isFixed)
{
noOfOverlappingDisplayTimesFixed++;
status = string.Format(language.XFixedToYZ, status, Environment.NewLine, p);
callbacks.LogStatus(language.FixOverlappingDisplayTimes, status);
callbacks.AddFixToListView(p, fixAction, oldP.ToString(), p.ToString());
}
}
}
// overlapping display time
for (int i = 1; i < subtitle.Paragraphs.Count; i++)
{
Paragraph p = subtitle.Paragraphs[i];
Paragraph prev = subtitle.GetParagraphOrDefault(i - 1);
Paragraph target = prev;
string oldCurrent = p.ToString();
string oldPrevious = prev.ToString();
double prevWantedDisplayTime = Utilities.GetOptimalDisplayMilliseconds(prev.Text, Configuration.Settings.General.SubtitleMaximumCharactersPerSeconds);
double currentWantedDisplayTime = Utilities.GetOptimalDisplayMilliseconds(p.Text, Configuration.Settings.General.SubtitleMaximumCharactersPerSeconds);
double prevOptimalDisplayTime = Utilities.GetOptimalDisplayMilliseconds(prev.Text);
double currentOptimalDisplayTime = Utilities.GetOptimalDisplayMilliseconds(p.Text);
bool canBeEqual = callbacks.Format != null && callbacks.Format.GetType() == typeof(AdvancedSubStationAlpha) || callbacks.Format.GetType() == typeof(SubStationAlpha);
if (!canBeEqual)
canBeEqual = Configuration.Settings.Tools.FixCommonErrorsFixOverlapAllowEqualEndStart;
double diff = prev.EndTime.TotalMilliseconds - p.StartTime.TotalMilliseconds;
if (!prev.StartTime.IsMaxTime && !p.StartTime.IsMaxTime && diff >= 0 && !(canBeEqual && Math.Abs(diff) < 0.001))
{
int diffHalf = (int)(diff / 2);
if (!Configuration.Settings.Tools.FixCommonErrorsFixOverlapAllowEqualEndStart && Math.Abs(p.StartTime.TotalMilliseconds - prev.EndTime.TotalMilliseconds) < 0.001 &&
prev.Duration.TotalMilliseconds > 100)
{
if (callbacks.AllowFix(target, fixAction))
{
if (!canBeEqual)
{
bool okEqual = true;
if (prev.Duration.TotalMilliseconds > Configuration.Settings.General.SubtitleMinimumDisplayMilliseconds)
prev.EndTime.TotalMilliseconds--;
else if (p.Duration.TotalMilliseconds > Configuration.Settings.General.SubtitleMinimumDisplayMilliseconds)
p.StartTime.TotalMilliseconds++;
else
okEqual = false;
if (okEqual)
{
noOfOverlappingDisplayTimesFixed++;
callbacks.AddFixToListView(target, fixAction, oldPrevious, prev.ToString());
}
}
}
//prev.EndTime.TotalMilliseconds--;
}
else if (prevOptimalDisplayTime <= (p.StartTime.TotalMilliseconds - prev.StartTime.TotalMilliseconds))
{
if (callbacks.AllowFix(target, fixAction))
{
prev.EndTime.TotalMilliseconds = p.StartTime.TotalMilliseconds - 1;
if (canBeEqual)
prev.EndTime.TotalMilliseconds++;
noOfOverlappingDisplayTimesFixed++;
callbacks.AddFixToListView(target, fixAction, oldPrevious, prev.ToString());
}
}
else if (diff > 0 && currentOptimalDisplayTime <= p.Duration.TotalMilliseconds - diffHalf &&
prevOptimalDisplayTime <= prev.Duration.TotalMilliseconds - diffHalf)
{
if (callbacks.AllowFix(p, fixAction))
{
prev.EndTime.TotalMilliseconds -= diffHalf;
p.StartTime.TotalMilliseconds = prev.EndTime.TotalMilliseconds + 1;
noOfOverlappingDisplayTimesFixed++;
callbacks.AddFixToListView(p, fixAction, oldCurrent, p.ToString());
}
}
else if (currentOptimalDisplayTime <= p.EndTime.TotalMilliseconds - prev.EndTime.TotalMilliseconds)
{
if (callbacks.AllowFix(p, fixAction))
{
p.StartTime.TotalMilliseconds = prev.EndTime.TotalMilliseconds + 1;
if (canBeEqual)
p.StartTime.TotalMilliseconds = prev.EndTime.TotalMilliseconds;
noOfOverlappingDisplayTimesFixed++;
callbacks.AddFixToListView(p, fixAction, oldCurrent, p.ToString());
}
}
else if (diff > 0 && currentWantedDisplayTime <= p.Duration.TotalMilliseconds - diffHalf &&
prevWantedDisplayTime <= prev.Duration.TotalMilliseconds - diffHalf)
{
if (callbacks.AllowFix(p, fixAction))
{
prev.EndTime.TotalMilliseconds -= diffHalf;
p.StartTime.TotalMilliseconds = prev.EndTime.TotalMilliseconds + 1;
noOfOverlappingDisplayTimesFixed++;
callbacks.AddFixToListView(p, fixAction, oldCurrent, p.ToString());
}
}
else if (prevWantedDisplayTime <= (p.StartTime.TotalMilliseconds - prev.StartTime.TotalMilliseconds))
{
if (callbacks.AllowFix(target, fixAction))
{
prev.EndTime.TotalMilliseconds = p.StartTime.TotalMilliseconds - 1;
if (canBeEqual)
prev.EndTime.TotalMilliseconds++;
noOfOverlappingDisplayTimesFixed++;
callbacks.AddFixToListView(target, fixAction, oldPrevious, prev.ToString());
}
}
else if (currentWantedDisplayTime <= p.EndTime.TotalMilliseconds - prev.EndTime.TotalMilliseconds)
{
if (callbacks.AllowFix(p, fixAction))
{
p.StartTime.TotalMilliseconds = prev.EndTime.TotalMilliseconds + 1;
if (canBeEqual)
p.StartTime.TotalMilliseconds = prev.EndTime.TotalMilliseconds;
noOfOverlappingDisplayTimesFixed++;
callbacks.AddFixToListView(p, fixAction, oldCurrent, p.ToString());
}
}
else if (Math.Abs(p.StartTime.TotalMilliseconds - prev.EndTime.TotalMilliseconds) < 10 && p.Duration.TotalMilliseconds > 1)
{
if (callbacks.AllowFix(p, fixAction))
{
prev.EndTime.TotalMilliseconds -= 2;
p.StartTime.TotalMilliseconds = prev.EndTime.TotalMilliseconds + 1;
if (canBeEqual)
p.StartTime.TotalMilliseconds = prev.EndTime.TotalMilliseconds;
noOfOverlappingDisplayTimesFixed++;
callbacks.AddFixToListView(p, fixAction, oldCurrent, p.ToString());
}
}
else if (Math.Abs(p.StartTime.TotalMilliseconds - prev.StartTime.TotalMilliseconds) < 10 && Math.Abs(p.EndTime.TotalMilliseconds - prev.EndTime.TotalMilliseconds) < 10)
{ // merge lines with same time codes
if (callbacks.AllowFix(target, fixAction))
{
prev.Text = prev.Text.Replace(Environment.NewLine, " ");
p.Text = p.Text.Replace(Environment.NewLine, " ");
string stripped = HtmlUtil.RemoveHtmlTags(prev.Text).TrimStart();
if (!stripped.StartsWith("- ", StringComparison.Ordinal))
prev.Text = "- " + prev.Text.TrimStart();
stripped = HtmlUtil.RemoveHtmlTags(p.Text).TrimStart();
if (!stripped.StartsWith("- ", StringComparison.Ordinal))
p.Text = "- " + p.Text.TrimStart();
prev.Text = prev.Text.Trim() + Environment.NewLine + p.Text;
p.Text = string.Empty;
noOfOverlappingDisplayTimesFixed++;
callbacks.AddFixToListView(target, fixAction, oldCurrent, p.ToString());
p.StartTime.TotalMilliseconds = prev.EndTime.TotalMilliseconds + 1;
p.EndTime.TotalMilliseconds = p.StartTime.TotalMilliseconds + 1;
if (canBeEqual)
{
p.StartTime.TotalMilliseconds = prev.EndTime.TotalMilliseconds;
p.EndTime.TotalMilliseconds = p.StartTime.TotalMilliseconds;
}
}
}
else
{
if (callbacks.AllowFix(p, fixAction))
{
callbacks.LogStatus(language.FixOverlappingDisplayTimes, string.Format(language.UnableToFixTextXY, i + 1, Environment.NewLine + prev.Number + " " + prev + Environment.NewLine + p.Number + " " + p), true);
callbacks.AddtoTotalErrors(1);
}
}
}
}
if (noOfOverlappingDisplayTimesFixed > 0)
{
callbacks.AddToTotalFixes(noOfOverlappingDisplayTimesFixed);
callbacks.LogStatus(fixAction, string.Format(language.XOverlappingTimestampsFixed, noOfOverlappingDisplayTimesFixed));
}
}
}
}

View File

@ -0,0 +1,170 @@
namespace Nikse.SubtitleEdit.Core.Forms.FixCommonErrors
{
public class FixShortDisplayTimes : IFixCommonError
{
private IFixCallbacks _callbacks;
public void Fix(Subtitle subtitle, IFixCallbacks callbacks)
{
var language = Configuration.Settings.Language.FixCommonErrors;
_callbacks = callbacks;
string fixAction = language.FixShortDisplayTime;
int noOfShortDisplayTimes = 0;
for (int i = 0; i < subtitle.Paragraphs.Count; i++)
{
Paragraph p = subtitle.Paragraphs[i];
var skip = p.StartTime.IsMaxTime || p.EndTime.IsMaxTime;
double displayTime = p.Duration.TotalMilliseconds;
if (!skip && displayTime < Configuration.Settings.General.SubtitleMinimumDisplayMilliseconds)
{
Paragraph next = subtitle.GetParagraphOrDefault(i + 1);
Paragraph prev = subtitle.GetParagraphOrDefault(i - 1);
if (next == null || (p.StartTime.TotalMilliseconds + Configuration.Settings.General.SubtitleMinimumDisplayMilliseconds + Configuration.Settings.General.MinimumMillisecondsBetweenLines) < next.StartTime.TotalMilliseconds)
{
var temp = new Paragraph(p) { EndTime = { TotalMilliseconds = p.StartTime.TotalMilliseconds + Configuration.Settings.General.SubtitleMinimumDisplayMilliseconds } };
if (Utilities.GetCharactersPerSecond(temp) <= Configuration.Settings.General.SubtitleMaximumCharactersPerSeconds)
{
if (callbacks.AllowFix(p, fixAction))
{
string oldCurrent = p.ToString();
p.EndTime.TotalMilliseconds = p.StartTime.TotalMilliseconds + Configuration.Settings.General.SubtitleMinimumDisplayMilliseconds;
noOfShortDisplayTimes++;
callbacks.AddFixToListView(p, fixAction, oldCurrent, p.ToString());
}
}
}
else if (Configuration.Settings.Tools.FixShortDisplayTimesAllowMoveStartTime && p.StartTime.TotalMilliseconds > Configuration.Settings.General.SubtitleMinimumDisplayMilliseconds &&
(prev == null || prev.EndTime.TotalMilliseconds < p.EndTime.TotalMilliseconds - Configuration.Settings.General.SubtitleMinimumDisplayMilliseconds - Configuration.Settings.General.MinimumMillisecondsBetweenLines))
{
if (callbacks.AllowFix(p, fixAction))
{
string oldCurrent = p.ToString();
if (next.StartTime.TotalMilliseconds - Configuration.Settings.General.MinimumMillisecondsBetweenLines > p.EndTime.TotalMilliseconds)
p.EndTime.TotalMilliseconds = next.StartTime.TotalMilliseconds - Configuration.Settings.General.MinimumMillisecondsBetweenLines;
p.StartTime.TotalMilliseconds = p.EndTime.TotalMilliseconds - Configuration.Settings.General.SubtitleMinimumDisplayMilliseconds;
noOfShortDisplayTimes++;
callbacks.AddFixToListView(p, fixAction, oldCurrent, p.ToString());
}
}
else
{
callbacks.LogStatus(language.FixShortDisplayTimes, string.Format(language.UnableToFixTextXY, i + 1, p));
callbacks.AddtoTotalErrors(1);
skip = true;
}
}
double charactersPerSecond = Utilities.GetCharactersPerSecond(p);
if (!skip && charactersPerSecond > Configuration.Settings.General.SubtitleMaximumCharactersPerSeconds)
{
var temp = new Paragraph(p);
while (Utilities.GetCharactersPerSecond(temp) > Configuration.Settings.General.SubtitleMaximumCharactersPerSeconds)
{
temp.EndTime.TotalMilliseconds++;
}
Paragraph next = subtitle.GetParagraphOrDefault(i + 1);
Paragraph nextNext = subtitle.GetParagraphOrDefault(i + 2);
Paragraph prev = subtitle.GetParagraphOrDefault(i - 1);
double diffMs = temp.Duration.TotalMilliseconds - p.Duration.TotalMilliseconds;
// Normal - just make current subtitle duration longer
if (next == null || temp.EndTime.TotalMilliseconds + Configuration.Settings.General.MinimumMillisecondsBetweenLines < next.StartTime.TotalMilliseconds)
{
if (callbacks.AllowFix(p, fixAction))
{
string oldCurrent = p.ToString();
p.EndTime.TotalMilliseconds = temp.EndTime.TotalMilliseconds;
noOfShortDisplayTimes++;
callbacks.AddFixToListView(p, fixAction, oldCurrent, p.ToString());
}
}
// Start current subtitle earlier (max 50 ms)
else if (Configuration.Settings.Tools.FixShortDisplayTimesAllowMoveStartTime && p.StartTime.TotalMilliseconds > Configuration.Settings.General.SubtitleMinimumDisplayMilliseconds &&
diffMs < 50 && (prev == null || prev.EndTime.TotalMilliseconds < p.EndTime.TotalMilliseconds - temp.Duration.TotalMilliseconds - Configuration.Settings.General.MinimumMillisecondsBetweenLines))
{
noOfShortDisplayTimes = MoveStartTime(fixAction, noOfShortDisplayTimes, p, temp, next);
}
// Make current subtitle duration longer + move next subtitle
else if (diffMs < 1000 &&
Configuration.Settings.Tools.FixShortDisplayTimesAllowMoveStartTime &&
p.StartTime.TotalMilliseconds > Configuration.Settings.General.SubtitleMinimumDisplayMilliseconds &&
(nextNext == null || next.EndTime.TotalMilliseconds + diffMs + Configuration.Settings.General.MinimumMillisecondsBetweenLines * 2 < nextNext.StartTime.TotalMilliseconds))
{
if (callbacks.AllowFix(p, fixAction))
{
string oldCurrent = p.ToString();
p.EndTime.TotalMilliseconds = p.StartTime.TotalMilliseconds + temp.Duration.TotalMilliseconds;
var nextDurationMs = next.Duration.TotalMilliseconds;
next.StartTime.TotalMilliseconds = p.EndTime.TotalMilliseconds + Configuration.Settings.General.MinimumMillisecondsBetweenLines;
next.EndTime.TotalMilliseconds = next.StartTime.TotalMilliseconds + nextDurationMs;
noOfShortDisplayTimes++;
callbacks.AddFixToListView(p, fixAction, oldCurrent, p.ToString());
}
}
// Make next subtitle duration shorter + make current subtitle duration longer
else if (diffMs < 1000 &&
Configuration.Settings.Tools.FixShortDisplayTimesAllowMoveStartTime && Utilities.GetCharactersPerSecond(new Paragraph(next.Text, p.StartTime.TotalMilliseconds + temp.Duration.TotalMilliseconds + Configuration.Settings.General.MinimumMillisecondsBetweenLines, next.EndTime.TotalMilliseconds)) < Configuration.Settings.General.SubtitleMaximumCharactersPerSeconds)
{
if (callbacks.AllowFix(p, fixAction))
{
string oldCurrent = p.ToString();
next.StartTime.TotalMilliseconds = p.StartTime.TotalMilliseconds + temp.Duration.TotalMilliseconds + Configuration.Settings.General.MinimumMillisecondsBetweenLines;
p.EndTime.TotalMilliseconds = next.StartTime.TotalMilliseconds - Configuration.Settings.General.MinimumMillisecondsBetweenLines;
noOfShortDisplayTimes++;
callbacks.AddFixToListView(p, fixAction, oldCurrent, p.ToString());
}
}
// Make next-next subtitle duration shorter + move next + make current subtitle duration longer
else if (diffMs < 500 &&
Configuration.Settings.Tools.FixShortDisplayTimesAllowMoveStartTime && nextNext != null &&
Utilities.GetCharactersPerSecond(new Paragraph(nextNext.Text, nextNext.StartTime.TotalMilliseconds + diffMs + Configuration.Settings.General.MinimumMillisecondsBetweenLines, nextNext.EndTime.TotalMilliseconds - (diffMs))) < Configuration.Settings.General.SubtitleMaximumCharactersPerSeconds)
{
if (callbacks.AllowFix(p, fixAction))
{
string oldCurrent = p.ToString();
p.EndTime.TotalMilliseconds += diffMs;
next.StartTime.TotalMilliseconds += diffMs;
next.EndTime.TotalMilliseconds += diffMs;
nextNext.StartTime.TotalMilliseconds += diffMs;
noOfShortDisplayTimes++;
callbacks.AddFixToListView(p, fixAction, oldCurrent, p.ToString());
}
}
// Start current subtitle earlier (max 200 ms)
else if (Configuration.Settings.Tools.FixShortDisplayTimesAllowMoveStartTime && p.StartTime.TotalMilliseconds > Configuration.Settings.General.SubtitleMinimumDisplayMilliseconds &&
diffMs < 200 && (prev == null || prev.EndTime.TotalMilliseconds < p.EndTime.TotalMilliseconds - temp.Duration.TotalMilliseconds - Configuration.Settings.General.MinimumMillisecondsBetweenLines))
{
noOfShortDisplayTimes = MoveStartTime(fixAction, noOfShortDisplayTimes, p, temp, next);
}
else
{
callbacks.LogStatus(language.FixShortDisplayTimes, string.Format(language.UnableToFixTextXY, i + 1, p));
callbacks.AddtoTotalErrors(1);
}
}
}
if (noOfShortDisplayTimes > 0)
{
callbacks.AddToTotalFixes(noOfShortDisplayTimes);
callbacks.LogStatus(fixAction, string.Format(language.XDisplayTimesProlonged, noOfShortDisplayTimes));
}
}
private int MoveStartTime(string fixAction, int noOfShortDisplayTimes, Paragraph p, Paragraph temp, Paragraph next)
{
if (_callbacks.AllowFix(p, fixAction))
{
string oldCurrent = p.ToString();
if (next != null && next.StartTime.TotalMilliseconds - Configuration.Settings.General.MinimumMillisecondsBetweenLines > p.EndTime.TotalMilliseconds)
p.EndTime.TotalMilliseconds = next.StartTime.TotalMilliseconds - Configuration.Settings.General.MinimumMillisecondsBetweenLines;
p.StartTime.TotalMilliseconds = p.EndTime.TotalMilliseconds - temp.Duration.TotalMilliseconds;
noOfShortDisplayTimes++;
_callbacks.AddFixToListView(p, fixAction, oldCurrent, p.ToString());
}
return noOfShortDisplayTimes;
}
}
}

View File

@ -0,0 +1,34 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Nikse.SubtitleEdit.Core.Forms.FixCommonErrors
{
public class FixShortLines : IFixCommonError
{
public void Fix(Subtitle subtitle, IFixCallbacks callbacks)
{
var language = Configuration.Settings.Language.FixCommonErrors;
string fixAction = language.MergeShortLine;
int noOfShortLines = 0;
for (int i = 0; i < subtitle.Paragraphs.Count; i++)
{
Paragraph p = subtitle.Paragraphs[i];
string oldText = p.Text;
var text = Helper.FixShortLines(p.Text);
if (callbacks.AllowFix(p, fixAction) && oldText != text)
{
p.Text = text;
noOfShortLines++;
callbacks.AddFixToListView(p, fixAction, oldText, p.Text);
}
}
if (noOfShortLines > 0)
{
callbacks.AddToTotalFixes(noOfShortLines);
callbacks.LogStatus(language.RemoveLineBreaks, string.Format(language.XLinesUnbreaked, noOfShortLines));
}
}
}
}

View File

@ -0,0 +1,61 @@
using System;
namespace Nikse.SubtitleEdit.Core.Forms.FixCommonErrors
{
public class FixUnneededPeriods : IFixCommonError
{
public void Fix(Subtitle subtitle, IFixCallbacks callbacks)
{
var language = Configuration.Settings.Language.FixCommonErrors;
string fixAction = language.UnneededPeriod;
int unneededPeriodsFixed = 0;
for (int i = 0; i < subtitle.Paragraphs.Count; i++)
{
Paragraph p = subtitle.Paragraphs[i];
var oldText = p.Text;
if (callbacks.AllowFix(p, fixAction))
{
if (p.Text.Contains("!." + Environment.NewLine))
{
p.Text = p.Text.Replace("!." + Environment.NewLine, "!" + Environment.NewLine);
unneededPeriodsFixed++;
}
if (p.Text.Contains("?." + Environment.NewLine))
{
p.Text = p.Text.Replace("?." + Environment.NewLine, "?" + Environment.NewLine);
unneededPeriodsFixed++;
}
if (p.Text.EndsWith("!.", StringComparison.Ordinal))
{
p.Text = p.Text.TrimEnd('.');
unneededPeriodsFixed++;
}
if (p.Text.EndsWith("?.", StringComparison.Ordinal))
{
p.Text = p.Text.TrimEnd('.');
unneededPeriodsFixed++;
}
if (p.Text.Contains("!. "))
{
p.Text = p.Text.Replace("!. ", "! ");
unneededPeriodsFixed++;
}
if (p.Text.Contains("?. "))
{
p.Text = p.Text.Replace("?. ", "? ");
unneededPeriodsFixed++;
}
if (p.Text != oldText)
callbacks.AddFixToListView(p, fixAction, oldText, p.Text);
}
}
if (unneededPeriodsFixed > 0)
{
callbacks.AddToTotalFixes(unneededPeriodsFixed);
callbacks.LogStatus(language.RemoveUnneededPeriods, string.Format(language.XUnneededPeriodsRemoved, unneededPeriodsFixed));
}
}
}
}

View File

@ -0,0 +1,32 @@
namespace Nikse.SubtitleEdit.Core.Forms.FixCommonErrors
{
public class FixUnneededSpaces : IFixCommonError
{
public void Fix(Subtitle subtitle, IFixCallbacks callbacks)
{
var language = Configuration.Settings.Language.FixCommonErrors;
string fixAction = language.UnneededSpace;
int doubleSpaces = 0;
for (int i = 0; i < subtitle.Paragraphs.Count; i++)
{
Paragraph p = subtitle.Paragraphs[i];
if (callbacks.AllowFix(p, fixAction))
{
var oldText = p.Text;
var text = Utilities.RemoveUnneededSpaces(p.Text, callbacks.Language);
if (text.Length != oldText.Length && (Utilities.CountTagInText(text, ' ') + Utilities.CountTagInText(text, '\t')) < (Utilities.CountTagInText(oldText, ' ') + Utilities.CountTagInText(oldText, '\u00A0') + Utilities.CountTagInText(oldText, '\t')))
{
doubleSpaces++;
p.Text = text;
callbacks.AddFixToListView(p, fixAction, oldText, p.Text);
}
}
}
if (doubleSpaces > 0)
{
callbacks.AddToTotalFixes(doubleSpaces);
callbacks.LogStatus(language.RemoveUnneededSpaces, string.Format(language.XUnneededSpacesRemoved, doubleSpaces));
}
}
}
}

View File

@ -1,9 +1,9 @@
using System;
using System.Linq;
namespace Nikse.SubtitleEdit.Core.Forms
namespace Nikse.SubtitleEdit.Core.Forms.FixCommonErrors
{
public static class FixCommonErrorsHelper
public static class Helper
{
public static string FixEllipsesStartHelper(string text)
{

View File

@ -0,0 +1,17 @@
using Nikse.SubtitleEdit.Core.SubtitleFormats;
namespace Nikse.SubtitleEdit.Core.Forms.FixCommonErrors
{
public interface IFixCallbacks
{
bool AllowFix(Paragraph p, string action);
void AddFixToListView(Paragraph p, string action, string before, string after);
void LogStatus(string sender, string message);
void LogStatus(string sender, string message, bool isImportant);
void AddToTotalFixes(int count);
void AddtoTotalErrors(int count);
void AddtoDeleteIndices(int index);
SubtitleFormat Format { get; }
string Language { get; }
}
}

View File

@ -0,0 +1,7 @@
namespace Nikse.SubtitleEdit.Core.Forms.FixCommonErrors
{
public interface IFixCommonError
{
void Fix(Subtitle subtitle, IFixCallbacks callbacks);
}
}

View File

@ -128,7 +128,20 @@
<Compile Include="FileUtil.cs" />
<Compile Include="FindReplaceDialogHelper.cs" />
<Compile Include="Forms\CheckForUpdatesHelper.cs" />
<Compile Include="Forms\FixCommonErrorsHelper.cs" />
<Compile Include="Forms\FixCommonErrors\EmptyFixCallback.cs" />
<Compile Include="Forms\FixCommonErrors\FixEmptyLines.cs" />
<Compile Include="Forms\FixCommonErrors\FixInvalidItalicTags.cs" />
<Compile Include="Forms\FixCommonErrors\FixLongDisplayTimes.cs" />
<Compile Include="Forms\FixCommonErrors\FixLongLines.cs" />
<Compile Include="Forms\FixCommonErrors\FixMissingSpaces.cs" />
<Compile Include="Forms\FixCommonErrors\FixOverlappingDisplayTimes.cs" />
<Compile Include="Forms\FixCommonErrors\FixShortDisplayTimes.cs" />
<Compile Include="Forms\FixCommonErrors\FixShortLines.cs" />
<Compile Include="Forms\FixCommonErrors\FixUnneededPeriods.cs" />
<Compile Include="Forms\FixCommonErrors\FixUnneededSpaces.cs" />
<Compile Include="Forms\FixCommonErrors\Helper.cs" />
<Compile Include="Forms\FixCommonErrors\IFixCallbacks.cs" />
<Compile Include="Forms\FixCommonErrors\IFixCommonError.cs" />
<Compile Include="Forms\RemoveTextForHI.cs" />
<Compile Include="Forms\RemoveTextForHISettings.cs" />
<Compile Include="Forms\SplitLongLinesHelper.cs" />

File diff suppressed because it is too large Load Diff

View File

@ -1,5 +1,6 @@
using Nikse.SubtitleEdit.Controls;
using Nikse.SubtitleEdit.Core;
using Nikse.SubtitleEdit.Core.Forms.FixCommonErrors;
using Nikse.SubtitleEdit.Logic;
using Nikse.SubtitleEdit.Logic.VideoPlayers;
using System;
@ -421,8 +422,9 @@ namespace Nikse.SubtitleEdit.Forms
var tmpSubtitle = new Subtitle { WasLoadedWithFrameNumbers = _originalSubtitle.WasLoadedWithFrameNumbers };
foreach (Paragraph p in _paragraphs)
tmpSubtitle.Paragraphs.Add(new Paragraph(p));
formFix.Initialize(tmpSubtitle, tmpSubtitle.OriginalFormat, System.Text.Encoding.UTF8);
formFix.FixOverlappingDisplayTimes();
new FixOverlappingDisplayTimes().Fix(tmpSubtitle, new EmptyFixCallback());
_paragraphs.Clear();
foreach (Paragraph p in formFix.FixedSubtitle.Paragraphs)
_paragraphs.Add(new Paragraph(p));

View File

@ -2,7 +2,7 @@
using System.Collections.Generic;
using System.IO;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Nikse.SubtitleEdit.Core.Forms;
using Nikse.SubtitleEdit.Core.Forms.FixCommonErrors;
using Nikse.SubtitleEdit.Core.SubtitleFormats;
using Nikse.SubtitleEdit.Forms;
using Nikse.SubtitleEdit.Core;
@ -22,24 +22,26 @@ namespace Test
///</summary>
public TestContext TestContext { get; set; }
private Subtitle _subtitle;
private static FixCommonErrors GetFixCommonErrorsLib()
{
return new FixCommonErrors();
}
private static void InitializeFixCommonErrorsLine(FixCommonErrors target, string line)
private void InitializeFixCommonErrorsLine(FixCommonErrors target, string line)
{
var subtitle = new Subtitle();
subtitle.Paragraphs.Add(new Paragraph(line, 100, 10000));
target.Initialize(subtitle, new SubRip(), System.Text.Encoding.UTF8);
_subtitle = new Subtitle();
_subtitle.Paragraphs.Add(new Paragraph(line, 100, 10000));
target.Initialize(_subtitle, new SubRip(), System.Text.Encoding.UTF8);
}
private static void InitializeFixCommonErrorsLine(FixCommonErrors target, string line, string line2)
private void InitializeFixCommonErrorsLine(FixCommonErrors target, string line, string line2)
{
var subtitle = new Subtitle();
subtitle.Paragraphs.Add(new Paragraph(line, 100, 10000));
subtitle.Paragraphs.Add(new Paragraph(line2, 10001, 30000));
target.Initialize(subtitle, new SubRip(), System.Text.Encoding.UTF8);
_subtitle = new Subtitle();
_subtitle.Paragraphs.Add(new Paragraph(line, 100, 10000));
_subtitle.Paragraphs.Add(new Paragraph(line2, 10001, 30000));
target.Initialize(_subtitle, new SubRip(), System.Text.Encoding.UTF8);
}
#region Additional test attributes
@ -127,8 +129,8 @@ namespace Test
using (var target = GetFixCommonErrorsLib())
{
InitializeFixCommonErrorsLine(target, "This is" + Environment.NewLine + "short!");
target.FixShortLines();
Assert.AreEqual(target.Subtitle.Paragraphs[0].Text, "This is short!");
new FixShortLines().Fix(_subtitle, new EmptyFixCallback());
Assert.AreEqual(_subtitle.Paragraphs[0].Text, "This is short!");
}
}
@ -139,7 +141,7 @@ namespace Test
using (var target = GetFixCommonErrorsLib())
{
InitializeFixCommonErrorsLine(target, "This I'm pretty sure is not a" + Environment.NewLine + "short line, that should be merged!!!");
target.FixShortLines();
new FixShortLines().Fix(_subtitle, new EmptyFixCallback());
Assert.AreEqual(target.Subtitle.Paragraphs[0].Text, "This I'm pretty sure is not a" + Environment.NewLine + "short line, that should be merged!!!");
}
}
@ -151,8 +153,8 @@ namespace Test
using (var target = GetFixCommonErrorsLib())
{
InitializeFixCommonErrorsLine(target, "<i>This is" + Environment.NewLine + "short!</i>");
target.FixShortLines();
Assert.AreEqual(target.Subtitle.Paragraphs[0].Text, "<i>This is short!</i>");
new FixShortLines().Fix(_subtitle, new EmptyFixCallback());
Assert.AreEqual(_subtitle.Paragraphs[0].Text, "<i>This is short!</i>");
}
}
@ -163,7 +165,7 @@ namespace Test
using (var target = GetFixCommonErrorsLib())
{
InitializeFixCommonErrorsLine(target, "- Hallo!" + Environment.NewLine + "- Hi");
target.FixShortLines();
new FixShortLines().Fix(_subtitle, new EmptyFixCallback());
Assert.AreEqual(target.Subtitle.Paragraphs[0].Text, "- Hallo!" + Environment.NewLine + "- Hi");
}
}
@ -175,7 +177,7 @@ namespace Test
using (var target = GetFixCommonErrorsLib())
{
InitializeFixCommonErrorsLine(target, "<i>- Hallo!" + Environment.NewLine + "- Hi</i>");
target.FixShortLines();
new FixShortLines().Fix(_subtitle, new EmptyFixCallback());
Assert.AreEqual(target.Subtitle.Paragraphs[0].Text, "<i>- Hallo!" + Environment.NewLine + "- Hi</i>");
}
}
@ -187,7 +189,7 @@ namespace Test
using (var target = GetFixCommonErrorsLib())
{
InitializeFixCommonErrorsLine(target, "<i>- Hallo!</i>" + Environment.NewLine + "<i>- Hi<i>");
target.FixShortLines();
new FixShortLines().Fix(_subtitle, new EmptyFixCallback());
Assert.AreEqual(target.Subtitle.Paragraphs[0].Text, "<i>- Hallo!</i>" + Environment.NewLine + "<i>- Hi<i>");
}
}
@ -200,7 +202,7 @@ namespace Test
{
string source = "♪ La, la, la ♪" + Environment.NewLine + "♪ La, la, la ♪";
InitializeFixCommonErrorsLine(target, source);
target.FixShortLines();
new FixShortLines().Fix(_subtitle, new EmptyFixCallback());
Assert.AreEqual(target.Subtitle.Paragraphs[0].Text, source);
}
}
@ -215,8 +217,8 @@ namespace Test
string expected = input;
string expected2 = input2;
var result = FixCommonErrorsHelper.FixShortLines(input);
var result2 = FixCommonErrorsHelper.FixShortLines(input2);
var result = Helper.FixShortLines(input);
var result2 = Helper.FixShortLines(input2);
Assert.AreEqual(result, expected); Assert.AreEqual(result2, expected2.Replace(Environment.NewLine, " "));
}
@ -233,8 +235,8 @@ namespace Test
using (var target = GetFixCommonErrorsLib())
{
InitializeFixCommonErrorsLine(target, "<i>Hey!" + Environment.NewLine + "<i>Boy!");
target.FixInvalidItalicTags();
Assert.AreEqual(target.Subtitle.Paragraphs[0].Text, "<i>Hey!</i>" + Environment.NewLine + "<i>Boy!</i>");
new FixInvalidItalicTags().Fix(_subtitle, new EmptyFixCallback());
Assert.AreEqual(_subtitle.Paragraphs[0].Text, "<i>Hey!</i>" + Environment.NewLine + "<i>Boy!</i>");
}
}
@ -245,8 +247,8 @@ namespace Test
using (var target = GetFixCommonErrorsLib())
{
InitializeFixCommonErrorsLine(target, "<i>(jones) seems their attackers headed north." + Environment.NewLine + "<i>Hi!</i>");
target.FixInvalidItalicTags();
Assert.AreEqual(target.Subtitle.Paragraphs[0].Text, "<i>(jones) seems their attackers headed north." + Environment.NewLine + "Hi!</i>");
new FixInvalidItalicTags().Fix(_subtitle, new EmptyFixCallback());
Assert.AreEqual(_subtitle.Paragraphs[0].Text, "<i>(jones) seems their attackers headed north." + Environment.NewLine + "Hi!</i>");
}
}
@ -257,8 +259,8 @@ namespace Test
using (var target = GetFixCommonErrorsLib())
{
InitializeFixCommonErrorsLine(target, "Seems their <i>attackers headed north.");
target.FixInvalidItalicTags();
Assert.AreEqual(target.Subtitle.Paragraphs[0].Text, "Seems their attackers headed north.");
new FixInvalidItalicTags().Fix(_subtitle, new EmptyFixCallback());
Assert.AreEqual(_subtitle.Paragraphs[0].Text, "Seems their attackers headed north.");
}
}
@ -269,8 +271,8 @@ namespace Test
using (var target = GetFixCommonErrorsLib())
{
InitializeFixCommonErrorsLine(target, "<i></i>test");
target.FixInvalidItalicTags();
Assert.AreEqual(target.Subtitle.Paragraphs[0].Text, "test");
new FixInvalidItalicTags().Fix(_subtitle, new EmptyFixCallback());
Assert.AreEqual(_subtitle.Paragraphs[0].Text, "test");
}
}
@ -281,8 +283,8 @@ namespace Test
using (var target = GetFixCommonErrorsLib())
{
InitializeFixCommonErrorsLine(target, "- And..." + Environment.NewLine + "<i>Awesome it is!");
target.FixInvalidItalicTags();
Assert.AreEqual(target.Subtitle.Paragraphs[0].Text, "- And..." + Environment.NewLine + "<i>Awesome it is!</i>");
new FixInvalidItalicTags().Fix(_subtitle, new EmptyFixCallback());
Assert.AreEqual(_subtitle.Paragraphs[0].Text, "- And..." + Environment.NewLine + "<i>Awesome it is!</i>");
}
}
@ -293,8 +295,8 @@ namespace Test
using (var target = GetFixCommonErrorsLib())
{
InitializeFixCommonErrorsLine(target, "Awesome it is!</i>");
target.FixInvalidItalicTags();
Assert.AreEqual(target.Subtitle.Paragraphs[0].Text, "<i>Awesome it is!</i>");
new FixInvalidItalicTags().Fix(_subtitle, new EmptyFixCallback());
Assert.AreEqual(_subtitle.Paragraphs[0].Text, "<i>Awesome it is!</i>");
}
}
@ -305,8 +307,8 @@ namespace Test
using (var target = GetFixCommonErrorsLib())
{
InitializeFixCommonErrorsLine(target, "Awesome it is!<i></i>");
target.FixInvalidItalicTags();
Assert.AreEqual(target.Subtitle.Paragraphs[0].Text, "Awesome it is!");
new FixInvalidItalicTags().Fix(_subtitle, new EmptyFixCallback());
Assert.AreEqual(_subtitle.Paragraphs[0].Text, "Awesome it is!");
}
}
@ -317,8 +319,8 @@ namespace Test
using (var target = GetFixCommonErrorsLib())
{
InitializeFixCommonErrorsLine(target, "Awesome it is!<i>");
target.FixInvalidItalicTags();
Assert.AreEqual(target.Subtitle.Paragraphs[0].Text, "Awesome it is!");
new FixInvalidItalicTags().Fix(_subtitle, new EmptyFixCallback());
Assert.AreEqual(_subtitle.Paragraphs[0].Text, "Awesome it is!");
}
}
@ -329,8 +331,8 @@ namespace Test
using (var target = GetFixCommonErrorsLib())
{
InitializeFixCommonErrorsLine(target, "Awesome it is!</i><i>");
target.FixInvalidItalicTags();
Assert.AreEqual(target.Subtitle.Paragraphs[0].Text, "Awesome it is!");
new FixInvalidItalicTags().Fix(_subtitle, new EmptyFixCallback());
Assert.AreEqual(_subtitle.Paragraphs[0].Text, "Awesome it is!");
}
}
@ -341,8 +343,8 @@ namespace Test
using (var target = GetFixCommonErrorsLib())
{
InitializeFixCommonErrorsLine(target, "</i>What do i care.</i>");
target.FixInvalidItalicTags();
Assert.AreEqual(target.Subtitle.Paragraphs[0].Text, "<i>What do i care.</i>");
new FixInvalidItalicTags().Fix(_subtitle, new EmptyFixCallback());
Assert.AreEqual(_subtitle.Paragraphs[0].Text, "<i>What do i care.</i>");
}
}
@ -353,8 +355,8 @@ namespace Test
using (var target = GetFixCommonErrorsLib())
{
InitializeFixCommonErrorsLine(target, "<i>To be a life-changing weekend</i>" + Environment.NewLine + "<i>for all of us.");
target.FixInvalidItalicTags();
Assert.AreEqual(target.Subtitle.Paragraphs[0].Text, "<i>To be a life-changing weekend" + Environment.NewLine + "for all of us.</i>");
new FixInvalidItalicTags().Fix(_subtitle, new EmptyFixCallback());
Assert.AreEqual(_subtitle.Paragraphs[0].Text, "<i>To be a life-changing weekend" + Environment.NewLine + "for all of us.</i>");
}
}
@ -603,8 +605,8 @@ namespace Test
using (var target = GetFixCommonErrorsLib())
{
InitializeFixCommonErrorsLine(target, "The<i>Bombshell</i> will gone.");
target.FixMissingSpaces();
Assert.AreEqual(target.Subtitle.Paragraphs[0].Text, "The <i>Bombshell</i> will gone.");
new FixMissingSpaces().Fix(_subtitle, new EmptyFixCallback());
Assert.AreEqual(_subtitle.Paragraphs[0].Text, "The <i>Bombshell</i> will gone.");
}
}
@ -615,8 +617,8 @@ namespace Test
using (var target = GetFixCommonErrorsLib())
{
InitializeFixCommonErrorsLine(target, "The <i>Bombshell</i>will gone.");
target.FixMissingSpaces();
Assert.AreEqual(target.Subtitle.Paragraphs[0].Text, "The <i>Bombshell</i> will gone.");
new FixMissingSpaces().Fix(_subtitle, new EmptyFixCallback());
Assert.AreEqual(_subtitle.Paragraphs[0].Text, "The <i>Bombshell</i> will gone.");
}
}
@ -627,8 +629,8 @@ namespace Test
using (var target = GetFixCommonErrorsLib())
{
InitializeFixCommonErrorsLine(target, "It will be okay.It surely will be!");
target.FixMissingSpaces();
Assert.AreEqual(target.Subtitle.Paragraphs[0].Text, "It will be okay. It surely will be!");
new FixMissingSpaces().Fix(_subtitle, new EmptyFixCallback());
Assert.AreEqual(_subtitle.Paragraphs[0].Text, "It will be okay. It surely will be!");
}
}
@ -639,8 +641,8 @@ namespace Test
using (var target = GetFixCommonErrorsLib())
{
InitializeFixCommonErrorsLine(target, "you can't get out.Alright?");
target.FixMissingSpaces();
Assert.AreEqual(target.Subtitle.Paragraphs[0].Text, "you can't get out. Alright?");
new FixMissingSpaces().Fix(_subtitle, new EmptyFixCallback());
Assert.AreEqual(_subtitle.Paragraphs[0].Text, "you can't get out. Alright?");
}
}
@ -651,8 +653,8 @@ namespace Test
using (var target = GetFixCommonErrorsLib())
{
InitializeFixCommonErrorsLine(target, "What did Dr. Gey say?");
target.FixMissingSpaces();
Assert.AreEqual(target.Subtitle.Paragraphs[0].Text, "What did Dr. Gey say?");
new FixMissingSpaces().Fix(_subtitle, new EmptyFixCallback());
Assert.AreEqual(_subtitle.Paragraphs[0].Text, "What did Dr. Gey say?");
}
}
@ -663,8 +665,8 @@ namespace Test
using (var target = GetFixCommonErrorsLib())
{
InitializeFixCommonErrorsLine(target, "To be,or not to be!");
target.FixMissingSpaces();
Assert.AreEqual(target.Subtitle.Paragraphs[0].Text, "To be, or not to be!");
new FixMissingSpaces().Fix(_subtitle, new EmptyFixCallback());
Assert.AreEqual(_subtitle.Paragraphs[0].Text, "To be, or not to be!");
}
}
@ -675,8 +677,8 @@ namespace Test
using (var target = GetFixCommonErrorsLib())
{
InitializeFixCommonErrorsLine(target, "Go to the O.R. now!");
target.FixMissingSpaces();
Assert.AreEqual(target.Subtitle.Paragraphs[0].Text, "Go to the O.R. now!");
new FixMissingSpaces().Fix(_subtitle, new EmptyFixCallback());
Assert.AreEqual(_subtitle.Paragraphs[0].Text, "Go to the O.R. now!");
}
}
@ -687,8 +689,8 @@ namespace Test
using (var target = GetFixCommonErrorsLib())
{
InitializeFixCommonErrorsLine(target, "Email niksedk@gmail.Com now!");
target.FixMissingSpaces();
Assert.AreEqual(target.Subtitle.Paragraphs[0].Text, "Email niksedk@gmail.Com now!");
new FixMissingSpaces().Fix(_subtitle, new EmptyFixCallback());
Assert.AreEqual(_subtitle.Paragraphs[0].Text, "Email niksedk@gmail.Com now!");
}
}
@ -699,8 +701,8 @@ namespace Test
using (var target = GetFixCommonErrorsLib())
{
InitializeFixCommonErrorsLine(target, "Go to www.nikse.dk for more info");
target.FixMissingSpaces();
Assert.AreEqual(target.Subtitle.Paragraphs[0].Text, "Go to www.nikse.dk for more info");
new FixMissingSpaces().Fix(_subtitle, new EmptyFixCallback());
Assert.AreEqual(_subtitle.Paragraphs[0].Text, "Go to www.nikse.dk for more info");
}
}
@ -711,9 +713,8 @@ namespace Test
using (var target = GetFixCommonErrorsLib())
{
InitializeFixCommonErrorsLine(target, "Aφαίρεσαν ό,τι αντρικό είχες.");
target.Language = "el"; // Greek
target.FixMissingSpaces();
Assert.AreEqual(target.Subtitle.Paragraphs[0].Text, "Aφαίρεσαν ό,τι αντρικό είχες.");
new FixMissingSpaces().Fix(_subtitle, new EmptyFixCallback() { Language = "el" }); // Greek
Assert.AreEqual(_subtitle.Paragraphs[0].Text, "Aφαίρεσαν ό,τι αντρικό είχες.");
}
}
@ -727,8 +728,8 @@ namespace Test
using (var target = GetFixCommonErrorsLib())
{
InitializeFixCommonErrorsLine(target, "To be , or not to be!");
target.FixUnneededSpaces();
Assert.AreEqual(target.Subtitle.Paragraphs[0].Text, "To be, or not to be!");
new FixUnneededSpaces().Fix(_subtitle, new EmptyFixCallback());
Assert.AreEqual(_subtitle.Paragraphs[0].Text, "To be, or not to be!");
}
}
@ -738,9 +739,9 @@ namespace Test
using (var target = GetFixCommonErrorsLib())
{
InitializeFixCommonErrorsLine(target, " To be, or not to be!");
target.FixUnneededSpaces();
new FixUnneededSpaces().Fix(_subtitle, new EmptyFixCallback());
const string expected = "To be, or not to be!";
Assert.AreEqual(expected, target.Subtitle.Paragraphs[0].Text);
Assert.AreEqual(expected, _subtitle.Paragraphs[0].Text);
}
}
@ -750,8 +751,8 @@ namespace Test
using (var target = GetFixCommonErrorsLib())
{
InitializeFixCommonErrorsLine(target, "To be , or not to be! ");
target.FixUnneededSpaces();
Assert.AreEqual(target.Subtitle.Paragraphs[0].Text, "To be, or not to be!");
new FixUnneededSpaces().Fix(_subtitle, new EmptyFixCallback());
Assert.AreEqual(_subtitle.Paragraphs[0].Text, "To be, or not to be!");
}
}
@ -761,8 +762,8 @@ namespace Test
using (var target = GetFixCommonErrorsLib())
{
InitializeFixCommonErrorsLine(target, "To be , or not to be! " + Environment.NewLine + " Line two.");
target.FixUnneededSpaces();
Assert.AreEqual(target.Subtitle.Paragraphs[0].Text, "To be, or not to be!" + Environment.NewLine + "Line two.");
new FixUnneededSpaces().Fix(_subtitle, new EmptyFixCallback());
Assert.AreEqual(_subtitle.Paragraphs[0].Text, "To be, or not to be!" + Environment.NewLine + "Line two.");
}
}
@ -773,9 +774,9 @@ namespace Test
{
const string expected = "\"Foo\" bar.";
InitializeFixCommonErrorsLine(target, "\"Foo \" bar.", "\" Foo \" bar.");
target.FixUnneededSpaces();
Assert.AreEqual(target.Subtitle.Paragraphs[0].Text, expected);
Assert.AreEqual(target.Subtitle.Paragraphs[1].Text, expected);
new FixUnneededSpaces().Fix(_subtitle, new EmptyFixCallback());
Assert.AreEqual(_subtitle.Paragraphs[0].Text, expected);
Assert.AreEqual(_subtitle.Paragraphs[1].Text, expected);
}
}
@ -786,8 +787,8 @@ namespace Test
{
const string expected = "Foo bar.";
InitializeFixCommonErrorsLine(target, "Foo \t\tbar.");
target.FixUnneededSpaces();
Assert.AreEqual(target.Subtitle.Paragraphs[0].Text, expected);
new FixUnneededSpaces().Fix(_subtitle, new EmptyFixCallback());
Assert.AreEqual(_subtitle.Paragraphs[0].Text, expected);
}
}
@ -798,8 +799,8 @@ namespace Test
{
const string expected = "Hi <i>bad</i> man!";
InitializeFixCommonErrorsLine(target, "Hi <i> bad</i> man!");
target.FixUnneededSpaces();
Assert.AreEqual(target.Subtitle.Paragraphs[0].Text, expected);
new FixUnneededSpaces().Fix(_subtitle, new EmptyFixCallback());
Assert.AreEqual(_subtitle.Paragraphs[0].Text, expected);
}
}
@ -810,8 +811,8 @@ namespace Test
{
const string expected = "Hi <i>bad</i> man!";
InitializeFixCommonErrorsLine(target, "Hi <i>bad </i> man!");
target.FixUnneededSpaces();
Assert.AreEqual(target.Subtitle.Paragraphs[0].Text, expected);
new FixUnneededSpaces().Fix(_subtitle, new EmptyFixCallback());
Assert.AreEqual(_subtitle.Paragraphs[0].Text, expected);
}
}
@ -822,8 +823,8 @@ namespace Test
{
const string expected = "Hi <font color='red'>bad</font> man!";
InitializeFixCommonErrorsLine(target, "Hi <font color='red'> bad</font> man!");
target.FixUnneededSpaces();
Assert.AreEqual(target.Subtitle.Paragraphs[0].Text, expected);
new FixUnneededSpaces().Fix(_subtitle, new EmptyFixCallback());
Assert.AreEqual(_subtitle.Paragraphs[0].Text, expected);
}
}
@ -838,8 +839,8 @@ namespace Test
using (var target = GetFixCommonErrorsLib())
{
InitializeFixCommonErrorsLine(target, "<i>\r\nHello world!\r\n</i>");
target.FixEmptyLines();
Assert.AreEqual(target.Subtitle.Paragraphs[0].Text, "<i>Hello world!</i>");
new FixEmptyLines().Fix(_subtitle, new EmptyFixCallback());
Assert.AreEqual(_subtitle.Paragraphs[0].Text, "<i>Hello world!</i>");
}
}
@ -850,8 +851,8 @@ namespace Test
using (var target = GetFixCommonErrorsLib())
{
InitializeFixCommonErrorsLine(target, "<font color=\"#000000\">\r\nHello world!\r\n</font>");
target.FixEmptyLines();
Assert.AreEqual(target.Subtitle.Paragraphs[0].Text, "<font color=\"#000000\">Hello world!</font>");
new FixEmptyLines().Fix(_subtitle, new EmptyFixCallback());
Assert.AreEqual(_subtitle.Paragraphs[0].Text, "<font color=\"#000000\">Hello world!</font>");
}
}
@ -1154,7 +1155,7 @@ namespace Test
subtitle.Paragraphs.Add(new Paragraph(t1, 0, 1000));
subtitle.Paragraphs.Add(new Paragraph(t2, 1000, 4000));
{
var result = FixCommonErrorsHelper.FixHyphensRemove(subtitle, 1);
var result = Helper.FixHyphensRemove(subtitle, 1);
string target = "oh, no, no, no, you're gonna" + Environment.NewLine + "need to add the mattress,";
Assert.AreEqual(target, result);
}
@ -1170,7 +1171,7 @@ namespace Test
subtitle.Paragraphs.Add(new Paragraph(t1, 0, 1000));
subtitle.Paragraphs.Add(new Paragraph(t2, 1000, 4000));
{
var result = FixCommonErrorsHelper.FixHyphensRemove(subtitle, 1);
var result = Helper.FixHyphensRemove(subtitle, 1);
const string target = "PREVIOUSLY ON<I> HAVEN...</I>";
Assert.AreEqual(target, result);
}
@ -1184,7 +1185,7 @@ namespace Test
[DeploymentItem("SubtitleEdit.exe")]
public void FixEllipsesStartNormal1()
{
var result = FixCommonErrorsHelper.FixEllipsesStartHelper("...But that is true.");
var result = Helper.FixEllipsesStartHelper("...But that is true.");
Assert.AreEqual(result, "But that is true.");
}
@ -1192,7 +1193,7 @@ namespace Test
[DeploymentItem("SubtitleEdit.exe")]
public void FixEllipsesStartNormal2()
{
var result = FixCommonErrorsHelper.FixEllipsesStartHelper("... But that is true.");
var result = Helper.FixEllipsesStartHelper("... But that is true.");
Assert.AreEqual(result, "But that is true.");
}
@ -1200,7 +1201,7 @@ namespace Test
[DeploymentItem("SubtitleEdit.exe")]
public void FixEllipsesStartNormal3()
{
var result = FixCommonErrorsHelper.FixEllipsesStartHelper("Kurt: ... true but bad.");
var result = Helper.FixEllipsesStartHelper("Kurt: ... true but bad.");
Assert.AreEqual(result, "Kurt: true but bad.");
}
@ -1208,7 +1209,7 @@ namespace Test
[DeploymentItem("SubtitleEdit.exe")]
public void FixEllipsesStartNormal4()
{
var result = FixCommonErrorsHelper.FixEllipsesStartHelper("Kurt: ... true but bad.");
var result = Helper.FixEllipsesStartHelper("Kurt: ... true but bad.");
Assert.AreEqual(result, "Kurt: true but bad.");
}
@ -1216,7 +1217,7 @@ namespace Test
[DeploymentItem("SubtitleEdit.exe")]
public void FixEllipsesStartItalic1()
{
var result = FixCommonErrorsHelper.FixEllipsesStartHelper("<i>...But that is true.</i>");
var result = Helper.FixEllipsesStartHelper("<i>...But that is true.</i>");
Assert.AreEqual(result, "<i>But that is true.</i>");
}
@ -1224,7 +1225,7 @@ namespace Test
[DeploymentItem("SubtitleEdit.exe")]
public void FixEllipsesStartItalic2()
{
var result = FixCommonErrorsHelper.FixEllipsesStartHelper("<i>... But that is true.</i>");
var result = Helper.FixEllipsesStartHelper("<i>... But that is true.</i>");
Assert.AreEqual(result, "<i>But that is true.</i>");
}
@ -1232,7 +1233,7 @@ namespace Test
[DeploymentItem("SubtitleEdit.exe")]
public void FixEllipsesStartItalic3()
{
var result = FixCommonErrorsHelper.FixEllipsesStartHelper("<i>Kurt: ... true but bad.</i>");
var result = Helper.FixEllipsesStartHelper("<i>Kurt: ... true but bad.</i>");
Assert.AreEqual(result, "<i>Kurt: true but bad.</i>");
}
@ -1240,7 +1241,7 @@ namespace Test
[DeploymentItem("SubtitleEdit.exe")]
public void FixEllipsesStartItalic4()
{
var result = FixCommonErrorsHelper.FixEllipsesStartHelper("<i>Kurt: ... true but bad.</i>");
var result = Helper.FixEllipsesStartHelper("<i>Kurt: ... true but bad.</i>");
Assert.AreEqual(result, "<i>Kurt: true but bad.</i>");
}
@ -1248,7 +1249,7 @@ namespace Test
[DeploymentItem("SubtitleEdit.exe")]
public void FixEllipsesStartItalic5()
{
var result = FixCommonErrorsHelper.FixEllipsesStartHelper("WOMAN 2: <i>...24 hours a day at BabyC.</i>");
var result = Helper.FixEllipsesStartHelper("WOMAN 2: <i>...24 hours a day at BabyC.</i>");
Assert.AreEqual(result, "WOMAN 2: <i>24 hours a day at BabyC.</i>");
}
@ -1256,7 +1257,7 @@ namespace Test
[DeploymentItem("SubtitleEdit.exe")]
public void FixEllipsesStartFont1()
{
var result = FixCommonErrorsHelper.FixEllipsesStartHelper("<font color=\"#000000\">... true but bad.</font>");
var result = Helper.FixEllipsesStartHelper("<font color=\"#000000\">... true but bad.</font>");
Assert.AreEqual(result, "<font color=\"#000000\">true but bad.</font>");
}
@ -1264,7 +1265,7 @@ namespace Test
[DeploymentItem("SubtitleEdit.exe")]
public void FixEllipsesStartFont2()
{
var result = FixCommonErrorsHelper.FixEllipsesStartHelper("<font color=\"#000000\"><i>Kurt: ... true but bad.</i></font>");
var result = Helper.FixEllipsesStartHelper("<font color=\"#000000\"><i>Kurt: ... true but bad.</i></font>");
Assert.AreEqual(result, "<font color=\"#000000\"><i>Kurt: true but bad.</i></font>");
}
@ -1272,7 +1273,7 @@ namespace Test
[DeploymentItem("SubtitleEdit.exe")]
public void FixEllipsesStartFont3()
{
var result = FixCommonErrorsHelper.FixEllipsesStartHelper("<i><font color=\"#000000\">Kurt: ...true but bad.</font></i>");
var result = Helper.FixEllipsesStartHelper("<i><font color=\"#000000\">Kurt: ...true but bad.</font></i>");
Assert.AreEqual(result, "<i><font color=\"#000000\">Kurt: true but bad.</font></i>");
}
@ -1282,7 +1283,7 @@ namespace Test
{
var actual = "\"...Foobar\"";
const string expected = "\"Foobar\"";
actual = FixCommonErrorsHelper.FixEllipsesStartHelper(actual);
actual = Helper.FixEllipsesStartHelper(actual);
Assert.AreEqual(actual, expected);
}
@ -1292,7 +1293,7 @@ namespace Test
{
var actual = "\"... Foobar\"";
const string expected = "\"Foobar\"";
actual = FixCommonErrorsHelper.FixEllipsesStartHelper(actual);
actual = Helper.FixEllipsesStartHelper(actual);
Assert.AreEqual(actual, expected);
}
@ -1302,7 +1303,7 @@ namespace Test
{
var actual = "\" . . . Foobar\"";
const string expected = "\"Foobar\"";
actual = FixCommonErrorsHelper.FixEllipsesStartHelper(actual);
actual = Helper.FixEllipsesStartHelper(actual);
Assert.AreEqual(actual, expected);
}
@ -1311,7 +1312,7 @@ namespace Test
public void FixEllipsesStartDontChange()
{
const string input = "- I...";
string actual = FixCommonErrorsHelper.FixEllipsesStartHelper(input);
string actual = Helper.FixEllipsesStartHelper(input);
Assert.AreEqual(actual, input);
}
@ -1340,10 +1341,10 @@ namespace Test
for (int i = 0; i < lines1.Length; i++)
{
lines1[i] = FixCommonErrorsHelper.FixDoubleGreaterThanHelper(lines1[i]);
lines2[i] = FixCommonErrorsHelper.FixDoubleGreaterThanHelper(lines2[i]);
lines3[i] = FixCommonErrorsHelper.FixDoubleGreaterThanHelper(lines3[i]);
lines4[i] = FixCommonErrorsHelper.FixDoubleGreaterThanHelper(lines4[i]);
lines1[i] = Helper.FixDoubleGreaterThanHelper(lines1[i]);
lines2[i] = Helper.FixDoubleGreaterThanHelper(lines2[i]);
lines3[i] = Helper.FixDoubleGreaterThanHelper(lines3[i]);
lines4[i] = Helper.FixDoubleGreaterThanHelper(lines4[i]);
}
var result1 = string.Join(Environment.NewLine, lines1);
@ -1395,7 +1396,7 @@ namespace Test
{
const string source = "- I was here, putting our child to sleep-- - Emma.";
string target = "- I was here, putting our child to sleep--" + Environment.NewLine + "- Emma.";
string result = FixCommonErrorsHelper.FixDialogsOnOneLine(source, "en");
string result = Helper.FixDialogsOnOneLine(source, "en");
Assert.AreEqual(result, target);
}
@ -1405,7 +1406,7 @@ namespace Test
{
const string source = "- Seriously, though. Are you being bullied? - Nope.";
string target = "- Seriously, though. Are you being bullied?" + Environment.NewLine + "- Nope.";
string result = FixCommonErrorsHelper.FixDialogsOnOneLine(source, "en");
string result = Helper.FixDialogsOnOneLine(source, "en");
Assert.AreEqual(result, target);
}
@ -1415,7 +1416,7 @@ namespace Test
{
string source = "- Having sexual relationships" + Environment.NewLine + "with other women. - A'ight.";
string target = "- Having sexual relationships with other women." + Environment.NewLine + "- A'ight.";
string result = FixCommonErrorsHelper.FixDialogsOnOneLine(source, "en");
string result = Helper.FixDialogsOnOneLine(source, "en");
Assert.AreEqual(result, target);
}

View File

@ -1,6 +1,7 @@
using System;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Nikse.SubtitleEdit.Core.Forms;
using Nikse.SubtitleEdit.Core.Forms.FixCommonErrors;
using Nikse.SubtitleEdit.Logic;
using Nikse.SubtitleEdit.Core;
@ -343,8 +344,8 @@ namespace Test.Logic
sub.Paragraphs.Add(new Paragraph(test1, 0000, 11111));
sub.Paragraphs.Add(new Paragraph(test2, 0000, 11111));
string output1 = FixCommonErrorsHelper.FixHyphensAdd(sub, 0, "en");
string output2 = FixCommonErrorsHelper.FixHyphensAdd(sub, 1, "en");
string output1 = Helper.FixHyphensAdd(sub, 0, "en");
string output2 = Helper.FixHyphensAdd(sub, 1, "en");
Assert.AreEqual(output1, expected1);
Assert.AreEqual(output2, expected2);