From c4b8255f45ec9ee469ae403f703bdcc2c856a792 Mon Sep 17 00:00:00 2001 From: Nikolaj Olsson Date: Thu, 23 May 2024 09:27:55 +0200 Subject: [PATCH] Improve FixMissingPeriodsAtEndOfLine - thx Leon :) Fix #8386 --- .../FixCommonErrors/FixCommonErrorsTest.cs | 20 +++++++++++++++++++ .../FixMissingPeriodsAtEndOfLine.cs | 4 ++-- 2 files changed, 22 insertions(+), 2 deletions(-) diff --git a/src/Test/FixCommonErrors/FixCommonErrorsTest.cs b/src/Test/FixCommonErrors/FixCommonErrorsTest.cs index cbde21296..bac3e5a43 100644 --- a/src/Test/FixCommonErrors/FixCommonErrorsTest.cs +++ b/src/Test/FixCommonErrors/FixCommonErrorsTest.cs @@ -1363,6 +1363,26 @@ namespace Test.FixCommonErrors Assert.AreEqual(s.Paragraphs[0].Text, "The house seemed desolate to me and"); } + [TestMethod] + public void AddPeriodChineseDoNotAdd1() + { + var s = new Subtitle(); + s.Paragraphs.Add(new Paragraph("→「Adobe」の順に移動します。", 0, 2000)); + s.Paragraphs.Add(new Paragraph("Bye.", 7000, 9000)); + new FixMissingPeriodsAtEndOfLine().Fix(s, new EmptyFixCallback()); + Assert.AreEqual(s.Paragraphs[0].Text, "→「Adobe」の順に移動します。"); + } + + [TestMethod] + public void AddPeriodChineseDoNotAdd2() + { + var s = new Subtitle(); + s.Paragraphs.Add(new Paragraph("この新しいplistファイルを\r\n作成するには、", 0, 2000)); + s.Paragraphs.Add(new Paragraph("Bye.", 7000, 9000)); + new FixMissingPeriodsAtEndOfLine().Fix(s, new EmptyFixCallback()); + Assert.AreEqual(s.Paragraphs[0].Text, "この新しいplistファイルを\r\n作成するには、"); + } + #endregion Fix missing periods at end of line #region Start with uppercase after paragraph diff --git a/src/libse/Forms/FixCommonErrors/FixMissingPeriodsAtEndOfLine.cs b/src/libse/Forms/FixCommonErrors/FixMissingPeriodsAtEndOfLine.cs index 9bd117026..b2be3f401 100644 --- a/src/libse/Forms/FixCommonErrors/FixMissingPeriodsAtEndOfLine.cs +++ b/src/libse/Forms/FixCommonErrors/FixMissingPeriodsAtEndOfLine.cs @@ -48,7 +48,7 @@ namespace Nikse.SubtitleEdit.Core.Forms.FixCommonErrors // Cached variables private static readonly char[] ExpectedChars = { '♪', '♫' }; - private const string ExpectedString1 = ",.!?:;>-])♪♫…"; + private const string DoNotAddPeriodAfterChars = ",.!?:;>-])♪♫…、。"; private const string ExpectedString2 = ")]*#¶.!?"; public void Fix(Subtitle subtitle, IFixCallbacks callbacks) @@ -79,7 +79,7 @@ namespace Nikse.SubtitleEdit.Core.Forms.FixCommonErrors next.Text.Length > 0 && char.IsUpper(nextText[0]) && tempNoHtml.Length > 0 && - !ExpectedString1.Contains(tempNoHtml[tempNoHtml.Length - 1])) + !DoNotAddPeriodAfterChars.Contains(tempNoHtml[tempNoHtml.Length - 1])) { var tempTrimmed = tempNoHtml.TrimEnd().TrimEnd('\'', '"', '“', '”').TrimEnd(); if (tempTrimmed.Length > 0 && !ExpectedString2.Contains(tempTrimmed[tempTrimmed.Length - 1]) && p.Text != p.Text.ToUpperInvariant())