mirror of
https://github.com/reactos/reactos.git
synced 2024-09-28 21:44:31 +00:00
[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:
parent
55e3feba53
commit
8c7233e015
|
@ -109,30 +109,36 @@ static int NOTEPAD_MenuCommand(WPARAM wParam)
|
||||||
*/
|
*/
|
||||||
|
|
||||||
static BOOL
|
static BOOL
|
||||||
NOTEPAD_FindTextAt(FINDREPLACE *pFindReplace, LPCTSTR pszText, int iTextLength, DWORD dwPosition)
|
NOTEPAD_FindTextAt(FINDREPLACE *pFindReplace, LPCTSTR pszText, INT iTextLength, DWORD dwPosition)
|
||||||
{
|
{
|
||||||
BOOL bMatches;
|
BOOL bMatches;
|
||||||
size_t iTargetLength;
|
size_t iTargetLength;
|
||||||
|
LPCTSTR pchPosition;
|
||||||
|
|
||||||
if ((!pFindReplace) || (!pszText))
|
if (!pFindReplace || !pszText)
|
||||||
{
|
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
|
||||||
|
|
||||||
iTargetLength = _tcslen(pFindReplace->lpstrFindWhat);
|
iTargetLength = _tcslen(pFindReplace->lpstrFindWhat);
|
||||||
|
pchPosition = &pszText[dwPosition];
|
||||||
|
|
||||||
/* Make proper comparison */
|
/* Make proper comparison */
|
||||||
if (pFindReplace->Flags & FR_MATCHCASE)
|
if (pFindReplace->Flags & FR_MATCHCASE)
|
||||||
bMatches = !_tcsncmp(&pszText[dwPosition], pFindReplace->lpstrFindWhat, iTargetLength);
|
bMatches = !_tcsncmp(pchPosition, pFindReplace->lpstrFindWhat, iTargetLength);
|
||||||
else
|
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]))
|
if (dwPosition > 0)
|
||||||
bMatches = FALSE;
|
{
|
||||||
if ((dwPosition < (DWORD) iTextLength - 1) && !_istspace(pszText[dwPosition+1]))
|
if (_istalnum(*(pchPosition - 1)) || *(pchPosition - 1) == _T('_'))
|
||||||
bMatches = FALSE;
|
bMatches = FALSE;
|
||||||
|
}
|
||||||
|
if ((INT)dwPosition + iTargetLength < iTextLength)
|
||||||
|
{
|
||||||
|
if (_istalnum(pchPosition[iTargetLength]) || pchPosition[iTargetLength] == _T('_'))
|
||||||
|
bMatches = FALSE;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return bMatches;
|
return bMatches;
|
||||||
|
|
Loading…
Reference in a new issue