From b6f514a2cf8ed1b5c9cf3cdc6d361d0947fce10e Mon Sep 17 00:00:00 2001 From: niksedk Date: Sun, 5 Oct 2014 09:49:53 +0200 Subject: [PATCH] Fix #281 --- src/Forms/FixCommonErrors.cs | 32 ++++++++++----- src/Test/FixCommonErrorsTest.cs | 71 +++++++++++++++++++++++++++++++++ 2 files changed, 93 insertions(+), 10 deletions(-) diff --git a/src/Forms/FixCommonErrors.cs b/src/Forms/FixCommonErrors.cs index 3ec1e0c5c..a15704d82 100644 --- a/src/Forms/FixCommonErrors.cs +++ b/src/Forms/FixCommonErrors.cs @@ -201,6 +201,15 @@ namespace Nikse.SubtitleEdit.Forms return "en"; return ci.TwoLetterISOLanguageName; } + set + { + for (int index = 0; index < comboBoxLanguage.Items.Count; index++) + { + var item = comboBoxLanguage.Items[index]; + if (item.ToString() == value) + comboBoxLanguage.SelectedIndex = index; + } + } } public void RunBatch(Subtitle subtitle, SubtitleFormat format, Encoding encoding, string language) @@ -1335,6 +1344,7 @@ namespace Nikse.SubtitleEdit.Forms public void FixMissingSpaces() { + string languageCode = Language; string fixAction = _language.FixMissingSpace; int missingSpaces = 0; for (int i = 0; i < Subtitle.Paragraphs.Count; i++) @@ -1347,17 +1357,19 @@ namespace Nikse.SubtitleEdit.Forms { while (match.Success) { - if (!@"""”<.".Contains(p.Text[match.Index + 2])) - { - if (AllowFix(p, fixAction)) - { - _totalFixes++; - missingSpaces++; + bool doFix = !@"""”<.".Contains(p.Text[match.Index + 2]); - string oldText = p.Text; - p.Text = p.Text.Replace(match.Value, match.Value[0] + ", " + match.Value[match.Value.Length - 1]); - AddFixToListView(p, fixAction, oldText, p.Text); - } + if (doFix && languageCode == "el" && (p.Text.Substring(match.Index).StartsWith("ό,τι") || p.Text.Substring(match.Index).StartsWith("ο,τι"))) + doFix = false; + + if (doFix && AllowFix(p, fixAction)) + { + _totalFixes++; + missingSpaces++; + + string oldText = p.Text; + p.Text = p.Text.Replace(match.Value, match.Value[0] + ", " + match.Value[match.Value.Length - 1]); + AddFixToListView(p, fixAction, oldText, p.Text); } match = match.NextMatch(); } diff --git a/src/Test/FixCommonErrorsTest.cs b/src/Test/FixCommonErrorsTest.cs index 1f8c05b29..31180b9d1 100644 --- a/src/Test/FixCommonErrorsTest.cs +++ b/src/Test/FixCommonErrorsTest.cs @@ -576,6 +576,18 @@ namespace Test } } + [TestMethod] + [DeploymentItem("SubtitleEdit.exe")] + public void FixMissingSpacesChange2() + { + using (var target = GetFixCommonErrorsLib()) + { + InitializeFixCommonErrorsLine(target, "To be,or not to be!"); + target.FixMissingSpaces(); + Assert.AreEqual(target.Subtitle.Paragraphs[0].Text, "To be, or not to be!"); + } + } + [TestMethod] [DeploymentItem("SubtitleEdit.exe")] public void FixMissingSpacesNoChange2() @@ -612,8 +624,67 @@ namespace Test } } + [TestMethod] + [DeploymentItem("SubtitleEdit.exe")] + public void FixMissingSpacesNoChange5Greek() + { + using (var target = GetFixCommonErrorsLib()) + { + InitializeFixCommonErrorsLine(target, "Aφαίρεσαν ό,τι αντρικό είχες."); + target.Language = "el"; // Greek + target.FixMissingSpaces(); + Assert.AreEqual(target.Subtitle.Paragraphs[0].Text, "Aφαίρεσαν ό,τι αντρικό είχες."); + } + } + #endregion Fix missing spaces + #region Fix unneeded spaces + + [TestMethod] + [DeploymentItem("SubtitleEdit.exe")] + public void FixUnneededSpaces1() + { + using (var target = GetFixCommonErrorsLib()) + { + InitializeFixCommonErrorsLine(target, "To be , or not to be!"); + target.FixUnneededSpaces(); + Assert.AreEqual(target.Subtitle.Paragraphs[0].Text, "To be, or not to be!"); + } + } + + public void FixUnneededSpaces2() + { + using (var target = GetFixCommonErrorsLib()) + { + InitializeFixCommonErrorsLine(target, " To be, or not to be!"); + target.FixUnneededSpaces(); + Assert.AreEqual(target.Subtitle.Paragraphs[0].Text, " To be, or not to be!"); + } + } + + public void FixUnneededSpaces3() + { + using (var target = GetFixCommonErrorsLib()) + { + InitializeFixCommonErrorsLine(target, "To be , or not to be! "); + target.FixUnneededSpaces(); + Assert.AreEqual(target.Subtitle.Paragraphs[0].Text, "To be, or not to be!"); + } + } + + public void FixUnneededSpaces4() + { + using (var target = GetFixCommonErrorsLib()) + { + InitializeFixCommonErrorsLine(target, "To be , or not to be! " + Environment.NewLine + " Line two."); + target.FixUnneededSpaces(); + Assert.AreEqual(target.Subtitle.Paragraphs[0].Text, "To be, or not to be!" + Environment.NewLine + "Line two."); + } + } + + #endregion Fix unneeded spaces + #region Start with uppercase after paragraph [TestMethod]