Kaydet (Commit) ffbe1b43 authored tarafından Eike Rathke's avatar Eike Rathke

Resolves: tdf#99468 do greedy '*' match if substring match is not allowed

Change-Id: I89ac29b7e8c2e8c567e85a5025dbc1f50050465d
üst 618e7622
......@@ -1188,7 +1188,7 @@ SearchResult TextSearch::WildcardSrchFrwrd( const OUString& searchStr, sal_Int32
rPattern.iterateCodePoints( &nAfterFakePattern);
}
sal_Int32 nString = nStartPos, nPat = -1, nStr = -1;
sal_Int32 nString = nStartPos, nPat = -1, nStr = -1, nLastAsterisk = -1;
sal_uInt32 cPatternAfterAsterisk = 0;
bool bEscaped = false, bEscapedAfterAsterisk = false;
......@@ -1215,11 +1215,21 @@ SearchResult TextSearch::WildcardSrchFrwrd( const OUString& searchStr, sal_Int32
}
else
{
// A trailing '*' is handled below. If the pattern is consumed and
// substring match allowed we're good.
// A trailing '*' is handled below.
if (mbWildcardAllowSubstring)
{
// If the pattern is consumed and substring match allowed we're good.
setWildcardMatch( aRes, nStartOffset, nString);
return aRes;
return aRes;
}
else if (nString < nEndPos && nLastAsterisk >= 0)
{
// If substring match is not allowed try a greedy '*' match.
nPattern = nLastAsterisk;
continue; // do
}
else
return aRes;
}
if (cPattern == '*' && !bEscaped)
......@@ -1235,6 +1245,8 @@ SearchResult TextSearch::WildcardSrchFrwrd( const OUString& searchStr, sal_Int32
return aRes;
}
nLastAsterisk = nPattern; // Remember last encountered '*'.
// cPattern will be the next non-'*' character, nPattern
// incremented.
cPattern = rPattern.iterateCodePoints( &nPattern);
......@@ -1406,7 +1418,7 @@ SearchResult TextSearch::WildcardSrchBkwrd( const OUString& searchStr, sal_Int32
rReversePattern.iterateCodePoints( &nAfterFakePattern, -1);
}
sal_Int32 nString = nStartPos, nPat = -1, nStr = -1;
sal_Int32 nString = nStartPos, nPat = -1, nStr = -1, nLastAsterisk = -1;
sal_uInt32 cPatternAfterAsterisk = 0;
bool bEscaped = false, bEscapedAfterAsterisk = false;
......@@ -1433,11 +1445,21 @@ SearchResult TextSearch::WildcardSrchBkwrd( const OUString& searchStr, sal_Int32
}
else
{
// A leading '*' is handled below. If the pattern is consumed and
// substring match allowed we're good.
// A trailing '*' is handled below.
if (mbWildcardAllowSubstring)
{
// If the pattern is consumed and substring match allowed we're good.
setWildcardMatch( aRes, nStartOffset, nString);
return aRes;
return aRes;
}
else if (nString > nEndPos && nLastAsterisk >= 0)
{
// If substring match is not allowed try a greedy '*' match.
nPattern = nLastAsterisk;
continue; // do
}
else
return aRes;
}
if (cPattern == '*' && !bEscaped)
......@@ -1453,6 +1475,8 @@ SearchResult TextSearch::WildcardSrchBkwrd( const OUString& searchStr, sal_Int32
return aRes;
}
nLastAsterisk = nPattern; // Remember last encountered '*'.
// cPattern will be the previous non-'*' character, nPattern
// decremented.
cPattern = rReversePattern.iterateCodePoints( &nPattern, -1);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment