diff --git a/src/AddIns/Misc/SearchAndReplace/Project/Engine/SearchReplaceUtilities.cs b/src/AddIns/Misc/SearchAndReplace/Project/Engine/SearchReplaceUtilities.cs index da0da2dbc4..0e4bdfb18b 100644 --- a/src/AddIns/Misc/SearchAndReplace/Project/Engine/SearchReplaceUtilities.cs +++ b/src/AddIns/Misc/SearchAndReplace/Project/Engine/SearchReplaceUtilities.cs @@ -30,10 +30,15 @@ namespace SearchAndReplace } } + static bool IsWordPart(char c) + { + return char.IsLetterOrDigit(c) || c == '_'; + } + public static bool IsWholeWordAt(IDocument document, int offset, int length) { - return (offset - 1 < 0 || Char.IsWhiteSpace(document.GetCharAt(offset - 1))) && - (offset + length + 1 >= document.TextLength || Char.IsWhiteSpace(document.GetCharAt(offset + length))); + return (offset - 1 < 0 || !IsWordPart(document.GetCharAt(offset - 1))) && + (offset + length + 1 >= document.TextLength || !IsWordPart(document.GetCharAt(offset + length))); } public static ISearchStrategy CreateSearchStrategy(SearchStrategyType type) diff --git a/src/AddIns/Misc/SearchAndReplace/Project/Engine/SearchStrategy/BruteForceSearchStrategy.cs b/src/AddIns/Misc/SearchAndReplace/Project/Engine/SearchStrategy/BruteForceSearchStrategy.cs index 0ad639b754..7bd15be0ef 100644 --- a/src/AddIns/Misc/SearchAndReplace/Project/Engine/SearchStrategy/BruteForceSearchStrategy.cs +++ b/src/AddIns/Misc/SearchAndReplace/Project/Engine/SearchStrategy/BruteForceSearchStrategy.cs @@ -34,17 +34,11 @@ namespace SearchAndReplace return true; } - bool IsWholeWordAt(IDocument document, int offset, int length) - { - return (offset - 1 < 0 || !Char.IsLetterOrDigit(document.GetCharAt(offset - 1))) && - (offset + length + 1 >= document.TextLength || !Char.IsLetterOrDigit(document.GetCharAt(offset + length))); - } - int InternalFindNext(ITextIterator textIterator) { while (textIterator.MoveAhead(1)) { if (SearchOptions.MatchCase ? MatchCaseSensitive(textIterator.Document, textIterator.Position, searchPattern) : MatchCaseInsensitive(textIterator.Document, textIterator.Position, searchPattern)) { - if (!SearchOptions.MatchWholeWord || IsWholeWordAt(textIterator.Document, textIterator.Position, searchPattern.Length)) { + if (!SearchOptions.MatchWholeWord || SearchReplaceUtilities.IsWholeWordAt(textIterator.Document, textIterator.Position, searchPattern.Length)) { return textIterator.Position; } } @@ -59,7 +53,7 @@ namespace SearchAndReplace textIterator.Position = offset; } if (SearchOptions.MatchCase ? MatchCaseSensitive(textIterator.Document, textIterator.Position, searchPattern) : MatchCaseInsensitive(textIterator.Document, textIterator.Position, searchPattern)) { - if (!SearchOptions.MatchWholeWord || IsWholeWordAt(textIterator.Document, textIterator.Position, searchPattern.Length)) { + if (!SearchOptions.MatchWholeWord || SearchReplaceUtilities.IsWholeWordAt(textIterator.Document, textIterator.Position, searchPattern.Length)) { if (TextSelection.IsInsideRange(textIterator.Position + searchPattern.Length - 1, offset, length)) { return textIterator.Position; } else {