Add more continuation stuff

This commit is contained in:
Martijn van Berkel (Flitskikker) 2020-04-09 00:09:39 +02:00
parent 526a234472
commit f48cb967d1
7 changed files with 437 additions and 268 deletions

View File

@ -2159,7 +2159,7 @@ Continue?</RestoreDefaultSettingsMsg>
<EditFixContinuationStyleSettings>Edit settings for fixing continuation style...</EditFixContinuationStyleSettings>
<FixContinuationStyleSettings>Settings for fixing continuation style</FixContinuationStyleSettings>
<UncheckInsertsAllCaps>Detect and uncheck inserts in all-caps (for example: NO ENTRY)</UncheckInsertsAllCaps>
<UncheckInsertsItalic>Try to detect and uncheck inserts or lyrics in lowercase and italic</UncheckInsertsItalic>
<UncheckInsertsItalic>Try to detect and uncheck italic inserts or lyrics in lowercase</UncheckInsertsItalic>
<UncheckInsertsLowercase>Try to detect and uncheck inserts or lyrics in lowercase</UncheckInsertsLowercase>
</Settings>
<SettingsMpv>

View File

@ -9,22 +9,7 @@ namespace Nikse.SubtitleEdit.Core.Forms.FixCommonErrors
{
public class FixContinuationStyle : IFixCommonError
{
class ContinuationProfile
{
public string Suffix;
public bool SuffixAddSpace;
public bool SuffixReplaceComma;
public string Prefix;
public bool PrefixAddSpace;
public bool UseDifferentStyleGap;
public string GapSuffix;
public bool GapSuffixAddSpace;
public bool GapSuffixReplaceComma;
public string GapPrefix;
public bool GapPrefixAddSpace;
}
private ContinuationProfile continuationProfile = null;
private ContinuationUtilities.ContinuationProfile continuationProfile = null;
private List<string> prefixes = null;
private List<string> suffixes = null;
private List<string> suffixesToAlwaysFix = new List<string>() { ",", "-", "", "", "—" };
@ -33,7 +18,7 @@ namespace Nikse.SubtitleEdit.Core.Forms.FixCommonErrors
public void Fix(Subtitle subtitle, IFixCallbacks callbacks)
{
var language = Configuration.Settings.Language.FixCommonErrors;
string fixAction = string.Format(language.FixContinuationStyleX, GetContinuationStyle(Configuration.Settings.General.ContinuationStyle));
string fixAction = string.Format(language.FixContinuationStyleX, ContinuationUtilities.GetContinuationStyleName(Configuration.Settings.General.ContinuationStyle));
int fixCount = 0;
// Check continuation profile
@ -70,8 +55,8 @@ namespace Nikse.SubtitleEdit.Core.Forms.FixCommonErrors
Paragraph pNext = subtitle.Paragraphs[i + 1];
var oldText = p.Text;
var oldTextNext = pNext.Text;
var text = Helper.SanitizeString(p.Text);
var textNext = Helper.SanitizeString(pNext.Text);
var text = ContinuationUtilities.SanitizeString(p.Text);
var textNext = ContinuationUtilities.SanitizeString(pNext.Text);
var isChecked = true;
// Check if we should fix this paragraph
@ -131,7 +116,7 @@ namespace Nikse.SubtitleEdit.Core.Forms.FixCommonErrors
}
// Replace it
var newText = Helper.ReplaceLastOccurrence(oldText, lastWord, newLastWord);
var newText = ContinuationUtilities.ReplaceLastOccurrence(oldText, lastWord, newLastWord);
// Commit if changed
if (oldText != newText)
@ -164,7 +149,7 @@ namespace Nikse.SubtitleEdit.Core.Forms.FixCommonErrors
}
// Replace it
var newTextNext = Helper.ReplaceLastOccurrence(oldTextNext, firstWord, newFirstWord);
var newTextNext = ContinuationUtilities.ReplaceLastOccurrence(oldTextNext, firstWord, newFirstWord);
// If ends with dots (possible interruptions), check if next sentence is new sentence, otherwise don't check by default
if (text.EndsWith("..") || text.EndsWith("…"))
@ -299,7 +284,7 @@ namespace Nikse.SubtitleEdit.Core.Forms.FixCommonErrors
private bool IsItalic(string input)
{
input = Helper.ExtractParagraphOnly(input);
input = ContinuationUtilities.ExtractParagraphOnly(input);
if (input.Length > 2)
{
@ -314,84 +299,7 @@ namespace Nikse.SubtitleEdit.Core.Forms.FixCommonErrors
private void SetContinuationProfile(ContinuationStyle continuationStyle)
{
switch (continuationStyle)
{
case ContinuationStyle.NoneLeadingTrailingDots:
this.continuationProfile = new ContinuationProfile {
Suffix = "",
SuffixAddSpace = false,
SuffixReplaceComma = false,
Prefix = "",
PrefixAddSpace = false,
UseDifferentStyleGap = true,
GapSuffix = "...",
GapSuffixAddSpace = false,
GapSuffixReplaceComma = true,
GapPrefix = "...",
GapPrefixAddSpace = false
};
break;
case ContinuationStyle.OnlyTrailingDots:
this.continuationProfile = new ContinuationProfile
{
Suffix = "...",
SuffixAddSpace = false,
SuffixReplaceComma = true,
Prefix = "",
PrefixAddSpace = false,
UseDifferentStyleGap = false
};
break;
case ContinuationStyle.LeadingTrailingDots:
this.continuationProfile = new ContinuationProfile
{
Suffix = "...",
SuffixAddSpace = false,
SuffixReplaceComma = true,
Prefix = "...",
PrefixAddSpace = false,
UseDifferentStyleGap = false
};
break;
case ContinuationStyle.LeadingTrailingDash:
this.continuationProfile = new ContinuationProfile
{
Suffix = "-",
SuffixAddSpace = true,
SuffixReplaceComma = true,
Prefix = "-",
PrefixAddSpace = true,
UseDifferentStyleGap = false
};
break;
case ContinuationStyle.LeadingTrailingDashDots:
this.continuationProfile = new ContinuationProfile
{
Suffix = "-",
SuffixAddSpace = true,
SuffixReplaceComma = true,
Prefix = "-",
PrefixAddSpace = true,
UseDifferentStyleGap = true,
GapSuffix = "...",
GapSuffixAddSpace = false,
GapSuffixReplaceComma = true,
GapPrefix = "...",
GapPrefixAddSpace = false
};
break;
default:
this.continuationProfile = new ContinuationProfile
{
Suffix = "",
SuffixAddSpace = false,
SuffixReplaceComma = false,
Prefix = "",
PrefixAddSpace = false,
UseDifferentStyleGap = false
};
break;
}
this.continuationProfile = ContinuationUtilities.GetContinuationProfile(continuationStyle);
this.prefixes = new List<string>() { "...", "..", "-", "", "", "—", "…", this.continuationProfile.Prefix };
this.suffixes = new List<string>() { ",", "...", "..", "-", "", "", "—", "…", this.continuationProfile.Suffix };
@ -402,30 +310,5 @@ namespace Nikse.SubtitleEdit.Core.Forms.FixCommonErrors
this.suffixes.Add(this.continuationProfile.GapSuffix);
}
}
private static string GetContinuationStyle(ContinuationStyle continuationStyle)
{
if (continuationStyle == ContinuationStyle.NoneLeadingTrailingDots)
{
return Configuration.Settings.Language.Settings.ContinuationStyleNoneLeadingTrailingDots;
}
if (continuationStyle == ContinuationStyle.OnlyTrailingDots)
{
return Configuration.Settings.Language.Settings.ContinuationStyleOnlyTrailingDots;
}
if (continuationStyle == ContinuationStyle.LeadingTrailingDots)
{
return Configuration.Settings.Language.Settings.ContinuationStyleLeadingTrailingDots;
}
if (continuationStyle == ContinuationStyle.LeadingTrailingDash)
{
return Configuration.Settings.Language.Settings.ContinuationStyleLeadingTrailingDash;
}
if (continuationStyle == ContinuationStyle.LeadingTrailingDashDots)
{
return Configuration.Settings.Language.Settings.ContinuationStyleLeadingTrailingDashDots;
}
return Configuration.Settings.Language.Settings.ContinuationStyleNone;
}
}
}

