summaryrefslogtreecommitdiff
path: root/i18npool/source
diff options
context:
space:
mode:
authorKhaled Hosny <khaled@aliftype.com>2022-08-17 10:45:24 +0200
committerخالد حسني <khaled@aliftype.com>2022-08-22 16:35:08 +0200
commita8ba4ed2966a6f39b9aea6ce9deaed63db2023f2 (patch)
tree380c4ac3753c83f539cf6fdca95e1dd530a24a9d /i18npool/source
parenta727400328fca3884afbd287c19f3d13edc60d3d (diff)
tdf#91764: Combining marks from “complex” scripts can’t be searched for
Don’t skip search results that are in the middle of a grapheme cluster (AKA cell in LO speak). It is not clear why it was done like this, as these checks are present all the way back to the first commit of this file: commit 36eb193f4809221af42c01c5ac226a97cf74ec21 Author: Rüdiger Timm <rt@openoffice.org> Date: Tue Apr 8 15:01:00 2003 +0000 INTEGRATION: CWS calc06 (1.1.2); FILE ADDED 2003/03/26 15:54:42 er 1.1.2.1: #i3393# moved from i18n module, cleaned out tools module usage, and added support for regexp But ignoring such results and only for so-called “complex” scripts seems arbitrary, and as the linked issue shows, people want to be able to search for combining marks. Furthermore, it prevents searching for a base character followed by a combining mark, unless ignoring diacritics is enabled. Change-Id: I530788d928861ddfa18dd7b813d0a13f53c0b77b Reviewed-on: https://gerrit.libreoffice.org/c/core/+/138410 Tested-by: Jenkins Reviewed-by: خالد حسني <khaled@aliftype.com> (cherry picked from commit 2a78fbf4e4a49f2b52aa1352aac41ee024d0cf72) Reviewed-on: https://gerrit.libreoffice.org/c/core/+/138542
Diffstat (limited to 'i18npool/source')
-rw-r--r--i18npool/source/search/textsearch.cxx79
-rw-r--r--i18npool/source/search/textsearch.hxx4
2 files changed, 27 insertions, 56 deletions
diff --git a/i18npool/source/search/textsearch.cxx b/i18npool/source/search/textsearch.cxx
index c80afc19890f..a16c3e1cc4c7 100644
--- a/i18npool/source/search/textsearch.cxx
+++ b/i18npool/source/search/textsearch.cxx
@@ -214,13 +214,6 @@ void TextSearch::setOptions2( const SearchOptions2& rOptions )
aSrchPara.searchString, 0, aSrchPara.searchString.getLength());
}
- // When start or end of search string is a complex script type, we need to
- // make sure the result boundary is not located in the middle of cell.
- checkCTLStart = (xBreak.is() && (xBreak->getScriptType(sSrchStr, 0) ==
- ScriptType::COMPLEX));
- checkCTLEnd = (xBreak.is() && (xBreak->getScriptType(sSrchStr,
- sSrchStr.getLength()-1) == ScriptType::COMPLEX));
-
if ( bReplaceApostrophe )
sSrchStr = sSrchStr.replace(u'\u2019', '\'');
@@ -305,13 +298,6 @@ static sal_Int32 FindPosInSeq_Impl( const Sequence <sal_Int32>& rOff, sal_Int32
return static_cast<sal_Int32>(std::distance(rOff.begin(), pOff));
}
-bool TextSearch::isCellStart(const OUString& searchStr, sal_Int32 nPos)
-{
- sal_Int32 nDone;
- return nPos == xBreak->previousCharacters(searchStr, nPos+1,
- aSrchPara.Locale, CharacterIteratorMode::SKIPCELL, 1, nDone);
-}
-
SearchResult TextSearch::searchForward( const OUString& searchStr, sal_Int32 startPos, sal_Int32 endPos )
{
std::unique_lock g(m_aMutex);
@@ -737,11 +723,6 @@ SearchResult TextSearch::NSrchFrwrd( const OUString& searchStr, sal_Int32 startP
nCmpIdx <= nEnd;
nCmpIdx += GetDiff( searchStr[nCmpIdx + sSearchKey.getLength()-1]))
{
- // if the match would be the completed cells, skip it.
- if ( (checkCTLStart && !isCellStart( searchStr, nCmpIdx )) || (checkCTLEnd
- && !isCellStart( searchStr, nCmpIdx + sSearchKey.getLength())) )
- continue;
-
nSuchIdx = sSearchKey.getLength() - 1;
while( nSuchIdx >= 0 && sSearchKey[nSuchIdx] == searchStr[nCmpIdx + nSuchIdx])
{
@@ -804,41 +785,28 @@ SearchResult TextSearch::NSrchBkwrd( const OUString& searchStr, sal_Int32 startP
while (nCmpIdx >= nEnd)
{
- // if the match would be the completed cells, skip it.
- if ( (!checkCTLStart || isCellStart( searchStr, nCmpIdx -
- sSearchKey.getLength() )) && (!checkCTLEnd ||
- isCellStart( searchStr, nCmpIdx)))
+ nSuchIdx = 0;
+ while( nSuchIdx < sSearchKey.getLength() && sSearchKey[nSuchIdx] ==
+ searchStr[nCmpIdx + nSuchIdx - sSearchKey.getLength()] )
+ nSuchIdx++;
+ if( nSuchIdx >= sSearchKey.getLength() )
{
- nSuchIdx = 0;
- while( nSuchIdx < sSearchKey.getLength() && sSearchKey[nSuchIdx] ==
- searchStr[nCmpIdx + nSuchIdx - sSearchKey.getLength()] )
- nSuchIdx++;
- if( nSuchIdx >= sSearchKey.getLength() )
+ if( SearchFlags::NORM_WORD_ONLY & aSrchPara.searchFlag )
{
- if( SearchFlags::NORM_WORD_ONLY & aSrchPara.searchFlag )
- {
- sal_Int32 nFndStt = nCmpIdx - sSearchKey.getLength();
- bool bAtStart = !nFndStt;
- bool bAtEnd = nCmpIdx == startPos;
- bool bDelimBehind = bAtEnd || IsDelimiter( searchStr, nCmpIdx );
- bool bDelimBefore = bAtStart || // begin of paragraph
- IsDelimiter( searchStr, nFndStt-1 );
- // * 1 -> only one word in the paragraph
- // * 2 -> at begin of paragraph
- // * 3 -> at end of paragraph
- // * 4 -> inside the paragraph
- if( ( bAtStart && bAtEnd ) || // 1
- ( bAtStart && bDelimBehind ) || // 2
- ( bAtEnd && bDelimBefore ) || // 3
- ( bDelimBefore && bDelimBehind )) // 4
- {
- aRet.subRegExpressions = 1;
- aRet.startOffset = { nCmpIdx };
- aRet.endOffset = { nCmpIdx - sSearchKey.getLength() };
- return aRet;
- }
- }
- else
+ sal_Int32 nFndStt = nCmpIdx - sSearchKey.getLength();
+ bool bAtStart = !nFndStt;
+ bool bAtEnd = nCmpIdx == startPos;
+ bool bDelimBehind = bAtEnd || IsDelimiter( searchStr, nCmpIdx );
+ bool bDelimBefore = bAtStart || // begin of paragraph
+ IsDelimiter( searchStr, nFndStt-1 );
+ // * 1 -> only one word in the paragraph
+ // * 2 -> at begin of paragraph
+ // * 3 -> at end of paragraph
+ // * 4 -> inside the paragraph
+ if( ( bAtStart && bAtEnd ) || // 1
+ ( bAtStart && bDelimBehind ) || // 2
+ ( bAtEnd && bDelimBefore ) || // 3
+ ( bDelimBefore && bDelimBehind )) // 4
{
aRet.subRegExpressions = 1;
aRet.startOffset = { nCmpIdx };
@@ -846,6 +814,13 @@ SearchResult TextSearch::NSrchBkwrd( const OUString& searchStr, sal_Int32 startP
return aRet;
}
}
+ else
+ {
+ aRet.subRegExpressions = 1;
+ aRet.startOffset = { nCmpIdx };
+ aRet.endOffset = { nCmpIdx - sSearchKey.getLength() };
+ return aRet;
+ }
}
nSuchIdx = GetDiff( searchStr[nCmpIdx - sSearchKey.getLength()] );
if( nCmpIdx < nSuchIdx )
diff --git a/i18npool/source/search/textsearch.hxx b/i18npool/source/search/textsearch.hxx
index 0a4da19dfadc..43a643537a3a 100644
--- a/i18npool/source/search/textsearch.hxx
+++ b/i18npool/source/search/textsearch.hxx
@@ -130,10 +130,6 @@ class TextSearch: public cppu::WeakImplHelper
bool IsDelimiter( const OUString& rStr, sal_Int32 nPos ) const;
- bool checkCTLStart, checkCTLEnd;
- /// @throws css::uno::RuntimeException
- bool isCellStart(const OUString& searchStr, sal_Int32 nPos);
-
public:
explicit TextSearch(
const css::uno::Reference < css::uno::XComponentContext >& rxContext );