From 4cf1d290bab29e18e1312b63ff862f5102e00387 Mon Sep 17 00:00:00 2001 From: Mike Kaganski Date: Sun, 8 Nov 2015 22:23:44 +1000 Subject: tdf#94810: fix reverse offset mapping With simple transliteration, TextSearch::searchForward used to use whole string to perform the search, then started to create substring to search. But it left the precautions from commit c00601dab0f5533b152cd63cec0a89bfec1ba95f by Eike Rathke: searching for $ may actually return a result set pointing behind the search string which it does with the ICU regex engine. The precaution made it to skip reverse mapping if index was 0. Commit 9aae521b451269007f03527c83645b8b935eb419 by Michael Stahl didn't consider the case when nStop is 0, and startPos > 0. Then it tried to get offset[-1]. Anyway, using value of startPos in those conditions seems illogical. Removed those precautions (and made assertions for that). Fixed handling zero indexes. Change-Id: I2066abc51fff7fb7323bc7f6198bdea06439d4f3 Reviewed-on: https://gerrit.libreoffice.org/19840 Tested-by: Jenkins Reviewed-by: Eike Rathke Tested-by: Eike Rathke --- i18npool/source/search/textsearch.cxx | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) (limited to 'i18npool/source') diff --git a/i18npool/source/search/textsearch.cxx b/i18npool/source/search/textsearch.cxx index e4804376cc9f..fa4cdba4a049 100644 --- a/i18npool/source/search/textsearch.cxx +++ b/i18npool/source/search/textsearch.cxx @@ -301,15 +301,18 @@ SearchResult TextSearch::searchForward( const OUString& searchStr, sal_Int32 sta for ( sal_Int32 k = 0; k < nGroups; k++ ) { const sal_Int32 nStart = sres.startOffset[k] - nExtraOffset; - if (startPos > 0 || nStart > 0) - sres.startOffset[k] = (nStart < nOffsets ? offset[nStart] : (offset[nOffsets - 1] + 1)); + assert(nStart >= 0); // if not (e.g. searching for $ with ICU regex engine), then what? + sres.startOffset[k] = (nStart < nOffsets ? offset[nStart] : (offset[nOffsets - 1] + 1)); // JP 20.6.2001: end is ever exclusive and then don't return // the position of the next character - return the // next position behind the last found character! // "a b c" find "b" must return 2,3 and not 2,4!!! const sal_Int32 nStop = sres.endOffset[k] - nExtraOffset; - if (startPos > 0 || nStop > 0) + assert(nStop >= 0); + if (nStop > 0) sres.endOffset[k] = offset[(nStop <= nOffsets ? nStop : nOffsets) - 1] + 1; + else + sres.endOffset[k] = offset[0]; } } } -- cgit