View File

@ -17,17 +17,17 @@ namespace Nikse.SubtitleEdit.Core.Forms.FixCommonErrors
for (int i = 1; i < subtitle.Paragraphs.Count; i++)
{
Paragraph p = subtitle.Paragraphs[i];
var text = Helper.SanitizeString(p.Text);
var text = ContinuationUtilities.SanitizeString(p.Text);
if ((text.StartsWith("..") || text.StartsWith("…")) && callbacks.AllowFix(p, fixAction))
{
var oldText = p.Text;
Paragraph pPrev = subtitle.Paragraphs[i - 1];
var previousText = Helper.SanitizeString(pPrev.Text);
var previousText = ContinuationUtilities.SanitizeString(pPrev.Text);
if (previousText.EndsWith("..") || previousText.EndsWith("…"))
{
// Yes: Remove starting dots
// Remove starting dots
// Get first word
string[] split = text.Split(Convert.ToChar(" "));
@ -39,7 +39,7 @@ namespace Nikse.SubtitleEdit.Core.Forms.FixCommonErrors
if (newFirstWord.StartsWith("..")) newFirstWord = newFirstWord.Substring(2);
if (newFirstWord.StartsWith("…")) newFirstWord = newFirstWord.Substring(1);
newFirstWord = newFirstWord.Trim();
var newText = Helper.ReplaceFirstOccurrence(oldText, firstWord, newFirstWord);
var newText = ContinuationUtilities.ReplaceFirstOccurrence(oldText, firstWord, newFirstWord);
// Commit
p.Text = newText;

View File

@ -590,112 +590,5 @@ namespace Nikse.SubtitleEdit.Core.Forms.FixCommonErrors
}
return text;
}
private static string dashes = "-‐–—";
private static string quotes = "'\"“”‘’«»‹›„“‚‘";
private static string singleQuotes = "'";
private static string doubleQuotes = "''";
public static string SanitizeString(string input, bool removeDashes = true)
{
string checkString = input;
checkString = Regex.Replace(checkString, "<.*?>", String.Empty);
checkString = Regex.Replace(checkString, "\\(.*?\\)", String.Empty);
checkString = Regex.Replace(checkString, "\\[.*?\\]", String.Empty);
checkString = Regex.Replace(checkString, "\\{.*?\\}", String.Empty);
checkString = checkString.Trim();
// Remove string elevation
if (checkString.EndsWith("\r\n_") || checkString.EndsWith("\r\n.") || checkString.EndsWith("\n_") || checkString.EndsWith("\n."))
{
checkString = checkString.Substring(0, checkString.Length - 1).Trim();
}
// Remove dashes from the beginning
if (removeDashes)
{
if (dashes.Contains(checkString[0]))
{
checkString = checkString.Substring(1).Trim();
}
}
// Remove single-char quotes from the beginning
if (quotes.Contains(checkString[0]))
{
if (singleQuotes.Contains(checkString[0]) && Char.IsLetter(checkString[1]) && !Char.IsUpper(checkString[1]) && Char.IsWhiteSpace(checkString[2]) && Char.IsLetter(checkString[3]))
{
// 's Avonds -- don't remove
}
else
{
checkString = checkString.Substring(1).Trim();
}
}
// Remove double-char quotes from the beginning
if (doubleQuotes.Contains(checkString.Substring(0, 2)))
{
checkString = checkString.Substring(2).Trim();
}
// Remove single-char quotes from the ending
if (quotes.Contains(checkString[checkString.Length - 1]))
{
if (singleQuotes.Contains(checkString[checkString.Length - 1]))
{
// Could be something like: nothin'
// TODO
}
checkString = checkString.Substring(0, checkString.Length - 1).Trim();
}
// Remove double-char quotes from the ending
if (doubleQuotes.Contains(checkString.Substring(checkString.Length - 2, 2)))
{
checkString = checkString.Substring(0, checkString.Length - 2).Trim();
}
return checkString;
}
public static string ExtractParagraphOnly(string input, bool removeDashes = true)
{
string checkString = input;
checkString = Regex.Replace(checkString, "\\{.*?\\}", String.Empty);
checkString = checkString.Trim();
// Remove string elevation
if (checkString.EndsWith("\r\n_") || checkString.EndsWith("\r\n.") || checkString.EndsWith("\n_") || checkString.EndsWith("\n."))
{
checkString = checkString.Substring(0, checkString.Length - 1).Trim();
}
return checkString;
}
public static string ReplaceFirstOccurrence(string Source, string Find, string Replace)
{
int place = Source.IndexOf(Find);
if (place == -1)
return Source;
string result = Source.Remove(place, Find.Length).Insert(place, Replace);
return result;
}
public static string ReplaceLastOccurrence(string Source, string Find, string Replace)
{
int place = Source.LastIndexOf(Find);
if (place == -1)
return Source;
string result = Source.Remove(place, Find.Length).Insert(place, Replace);
return result;
}
}
}

