[NOTEPAD] Fix NOTEPAD_FindTextAt (#5103)

The whole-word search of Notepad had a bug around punctuation. For example, the text "Windows" didn't match in the text "MS-DOS,Windows,ReactOS". Use _istalnum instead of _istspace. Fix the position to check. _istalnum matches an alphabet letter or numeric digit. CORE-18837
This commit is contained in:
Katayama Hirofumi MZ 2023-03-01 19:57:10 +09:00 committed by GitHub
parent 55e3feba53
commit 8c7233e015
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -109,30 +109,36 @@ static int NOTEPAD_MenuCommand(WPARAM wParam)
*/
static BOOL
NOTEPAD_FindTextAt(FINDREPLACE *pFindReplace, LPCTSTR pszText, int iTextLength, DWORD dwPosition)
NOTEPAD_FindTextAt(FINDREPLACE *pFindReplace, LPCTSTR pszText, INT iTextLength, DWORD dwPosition)
{
BOOL bMatches;
size_t iTargetLength;
LPCTSTR pchPosition;
if ((!pFindReplace) || (!pszText))
{
if (!pFindReplace || !pszText)
return FALSE;
}
iTargetLength = _tcslen(pFindReplace->lpstrFindWhat);
pchPosition = &pszText[dwPosition];
/* Make proper comparison */
if (pFindReplace->Flags & FR_MATCHCASE)
bMatches = !_tcsncmp(&pszText[dwPosition], pFindReplace->lpstrFindWhat, iTargetLength);
bMatches = !_tcsncmp(pchPosition, pFindReplace->lpstrFindWhat, iTargetLength);
else
bMatches = !_tcsnicmp(&pszText[dwPosition], pFindReplace->lpstrFindWhat, iTargetLength);
bMatches = !_tcsnicmp(pchPosition, pFindReplace->lpstrFindWhat, iTargetLength);
if (bMatches && pFindReplace->Flags & FR_WHOLEWORD)
if (bMatches && (pFindReplace->Flags & FR_WHOLEWORD))
{
if ((dwPosition > 0) && !_istspace(pszText[dwPosition-1]))
bMatches = FALSE;
if ((dwPosition < (DWORD) iTextLength - 1) && !_istspace(pszText[dwPosition+1]))
bMatches = FALSE;
if (dwPosition > 0)
{
if (_istalnum(*(pchPosition - 1)) || *(pchPosition - 1) == _T('_'))
bMatches = FALSE;
}
if ((INT)dwPosition + iTargetLength < iTextLength)
{
if (_istalnum(pchPosition[iTargetLength]) || pchPosition[iTargetLength] == _T('_'))
bMatches = FALSE;
}
}
return bMatches;