diff --git a/src/Core/StringExtensions.cs b/src/Core/StringExtensions.cs index 581d50f8c..c04d69a74 100644 --- a/src/Core/StringExtensions.cs +++ b/src/Core/StringExtensions.cs @@ -27,8 +27,8 @@ namespace Nikse.SubtitleEdit.Core { if (threeLengthTag && text.Length > 3 && text[0] == '<' && text[2] == '>' && (text[1] == 'i' || text[1] == 'I' || text[1] == 'u' || text[1] == 'U' || text[1] == 'b' || text[1] == 'B')) return true; - if (includeFont && text.Length > 22 && text.StartsWith(" 5 && text.StartsWith("', 5) >= 5; // or return false; } diff --git a/src/Forms/FixCommonErrors.cs b/src/Forms/FixCommonErrors.cs index de91c6c99..5bc2c1574 100644 --- a/src/Forms/FixCommonErrors.cs +++ b/src/Forms/FixCommonErrors.cs @@ -2884,14 +2884,18 @@ namespace Nikse.SubtitleEdit.Forms text = text.Replace("... , ... text = text.Replace("... ?", "...?"); text = text.Replace("... !", "...!"); - if (text.StartsWith("... ", StringComparison.Ordinal)) - text = text.Remove(3, 1); - if (text.StartsWith("... ", StringComparison.Ordinal)) - text = text.Remove(6, 1); - if (text.StartsWith("... ", StringComparison.Ordinal)) - text = text.Remove("... ".Length - 1, 1); - if (text.StartsWith("... ", StringComparison.Ordinal)) - text = text.Remove("... ".Length - 1, 1); + + if (text.IndexOf(Environment.NewLine, StringComparison.Ordinal) > 1) + { + var lines = text.SplitToLines(); + for (int k = 0; k < lines.Length; k++) + lines[k] = FixCommonErrorsHelper.RemoveSpacesBeingLineAfterEllipese(lines[k]); + text = string.Join(Environment.NewLine, lines); + } + else + { + text = FixCommonErrorsHelper.RemoveSpacesBeingLineAfterEllipese(text); + } } //if (text.EndsWith('-')) //{ diff --git a/src/Logic/Forms/FixCommonErrorsHelper.cs b/src/Logic/Forms/FixCommonErrorsHelper.cs index 7c0df1fc9..5db298ac0 100644 --- a/src/Logic/Forms/FixCommonErrorsHelper.cs +++ b/src/Logic/Forms/FixCommonErrorsHelper.cs @@ -29,10 +29,10 @@ namespace Nikse.SubtitleEdit.Logic.Forms } // "...foobar" - if(text.StartsWith("\"..", StringComparison.Ordinal)) + if (text.StartsWith("\"..", StringComparison.Ordinal)) { var endIdx = 0; - while (text[++endIdx] == '.'); + while (text[++endIdx] == '.') ; text = text.Remove(1, endIdx - 1); } @@ -305,14 +305,41 @@ namespace Nikse.SubtitleEdit.Logic.Forms if (text.LineStartsWithHtmlTag(false, true)) { var closeIdx = text.IndexOf('>'); - if (closeIdx > -1 && text[closeIdx + 1] == 0x20) - { + if (closeIdx > 6 && text[closeIdx + 1] == 0x20) text = text.Remove(closeIdx + 1, 1); - } } return text; } + public static string RemoveSpacesBeingLineAfterEllipese(string line) + { + if (line.StartsWith("... ", StringComparison.Ordinal)) + line = line.Remove(3, 1); + if (line.Length > 6 && line.LineStartsWithHtmlTag(true)) // ... foobar + { + var idx = line.IndexOf('>') + 1; + var pre = line.Substring(0, idx); + line = line.Remove(0, idx).TrimStart(); + if(line.StartsWith("... ")) + line = line.Remove(3, 1); + line = pre + line; + } + if (line.LineStartsWithHtmlTag(false, true)) // and + { + // Todo: what if line number is > 1 + var closeIdx = line.IndexOf('>', 5); + if (closeIdx >= 5 && line.Length > closeIdx + 5) + { + var fontTag = line.Substring(0, closeIdx + 1).TrimStart(); + line = line.Substring(closeIdx + 1).TrimStart(); + if (line.StartsWith("... ", StringComparison.Ordinal)) + line = line.Remove("... ".Length - 1, 1); + line = fontTag + line; + } + } + return line; + } + public static string FixHyphensAdd(Subtitle subtitle, int i, string language) { Paragraph p = subtitle.Paragraphs[i]; @@ -351,7 +378,7 @@ namespace Nikse.SubtitleEdit.Logic.Forms { // add dash in second line. newLineIdx += 2; - if(text.LineBreakStartsWithHtmlTag(true)) + if (text.LineBreakStartsWithHtmlTag(true)) { text = text.Insert(newLineIdx + 3, "- ").TrimEnd(); } diff --git a/src/Test/FixCommonErrorsTest.cs b/src/Test/FixCommonErrorsTest.cs index ba9e2c2d6..1b5b22041 100644 --- a/src/Test/FixCommonErrorsTest.cs +++ b/src/Test/FixCommonErrorsTest.cs @@ -1312,5 +1312,34 @@ namespace Test #endregion Fix dialogs on one line + #region FixDoubleDash + + [TestMethod] + [DeploymentItem("SubtitleEdit.exe")] + public void FixDoubleDashTest1() + { + using (var target = GetFixCommonErrorsLib()) + { + // and + InitializeFixCommonErrorsLine(target, "-- Mm-hmm."); + target.FixDoubleDash(); + Assert.AreEqual(target.Subtitle.Paragraphs[0].Text, "...Mm-hmm."); + } + } + + [TestMethod] + [DeploymentItem("SubtitleEdit.exe")] + public void FixDoubleDashTest2() + { + using (var target = GetFixCommonErrorsLib()) + { + // and + InitializeFixCommonErrorsLine(target, "Mm-hmm.\r\n-- foobar"); + target.FixDoubleDash(); + Assert.AreEqual(target.Subtitle.Paragraphs[0].Text, "Mm-hmm.\r\n...foobar"); + } + } + + #endregion } }