/* findStringAndScrollToShow.c Copyright (C) 2021-2025 Pierre Sarrazin 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 . */ #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; }