fdo#74209: This search algorithm had another issue. This fixes it.

When the search range was i.e. 1-3, and the match was found at 5, the old
code would return 5 when in fact it should have failed.  This change would
honor the end position and limit the search within specified search range.

Change-Id: If12a92fd3930ad128a5b0699a1addd96fb3a8eba
(cherry picked from commit 1da03a88a98b50633d61557de27e4c0702a665eb)
Reviewed-on: https://gerrit.libreoffice.org/7988
Tested-by: Markus Mohrhard <markus.mohrhard@googlemail.com>
Reviewed-by: Markus Mohrhard <markus.mohrhard@googlemail.com>