[Libreoffice-commits] .: Branch 'feature/new-autofilter-popup' - 5 commits - sc/inc sc/source
Kohei Yoshida
kohei at kemper.freedesktop.org
Fri Nov 4 13:13:36 PDT 2011
sc/inc/queryparam.hxx | 3 -
sc/source/core/data/table3.cxx | 83 +++++++++++++++++++++++++------------
sc/source/core/tool/queryparam.cxx | 12 ++++-
3 files changed, 70 insertions(+), 28 deletions(-)
New commits:
commit 3ebf6c52dc469c199f090ac5190abebdc2934fad
Author: Kohei Yoshida <kohei.yoshida at suse.com>
Date: Fri Nov 4 16:13:17 2011 -0400
Do the simple string equality matching in ScQueryEntry instead.
diff --git a/sc/inc/queryparam.hxx b/sc/inc/queryparam.hxx
index 79330ae..f3d755c 100644
--- a/sc/inc/queryparam.hxx
+++ b/sc/inc/queryparam.hxx
@@ -72,7 +72,8 @@ public:
// creates pSearchParam and pSearchText if necessary, always RegExp!
utl::TextSearch* GetSearchTextPtr( bool bCaseSens ) const;
- bool MatchByString(const rtl::OUString& rStr) const;
+ bool IsQueryStringEmpty() const;
+ bool MatchByString(const rtl::OUString& rStr, bool bCaseSens) const;
SC_DLLPUBLIC void SetQueryString(const rtl::OUString& rStr);
SC_DLLPUBLIC rtl::OUString GetQueryString() const;
void Clear();
diff --git a/sc/source/core/data/table3.cxx b/sc/source/core/data/table3.cxx
index 4f0b540..7cae817 100644
--- a/sc/source/core/data/table3.cxx
+++ b/sc/source/core/data/table3.cxx
@@ -1077,7 +1077,7 @@ bool isQueryByValue(const ScTable& rTable, const ScQueryEntry& rEntry, SCROW nRo
return rTable.HasValueData(static_cast<SCCOL>(rEntry.nField), nRow);
}
-bool isTextMatchOnlyOp(const ScQueryEntry& rEntry)
+bool isPartialTextMatchOp(const ScQueryEntry& rEntry)
{
switch (rEntry.eOp)
{
@@ -1097,7 +1097,7 @@ bool isTextMatchOnlyOp(const ScQueryEntry& rEntry)
bool isTextMatchOp(const ScQueryEntry& rEntry)
{
- if (isTextMatchOnlyOp(rEntry))
+ if (isPartialTextMatchOp(rEntry))
return true;
switch (rEntry.eOp)
@@ -1266,7 +1266,8 @@ bool ScTable::ValidQuery(SCROW nRow, const ScQueryParam& rParam,
else if (isQueryByString(*this, rEntry, nRow, pCell))
{
String aCellStr;
- if (isTextMatchOnlyOp(rEntry))
+ if (isPartialTextMatchOp(rEntry))
+ // may have to do partial textural comparison.
bMatchWholeCell = false;
if ( pCell )
@@ -1338,11 +1339,10 @@ bool ScTable::ValidQuery(SCROW nRow, const ScQueryParam& rParam,
}
if ( !bRealRegExp )
{
- // Simple string matching.
- rtl::OUString aQueryStr = rEntry.GetQueryString();
+ // Simple string matching i.e. no regexp match.
if (isTextMatchOp(rEntry))
{
- if (!rEntry.bQueryByString && aQueryStr.isEmpty())
+ if (!rEntry.bQueryByString && rEntry.IsQueryStringEmpty())
{
// #i18374# When used from functions (match, countif, sumif, vlookup, hlookup, lookup),
// the query value is assigned directly, and the string is empty. In that case,
@@ -1353,12 +1353,13 @@ bool ScTable::ValidQuery(SCROW nRow, const ScQueryParam& rParam,
}
else if ( bMatchWholeCell )
{
- bOk = pTransliteration->isEqual(aCellStr, aQueryStr);
+ bOk = rEntry.MatchByString(aCellStr, rParam.bCaseSens);
if ( rEntry.eOp == SC_NOT_EQUAL )
bOk = !bOk;
}
else
{
+ rtl::OUString aQueryStr = rEntry.GetQueryString();
String aCell( pTransliteration->transliterate(
aCellStr, ScGlobal::eLnge, 0, aCellStr.Len(),
NULL ) );
@@ -1400,7 +1401,7 @@ bool ScTable::ValidQuery(SCROW nRow, const ScQueryParam& rParam,
else
{ // use collator here because data was probably sorted
sal_Int32 nCompare = pCollator->compareString(
- aCellStr, aQueryStr);
+ aCellStr, rEntry.GetQueryString());
switch (rEntry.eOp)
{
case SC_LESS :
diff --git a/sc/source/core/tool/queryparam.cxx b/sc/source/core/tool/queryparam.cxx
index bfb31d2..ca7d3a2 100644
--- a/sc/source/core/tool/queryparam.cxx
+++ b/sc/source/core/tool/queryparam.cxx
@@ -33,6 +33,7 @@
#include "queryparam.hxx"
#include <unotools/textsearch.hxx>
+#include <unotools/transliterationwrapper.hxx>
using ::std::vector;
@@ -96,9 +97,16 @@ ScQueryEntry& ScQueryEntry::operator=( const ScQueryEntry& r )
return *this;
}
-bool ScQueryEntry::MatchByString(const rtl::OUString& rStr) const
+bool ScQueryEntry::IsQueryStringEmpty() const
{
- return rStr.equals(*pStr);
+ return pStr->Len() == 0;
+}
+
+bool ScQueryEntry::MatchByString(const rtl::OUString& rStr, bool bCaseSens) const
+{
+ utl::TransliterationWrapper* pTransliteration = bCaseSens ?
+ ScGlobal::GetCaseTransliteration() : ScGlobal::GetpTransliteration();
+ return pTransliteration->isEqual(rStr, *pStr);
}
void ScQueryEntry::SetQueryString(const rtl::OUString& rStr)
commit acc88e8b260c23b911febd29ca238ba61e1193a4
Author: Kohei Yoshida <kohei.yoshida at suse.com>
Date: Fri Nov 4 15:34:28 2011 -0400
A little cleanup.
diff --git a/sc/source/core/data/table3.cxx b/sc/source/core/data/table3.cxx
index 2490bf7..4f0b540 100644
--- a/sc/source/core/data/table3.cxx
+++ b/sc/source/core/data/table3.cxx
@@ -1077,12 +1077,11 @@ bool isQueryByValue(const ScTable& rTable, const ScQueryEntry& rEntry, SCROW nRo
return rTable.HasValueData(static_cast<SCCOL>(rEntry.nField), nRow);
}
-bool isQueryByString(const ScTable& rTable, const ScQueryEntry& rEntry, SCROW nRow, const ScBaseCell* pCell)
+bool isTextMatchOnlyOp(const ScQueryEntry& rEntry)
{
switch (rEntry.eOp)
{
- case SC_EQUAL:
- case SC_NOT_EQUAL:
+ // these operators can only be used with textural comparisons.
case SC_CONTAINS:
case SC_DOES_NOT_CONTAIN:
case SC_BEGINS_WITH:
@@ -1093,26 +1092,19 @@ bool isQueryByString(const ScTable& rTable, const ScQueryEntry& rEntry, SCROW nR
default:
;
}
-
- if (!rEntry.bQueryByString)
- return false;
-
- if (pCell)
- return pCell->HasStringData();
-
- return rTable.HasStringData(static_cast<SCCOL>(rEntry.nField), nRow);
+ return false;
}
-bool isPartialStringMatch(const ScQueryEntry& rEntry)
+bool isTextMatchOp(const ScQueryEntry& rEntry)
{
+ if (isTextMatchOnlyOp(rEntry))
+ return true;
+
switch (rEntry.eOp)
{
- case SC_CONTAINS:
- case SC_DOES_NOT_CONTAIN:
- case SC_BEGINS_WITH:
- case SC_ENDS_WITH:
- case SC_DOES_NOT_BEGIN_WITH:
- case SC_DOES_NOT_END_WITH:
+ // these operators can be used for either textural or value comparison.
+ case SC_EQUAL:
+ case SC_NOT_EQUAL:
return true;
default:
;
@@ -1120,27 +1112,26 @@ bool isPartialStringMatch(const ScQueryEntry& rEntry)
return false;
}
+bool isQueryByString(const ScTable& rTable, const ScQueryEntry& rEntry, SCROW nRow, const ScBaseCell* pCell)
+{
+ if (isTextMatchOp(rEntry))
+ return true;
+
+ if (!rEntry.bQueryByString)
+ return false;
+
+ if (pCell)
+ return pCell->HasStringData();
+
+ return rTable.HasStringData(static_cast<SCCOL>(rEntry.nField), nRow);
+}
+
bool isRealRegExp(const ScQueryParam& rParam, const ScQueryEntry& rEntry)
{
if (!rParam.bRegExp)
return false;
- switch (rEntry.eOp)
- {
- case SC_EQUAL:
- case SC_NOT_EQUAL:
- case SC_CONTAINS:
- case SC_DOES_NOT_CONTAIN:
- case SC_BEGINS_WITH:
- case SC_ENDS_WITH:
- case SC_DOES_NOT_BEGIN_WITH:
- case SC_DOES_NOT_END_WITH:
- return true;
- default:
- ;
- }
-
- return false;
+ return isTextMatchOp(rEntry);
}
bool isTestRegExp(const ScQueryParam& rParam, const ScQueryEntry& rEntry, bool* pbTestEqualCondition)
@@ -1275,7 +1266,7 @@ bool ScTable::ValidQuery(SCROW nRow, const ScQueryParam& rParam,
else if (isQueryByString(*this, rEntry, nRow, pCell))
{
String aCellStr;
- if (isPartialStringMatch(rEntry))
+ if (isTextMatchOnlyOp(rEntry))
bMatchWholeCell = false;
if ( pCell )
@@ -1347,11 +1338,9 @@ bool ScTable::ValidQuery(SCROW nRow, const ScQueryParam& rParam,
}
if ( !bRealRegExp )
{
+ // Simple string matching.
rtl::OUString aQueryStr = rEntry.GetQueryString();
- if ( rEntry.eOp == SC_EQUAL || rEntry.eOp == SC_NOT_EQUAL
- || rEntry.eOp == SC_CONTAINS || rEntry.eOp == SC_DOES_NOT_CONTAIN
- || rEntry.eOp == SC_BEGINS_WITH || rEntry.eOp == SC_ENDS_WITH
- || rEntry.eOp == SC_DOES_NOT_BEGIN_WITH || rEntry.eOp == SC_DOES_NOT_END_WITH )
+ if (isTextMatchOp(rEntry))
{
if (!rEntry.bQueryByString && aQueryStr.isEmpty())
{
commit 43f53bbe14acbd0a1e9d846e428c002405192c03
Author: Kohei Yoshida <kohei.yoshida at suse.com>
Date: Fri Nov 4 14:57:30 2011 -0400
More on extracting complex evaluations...
diff --git a/sc/source/core/data/table3.cxx b/sc/source/core/data/table3.cxx
index 33208e0..2490bf7 100644
--- a/sc/source/core/data/table3.cxx
+++ b/sc/source/core/data/table3.cxx
@@ -1120,6 +1120,40 @@ bool isPartialStringMatch(const ScQueryEntry& rEntry)
return false;
}
+bool isRealRegExp(const ScQueryParam& rParam, const ScQueryEntry& rEntry)
+{
+ if (!rParam.bRegExp)
+ return false;
+
+ switch (rEntry.eOp)
+ {
+ case SC_EQUAL:
+ case SC_NOT_EQUAL:
+ case SC_CONTAINS:
+ case SC_DOES_NOT_CONTAIN:
+ case SC_BEGINS_WITH:
+ case SC_ENDS_WITH:
+ case SC_DOES_NOT_BEGIN_WITH:
+ case SC_DOES_NOT_END_WITH:
+ return true;
+ default:
+ ;
+ }
+
+ return false;
+}
+
+bool isTestRegExp(const ScQueryParam& rParam, const ScQueryEntry& rEntry, bool* pbTestEqualCondition)
+{
+ if (!pbTestEqualCondition)
+ return false;
+
+ if (!rParam.bRegExp)
+ return false;
+
+ return (rEntry.eOp == SC_LESS_EQUAL || rEntry.eOp == SC_GREATER_EQUAL);
+}
+
}
bool ScTable::ValidQuery(SCROW nRow, const ScQueryParam& rParam,
@@ -1255,14 +1289,9 @@ bool ScTable::ValidQuery(SCROW nRow, const ScQueryParam& rParam,
else
GetInputString( static_cast<SCCOL>(rEntry.nField), nRow, aCellStr );
- bool bRealRegExp = (rParam.bRegExp && ((rEntry.eOp == SC_EQUAL)
- || (rEntry.eOp == SC_NOT_EQUAL) || (rEntry.eOp == SC_CONTAINS)
- || (rEntry.eOp == SC_DOES_NOT_CONTAIN) || (rEntry.eOp == SC_BEGINS_WITH)
- || (rEntry.eOp == SC_ENDS_WITH) || (rEntry.eOp == SC_DOES_NOT_BEGIN_WITH)
- || (rEntry.eOp == SC_DOES_NOT_END_WITH)));
- bool bTestRegExp = (pbTestEqualCondition && rParam.bRegExp
- && ((rEntry.eOp == SC_LESS_EQUAL)
- || (rEntry.eOp == SC_GREATER_EQUAL)));
+ bool bRealRegExp = isRealRegExp(rParam, rEntry);
+ bool bTestRegExp = isTestRegExp(rParam, rEntry, pbTestEqualCondition);
+
if ( bRealRegExp || bTestRegExp )
{
xub_StrLen nStart = 0;
commit ebcb73a2b1ac054bbd0abdf5aaa14407e72ca7d6
Author: Kohei Yoshida <kohei.yoshida at suse.com>
Date: Fri Nov 4 14:47:12 2011 -0400
Another complex if condition extracted.
diff --git a/sc/source/core/data/table3.cxx b/sc/source/core/data/table3.cxx
index 99f3d21..33208e0 100644
--- a/sc/source/core/data/table3.cxx
+++ b/sc/source/core/data/table3.cxx
@@ -1103,6 +1103,23 @@ bool isQueryByString(const ScTable& rTable, const ScQueryEntry& rEntry, SCROW nR
return rTable.HasStringData(static_cast<SCCOL>(rEntry.nField), nRow);
}
+bool isPartialStringMatch(const ScQueryEntry& rEntry)
+{
+ switch (rEntry.eOp)
+ {
+ case SC_CONTAINS:
+ case SC_DOES_NOT_CONTAIN:
+ case SC_BEGINS_WITH:
+ case SC_ENDS_WITH:
+ case SC_DOES_NOT_BEGIN_WITH:
+ case SC_DOES_NOT_END_WITH:
+ return true;
+ default:
+ ;
+ }
+ return false;
+}
+
}
bool ScTable::ValidQuery(SCROW nRow, const ScQueryParam& rParam,
@@ -1224,10 +1241,9 @@ bool ScTable::ValidQuery(SCROW nRow, const ScQueryParam& rParam,
else if (isQueryByString(*this, rEntry, nRow, pCell))
{
String aCellStr;
- if( rEntry.eOp == SC_CONTAINS || rEntry.eOp == SC_DOES_NOT_CONTAIN
- || rEntry.eOp == SC_BEGINS_WITH || rEntry.eOp == SC_ENDS_WITH
- || rEntry.eOp == SC_DOES_NOT_BEGIN_WITH || rEntry.eOp == SC_DOES_NOT_END_WITH )
+ if (isPartialStringMatch(rEntry))
bMatchWholeCell = false;
+
if ( pCell )
{
if (pCell->GetCellType() != CELLTYPE_NOTE)
commit d290677b82e4bb25ec0897a587075e721b7dced5
Author: Kohei Yoshida <kohei.yoshida at suse.com>
Date: Fri Nov 4 14:43:28 2011 -0400
Using for loop here is better than while loop.
diff --git a/sc/source/core/data/table3.cxx b/sc/source/core/data/table3.cxx
index e4c7597..99f3d21 100644
--- a/sc/source/core/data/table3.cxx
+++ b/sc/source/core/data/table3.cxx
@@ -1119,14 +1119,13 @@ bool ScTable::ValidQuery(SCROW nRow, const ScQueryParam& rParam,
std::vector<bool> aTestEqual(nEntryCount, false);
long nPos = -1;
- SCSIZE i = 0;
bool bMatchWholeCell = pDocument->GetDocOptions().IsMatchWholeCell();
CollatorWrapper* pCollator = (rParam.bCaseSens ? ScGlobal::GetCaseCollator() :
ScGlobal::GetCollator());
::utl::TransliterationWrapper* pTransliteration = (rParam.bCaseSens ?
ScGlobal::GetCaseTransliteration() : ScGlobal::GetpTransliteration());
- while ( (i < nEntryCount) && rParam.GetEntry(i).bDoQuery )
+ for (size_t i = 0; i < nEntryCount && rParam.GetEntry(i).bDoQuery; ++i)
{
const ScQueryEntry& rEntry = rParam.GetEntry(i);
// we can only handle one single direct query
@@ -1432,7 +1431,6 @@ bool ScTable::ValidQuery(SCROW nRow, const ScQueryParam& rParam,
aTestEqual[nPos] = bTestEqual;
}
}
- i++;
}
for ( long j=1; j <= nPos; j++ )
More information about the Libreoffice-commits
mailing list