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);
597 bool bHasConditionalColor =
false;
607 bHasConditionalColor =
true;
611 if (!bHasConditionalColor)
618 return std::pair<bool, bool>(bMatch,
false);
628 bool bHasConditionalColor =
false;
637 bHasConditionalColor =
true;
644 for (
size_t i = 0;
i < pCondFormat->
size();
i++)
652 bHasConditionalColor =
true;
657 if (!bHasConditionalColor)
664 return std::pair<bool, bool>(bMatch,
false);
674 bool bTestEqual =
false;
678 return std::pair<bool, bool>(
false, bTestEqual);
682 return std::pair<bool, bool>(
false, bTestEqual);
689 return std::pair<bool, bool>(
false, bTestEqual);
691 return std::pair<bool, bool>(rCell.
hasNumeric(), bTestEqual);
694 return std::pair<bool, bool>(!rCell.
hasNumeric(), bTestEqual);
700 std::pair<bool, bool> aRes(
false,
false);
735 if (rItems.size() >= 100)
743 values.reserve(rItems.size());
744 for (
const auto& rItem : rItems)
746 values.push_back(rItem.mfVal);
752 return std::make_pair(
true,
true);
756 for (
const auto& rItem : rItems)
762 return std::make_pair(
true,
true);
769 std::optional<OUString> oCellString;
771 if (rEntry.
eOp ==
SC_EQUAL && rItems.size() >= 10 && bFastCompareByString)
785 if (cellSharedString !=
nullptr)
787 if (rItems.size() >= 100)
796 values.reserve(rItems.size());
797 for (
const auto& rItem : rItems)
803 ? rItem.maString.getData()
804 : rItem.maString.getDataIgnoreCase());
813 auto it = std::lower_bound(
values.begin(),
values.end(),
string);
814 if (it !=
values.end() && *it ==
string)
815 return std::make_pair(
true,
true);
819 for (
const auto& rItem : rItems)
824 ? cellSharedString->
getData() == rItem.maString.getData()
826 == rItem.maString.getDataIgnoreCase()))
828 return std::make_pair(
true,
true);
835 for (
const auto& rItem : rItems)
840 aRes.first |= aThisRes.first;
841 aRes.second |= aThisRes.second;
846 aRes.first |= aThisRes.first;
847 aRes.second |= aThisRes.second;
851 std::pair<bool, bool> aThisRes =
compareByValue(aCell, nCol, nRow, rEntry, rItem);
852 aRes.first |= aThisRes.first;
853 aRes.second |= aThisRes.second;
859 std::pair<bool, bool> aThisRes;
860 if (cellSharedString && bFastCompareByString)
861 aThisRes = compareByString<true>(rEntry, rItem, cellSharedString,
nullptr);
862 else if (cellSharedString)
866 aRes.first |= aThisRes.first;
867 aRes.second |= aThisRes.second;
872 aRes.first |= aThisRes.first;
873 aRes.second |= aThisRes.second;
890 for (it = itBeg; it != itEnd && it->bDoQuery; ++it)
910 if (pCell && it == itBeg)
920 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 ScConditionalFormat * GetCondFormat(SCCOL nCol, SCROW nRow, SCTAB nTab) const
SC_DLLPUBLIC SvNumberFormatter * GetFormatTable() const
SC_DLLPUBLIC const SfxPoolItem * GetAttr(SCCOL nCol, SCROW nRow, SCTAB nTab, sal_uInt16 nWhich) const
SC_DLLPUBLIC const SfxItemSet * GetCondResult(SCCOL nCol, SCROW nRow, SCTAB nTab, ScRefCellValue *pCell=nullptr) const
SC_DLLPUBLIC const ScPatternAttr * GetPattern(SCCOL nCol, SCROW nRow, SCTAB nTab) 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)
const SfxPoolItem & GetItem(sal_uInt16 nWhichP) const
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
const Color & GetColor() const
const Color & GetValue() 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
constexpr TypedWhichId< SvxColorItem > ATTR_FONT_COLOR(109)
constexpr TypedWhichId< SvxBrushItem > ATTR_BACKGROUND(148)
constexpr TypedWhichId< ScCondFormatItem > ATTR_CONDITIONAL(154)
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