summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEike Rathke <erack@redhat.com>2016-04-24 16:16:51 +0200
committerEike Rathke <erack@redhat.com>2016-04-24 16:42:39 +0200
commitffbe1b43bff59aae506446a5f408bba8ba9315c2 (patch)
tree50dbcb98b9606cb11f0b76f4a74697e4ca387e03
parent618e7622d08b20f6ea5f38144b61a187aced86af (diff)
Resolves: tdf#99468 do greedy '*' match if substring match is not allowed
Change-Id: I89ac29b7e8c2e8c567e85a5025dbc1f50050465d
-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);