From aa2296a500028597fa8b3d2ddebf5f2624db194a Mon Sep 17 00:00:00 2001 From: Nikolaj Olsson Date: Fri, 16 Nov 2018 18:56:04 +0100 Subject: [PATCH] Do not ignore words of combined letters/numbers - thx Boulder08 :) Work on #3183 --- src/Forms/SpellCheck.cs | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/src/Forms/SpellCheck.cs b/src/Forms/SpellCheck.cs index 968175dc7..e92cfd379 100644 --- a/src/Forms/SpellCheck.cs +++ b/src/Forms/SpellCheck.cs @@ -8,6 +8,7 @@ using System; using System.Collections.Generic; using System.Drawing; using System.IO; +using System.Text.RegularExpressions; using System.Windows.Forms; namespace Nikse.SubtitleEdit.Forms @@ -51,8 +52,6 @@ namespace Nikse.SubtitleEdit.Forms private Main _mainWindow; private string _currentDictionary; - private static readonly char[] ExpectedChars = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '%', '&', '@', '$', '*', '=', '£', '#', '_', '½', '^' }; - public class SuggestionParameter { public string InputWord { get; set; } @@ -524,7 +523,7 @@ namespace Nikse.SubtitleEdit.Forms if (Configuration.Settings.Tools.SpellCheckOneLetterWords) minLength = 1; - if (_currentWord.Trim().Length >= minLength && !_currentWord.Contains(ExpectedChars)) + if (_currentWord.Trim().Length >= minLength) { _prefix = string.Empty; _postfix = string.Empty; @@ -555,6 +554,10 @@ namespace Nikse.SubtitleEdit.Forms { // "skip one" again (after change whole text) } + else if (IsNumber(_currentWord)) + { + _noOfSkippedWords++; + } else if (_spellCheckWordLists.HasUserWord(_currentWord)) { _noOfCorrectWords++; @@ -767,6 +770,17 @@ namespace Nikse.SubtitleEdit.Forms } } + private static readonly Regex RegexIsNumber = new Regex("^\\d+$", RegexOptions.Compiled); + private static readonly Regex RegexIsEpisodeNumber = new Regex("^\\d+x\\d+$", RegexOptions.Compiled); // e.g. 12x02 + private static bool IsNumber(string s) + { + s = s.Trim('$', '£'); + if (RegexIsNumber.IsMatch(s)) + return true; + if (RegexIsEpisodeNumber.IsMatch(s)) + return true; + return false; + } private void SetWords(string s) {