Merge pull request #2338 from ivandrofly/names-list

[Nameslist] - Minor fixes for NamesList.cs
This commit is contained in:
Nikolaj Olsson 2017-04-14 10:51:48 +02:00 committed by GitHub
commit 8f55e47a88
4 changed files with 11 additions and 9 deletions

View File

@ -244,7 +244,7 @@ namespace Nikse.SubtitleEdit.Core.Dictionaries
return false;
}
public bool IsInNamesEtcMultiWordList(string text, string word)
public bool IsInNamesMultiWordList(string text, string word)
{
if (string.IsNullOrEmpty(text))
return false;
@ -252,13 +252,15 @@ namespace Nikse.SubtitleEdit.Core.Dictionaries
text = text.Replace(Environment.NewLine, " ");
text = text.FixExtraSpaces();
foreach (string s in _namesMultiList)
if (_namesMultiList.Contains(word))
{
if (s.Contains(word) && text.Contains(s))
return true;
}
foreach (string multiWordName in _namesMultiList)
{
if (text.Contains(multiWordName))
{
if (s.StartsWith(word + " ", StringComparison.Ordinal) || s.EndsWith(" " + word, StringComparison.Ordinal) || s.Contains(" " + word + " "))
return true;
if (word == s)
if (multiWordName.StartsWith(word + " ", StringComparison.Ordinal) || multiWordName.EndsWith(" " + word, StringComparison.Ordinal) || multiWordName.Contains(" " + word + " "))
return true;
}
}

View File

@ -299,7 +299,7 @@ namespace Nikse.SubtitleEdit.Core.SpellCheck
public bool HasNameExtended(string word, string text)
{
return _namesEtcListUppercase.Contains(word) || _namesEtcListWithApostrophe.Contains(word) || _namesList.IsInNamesEtcMultiWordList(text, word);
return _namesEtcListUppercase.Contains(word) || _namesEtcListWithApostrophe.Contains(word) || _namesList.IsInNamesMultiWordList(text, word);
}
public bool HasUserWord(string word)

View File

@ -1388,7 +1388,7 @@ namespace Nikse.SubtitleEdit.Logic.Ocr
if (word.Length > 2 && _namesEtcListWithApostrophe.Contains(word))
return true;
if (_namesList != null && _namesList.IsInNamesEtcMultiWordList(line, word))
if (_namesList != null && _namesList.IsInNamesMultiWordList(line, word))
return true;
return false;

View File

@ -43,7 +43,7 @@ namespace Test.Logic.Dictionaries
// Act
namesList.Add("Charlie Parker123");
var exists = namesList.IsInNamesEtcMultiWordList("This is Charlie Parker123!", "Charlie Parker123");
var exists = namesList.IsInNamesMultiWordList("This is Charlie Parker123!", "Charlie Parker123");
// Assert
Assert.IsTrue(exists);