mirror of
https://github.com/SubtitleEdit/subtitleedit.git
synced 2024-11-25 12:44:46 +01:00
Some refact in Split long lines helper
This commit is contained in:
parent
796e0b08c5
commit
f02ab5d1e0
@ -9,7 +9,7 @@ namespace Nikse.SubtitleEdit.Logic.Forms
|
||||
|
||||
public static bool QualifiesForSplit(string text, int singleLineMaxCharacters, int totalLineMaxCharacters)
|
||||
{
|
||||
string s = HtmlUtil.RemoveHtmlTags(text.Trim());
|
||||
string s = HtmlUtil.RemoveHtmlTags(text.Trim(), true);
|
||||
if (s.Length > totalLineMaxCharacters)
|
||||
return true;
|
||||
|
||||
@ -23,16 +23,12 @@ namespace Nikse.SubtitleEdit.Logic.Forms
|
||||
var tempText = text.Replace(Environment.NewLine, " ").Replace(" ", " ");
|
||||
if (Utilities.CountTagInText(tempText, '-') == 2 && (text.StartsWith('-') || text.StartsWith("<i>-")))
|
||||
{
|
||||
int idx = tempText.IndexOf(". -", StringComparison.Ordinal);
|
||||
if (idx < 1)
|
||||
idx = tempText.IndexOf("! -", StringComparison.Ordinal);
|
||||
if (idx < 1)
|
||||
idx = tempText.IndexOf("? -", StringComparison.Ordinal);
|
||||
var idx = tempText.IndexOfAny(new[] { ". -", "! -", "? -" }, StringComparison.Ordinal);
|
||||
if (idx > 1)
|
||||
{
|
||||
string dialogText = tempText.Remove(idx + 1, 1).Insert(idx + 1, Environment.NewLine);
|
||||
arr = dialogText.SplitToLines();
|
||||
foreach (string line in arr)
|
||||
idx++;
|
||||
string dialogText = tempText.Remove(idx, 1).Insert(idx, Environment.NewLine);
|
||||
foreach (string line in dialogText.SplitToLines())
|
||||
{
|
||||
if (line.Length > singleLineMaxCharacters)
|
||||
return true;
|
||||
@ -57,16 +53,16 @@ namespace Nikse.SubtitleEdit.Logic.Forms
|
||||
{
|
||||
if (QualifiesForSplit(p.Text, singleLineMaxCharacters, totalLineMaxCharacters))
|
||||
{
|
||||
if (!QualifiesForSplit(Utilities.AutoBreakLine(p.Text, language), singleLineMaxCharacters, totalLineMaxCharacters))
|
||||
var text = Utilities.AutoBreakLine(p.Text, language);
|
||||
if (!QualifiesForSplit(text, singleLineMaxCharacters, totalLineMaxCharacters))
|
||||
{
|
||||
var newParagraph = new Paragraph(p) { Text = Utilities.AutoBreakLine(p.Text, language) };
|
||||
var newParagraph = new Paragraph(p) { Text = text };
|
||||
autoBreakedIndexes.Add(splittedSubtitle.Paragraphs.Count);
|
||||
splittedSubtitle.Paragraphs.Add(newParagraph);
|
||||
added = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
string text = Utilities.AutoBreakLine(p.Text, language);
|
||||
if (text.Contains(Environment.NewLine))
|
||||
{
|
||||
var arr = text.SplitToLines();
|
||||
@ -89,7 +85,8 @@ namespace Nikse.SubtitleEdit.Logic.Forms
|
||||
splittedIndexes.Add(splittedSubtitle.Paragraphs.Count + 1);
|
||||
|
||||
string p1 = HtmlUtil.RemoveHtmlTags(newParagraph1.Text);
|
||||
if (p1.EndsWith('.') || p1.EndsWith('!') || p1.EndsWith('?') || p1.EndsWith(':') || p1.EndsWith(')') || p1.EndsWith(']') || p1.EndsWith('♪'))
|
||||
var len = p1.Length - 1;
|
||||
if (p1.Length > 0 && (p1[len] == '.' || p1[len] == '!' || p1[len] == '?' || p1[len] == ':' || p1[len] == ')' || p1[len] == ']' || p1[len] == '♪'))
|
||||
{
|
||||
if (newParagraph1.Text.StartsWith('-') && newParagraph2.Text.StartsWith('-'))
|
||||
{
|
||||
@ -145,4 +142,4 @@ namespace Nikse.SubtitleEdit.Logic.Forms
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user