Original author: Pierre Sarrazin. Source: http://sarrazip.com/dev/ebitor-0.1.1.tar.gz Archive SHA-256: 6911a9d2ee80925622f1d82db1b77710a1f896865e63d29a04dc16489b150e83
50 lines
1.8 KiB
C
50 lines
1.8 KiB
C
/* findStringAndScrollToShow.c
|
|
|
|
Copyright (C) 2021-2025 Pierre Sarrazin <http://sarrazip.com/>
|
|
|
|
This program is free software: you can redistribute it and/or modify
|
|
it under the terms of the GNU General Public License as published by
|
|
the Free Software Foundation, either version 3 of the License, or
|
|
(at your option) any later version.
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
GNU General Public License for more details.
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
*/
|
|
|
|
#include "Ebitor_private.h"
|
|
|
|
|
|
BOOL
|
|
Ebitor_findStringAndScrollToShow(size_t startLogicalOffset, const char *strSearchedFor,
|
|
size_t *foundLogicalOffset)
|
|
{
|
|
Ebitor *self = &Ebitor_instance;
|
|
Ebitor_startCommandMode(); // put insert buffer into edit buffer, so that all the text is contiguous
|
|
|
|
size_t lenStrSearchedFor = strlen(strSearchedFor);
|
|
if (lenStrSearchedFor == 0 || startLogicalOffset >= self->bufferFilledSize)
|
|
return FALSE;
|
|
|
|
const char * const bufferEnd = self->bufferBegin + self->bufferFilledSize;
|
|
const char *startPtr = self->bufferBegin + startLogicalOffset;
|
|
const char *foundPtr;
|
|
do
|
|
{
|
|
foundPtr = (char *) memichr(startPtr, strSearchedFor[0], bufferEnd - startPtr);
|
|
if (!foundPtr)
|
|
return FALSE;
|
|
if (memicmp(foundPtr + 1, strSearchedFor + 1, lenStrSearchedFor - 1) == 0)
|
|
break;
|
|
startPtr = foundPtr + 1;
|
|
} while (startPtr < bufferEnd);
|
|
|
|
*foundLogicalOffset = foundPtr - self->bufferBegin;
|
|
Ebitor_scrollToShowLogicalOffset(*foundLogicalOffset, lenStrSearchedFor);
|
|
return TRUE;
|
|
}
|