View File

@ -1,4 +1,5 @@
using Nikse.SubtitleEdit.Core.ContainerFormats.Matroska;
using Nikse.SubtitleEdit.Core.Enums;
using Nikse.SubtitleEdit.Core.SubtitleFormats;
using System;
using System.Collections.Generic;
@ -887,7 +888,7 @@ namespace Nikse.SubtitleEdit.Core
}
var duration = text.CountCharacters(Configuration.Settings.General.CharactersPerSecondsIgnoreWhiteSpace) / optimalCharactersPerSecond * TimeCode.BaseUnit;
if (duration < 1400)
{
duration *= 1.2;
@ -2809,4 +2810,367 @@ namespace Nikse.SubtitleEdit.Core
return text;
}
}
public static class ContinuationUtilities {
private static string dashes = "-‐–—";
private static string quotes = "'\"“”‘’«»‹›„“‚‘";
private static string singleQuotes = "'";
private static string doubleQuotes = "''";
public static string SanitizeString(string input, bool removeDashes = true)
{
string checkString = input;
checkString = Regex.Replace(checkString, "<.*?>", String.Empty);
checkString = Regex.Replace(checkString, "\\(.*?\\)", String.Empty);
checkString = Regex.Replace(checkString, "\\[.*?\\]", String.Empty);
checkString = Regex.Replace(checkString, "\\{.*?\\}", String.Empty);
checkString = checkString.Trim();
// Remove string elevation
if (checkString.EndsWith("\r\n_") || checkString.EndsWith("\r\n.") || checkString.EndsWith("\n_") || checkString.EndsWith("\n."))
{
checkString = checkString.Substring(0, checkString.Length - 1).Trim();
}
// Remove dashes from the beginning
if (removeDashes)
{
if (dashes.Contains(checkString[0]))
{
checkString = checkString.Substring(1).Trim();
}
}
// Remove single-char quotes from the beginning
if (quotes.Contains(checkString[0]))
{
if (singleQuotes.Contains(checkString[0]) && Char.IsLetter(checkString[1]) && !Char.IsUpper(checkString[1]) && Char.IsWhiteSpace(checkString[2]) && Char.IsLetter(checkString[3]))
{
// 's Avonds -- don't remove
}
else
{
checkString = checkString.Substring(1).Trim();
}
}
// Remove double-char quotes from the beginning
if (doubleQuotes.Contains(checkString.Substring(0, 2)))
{
checkString = checkString.Substring(2).Trim();
}
// Remove single-char quotes from the ending
if (quotes.Contains(checkString[checkString.Length - 1]))
{
if (singleQuotes.Contains(checkString[checkString.Length - 1]))
{
// Could be something like: nothin'
// TODO
}
checkString = checkString.Substring(0, checkString.Length - 1).Trim();
}
// Remove double-char quotes from the ending
if (doubleQuotes.Contains(checkString.Substring(checkString.Length - 2, 2)))
{
checkString = checkString.Substring(0, checkString.Length - 2).Trim();
}
return checkString;
}
public static string ExtractParagraphOnly(string input, bool removeDashes = true)
{
string checkString = input;
checkString = Regex.Replace(checkString, "\\{.*?\\}", String.Empty);
checkString = checkString.Trim();
// Remove string elevation
if (checkString.EndsWith("\r\n_") || checkString.EndsWith("\r\n.") || checkString.EndsWith("\n_") || checkString.EndsWith("\n."))
{
checkString = checkString.Substring(0, checkString.Length - 1).Trim();
}
return checkString;
}
public static string ReplaceFirstOccurrence(string Source, string Find, string Replace)
{
int place = Source.IndexOf(Find);
if (place == -1)
return Source;
string result = Source.Remove(place, Find.Length).Insert(place, Replace);
return result;
}
public static string ReplaceLastOccurrence(string Source, string Find, string Replace)
{
int place = Source.LastIndexOf(Find);
if (place == -1)
return Source;
string result = Source.Remove(place, Find.Length).Insert(place, Replace);
return result;
}
public static string AddSuffixIfNeeded(string originalText, ContinuationProfile profile, bool gap)
{
// Get last word
string text = ContinuationUtilities.SanitizeString(originalText);
string[] split = text.Split(Convert.ToChar(" "));
string lastWord = split.Last();
string newLastWord = lastWord;
if (gap && profile.UseDifferentStyleGap)
{
// Check if needed
if (profile.GapSuffix.Length == 0 || lastWord.EndsWith(profile.GapSuffix))
{
return text;
}
// Make new last word
string gapAddEnd = (profile.GapSuffixAddSpace ? " " : "") + profile.GapSuffix;
newLastWord = newLastWord.TrimEnd(',') + (lastWord.EndsWith(",") && !profile.GapSuffixReplaceComma ? "," : "") + gapAddEnd;
}
else
{
// Check if needed
if (profile.Suffix.Length == 0 || lastWord.EndsWith(profile.Suffix))
{
return text;
}
// Make new last word
string addEnd = (profile.SuffixAddSpace ? " " : "") + profile.Suffix;
newLastWord = newLastWord.TrimEnd(',') + (lastWord.EndsWith(",") && !profile.SuffixReplaceComma ? "," : "") + addEnd;
}
// Replace it
return ContinuationUtilities.ReplaceLastOccurrence(originalText, lastWord, newLastWord);
}
public static string AddPrefixIfNeeded(string originalText, ContinuationProfile profile, bool gap)
{
// Get first word of the next paragraph
string text = ContinuationUtilities.SanitizeString(originalText);
string[] split = text.Split(Convert.ToChar(" "));
string firstWord = split.First();
string newFirstWord = firstWord;
if (gap && profile.UseDifferentStyleGap)
{
// Check if needed
if (profile.GapPrefix.Length == 0 || firstWord.StartsWith(profile.GapPrefix))
{
return text;
}
// Make new first word
newFirstWord = newFirstWord.Substring(profile.GapPrefix.Length);
}
else
{
// Check if needed
if (profile.Prefix.Length == 0 || firstWord.StartsWith(profile.Prefix))
{
return text;
}
// Make new first word
newFirstWord = newFirstWord.Substring(profile.Prefix.Length);
}
// Replace it
return ContinuationUtilities.ReplaceLastOccurrence(originalText, firstWord, newFirstWord);
}
public static string RemoveSuffixIfNeeded(string originalText, ContinuationProfile profile, bool gap)
{
// Get last word
string text = ContinuationUtilities.SanitizeString(originalText);
string[] split = text.Split(Convert.ToChar(" "));
string lastWord = split.Last();
string newLastWord = lastWord;
if (gap && profile.UseDifferentStyleGap)
{
// Check if needed
if (profile.GapSuffix.Length == 0 || !lastWord.EndsWith(profile.GapSuffix))
{
return text;
}
// Make new last word
newLastWord = newLastWord.Substring(0, newLastWord.Length - profile.GapSuffix.Length);
}
else
{
// Check if needed
if (profile.Suffix.Length == 0 || !lastWord.EndsWith(profile.Suffix))
{
return text;
}
// Make new last word
newLastWord = newLastWord.Substring(0, newLastWord.Length - profile.Suffix.Length);
}
// Replace it
return ContinuationUtilities.ReplaceLastOccurrence(originalText, lastWord, newLastWord);
}
public static string RemovePrefixIfNeeded(string originalText, ContinuationProfile profile, bool gap)
{
// Get first word of the next paragraph
string text = ContinuationUtilities.SanitizeString(originalText);
string[] split = text.Split(Convert.ToChar(" "));
string firstWord = split.First();
string newFirstWord = firstWord;
if (gap && profile.UseDifferentStyleGap)
{
// Check if needed
if (profile.GapPrefix.Length == 0 || !firstWord.StartsWith(profile.GapPrefix))
{
return text;
}
// Make new first word
string gapAddStart = profile.GapPrefix + (profile.GapPrefixAddSpace ? " " : "");
newFirstWord = gapAddStart + newFirstWord;
}
else
{
// Check if needed
if (profile.Prefix.Length == 0 || !firstWord.StartsWith(profile.Prefix))
{
return text;
}
// Make new first word
string addStart = profile.Prefix + (profile.PrefixAddSpace ? " " : "");
newFirstWord = addStart + newFirstWord;
}
// Replace it
return ContinuationUtilities.ReplaceLastOccurrence(originalText, firstWord, newFirstWord);
}
public static string GetContinuationStyleName(ContinuationStyle continuationStyle)
{
switch (continuationStyle)
{
case ContinuationStyle.NoneLeadingTrailingDots:
return Configuration.Settings.Language.Settings.ContinuationStyleNoneLeadingTrailingDots;
case ContinuationStyle.OnlyTrailingDots:
return Configuration.Settings.Language.Settings.ContinuationStyleOnlyTrailingDots;
case ContinuationStyle.LeadingTrailingDots:
return Configuration.Settings.Language.Settings.ContinuationStyleLeadingTrailingDots;
case ContinuationStyle.LeadingTrailingDash:
return Configuration.Settings.Language.Settings.ContinuationStyleLeadingTrailingDash;
case ContinuationStyle.LeadingTrailingDashDots:
return Configuration.Settings.Language.Settings.ContinuationStyleLeadingTrailingDashDots;
default:
return Configuration.Settings.Language.Settings.ContinuationStyleNone;
}
}
public static ContinuationProfile GetContinuationProfile(ContinuationStyle continuationStyle)
{
switch (continuationStyle)
{
case ContinuationStyle.NoneLeadingTrailingDots:
return new ContinuationProfile
{
Suffix = "",
SuffixAddSpace = false,
SuffixReplaceComma = false,
Prefix = "",
PrefixAddSpace = false,
UseDifferentStyleGap = true,
GapSuffix = "...",
GapSuffixAddSpace = false,
GapSuffixReplaceComma = true,
GapPrefix = "...",
GapPrefixAddSpace = false
};
case ContinuationStyle.OnlyTrailingDots:
return new ContinuationProfile
{
Suffix = "...",
SuffixAddSpace = false,
SuffixReplaceComma = true,
Prefix = "",
PrefixAddSpace = false,
UseDifferentStyleGap = false
};
case ContinuationStyle.LeadingTrailingDots:
return new ContinuationProfile
{
Suffix = "...",
SuffixAddSpace = false,
SuffixReplaceComma = true,
Prefix = "...",
PrefixAddSpace = false,
UseDifferentStyleGap = false
};
case ContinuationStyle.LeadingTrailingDash:
return new ContinuationProfile
{
Suffix = "-",
SuffixAddSpace = true,
SuffixReplaceComma = true,
Prefix = "-",
PrefixAddSpace = true,
UseDifferentStyleGap = false
};
case ContinuationStyle.LeadingTrailingDashDots:
return new ContinuationProfile
{
Suffix = "-",
SuffixAddSpace = true,
SuffixReplaceComma = true,
Prefix = "-",
PrefixAddSpace = true,
UseDifferentStyleGap = true,
GapSuffix = "...",
GapSuffixAddSpace = false,
GapSuffixReplaceComma = true,
GapPrefix = "...",
GapPrefixAddSpace = false
};
default:
return new ContinuationProfile
{
Suffix = "",
SuffixAddSpace = false,
SuffixReplaceComma = false,
Prefix = "",
PrefixAddSpace = false,
UseDifferentStyleGap = false
};
}
}
public class ContinuationProfile
{
public string Suffix;
public bool SuffixAddSpace;
public bool SuffixReplaceComma;
public string Prefix;
public bool PrefixAddSpace;
public bool UseDifferentStyleGap;
public string GapSuffix;
public bool GapSuffixAddSpace;
public bool GapSuffixReplaceComma;
public string GapPrefix;
public bool GapPrefixAddSpace;
}
}
}

View File

@ -391,7 +391,7 @@ namespace Nikse.SubtitleEdit.Forms
new FixItem(_language.Fix3PlusLines, string.Empty, () => new Fix3PlusLines().Fix(Subtitle, this), ce.Fix3PlusLinesTicked),
new FixItem(_language.FixDoubleDash, _language.FixDoubleDashExample, () => new FixDoubleDash().Fix(Subtitle, this), ce.FixDoubleDashTicked),
new FixItem(_language.FixDoubleGreaterThan, _language.FixDoubleGreaterThanExample, () => new FixDoubleGreaterThan().Fix(Subtitle, this), ce.FixDoubleGreaterThanTicked),
new FixItem( string.Format(_language.FixContinuationStyleX, GetContinuationStyle(Configuration.Settings.General.ContinuationStyle)), string.Empty, () => new FixContinuationStyle().Fix(Subtitle, this), ce.FixContinuationStyleTicked),
new FixItem( string.Format(_language.FixContinuationStyleX, ContinuationUtilities.GetContinuationStyleName(Configuration.Settings.General.ContinuationStyle)), string.Empty, () => new FixContinuationStyle().Fix(Subtitle, this), ce.FixContinuationStyleTicked),
(Configuration.Settings.General.ContinuationStyle == ContinuationStyle.OnlyTrailingDots
? new FixItem(_language.FixUnnecessaryLeadingDots, string.Empty, () => new FixUnnecessaryLeadingDots().Fix(Subtitle, this), ce.FixUnnecessaryLeadingDotsTicked)
: new FixItem(_language.FixEllipsesStart, _language.FixEllipsesStartExample, () => new FixEllipsesStart().Fix(Subtitle, this), ce.FixEllipsesStartTicked)),
@ -448,32 +448,7 @@ namespace Nikse.SubtitleEdit.Forms
}
return Configuration.Settings.Language.Settings.DialogStyleDashBothLinesWithSpace;
}
private static string GetContinuationStyle(ContinuationStyle continuationStyle)
{
if (continuationStyle == ContinuationStyle.NoneLeadingTrailingDots)
{
return Configuration.Settings.Language.Settings.ContinuationStyleNoneLeadingTrailingDots;
}
if (continuationStyle == ContinuationStyle.OnlyTrailingDots)
{
return Configuration.Settings.Language.Settings.ContinuationStyleOnlyTrailingDots;
}
if (continuationStyle == ContinuationStyle.LeadingTrailingDots)
{
return Configuration.Settings.Language.Settings.ContinuationStyleLeadingTrailingDots;
}
if (continuationStyle == ContinuationStyle.LeadingTrailingDash)
{
return Configuration.Settings.Language.Settings.ContinuationStyleLeadingTrailingDash;
}
if (continuationStyle == ContinuationStyle.LeadingTrailingDashDots)
{
return Configuration.Settings.Language.Settings.ContinuationStyleLeadingTrailingDashDots;
}
return Configuration.Settings.Language.Settings.ContinuationStyleNone;
}
public FixCommonErrors()
{
UiUtil.PreInitialize(this);

View File

@ -9530,6 +9530,7 @@ namespace Nikse.SubtitleEdit.Forms
{
string a = oldText.Substring(0, textIndex.Value).Trim();
string b = oldText.Substring(textIndex.Value).Trim();
if (oldText.TrimStart().StartsWith("<i>", StringComparison.Ordinal) && oldText.TrimEnd().EndsWith("</i>", StringComparison.Ordinal) &&
Utilities.CountTagInText(oldText, "<i>") == 1 && Utilities.CountTagInText(oldText, "</i>") == 1)
{
@ -9697,6 +9698,14 @@ namespace Nikse.SubtitleEdit.Forms
newParagraph.Text = newParagraph.Text.Remove(3, 1);
}
var continuationStyle = Configuration.Settings.General.ContinuationStyle;
if (continuationStyle != ContinuationStyle.None)
{
var continuationProfile = ContinuationUtilities.GetContinuationProfile(continuationStyle);
currentParagraph.Text = ContinuationUtilities.AddSuffixIfNeeded(currentParagraph.Text, continuationProfile, false);
newParagraph.Text = ContinuationUtilities.AddPrefixIfNeeded(newParagraph.Text, continuationProfile, false);
}
SetSplitTime(splitSeconds, currentParagraph, newParagraph, oldText);
if (Configuration.Settings.General.AllowEditOfOriginalSubtitle && _subtitleAlternate != null && _subtitleAlternate.Paragraphs.Count > 0)
@ -9848,6 +9857,13 @@ namespace Nikse.SubtitleEdit.Forms
{
originalCurrent.Text = originalCurrent.Text.Remove(3, 1);
}
if (continuationStyle != ContinuationStyle.None)
{
var continuationProfile = ContinuationUtilities.GetContinuationProfile(continuationStyle);
originalCurrent.Text = ContinuationUtilities.AddSuffixIfNeeded(originalCurrent.Text, continuationProfile, false);
originalNew.Text = ContinuationUtilities.AddPrefixIfNeeded(originalNew.Text, continuationProfile, false);
}
}
_subtitleAlternate.InsertParagraphInCorrectTimeOrder(originalNew);
@ -10137,6 +10153,22 @@ namespace Nikse.SubtitleEdit.Forms
}
var addText = _subtitle.Paragraphs[index].Text;
var continuationStyle = Configuration.Settings.General.ContinuationStyle;
if (continuationStyle != ContinuationStyle.None)
{
var continuationProfile = ContinuationUtilities.GetContinuationProfile(continuationStyle);
var gap = next < firstIndex + SubtitleListview1.SelectedIndices.Count ? _subtitle.Paragraphs[next].StartTime.TotalMilliseconds - _subtitle.Paragraphs[index].EndTime.TotalMilliseconds > Configuration.Settings.General.MinimumMillisecondsBetweenLines + 5 : false;
if (index != firstIndex)
{
addText = ContinuationUtilities.RemovePrefixIfNeeded(addText, continuationProfile, gap);
}
if (next < firstIndex + SubtitleListview1.SelectedIndices.Count)
{
addText = ContinuationUtilities.RemoveSuffixIfNeeded(addText, continuationProfile, gap);
}
}
if (firstIndex != index)
{
addText = RemoveAssStartAlignmentTag(addText);
@ -10287,12 +10319,12 @@ namespace Nikse.SubtitleEdit.Forms
private void ExtendBeforeToolStripMenuItemClick(object sender, EventArgs e)
{
ExtendSelectedLinesToPreviousLine();
}
private void ExtendAfterToolStripMenuItemClick(object sender, EventArgs e)
{
ExtendSelectedLinesToNextLine();
}
private static string ChangeAllLinesTagsToSingleTag(string text, string tag)
@ -10344,15 +10376,37 @@ namespace Nikse.SubtitleEdit.Forms
var nextParagraph = _subtitle.GetParagraphOrDefault(firstSelectedIndex + 1);
if (nextParagraph != null && currentParagraph != null)
{
{
SubtitleListview1.SelectedIndexChanged -= SubtitleListview1_SelectedIndexChanged;
MakeHistoryForUndo(_language.BeforeMergeLines);
var continuationStyle = Configuration.Settings.General.ContinuationStyle;
if (continuationStyle != ContinuationStyle.None)
{
var continuationProfile = ContinuationUtilities.GetContinuationProfile(continuationStyle);
var gap = nextParagraph.StartTime.TotalMilliseconds - currentParagraph.EndTime.TotalMilliseconds > Configuration.Settings.General.MinimumMillisecondsBetweenLines + 5;
currentParagraph.Text = ContinuationUtilities.RemoveSuffixIfNeeded(currentParagraph.Text, continuationProfile, gap);
nextParagraph.Text = ContinuationUtilities.RemovePrefixIfNeeded(nextParagraph.Text, continuationProfile, gap);
}
if (_subtitleAlternate != null)
{
var original = Utilities.GetOriginalParagraph(firstSelectedIndex, currentParagraph, _subtitleAlternate.Paragraphs);
var originalNext = Utilities.GetOriginalParagraph(firstSelectedIndex + 1, nextParagraph, _subtitleAlternate.Paragraphs);
if (original != null && originalNext != null)
{
if (continuationStyle != ContinuationStyle.None)
{
var continuationProfile = ContinuationUtilities.GetContinuationProfile(continuationStyle);
var gap = originalNext.StartTime.TotalMilliseconds - original.EndTime.TotalMilliseconds > Configuration.Settings.General.MinimumMillisecondsBetweenLines + 5;
original.Text = ContinuationUtilities.RemoveSuffixIfNeeded(original.Text, continuationProfile, gap);
originalNext.Text = ContinuationUtilities.RemovePrefixIfNeeded(originalNext.Text, continuationProfile, gap);
}
}
if (originalNext != null)
{
if (original == null)