25#include <document.hxx>
73 bool bMatchWholeCell = docMatchWholeCell;
76 bMatchWholeCell =
false;
77 return bMatchWholeCell;
104 bool* pTestEqualCondition)
106 , mrStrPool(rDoc.GetSharedStringPool())
109 , mpTestEqualCondition(pTestEqualCondition)
110 , mpTransliteration(nullptr)
111 , mpCollator(nullptr)
112 , mbMatchWholeCell(rDoc.GetDocOptions().IsMatchWholeCell())
113 , mbCaseSensitive(rParam.bCaseSens)
115 , mnEntryCount(mrParam.GetEntryCount())
197 bool bTestEqual =
false;
199 double fQueryVal = rItem.
mfVal;
259 if ((nNumFmtType & SvNumFormatType::DATE) && !(nNumFmtType & SvNumFormatType::TIME))
263 nCellVal = ::rtl::math::approxFloor(nCellVal);
272 bOk = ::rtl::math::approxEqual(nCellVal, fQueryVal);
275 bOk = (nCellVal < fQueryVal) && !::rtl::math::approxEqual(nCellVal, fQueryVal);
278 bOk = (nCellVal > fQueryVal) && !::rtl::math::approxEqual(nCellVal, fQueryVal);
281 bOk = (nCellVal < fQueryVal) || ::rtl::math::approxEqual(nCellVal, fQueryVal);
283 bTestEqual = ::rtl::math::approxEqual(nCellVal, fQueryVal);
286 bOk = (nCellVal > fQueryVal) || ::rtl::math::approxEqual(nCellVal, fQueryVal);
288 bTestEqual = ::rtl::math::approxEqual(nCellVal, fQueryVal);
291 bOk = !::rtl::math::approxEqual(nCellVal, fQueryVal);
298 return std::pair<bool, bool>(bOk, bTestEqual);
317 *sharedString = &it->second;
345 return rEntry.
eOp ==
SC_EQUAL && !bRealWildOrRegExp && !bTestWildOrRegExp
355 const OUString* pValueSource2)
358 bool bTestEqual =
false;
359 bool bMatchWholeCell;
361 bMatchWholeCell =
true;
367 assert(!bFast || pValueSource1 !=
nullptr);
369 assert((pValueSource1 !=
nullptr) != (pValueSource2 !=
nullptr));
371 if (!bFast && (bRealWildOrRegExp || bTestWildOrRegExp))
373 const OUString& rValue = pValueSource1 ? pValueSource1->
getString() : *pValueSource2;
375 sal_Int32 nStart = 0;
376 sal_Int32 nEnd = rValue.getLength();
383 nStart = rValue.getLength();
394 if (bMatch && bMatchWholeCell && (nStart != 0 || nEnd != rValue.getLength()))
396 if (bRealWildOrRegExp)
409 bOk = (bMatch && (nStart == 0));
412 bOk = !(bMatch && (nStart == 0));
415 bOk = (bMatch && (nEnd == rValue.getLength()));
418 bOk = !(bMatch && (nEnd == rValue.getLength()));
428 if (bFast || !bRealWildOrRegExp)
443 else if (bFast || bMatchWholeCell)
445 if (bFast || pValueSource1)
490 assert(pCellStr !=
nullptr);
491 if (pQuer ==
nullptr)
496 ? (pCellStr->length - pQuer->length)
503 nStrPos = rtl_ustr_indexOfStr_WithLength(pCellStr->buffer +
nIndex,
504 pCellStr->length -
nIndex,
505 pQuer->buffer, pQuer->length);
513 const OUString& rValue
514 = pValueSource1 ? pValueSource1->
getString() : *pValueSource2;
520 rValue, nLang, 0, rValue.getLength(),
nullptr));
523 aQueryStr, nLang, 0, aQueryStr.getLength(),
nullptr));
527 ? (aCell.getLength() - aQuer.getLength())
529 nStrPos = ((
nIndex < 0) ? -1 : aCell.indexOf(aQuer,
nIndex));
535 bOk = (nStrPos != -1);
539 bOk = (nStrPos == -1);
542 bOk = (nStrPos == 0);
545 bOk = (nStrPos != 0);
548 bOk = (nStrPos >= 0);
561 const OUString& rValue = pValueSource1 ? pValueSource1->
getString() : *pValueSource2;
567 bOk = (nCompare < 0);
570 bOk = (nCompare > 0);
573 bOk = (nCompare <= 0);
575 bTestEqual = (nCompare == 0);
578 bOk = (nCompare >= 0);
580 bTestEqual = (nCompare == 0);
589 return std::pair<bool, bool>(bOk, bTestEqual);
599 return std::pair<bool, bool>(bMatch,
false);
609 return std::pair<bool, bool>(bMatch,
false);
619 bool bTestEqual =
false;
623 return std::pair<bool, bool>(
false, bTestEqual);
627 return std::pair<bool, bool>(
false, bTestEqual);
634 return std::pair<bool, bool>(
false, bTestEqual);
636 return std::pair<bool, bool>(rCell.
hasNumeric(), bTestEqual);
639 return std::pair<bool, bool>(!rCell.
hasNumeric(), bTestEqual);
645 std::pair<bool, bool> aRes(
false,
false);
680 if (rItems.size() >= 100)
688 values.reserve(rItems.size());
689 for (
const auto& rItem : rItems)
691 values.push_back(rItem.mfVal);
697 return std::make_pair(
true,
true);
701 for (
const auto& rItem : rItems)
707 return std::make_pair(
true,
true);
714 std::optional<OUString> oCellString;
716 if (rEntry.
eOp ==
SC_EQUAL && rItems.size() >= 10 && bFastCompareByString)
730 if (cellSharedString !=
nullptr)
732 if (rItems.size() >= 100)
741 values.reserve(rItems.size());
742 for (
const auto& rItem : rItems)
748 ? rItem.maString.getData()
749 : rItem.maString.getDataIgnoreCase());
758 auto it = std::lower_bound(
values.begin(),
values.end(),
string);
759 if (it !=
values.end() && *it ==
string)
760 return std::make_pair(
true,
true);
764 for (
const auto& rItem : rItems)
769 ? cellSharedString->
getData() == rItem.maString.getData()
771 == rItem.maString.getDataIgnoreCase()))
773 return std::make_pair(
true,
true);
780 for (
const auto& rItem : rItems)
785 aRes.first |= aThisRes.first;
786 aRes.second |= aThisRes.second;
791 aRes.first |= aThisRes.first;
792 aRes.second |= aThisRes.second;
796 std::pair<bool, bool> aThisRes =
compareByValue(aCell, nCol, nRow, rEntry, rItem);
797 aRes.first |= aThisRes.first;
798 aRes.second |= aThisRes.second;
804 std::pair<bool, bool> aThisRes;
805 if (cellSharedString && bFastCompareByString)
806 aThisRes = compareByString<true>(rEntry, rItem, cellSharedString,
nullptr);
807 else if (cellSharedString)
811 aRes.first |= aThisRes.first;
812 aRes.second |= aThisRes.second;
817 aRes.first |= aThisRes.first;
818 aRes.second |= aThisRes.second;
835 for (it = itBeg; it != itEnd && it->bDoQuery; ++it)
855 if (pCell && it == itBeg)
865 std::pair<bool, bool> aRes =
processEntry(nRow, nCol, aCell, rEntry, it - itBeg);
sal_Int32 compareString(const OUString &s1, const OUString &s2) const
bool IsMatchWholeCell() const
SC_DLLPUBLIC double RoundValueAsShown(double fVal, sal_uInt32 nFormat, const ScInterpreterContext *pContext=nullptr) const
SC_DLLPUBLIC SvNumberFormatter * GetFormatTable() const
SC_DLLPUBLIC const ScDocOptions & GetDocOptions() const
static SC_DLLPUBLIC CollatorWrapper & GetCollator()
case-insensitive collator
static SC_DLLPUBLIC ::utl::TransliterationWrapper & GetTransliteration()
static std::optional< SvtSysLocale > oSysLocale
static OUString GetErrorString(FormulaError nErrNumber)
ScQueryEvaluator(ScDocument &rDoc, const ScTable &rTab, const ScQueryParam &rParam, const ScInterpreterContext *pContext=nullptr, bool *pTestEqualCondition=nullptr)
std::unique_ptr< bool[]> mpTestDynamic
const ScQueryParam & mrParam
OUString getCellString(const ScRefCellValue &rCell, SCROW nRow, SCCOL nCol, const svl::SharedString **sharedString)
bool isMatchWholeCell(ScQueryOp eOp) const
bool isTestWildOrRegExp(const ScQueryEntry &rEntry) const
std::pair< bool, bool > compareByString(const ScQueryEntry &rEntry, const ScQueryEntry::Item &rItem, const svl::SharedString *pValueSource1, const OUString *pValueSource2)
std::unique_ptr< bool[]> mpBoolDynamic
std::vector< std::vector< double > > mCachedSortedItemValues
void setupTransliteratorIfNeeded()
std::pair< bool, bool > compareByTextColor(SCCOL nCol, SCROW nRow, const ScQueryEntry::Item &rItem)
static bool isTextMatchOp(ScQueryOp eOp)
std::unordered_map< FormulaError, svl::SharedString > mCachedSharedErrorStrings
sal_uInt32 getNumFmt(SCCOL nCol, SCROW nRow)
static bool isPartialTextMatchOp(ScQueryOp eOp)
const ScInterpreterContext * mpContext
std::pair< bool, bool > processEntry(SCROW nRow, SCCOL nCol, ScRefCellValue &aCell, const ScQueryEntry &rEntry, size_t nEntryIndex)
const bool mbCaseSensitive
static bool isQueryByValueForCell(const ScRefCellValue &rCell)
svl::SharedStringPool & mrStrPool
const bool mbMatchWholeCell
utl::TransliterationWrapper * mpTransliteration
void setupCollatorIfNeeded()
static bool isQueryByValue(ScQueryOp eOp, ScQueryEntry::QueryType eType, const ScRefCellValue &rCell)
static std::pair< bool, bool > compareByRangeLookup(const ScRefCellValue &rCell, const ScQueryEntry &rEntry, const ScQueryEntry::Item &rItem)
CollatorWrapper * mpCollator
const SCSIZE mnEntryCount
bool ValidQuery(SCROW nRow, const ScRefCellValue *pCell=nullptr, sc::TableColumnBlockPositionSet *pBlockPos=nullptr)
bool isRealWildOrRegExp(const ScQueryEntry &rEntry) const
static bool isQueryByString(ScQueryOp eOp, ScQueryEntry::QueryType eType, const ScRefCellValue &rCell)
static constexpr SCSIZE nFixedBools
std::vector< std::vector< const rtl_uString * > > mCachedSortedItemStrings
bool isFastCompareByString(const ScQueryEntry &rEntry) const
bool * mpTestEqualCondition
static bool isMatchWholeCellHelper(bool docMatchWholeCell, ScQueryOp eOp)
std::pair< bool, bool > compareByValue(const ScRefCellValue &rCell, SCCOL nCol, SCROW nRow, const ScQueryEntry &rEntry, const ScQueryEntry::Item &rItem)
std::pair< bool, bool > compareByBackgroundColor(SCCOL nCol, SCROW nRow, const ScQueryEntry::Item &rItem)
ScRefCellValue GetCellValue(SCCOL nCol, sc::ColumnBlockPosition &rBlockPos, SCROW nRow)
sal_uInt32 GetNumberFormat(const ScInterpreterContext &rContext, const ScAddress &rPos) const
Color GetCellBackgroundColor(ScAddress aPos) const
Color GetCellTextColor(ScAddress aPos) const
Set of column block positions only for one table.
ColumnBlockPosition * getBlockPosition(SCCOL nCol)
SharedString intern(const OUString &rStr)
const OUString & getString() const
rtl_uString * getDataIgnoreCase()
static const SharedString & getEmptyString()
bool SearchForward(const OUString &rStr, sal_Int32 *pStart, sal_Int32 *pEnd, css::util::SearchResult *pRes=nullptr)
bool SearchBackward(const OUString &rStr, sal_Int32 *pStart, sal_Int32 *pEnd, css::util::SearchResult *pRes=nullptr)
OUString transliterate(const OUString &rStr, sal_Int32 nStart, sal_Int32 nLen) const
std::vector< char * > values
ParserContextSharedPtr mpContext
SvNumberFormatter * GetFormatTable() const
svl::SharedString maString
Each instance of this struct represents a single filtering criteria.
bool IsQueryByNonEmpty() const
std::vector< Item > QueryItemsType
bool IsQueryByEmpty() const
utl::TextSearch * GetSearchTextPtr(utl::SearchParam::SearchType eSearchType, bool bCaseSens, bool bWildMatchSel) const
creates pSearchParam and pSearchText if necessary
QueryItemsType & GetQueryItems()
const_iterator begin() const
EntriesType::const_iterator const_iterator
SC_DLLPUBLIC const ScQueryEntry & GetEntry(SCSIZE n) const
utl::SearchParam::SearchType eSearchType
const_iterator end() const
bool mbRangeLookup
for spreadsheet functions like MATCH, LOOKUP, HLOOKUP, VLOOKUP
This is very similar to ScCellValue, except that it references the original value instead of copying ...
ScFormulaCell * getFormula() const
const svl::SharedString * getSharedString() const
#define SV_COUNTRY_LANGUAGE_OFFSET
constexpr sal_uInt32 NUMBERFORMAT_ENTRY_NOT_FOUND