summaryrefslogtreecommitdiff
path: root/i18npool/source/search/textsearch.cxx
diff options
context:
space:
mode:
Diffstat (limited to 'i18npool/source/search/textsearch.cxx')
-rw-r--r--i18npool/source/search/textsearch.cxx40
1 files changed, 32 insertions, 8 deletions
diff --git a/i18npool/source/search/textsearch.cxx b/i18npool/source/search/textsearch.cxx
index 07cceb039868..5791ff6e2735 100644
--- a/i18npool/source/search/textsearch.cxx
+++ b/i18npool/source/search/textsearch.cxx
@@ -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);