Fix FCE remove dash single line - thx Ding-adong :)

Related to comment in #3416
comment https://github.com/SubtitleEdit/subtitleedit/issues/3416#issuecomment-587035108
This commit is contained in:
Nikolaj Olsson 2020-02-17 21:54:35 +01:00
parent 69649a0ee8
commit 3d3443dce4
3 changed files with 20 additions and 4 deletions

View File

@ -12,10 +12,10 @@ namespace Nikse.SubtitleEdit.Core.Forms.FixCommonErrors
for (int i = 0; i < subtitle.Paragraphs.Count; i++)
{
var p = subtitle.Paragraphs[i];
if (p.Text.SplitToLines().Count == 1 && callbacks.AllowFix(p, fixAction))
if (Helper.IsOneSentence(p.Text) && callbacks.AllowFix(p, fixAction))
{
string oldText = p.Text;
string text = Helper.FixHyphensRemoveForSingleLine(subtitle, p.Text, i);
string text = Helper.FixHyphensRemoveForSingleLine(subtitle, p.Text, i);
if (text != oldText)
{
p.Text = text;

View File

@ -275,9 +275,25 @@ namespace Nikse.SubtitleEdit.Core.Forms.FixCommonErrors
return isPrevEndOfLine;
}
public static bool IsOneSentence(string text)
{
var lines = HtmlUtil.RemoveHtmlTags(text).SplitToLines();
if (lines.Count == 1)
{
return true;
}
if (lines.Count > 2)
{
return false;
}
return !lines[0].HasSentenceEnding();
}
public static string FixHyphensRemoveForSingleLine(Subtitle subtitle, string input, int i)
{
if (string.IsNullOrEmpty(input) || input.SplitToLines().Count != 1)
if (string.IsNullOrEmpty(input) || !IsOneSentence(input))
{
return input;
}

View File

@ -464,7 +464,7 @@ namespace Nikse.SubtitleEdit.Core
}
var last = s[s.Length - 1];
return last == '.' || last == '!' || last == '?' || last == ']' || last == '…';
return last == '.' || last == '!' || last == '?' || last == ']' || last == '…' || last == '♪' || last == '؟';
}
}
}