20#include <config_features.h>
22#include <compiler.hxx>
37#include <osl/diagnose.h>
38#include <rtl/character.hxx>
41#include <com/sun/star/lang/Locale.hpp>
42#include <com/sun/star/sheet/FormulaOpCodeMapEntry.hpp>
43#include <com/sun/star/sheet/FormulaLanguage.hpp>
44#include <com/sun/star/i18n/KParseTokens.hpp>
45#include <com/sun/star/i18n/KParseType.hpp>
50#include <rtl/math.hxx>
51#include <rtl/ustring.hxx>
55#include <document.hxx>
72#include <tokenarray.hxx>
75#include <officecfg/Office/Common.hxx>
105static const char*
pInternal[2] = {
"TTT",
"__DEBUG_VAR" };
111 size_t nSymbolOffset;
116 case FormulaGrammar::GRAM_API:
117 case FormulaGrammar::GRAM_PODF:
118 nSymbolOffset = offsetof(
AddInMap, pUpper);
121 case FormulaGrammar::GRAM_ODFF:
122 nSymbolOffset = offsetof(
AddInMap, pODFF);
124 case FormulaGrammar::GRAM_ENGLISH:
125 nSymbolOffset = offsetof(
AddInMap, pEnglish);
131 char const *
const * ppSymbol =
132 reinterpret_cast< char const *
const *
>(
133 reinterpret_cast< char const *
>(pMap) + nSymbolOffset);
134 xMap->putExternal( OUString::createFromAscii( *ppSymbol),
135 OUString::createFromAscii( pMap->pOriginal));
137 if (_eGrammar == FormulaGrammar::GRAM_API)
143 nSymbolOffset = offsetof(
AddInMap, pEnglish);
146 char const *
const * ppSymbol =
147 reinterpret_cast< char const *
const *
>(
148 reinterpret_cast< char const *
>(pMap) + nSymbolOffset);
149 xMap->putExternal( OUString::createFromAscii( *ppSymbol),
150 OUString::createFromAscii( pMap->pOriginal));
178 if (!
aName.isEmpty())
221 return !aIntName.isEmpty();
262 assert( eGrammar != FormulaGrammar::GRAM_UNSPECIFIED &&
"ScCompiler::SetGrammar: don't pass FormulaGrammar::GRAM_UNSPECIFIED");
266 if( eGrammar == FormulaGrammar::GRAM_EXTERNAL )
274 const sal_Int32 nFormulaLanguage = FormulaGrammar::extractFormulaLanguage( eMyGrammar);
276 OSL_ENSURE( xMap,
"ScCompiler::SetGrammar: unknown formula language");
280 eMyGrammar = xMap->getGrammar();
301 if (rTabNames.empty())
304 for (
auto& rTabName : rTabNames)
344 if (eConv == FormulaGrammar::CONV_UNSPECIFIED && eOldGrammar == FormulaGrammar::GRAM_UNSPECIFIED)
369 for (
i = 0;
i < 128;
i++)
380 if (FormulaGrammar::CONV_ODF ==
meConv)
385 if (FormulaGrammar::CONV_ODF ==
meConv)
399 for (
i = 48;
i < 58;
i++)
410 for (
i = 65;
i < 91;
i++)
413 if (FormulaGrammar::CONV_ODF ==
meConv)
419 else if (FormulaGrammar::CONV_OOO ==
meConv)
425 else if (FormulaGrammar::CONV_XL_OOX ==
meConv)
431 else if (FormulaGrammar::CONV_XL_A1 ==
meConv)
437 else if( FormulaGrammar::CONV_XL_R1C1 ==
meConv )
454 for (
i = 97;
i < 123;
i++)
463 if( !(FormulaGrammar::CONV_XL_A1 ==
meConv || FormulaGrammar::CONV_XL_R1C1 ==
meConv || FormulaGrammar::CONV_XL_OOX ==
meConv) )
508 while (
nPos < rFormula.size())
510 if (rFormula[
nPos] ==
'\'')
512 if ( (
nPos+1 == rFormula.size()) || (rFormula[
nPos+1] !=
'\'') )
514 rRes.TokenType = KParseType::SINGLE_QUOTE_NAME;
515 rRes.EndPos =
nPos+1;
528 const OUString& rSymbol,
533 const uno::Sequence<sheet::ExternalLinkInfo>* pExternalLinks )
537 const sal_Unicode*
const pStart = rSymbol.getStr();
539 sal_Int32 nLen = rSymbol.getLength();
541 OUStringBuffer aTmpName;
543 bool bInName =
false;
549 OUString aStartTabName, aEndTabName;
552 aEndTabName, nFlags,
true, pExternalLinks );
553 if (!
p ||
p == pStart)
555 i = sal_Int32(
p - pStart);
557 for ( ;
i < nLen; ++
i, ++
p)
562 if (c ==
'.' || c == cSep)
571 for (sal_Int32 j =
i; j < nLen; ++j, ++
p)
586 aTmpFile += OUStringChar(c);
595 if (cPrev ==
'\'' && j !=
i)
607 aTmpFile += OUStringChar(c);
647 if (rtl::isAsciiAlphanumeric(c))
671 aTmpFile += OUStringChar(c);
682 sal_Int32 nNameLen = aTmpName.getLength();
689 if (aTmpName[0] != cSep)
695 if (aTmpName[nNameLen-1] ==
'!')
703 rName = aTmpName.makeStringAndClear().copy(1);
710 OUString aEscQuote(
"''");
711 OUString aFile(rFile.replaceAll(
"'", aEscQuote));
712 OUString
aName(rName);
715 OUStringBuffer
aBuf(aFile.getLength() +
aName.getLength() + 9);
718 aBuf.append(
"'" + aFile +
"'" + OUStringChar(cSep) );
720 aBuf.append(
"$$'" );
724 return aBuf.makeStringAndClear();
728 const vector<OUString>& rTabNames,
const ScRange& rRef )
733 size_t nCount = rTabNames.size();
734 vector<OUString>::const_iterator itrBeg = rTabNames.begin(), itrEnd = rTabNames.end();
735 vector<OUString>::const_iterator itr = ::std::find(itrBeg, itrEnd, rTabName1);
736 if (itr == rTabNames.end())
738 rTabName2 =
ScResId(STR_NO_REF_TABLE);
742 size_t nDist = ::std::distance(itrBeg, itr);
743 if (nDist +
static_cast<size_t>(nTabSpan) >=
nCount)
745 rTabName2 =
ScResId(STR_NO_REF_TABLE);
749 rTabName2 = rTabNames[nDist+nTabSpan];
752 rTabName2 = rTabName1;
762 static void MakeColStr(
const ScSheetLimits& rLimits, OUStringBuffer& rBuffer,
SCCOL nCol );
763 static void MakeRowStr(
const ScSheetLimits& rLimits, OUStringBuffer& rBuffer,
SCROW nRow );
765 ParseResult parseAnyToken(
const OUString& rFormula,
768 bool bGroupSeparator)
const override
774 constexpr sal_Int32 nStartFlags = KParseTokens::ANY_LETTER_OR_NUMBER |
775 KParseTokens::ASC_UNDERSCORE | KParseTokens::ASC_DOLLAR;
776 constexpr sal_Int32 nContFlags = nStartFlags | KParseTokens::ASC_DOT;
778 static constexpr OUStringLiteral aAddAllowed(u
"?#");
780 nSrcPos, nStartFlags, aAddAllowed,
781 (bGroupSeparator ? nContFlags | KParseTokens::GROUP_SEPARATOR_IN_NUMBER : nContFlags),
787 return mpCharTable[
static_cast<sal_uInt8>(c)];
793void Convention_A1::MakeColStr(
const ScSheetLimits& rLimits, OUStringBuffer& rBuffer,
SCCOL nCol )
796 rBuffer.append(
ScResId(STR_NO_REF_TABLE));
801void Convention_A1::MakeRowStr(
const ScSheetLimits& rLimits, OUStringBuffer& rBuffer,
SCROW nRow )
804 rBuffer.append(
ScResId(STR_NO_REF_TABLE));
806 rBuffer.append(sal_Int32(nRow + 1));
811struct ConventionOOO_A1 :
public Convention_A1
816 static void MakeTabStr( OUStringBuffer &rBuf,
const std::vector<OUString>& rTabNames,
SCTAB nTab )
819 rBuf.append(
ScResId(STR_NO_REF_TABLE));
821 rBuf.append(rTabNames[nTab]);
825 enum SingletonDisplay
832 static void MakeOneRefStrImpl(
834 std::u16string_view rErrRef,
const std::vector<OUString>& rTabNames,
836 bool bForceTab,
bool bODF, SingletonDisplay eSingletonDisplay )
844 rBuffer.append(rErrRef);
851 MakeTabStr(rBuffer, rTabNames, rAbsRef.
Tab());
857 if (eSingletonDisplay != SINGLETON_ROW)
862 rBuffer.append(rErrRef);
864 MakeColStr(rLimits, rBuffer, rAbsRef.
Col());
867 if (eSingletonDisplay != SINGLETON_COL)
872 rBuffer.append(rErrRef);
874 MakeRowStr(rLimits, rBuffer, rAbsRef.
Row());
884 return SINGLETON_NONE;
888 return SINGLETON_COL;
892 if (!bFromRangeName && rAbs1.
Row() == 0 && rAbs2.
Row() == rLimits.
mnMaxRow &&
894 return SINGLETON_COL;
898 return SINGLETON_ROW;
902 if (!bFromRangeName && rAbs1.
Col() == 0 && rAbs2.
Col() == rLimits.
mnMaxCol &&
904 return SINGLETON_ROW;
906 return SINGLETON_NONE;
909 virtual void makeRefStr(
911 OUStringBuffer& rBuffer,
914 const OUString& rErrRef,
const std::vector<OUString>& rTabNames,
917 bool bFromRangeName )
const override
925 SingletonDisplay eSingleton = bSingleRef ? SINGLETON_NONE :
926 getSingletonDisplay( rLimits, aAbs1, aAbs2, rRef, bFromRangeName);
927 MakeOneRefStrImpl(rLimits, rBuffer, rErrRef, rTabNames, rRef.
Ref1, aAbs1,
false,
false, eSingleton);
931 MakeOneRefStrImpl(rLimits, rBuffer, rErrRef, rTabNames, rRef.
Ref2, aAbs2, aAbs1.
Tab() != aAbs2.Tab(),
false,
936 virtual sal_Unicode getSpecialSymbol( SpecialSymbolType eSymType )
const override
949 virtual bool parseExternalName(
const OUString& rSymbol, OUString& rFile, OUString& rName,
951 const uno::Sequence<sheet::ExternalLinkInfo>* pExternalLinks )
const override
956 virtual OUString makeExternalNameStr( sal_uInt16 ,
const OUString& rFile,
957 const OUString& rName )
const override
962 static bool makeExternalSingleRefStr(
964 OUStringBuffer& rBuffer,
const OUString& rFileName,
const OUString& rTabName,
976 rBuffer.append(
"'" + aFile.replaceAll(
"'",
"''") +
"'#");
987 MakeColStr( rLimits, rBuffer, aAbsRef.
Col());
990 MakeRowStr( rLimits, rBuffer, aAbsRef.
Row());
995 static void makeExternalRefStrImpl(
997 OUStringBuffer& rBuffer,
const ScAddress& rPos,
const OUString& rFileName,
1001 rBuffer.append(
'[');
1003 bool bEncodeUrl = bODF;
1004 makeExternalSingleRefStr(rLimits, rBuffer, rFileName, rTabName, rRef, rPos,
true, bEncodeUrl);
1006 rBuffer.append(
']');
1009 virtual void makeExternalRefStr(
1011 OUStringBuffer& rBuffer,
const ScAddress& rPos, sal_uInt16 ,
const OUString& rFileName,
1012 const OUString& rTabName,
const ScSingleRefData& rRef )
const override
1014 makeExternalRefStrImpl(rLimits, rBuffer, rPos, rFileName, rTabName, rRef,
false);
1017 static void makeExternalRefStrImpl(
1019 OUStringBuffer& rBuffer,
const ScAddress& rPos,
const OUString& rFileName,
1020 const std::vector<OUString>& rTabNames,
const OUString& rTabName,
1026 rBuffer.append(
'[');
1028 bool bEncodeUrl = bODF;
1032 if (!makeExternalSingleRefStr(rLimits, rBuffer, rFileName, rTabName, rRef.
Ref1, rPos,
true, bEncodeUrl))
1035 rBuffer.append(
':');
1037 OUString aLastTabName;
1039 if (bDisplayTabName)
1044 OSL_FAIL(
"ConventionOOO_A1::makeExternalRefStrImpl: sheet name not found");
1049 rBuffer.append(
'.');
1050 makeExternalSingleRefStr(rLimits,
1051 rBuffer, rFileName, aLastTabName, rRef.
Ref2, rPos, bDisplayTabName, bEncodeUrl);
1055 rBuffer.append(
']');
1058 virtual void makeExternalRefStr(
1060 OUStringBuffer& rBuffer,
const ScAddress& rPos, sal_uInt16 ,
const OUString& rFileName,
1061 const std::vector<OUString>& rTabNames,
const OUString& rTabName,
1064 makeExternalRefStrImpl(rLimits, rBuffer, rPos, rFileName, rTabNames, rTabName, rRef,
false);
1068struct ConventionOOO_A1_ODF :
public ConventionOOO_A1
1070 ConventionOOO_A1_ODF() : ConventionOOO_A1 (
FormulaGrammar::CONV_ODF) { }
1072 virtual void makeRefStr(
1074 OUStringBuffer& rBuffer,
1077 const OUString& rErrRef,
const std::vector<OUString>& rTabNames,
1080 bool bFromRangeName )
const override
1082 rBuffer.append(
'[');
1092 rBuffer.append(rErrRef);
1099 SingletonDisplay eSingleton = bSingleRef ? SINGLETON_NONE :
1100 getSingletonDisplay( rLimits, aAbs1, aAbs2, rRef, bFromRangeName);
1101 MakeOneRefStrImpl(rLimits, rBuffer, rErrRef, rTabNames, rRef.
Ref1, aAbs1,
false,
true, eSingleton);
1104 rBuffer.append(
':');
1105 MakeOneRefStrImpl(rLimits, rBuffer, rErrRef, rTabNames, rRef.
Ref2, aAbs2, aAbs1.
Tab() != aAbs2.Tab(),
true,
1109 rBuffer.append(
']');
1112 virtual OUString makeExternalNameStr( sal_uInt16 ,
const OUString& rFile,
1113 const OUString& rName )
const override
1118 virtual void makeExternalRefStr(
1120 OUStringBuffer& rBuffer,
const ScAddress& rPos, sal_uInt16 ,
const OUString& rFileName,
1121 const OUString& rTabName,
const ScSingleRefData& rRef )
const override
1123 makeExternalRefStrImpl(rLimits, rBuffer, rPos, rFileName, rTabName, rRef,
true);
1126 virtual void makeExternalRefStr(
1128 OUStringBuffer& rBuffer,
const ScAddress& rPos, sal_uInt16 ,
const OUString& rFileName,
1129 const std::vector<OUString>& rTabNames,
1132 makeExternalRefStrImpl(rLimits, rBuffer, rPos, rFileName, rTabNames, rTabName, rRef,
true);
1138 virtual ~ConventionXL()
1144 const ScAddress& rPos,
const std::vector<OUString>& rTabNames,
1150 rTabName =
ScResId( STR_NO_REF_TABLE );
1153 rTabName = rTabNames[aAbs.
Tab()];
1156 static void MakeTabStr(
const ScSheetLimits& rLimits, OUStringBuffer& rBuf,
1158 const std::vector<OUString>& rTabNames,
1165 OUString aStartTabName, aEndTabName;
1167 GetTab(rLimits, rPos, rTabNames, rRef.
Ref1, aStartTabName);
1171 GetTab(rLimits, rPos, rTabNames, rRef.
Ref2, aEndTabName);
1174 rBuf.append( aStartTabName );
1175 if( !bSingleRef && rRef.
Ref2.
IsFlag3D() && aStartTabName != aEndTabName )
1178 rBuf.append( aEndTabName );
1196 static bool parseExternalName(
const OUString& rSymbol, OUString& rFile, OUString& rName,
1198 const uno::Sequence<sheet::ExternalLinkInfo>* pExternalLinks )
1203 static OUString makeExternalNameStr(
const OUString& rFile,
const OUString& rName )
1208 static void makeExternalDocStr( OUStringBuffer& rBuffer, std::u16string_view rFullName )
1217 rBuffer.append(
'[');
1218 rBuffer.append(
'\'');
1222 sal_Int32 nLen = aFullName.getLength();
1223 for (sal_Int32 i = 0;
i < nLen; ++
i)
1230 rBuffer.append(
'\'');
1231 rBuffer.append(
']');
1234 static void makeExternalTabNameRange( OUStringBuffer& rBuf,
const OUString& rTabName,
1235 const vector<OUString>& rTabNames,
1238 OUString aLastTabName;
1246 if (rTabName != aLastTabName)
1253 virtual void parseExternalDocName(
const OUString& rFormula, sal_Int32& rSrcPos )
const
1255 sal_Int32 nLen = rFormula.getLength();
1258 for (sal_Int32 i = rSrcPos;
i < nLen; ++
i)
1267 else if (i == rSrcPos + 1)
1287 if (rSrcPos >= nLen)
1297 if (i > rSrcPos + 2 && cPrev ==
'\'')
1307struct ConventionXL_A1 :
public Convention_A1,
public ConventionXL
1309 ConventionXL_A1() : Convention_A1(
FormulaGrammar::CONV_XL_A1 ) { }
1316 MakeColStr(rLimits, rBuf, rAbs.
Col());
1319 MakeRowStr(rLimits, rBuf, rAbs.
Row());
1322 virtual void makeRefStr(
1324 OUStringBuffer& rBuf,
1327 const OUString& rErrRef,
const std::vector<OUString>& rTabNames,
1330 bool )
const override
1336 ScAddress aAbs1 = aRef.Ref1.toAbs(rLimits, rPos), aAbs2;
1338 MakeTabStr(rLimits, rBuf, rPos, rTabNames, aRef, bSingleRef);
1342 rBuf.append(rErrRef);
1348 aAbs2 = aRef.Ref2.toAbs(rLimits, rPos);
1351 rBuf.append(rErrRef);
1355 if (aAbs1.
Col() == 0 && aAbs2.Col() >= rLimits.
mnMaxCol)
1357 if (!aRef.Ref1.IsRowRel())
1359 MakeRowStr(rLimits, rBuf, aAbs1.
Row());
1361 if (!aRef.Ref2.IsRowRel())
1363 MakeRowStr(rLimits, rBuf, aAbs2.Row());
1367 if (aAbs1.
Row() == 0 && aAbs2.Row() >= rLimits.
mnMaxRow)
1369 if (!aRef.Ref1.IsColRel())
1371 MakeColStr(rLimits, rBuf, aAbs1.
Col());
1373 if (!aRef.Ref2.IsColRel())
1375 MakeColStr(rLimits, rBuf, aAbs2.Col());
1380 makeSingleCellStr(rLimits, rBuf, aRef.Ref1, aAbs1);
1384 makeSingleCellStr(rLimits, rBuf, aRef.Ref2, aAbs2);
1388 virtual ParseResult parseAnyToken(
const OUString& rFormula,
1391 bool bGroupSeparator)
const override
1393 parseExternalDocName(rFormula,
nSrcPos);
1399 constexpr sal_Int32 nStartFlags = KParseTokens::ANY_LETTER_OR_NUMBER |
1400 KParseTokens::ASC_UNDERSCORE | KParseTokens::ASC_DOLLAR;
1401 constexpr sal_Int32 nContFlags = nStartFlags | KParseTokens::ASC_DOT;
1403 static constexpr OUStringLiteral aAddAllowed(u
"?!");
1405 nSrcPos, nStartFlags, aAddAllowed,
1406 (bGroupSeparator ? nContFlags | KParseTokens::GROUP_SEPARATOR_IN_NUMBER : nContFlags),
1410 virtual sal_Unicode getSpecialSymbol( SpecialSymbolType eSymType )
const override
1412 return ConventionXL::getSpecialSymbol(eSymType);
1415 virtual bool parseExternalName(
const OUString& rSymbol, OUString& rFile, OUString& rName,
1417 const uno::Sequence<sheet::ExternalLinkInfo>* pExternalLinks )
const override
1419 return ConventionXL::parseExternalName( rSymbol, rFile, rName,
rDoc, pExternalLinks);
1422 virtual OUString makeExternalNameStr( sal_uInt16 ,
const OUString& rFile,
1423 const OUString& rName )
const override
1425 return ConventionXL::makeExternalNameStr(rFile, rName);
1428 virtual void makeExternalRefStr(
1430 OUStringBuffer& rBuffer,
const ScAddress& rPos, sal_uInt16 ,
const OUString& rFileName,
1431 const OUString& rTabName,
const ScSingleRefData& rRef )
const override
1439 ConventionXL::makeExternalDocStr(rBuffer, rFileName);
1441 rBuffer.append(
'!');
1443 makeSingleCellStr(rLimits, rBuffer, rRef, rRef.
toAbs(rLimits, rPos));
1446 virtual void makeExternalRefStr(
1448 OUStringBuffer& rBuffer,
const ScAddress& rPos, sal_uInt16 ,
const OUString& rFileName,
1449 const std::vector<OUString>& rTabNames,
const OUString& rTabName,
1454 ConventionXL::makeExternalDocStr(rBuffer, rFileName);
1455 ConventionXL::makeExternalTabNameRange(rBuffer, rTabName, rTabNames, aAbsRef);
1456 rBuffer.append(
'!');
1458 makeSingleCellStr(rLimits, rBuffer, rRef.
Ref1, aAbsRef.
aStart);
1461 rBuffer.append(
':');
1462 makeSingleCellStr(rLimits, rBuffer, rRef.
Ref2, aAbsRef.
aEnd);
1467struct ConventionXL_OOX :
public ConventionXL_A1
1469 ConventionXL_OOX() : ConventionXL_A1(
FormulaGrammar::CONV_XL_OOX ) { }
1472 OUStringBuffer& rBuf,
1475 const OUString& rErrRef,
const std::vector<OUString>& rTabNames,
1478 bool bFromRangeName )
const override
1499 rBuf.append(rErrRef);
1508 rBuf.append(rErrRef);
1519 rBuf.append(rErrRef);
1524 ConventionXL_A1::makeRefStr( rLimits, rBuf, eGram,
aPos, rErrRef, rTabNames, rRef, bSingleRef, bFromRangeName);
1527 virtual OUString makeExternalNameStr( sal_uInt16 nFileId,
const OUString& ,
1528 const OUString& rName )
const override
1531 return OUString(
"[" + OUString::number(nFileId+1) +
"]!" + rName );
1539 virtual void parseExternalDocName(
const OUString& rFormula, sal_Int32& rSrcPos)
const override
1541 sal_Int32 nLen = rFormula.getLength();
1543 for (sal_Int32 i = rSrcPos;
i < nLen; ++
i)
1560 virtual void makeExternalRefStr(
1562 OUStringBuffer& rBuffer,
const ScAddress& rPos, sal_uInt16 nFileId,
const OUString& ,
1563 const OUString& rTabName,
const ScSingleRefData& rRef )
const override
1569 OUString aQuotedTab( rTabName);
1571 if (!aQuotedTab.isEmpty() && aQuotedTab[0] ==
'\'')
1573 rBuffer.append(
'\'');
1574 ConventionXL_OOX::makeExternalDocStr( rBuffer, nFileId);
1575 rBuffer.append( aQuotedTab.subView(1));
1579 ConventionXL_OOX::makeExternalDocStr( rBuffer, nFileId);
1580 rBuffer.append( aQuotedTab);
1582 rBuffer.append(
'!');
1584 makeSingleCellStr(rLimits, rBuffer, rRef, rRef.
toAbs(rLimits, rPos));
1587 virtual void makeExternalRefStr(
1589 OUStringBuffer& rBuffer,
const ScAddress& rPos, sal_uInt16 nFileId,
const OUString& ,
1590 const std::vector<OUString>& rTabNames,
const OUString& rTabName,
1601 OUStringBuffer
aBuf;
1602 ConventionXL::makeExternalTabNameRange( aBuf, rTabName, rTabNames, aAbsRef);
1603 if (!
aBuf.isEmpty() && aBuf[0] ==
'\'')
1605 rBuffer.append(
'\'');
1606 ConventionXL_OOX::makeExternalDocStr( rBuffer, nFileId);
1607 rBuffer.append(
aBuf.subView(1));
1611 ConventionXL_OOX::makeExternalDocStr( rBuffer, nFileId);
1612 rBuffer.append( aBuf);
1614 rBuffer.append(
'!');
1616 makeSingleCellStr(rLimits, rBuffer, rRef.
Ref1, aAbsRef.
aStart);
1619 rBuffer.append(
':');
1620 makeSingleCellStr(rLimits, rBuffer, rRef.
Ref2, aAbsRef.
aEnd);
1624 static void makeExternalDocStr( OUStringBuffer& rBuffer, sal_uInt16 nFileId )
1626 rBuffer.append(
"[" + OUString::number(
static_cast<sal_Int32
>(nFileId+1) ) +
"]");
1640 rBuf.append(
"[" + OUString::number(nCol) +
"]");
1643 rBuf.append(
static_cast<sal_Int32
>(rAbsRef.
Col() + 1) );
1651 if (rRef.
Row() != 0)
1653 rBuf.append(
"[" + OUString::number(rRef.
Row()) +
"]");
1657 rBuf.append( rAbsRef.
Row() + 1 );
1667 OUStringBuffer& rBuf,
1670 const OUString& rErrRef,
const std::vector<OUString>& rTabNames,
1673 bool )
const override
1678 MakeTabStr(rLimits, rBuf, rPos, rTabNames, aRef, bSingleRef);
1684 rBuf.append(rErrRef);
1692 rBuf.append(rErrRef);
1732 ParseResult parseAnyToken(
const OUString& rFormula,
1735 bool bGroupSeparator)
const override
1737 parseExternalDocName(rFormula,
nSrcPos);
1743 constexpr sal_Int32 nStartFlags = KParseTokens::ANY_LETTER_OR_NUMBER |
1744 KParseTokens::ASC_UNDERSCORE ;
1745 constexpr sal_Int32 nContFlags = nStartFlags | KParseTokens::ASC_DOT;
1747 static constexpr OUStringLiteral aAddAllowed(u
"?-[]!");
1750 nSrcPos, nStartFlags, aAddAllowed,
1751 (bGroupSeparator ? nContFlags | KParseTokens::GROUP_SEPARATOR_IN_NUMBER : nContFlags),
1755 virtual sal_Unicode getSpecialSymbol( SpecialSymbolType eSymType )
const override
1757 return ConventionXL::getSpecialSymbol(eSymType);
1760 virtual bool parseExternalName(
const OUString& rSymbol, OUString& rFile, OUString& rName,
1762 const uno::Sequence<sheet::ExternalLinkInfo>* pExternalLinks )
const override
1764 return ConventionXL::parseExternalName( rSymbol, rFile, rName,
rDoc, pExternalLinks);
1767 virtual OUString makeExternalNameStr( sal_uInt16 ,
const OUString& rFile,
1768 const OUString& rName )
const override
1770 return ConventionXL::makeExternalNameStr(rFile, rName);
1773 virtual void makeExternalRefStr(
1775 OUStringBuffer& rBuffer,
const ScAddress& rPos, sal_uInt16 ,
const OUString& rFileName,
1776 const OUString& rTabName,
const ScSingleRefData& rRef )
const override
1785 ConventionXL::makeExternalDocStr(rBuffer, rFileName);
1787 rBuffer.append(
'!');
1793 virtual void makeExternalRefStr(
1795 OUStringBuffer& rBuffer,
const ScAddress& rPos, sal_uInt16 ,
const OUString& rFileName,
1796 const std::vector<OUString>& rTabNames,
const OUString& rTabName,
1801 ConventionXL::makeExternalDocStr(rBuffer, rFileName);
1802 ConventionXL::makeExternalTabNameRange(rBuffer, rTabName, rTabNames, aAbsRef);
1803 rBuffer.append(
'!');
1807 rBuffer.append(
ScResId(STR_NO_REF_TABLE));
1816 rBuffer.append(
':');
1827 rBuffer.append(
':');
1835 rBuffer.append(
':');
1843 if (c ==
'-' && cLast ==
'[')
1855 rDoc(rCxt.getDoc()),
1857 mpFormatter(pContext ? pContext->GetFormatTable() :
rDoc.GetFormatTable()),
1881 mpFormatter(pContext ? pContext->GetFormatTable() : rDoc.GetFormatTable()),
1882 mpInterpreterContext(pContext),
1883 mnCurrentSheetTab(-1),
1884 mnCurrentSheetEndPos(0),
1887 mbCharClassesDiffer(false),
1888 mnPredetectedReference(0),
1889 mnRangeOpPosInSymbol(-1),
1891 meExtendedErrorDetection( EXTENDED_ERROR_DETECTION_NONE ),
1892 mbCloseBrackets( true ),
1894 mbRefConventionChartOOXML( false )
1904 rDoc(rCxt.getDoc()),
1906 mpFormatter(pContext ? pContext->GetFormatTable() : rDoc.GetFormatTable()),
1907 mpInterpreterContext(pContext),
1908 mnCurrentSheetTab(-1),
1909 mnCurrentSheetEndPos(0),
1911 mbCharClassesDiffer(false),
1912 mnPredetectedReference(0),
1913 mnRangeOpPosInSymbol(-1),
1915 meExtendedErrorDetection(EXTENDED_ERROR_DETECTION_NONE),
1916 mbCloseBrackets(true),
1918 mbRefConventionChartOOXML(false),
1919 maTabNames(rCxt.getTabNames())
1930 mpFormatter(pContext ? pContext->GetFormatTable() : rDoc.GetFormatTable()),
1931 mpInterpreterContext(pContext),
1932 mnCurrentSheetTab(-1),
1933 mnCurrentSheetEndPos(0),
1936 mbCharClassesDiffer(false),
1937 mnPredetectedReference(0),
1938 mnRangeOpPosInSymbol(-1),
1940 meExtendedErrorDetection( EXTENDED_ERROR_DETECTION_NONE ),
1941 mbCloseBrackets( true ),
1943 mbRefConventionChartOOXML( false )
1957 sal_Int32 nStartFlags = KParseTokens::ANY_LETTER_OR_NUMBER | KParseTokens::ASC_UNDERSCORE;
1958 sal_Int32 nContFlags = nStartFlags;
1960 KParseType::IDENTNAME, rString, 0, nStartFlags, OUString(), nContFlags, OUString());
1961 bool bNeedsQuote = !((aRes.TokenType & KParseType::IDENTNAME) && aRes.EndPos == rString.getLength());
1966 case FormulaGrammar::CONV_UNSPECIFIED :
1968 case FormulaGrammar::CONV_OOO :
1969 case FormulaGrammar::CONV_XL_A1 :
1970 case FormulaGrammar::CONV_XL_R1C1 :
1971 case FormulaGrammar::CONV_XL_OOX :
1972 case FormulaGrammar::CONV_ODF :
1976 rString = rString.replaceAll(
"'",
"''" );
1989 rString =
"'" + rString +
"'";
1995 if (rString[0] !=
'\'')
1999 if (
nPos != -1 && rString[
nPos-1] !=
'\'')
2016 case FormulaGrammar::CONV_OOO:
2018 static const ConventionOOO_A1 ConvOOO_A1;
2021 case FormulaGrammar::CONV_ODF:
2023 static const ConventionOOO_A1_ODF ConvOOO_A1_ODF;
2024 return &ConvOOO_A1_ODF;
2026 case FormulaGrammar::CONV_XL_A1:
2028 static const ConventionXL_A1 ConvXL_A1;
2031 case FormulaGrammar::CONV_XL_R1C1:
2033 static const ConventionXL_R1C1 ConvXL_R1C1;
2034 return &ConvXL_R1C1;
2036 case FormulaGrammar::CONV_XL_OOX:
2038 static const ConventionXL_OOX ConvXL_OOX;
2041 case FormulaGrammar::CONV_UNSPECIFIED:
2053 assert( FormulaGrammar::isSupported(
meGrammar));
2065 while ( pDst < pStop )
2078 for (
size_t i=0;
i<
n; ++
i)
2084 if (p1[
i] <
'a' ||
'z' < p1[
i])
2086 if (p2[
i] <
'A' ||
'Z' < p2[
i])
2088 if (p1[
i] != p2[
i] + 0x20)
2099 if (rSpace.
cChar != c)
2102 rvSpaces.emplace_back(rSpace);
2147 std::vector<Whitespace> vSpaces;
2155 bool bQuote =
false;
2157 ScanState eState = ssGetChar;
2170 bool bAutoIntersection =
false;
2171 size_t nAutoIntersectionSpacesPos = 0;
2173 bool bErrorConstantHadSlash =
false;
2176 while ((c != 0) && (eState != ssStop) )
2183 if (c == cSep || (bInArray && (c == cArrayColSep || c == cArrayRowSep)))
2190 case ssGetReference:
2191 case ssSkipReference:
2192 case ssGetTableRefItem:
2193 case ssGetTableRefColumn:
2196 if (eState == ssGetChar)
2203Label_MaskStateMachine:
2212 eState = ssGetTableRefColumn;
2227 if (!bAutoIntersection)
2235 nAutoIntersectionSpacesPos = vSpaces.size();
2236 bAutoIntersection =
true;
2247 goto Label_MaskStateMachine;
2261 goto Label_MaskStateMachine;
2272 if (c ==
'[' && FormulaGrammar::isExcelSyntax(
meGrammar)
2279 if (FormulaGrammar::isRefConventionOOXML(
meGrammar) &&
2280 pSrc[0] ==
'0' && pSrc[1] ==
']' && pSrc[2] ==
'!')
2288 goto Label_MaskStateMachine;
2299 eState = ssGetReference;
2310 eState = ssGetValue;
2315 eState = ssGetString;
2321 eState = ssGetTableRefItem;
2323 eState = ssGetErrorConstant;
2333 eState = ssGetIdent;
2348 SetError(FormulaError::StringOverflow);
2368 SetError(FormulaError::StringOverflow);
2387 SetError(FormulaError::StringOverflow);
2396 else if ( 128 <= c ||
'\'' == c )
2428 SetError(FormulaError::StringOverflow);
2431 else if (c == cDecSep || (cDecSepAlt && c == cDecSepAlt))
2449 else if (c ==
'E' || c ==
'e')
2462 if (((cLast ==
'E') || (cLast ==
'e')) &&
2499 SetError(FormulaError::StringOverflow);
2500 eState = ssSkipString;
2511 case ssGetErrorConstant:
2531 eState = ssGetIdent;
2537 if (!bErrorConstantHadSlash)
2538 bErrorConstantHadSlash =
true;
2546 (c < 128 && !rtl::isAsciiAlphanumeric( c)))
2557 SetError( FormulaError::StringOverflow);
2565 case ssGetTableRefItem:
2572 SetError( FormulaError::StringOverflow);
2585 case ssGetTableRefColumn:
2588 if (c !=
']' || cLast ==
'\'')
2592 SetError( FormulaError::StringOverflow);
2605 case ssGetReference:
2608 SetError( FormulaError::StringOverflow);
2609 eState = ssSkipReference;
2612 case ssSkipReference:
2631 constexpr int kDollar = (1 << 1);
2634 constexpr int kOpen = (1 << 2);
2636 constexpr int kName = (1 << 3);
2640 constexpr int kQuote = (1 << 4);
2642 constexpr int kClose = (1 << 5);
2644 constexpr int kFileSep = (1 << 6);
2646 constexpr int kPast = (1 << 7);
2650 constexpr int kMarkAhead = (1 << 8);
2652 constexpr int kDefName = (1 << 9);
2654 constexpr int kRefErr = (1 << 10);
2656 bool bAddToSymbol =
true;
2659 OSL_ENSURE( nRefInName & (kPast | kDefName | kRefErr),
2660 "ScCompiler::NextSymbol: reference: "
2661 "closing bracket ']' without prior sheet name separator '.' violates ODF spec");
2663 bAddToSymbol =
false;
2666 else if (cSheetSep == c && nRefInName == 0)
2669 bAddToSymbol =
false;
2670 nRefInName |= kPast;
2671 if (
'$' == pSrc[0] &&
'$' == pSrc[1])
2672 nRefInName |= kMarkAhead;
2674 else if (!(nRefInName & kPast) || (nRefInName & (kMarkAhead | kDefName)))
2680 else if (
'$' == c &&
'$' == pSrc[0] && !(nRefInName & kOpen))
2682 nRefInName &= ~kMarkAhead;
2683 if (!(nRefInName & kDefName))
2686 bAddToSymbol =
false;
2688 nRefInName &= kPast;
2689 nRefInName |= kDefName;
2695 if (eState != ssSkipReference)
2701 SetError( FormulaError::StringOverflow);
2707 bAddToSymbol =
false;
2710 else if (cSheetPrefix == c && nRefInName == 0)
2711 nRefInName |= kDollar;
2717 if (!(nRefInName & kName))
2719 nRefInName |= (kOpen | kName);
2720 bAddToSymbol = !(nRefInName & kDefName);
2722 else if (!(nRefInName & kOpen))
2724 OSL_FAIL(
"ScCompiler::NextSymbol: reference: "
2725 "a ''' without the name being enclosed in '...' violates ODF spec");
2727 else if (nRefInName & kQuote)
2730 nRefInName &= ~kQuote;
2738 nRefInName |= kQuote;
2742 nRefInName |= kFileSep;
2746 nRefInName |= kClose;
2747 nRefInName &= ~kOpen;
2749 bAddToSymbol = !(nRefInName & kDefName);
2752 else if (
'#' == c && nRefInName == 0)
2753 nRefInName |= kRefErr;
2754 else if (cSheetSep == c && !(nRefInName & kOpen))
2757 nRefInName |= kPast;
2758 if (
'$' == pSrc[0] &&
'$' == pSrc[1])
2759 nRefInName |= kMarkAhead;
2761 else if (
':' == c && !(nRefInName & kOpen))
2763 OSL_FAIL(
"ScCompiler::NextSymbol: reference: "
2764 "range operator ':' without prior sheet name separator '.' violates ODF spec");
2768 else if (!(nRefInName & kName))
2771 nRefInName |= kName;
2780 if (bAddToSymbol && eState != ssSkipReference)
2793 vSpaces.emplace_back(aSpace);
2797 const sal_Int32 nOldSrcPos =
nSrcPos;
2798 for (
const auto& r : vSpaces)
2807 const bool bGroupSeparator = (128 <= cGroupSep && cGroupSep != cSep &&
2808 cGroupSep != cArrayColSep && cGroupSep != cArrayRowSep &&
2809 cGroupSep != cDecSep && cGroupSep != cDecSepAlt &&
2810 cGroupSep != cSheetPrefix && cGroupSep != cSheetSep);
2815 OUStringBuffer aSymbol;
2822 if ( pStart[
nSrcPos] == cSheetPrefix && pStart[
nSrcPos+1] ==
'\'' )
2823 aSymbol.append(pStart[
nSrcPos++]);
2827 if ( !aRes.TokenType )
2829 nErr = FormulaError::IllegalChar;
2835 assert(!aRes.TokenType);
2836 nErr = FormulaError::IllegalChar;
2841 aSymbol.setLength(0);
2851 for (sal_Int32
i =
nSrcPos;
i < aRes.EndPos; ++
i)
2853 if (pStart[
i] == cSep)
2860 if ( aRes.TokenType & KParseType::SINGLE_QUOTE_NAME )
2871 aSymbol.append(pStart[
nSrcPos++]);
2873 }
while ( bi18n && nErr == FormulaError::NONE );
2874 sal_Int32 nLen = aSymbol.getLength();
2877 SetError( FormulaError::StringOverflow );
2900 if (bAutoIntersection && vSpaces[nAutoIntersectionSpacesPos].
nCount > 1)
2901 --vSpaces[nAutoIntersectionSpacesPos].nCount;
2909 OpCodeHashMap::const_iterator iLook(
mxSymbols->getHashMap().find( rName));
2910 bool bFound = (iLook !=
mxSymbols->getHashMap().end());
2913 OpCode eOp = iLook->second;
2925 else if (rName ==
";")
2927 switch (FormulaGrammar::extractFormulaLanguage(
meGrammar))
2931 case css::sheet::FormulaLanguage::NATIVE:
2932 case css::sheet::FormulaLanguage::ENGLISH:
2933 case css::sheet::FormulaLanguage::ODFF:
2934 case css::sheet::FormulaLanguage::ODF_11:
2965 static const FunctionName aOdffAliases[] = {
2978 for (
const FunctionName& rOdffAlias : aOdffAliases)
2980 if (rName.equalsIgnoreAsciiCaseAscii( rOdffAlias.pName))
2997 static const FunctionName aOoxmlAliases[] = {
3006 for (
const FunctionName& rOoxmlAlias : aOoxmlAliases)
3008 if (rName.equalsIgnoreAsciiCaseAscii( rOoxmlAlias.pName))
3028 static const FunctionName aPodfAliases[] = {
3031 for (
const FunctionName& rPodfAlias : aPodfAliases)
3033 if (rName.equalsIgnoreAsciiCaseAscii( rPodfAlias.pName))
3048 ExternalHashMap::const_iterator iExt(
3049 mxSymbols->getExternalHashMap().find( rName));
3050 if (iExt !=
mxSymbols->getExternalHashMap().end())
3053 aIntName = (*iExt).second;
3069 if (!aIntName.isEmpty())
3080 bool bShouldBeNegSub =
3085 if (bShouldBeNegSub && eOp ==
ocSub)
3088 else if (!bShouldBeNegSub && eOp ==
ocNegSub)
3117 const sal_Int32 nFormulaLanguage = FormulaGrammar::extractFormulaLanguage(
GetGrammar());
3118 if (nFormulaLanguage == css::sheet::FormulaLanguage::ODFF || nFormulaLanguage == css::sheet::FormulaLanguage::OOXML)
3122 rtl_math_ConversionStatus eStatus;
3123 sal_Int32 nParseEnd;
3124 double fVal = rtl::math::stringToDouble( rSym,
'.', 0, &eStatus, &nParseEnd);
3125 if (nParseEnd != rSym.getLength())
3137 if (rSym.equalsIgnoreAsciiCase(
"TRUE"))
3139 else if (rSym.equalsIgnoreAsciiCase(
"FALSE"))
3151 if (eStatus == rtl_math_ConversionStatus_OutOfRange)
3157 if (!std::isfinite(fVal) && rSym ==
"INF")
3168 SetError( FormulaError::IllegalArgument );
3187 if (
nType & (SvNumFormatType::TIME | SvNumFormatType::DATE))
3190 if (
nType == SvNumFormatType::LOGICAL)
3196 if(
nType == SvNumFormatType::TEXT )
3198 SetError( FormulaError::IllegalArgument );
3210 sal_Int32 nLen = sal::static_int_cast<sal_Int32>(
p -
cSymbol - 1 );
3211 if (!nLen ||
cSymbol[nLen] !=
'"')
3237 const OUString aErrRef(
"#REF!");
3238 sal_Int32
nPos = rName.indexOf( aErrRef);
3252 if (rName.getLength() == 5)
3271 if (
'$' == c2 ||
'#' == c2 || (
'0' <= c2 && c2 <=
'9'))
3279 (
'.' == c2 ||
'$' == c2 ||
'#' == c2 ||
3280 (
'0' <= c2 && c2 <=
'9')))
3287 if (rtl::isAsciiAlpha(c) &&
3433 if ( ch1 == cDecSep )
3440 if ( ch1 == cDecSep )
3461 if ( !(ch2 ==
'$' || rtl::isAsciiAlpha( ch2 )) )
3463 if ( cDecSep ==
'.' && (ch2 ==
'E' || ch2 ==
'e')
3476 OUString aTabName( rName.copy( 0,
nPos ) );
3514 case FormulaGrammar::CONV_XL_A1:
3515 case FormulaGrammar::CONV_XL_OOX:
3519 if (rName[0] !=
'\'')
3522 case FormulaGrammar::CONV_XL_R1C1:
3536#if !HAVE_FEATURE_SCRIPTING
3551 SAL_WARN(
"sc.core",
"ScCompiler::ParseMacro - SolarMutex would deadlock, not obtaining Basic");
3555 OUString
aName( rName);
3578 if (FormulaGrammar::isODFF(
GetGrammar()) &&
aName.startsWithIgnoreAsciiCase(
"USER."))
3589 ||
dynamic_cast<const SbMethod*
>( pMeth) == nullptr )
3670 rbInvalidExternalNameRange =
false;
3675 OUString aFile,
aName;
3683 OUString aTmp = aFile;
3689 rbInvalidExternalNameRange =
true;
3714 bool bInList =
false;
3715 bool bFound =
false;
3717 OUString
aName( rName );
3720 for (
short jThisTab = 1; jThisTab >= 0 && !bInList; jThisTab-- )
3722 for (
short jRow=0; jRow<2 && !bInList; jRow++ )
3729 for (
size_t iPair = 0, nPairs = pRL->
size(); iPair < nPairs && !bInList; ++iPair )
3733 if ( jThisTab && (rNameRange.
aStart.
Tab() > nThisTab ||
3734 nThisTab > rNameRange.
aEnd.
Tab()) )
3737 for (
bool bHas = aIter.
first(); bHas && !bInList; bHas = aIter.
next())
3765 bInList = bFound =
true;
3792 for (
const ScAddress& aAddress : rAddresses )
3796 if ( nMax <
static_cast<tools::Long>(aAddress.Col()) )
3799 if ( aAddress !=
aPos )
3803 SCCOL nCol = aAddress.Col();
3804 SCROW nRow = aAddress.Row();
3810 if ( nD < nDistance )
3812 if ( nC < 0 || nR < 0 )
3815 aTwo.
Set( nCol, nRow, aAddress.Tab() );
3816 nMax = std::max( nMyCol + std::abs( nC ), nMyRow + std::abs( nR ) );
3825 aOne.
Set( nCol, nRow, aAddress.Tab() );
3826 nMax = std::max( nMyCol + nC, nMyRow + nR );
3833 aOne.
Set( nCol, nRow, aAddress.Tab() );
3834 nDistance = nC * nC + nR * nR;
3835 nMax = std::max( nMyCol + std::abs( nC ), nMyRow + std::abs( nR ) );
3845 for (
bool bHas = aIter.
first(); bHas; bHas = aIter.
next())
3874 if ( nD < nDistance )
3876 if ( nC < 0 || nR < 0 )
3880 nMax = std::max( nMyCol + std::abs( nC ), nMyRow + std::abs( nR ) );
3890 nMax = std::max( nMyCol + nC, nMyRow + nR );
3898 nDistance = nC * nC + nR * nR;
3899 nMax = std::max( nMyCol + std::abs( nC ), nMyRow + std::abs( nR ) );
3929 if ( nC1 * nC1 + nR1 * nR1 <= nC2 * nC2 + nR2 * nR2 )
3944 aAdr.
Col(), aAdr.
Row() + 1, aAdr.
Tab()))
3946 aAdr.
Col(), aAdr.
Row() - 1, aAdr.
Tab()))
3969 OpCodeHashMap::const_iterator iLook(
mxSymbols->getHashMap().find( rName ) );
3970 if( iLook !=
mxSymbols->getHashMap().end() &&
3971 ((*iLook).second ==
ocTrue ||
3984 if (nError != FormulaError::NONE)
3996 OpCodeHashMap::const_iterator iLook(
mxSymbols->getHashMap().find( rName));
3997 if (iLook !=
mxSymbols->getHashMap().end())
4004 switch ((*iLook).second)
4036OUString unescapeTableRefColumnSpecifier(
const OUString& rStr )
4040 if (rStr.indexOf(
'\'' ) < 0)
4043 const sal_Int32
n = rStr.getLength();
4044 OUStringBuffer
aBuf( n );
4047 bool bEscaped =
false;
4048 for ( ;
p < pStop; ++
p)
4061 return aBuf.makeStringAndClear();
4076 OUString
aName( unescapeTableRefColumnSpecifier( rName));
4108 for (
bool bHas = aIter.
first(); bHas; bHas = aIter.
next())
4127 SAL_WARN(
"sc.core",
"ScCompiler::IsTableRefColumn - falling back to cell lookup");
4167 if ( c1 == cQuote && c2 != cQuote )
4181 else if ( c1 != cQuote && c2 == cQuote )
4186 else if (
nPos == 0 && (c1 == cx || c1 == cX) )
4211 if ( aSymbol[0] ==
'\'' )
4213 sal_Int32 nPosition = aSymbol.indexOf(
"'#" );
4214 if (nPosition != -1)
4216 aDoc = aSymbol.copy(0, nPosition + 2);
4217 aSymbol = aSymbol.copy(nPosition + 2);
4226 OUString aTmp1( aSymbol.getToken( 0,
':',
nIndex ) );
4227 sal_Int32 nLen1 = aTmp1.getLength();
4228 OUStringBuffer aSym;
4230 bool bLastAlp =
true;
4231 sal_Int32 nStrip = 0;
4232 sal_Int32
nCount = nRefs;
4233 for ( sal_Int32 j=1; j<
nCount; j++ )
4235 aTmp2 = aSymbol.getToken( 0,
':',
nIndex );
4236 sal_Int32 nLen2 = aTmp2.getLength();
4237 if ( nLen1 || nLen2 )
4247 if ( bLastAlp == bNextNum && nStrip < 1 )
4256 if ( !aSym.isEmpty() && aSym[aSym.getLength()-1] !=
':')
4260 bLastAlp = !bNextNum;
4277 aSymbol = aSym + aTmp1;
4282 if ( nRefs && nRefs <= 2 )
4284 OUString aTab[2], aRef[2];
4288 sal_Int32 nIdx{ 0 };
4289 aRef[0] = aSymbol.getToken( 0,
':', nIdx );
4290 aRef[1] = aSymbol.getToken( 0,
':', nIdx );
4295 bool bChanged =
false;
4298 for (
int j=0; j<nRefs; j++ )
4301 sal_Int32 nDotPos = -1;
4302 while ( (nTmp = aRef[j].indexOf(
'.', nTmp )) != -1 )
4304 if ( nDotPos != -1 )
4306 aTab[j] = aRef[j].copy( 0, nDotPos + 1 );
4307 aRef[j] = aRef[j].copy( nDotPos + 1 );
4309 OUString aOld( aRef[j] );
4310 OUStringBuffer aStr2;
4312 while ( *
p && rtl::isAsciiDigit( *
p ) )
4314 aRef[j] = OUString(
p );
4316 if ( bColons || aRef[j] != aOld )
4320 bOk &= ((aAdr.
Parse( aRef[j],
rDoc, aDetails ) & nMask) == nMask);
4323 if ( bChanged && bOk )
4346 rUpper = rOrg.toAsciiUpperCase();
4366 bool bAllowBooleans = bInArray;
4367 const std::vector<Whitespace> & vSpaces =
NextSymbol(bInArray);
4387 if (!vSpaces.empty())
4390 for (
const auto& rSpace : vSpaces)
4392 if (rSpace.cChar == 0x20)
4409 SetError(FormulaError::CodeOverflow);
4419 bool bInvalidExternalNameRange;
4447 bool bMayBeFuncName;
4448 bool bAsciiNonAlnum;
4451 bMayBeFuncName = rtl::isAsciiAlpha(
cSymbol[0] );
4454 bMayBeFuncName = officecfg::Office::Common::Misc::ExperimentalMode::get();
4457 bAsciiNonAlnum = !bMayBeFuncName && !rtl::isAsciiDigit(
cSymbol[0] );
4461 OUString aTmpStr(
cSymbol[0] );
4463 bAsciiNonAlnum =
false;
4479 if ( bMayBeFuncName )
4485 bMayBeFuncName = ( *
p ==
'(' );
4492 bool bAsciiUpper =
false;
4498 const OUString aOrg(
cSymbol );
4512 bAsciiUpper =
false;
4541 if (aUpper.isEmpty())
4565 if (aUpper.isEmpty())
4600 bool bInvalidExternalNameRange;
4605 if (bInvalidExternalNameRange)
4630 if (aUpper.indexOf( aErrRef) >= 0 &&
ParseReference( aUpper, &aErrRef))
4660 bool bExternal =
GetGrammar() == FormulaGrammar::GRAM_EXTERNAL;
4661 sal_uInt16 nExpectedCount = bExternal ? 2 : 1;
4662 OSL_ENSURE(
pArr->
GetLen() == nExpectedCount,
"ScCompiler::CreateStringFromXMLTokenArray - wrong number of tokens" );
4675class ExternalFileInserter
4681 maPos(rPos), mrRefMgr(rRefMgr) {}
4683 void operator() (sal_uInt16 nFileId)
const
4693 OSL_ENSURE(
meGrammar != FormulaGrammar::GRAM_EXTERNAL,
"ScCompiler::CompileString - unexpected grammar GRAM_EXTERNAL" );
4694 if(
meGrammar == FormulaGrammar::GRAM_EXTERNAL )
4724 struct FunctionStack
4730 bool bPODF = FormulaGrammar::isPODF(
meGrammar);
4731 bool bOOXML = FormulaGrammar::isOOXML(
meGrammar);
4732 bool bUseFunctionStack = (bPODF || bOOXML);
4733 const size_t nAlloc = 512;
4734 FunctionStack aFuncs[ nAlloc ];
4735 FunctionStack* pFunctionStack = (bUseFunctionStack &&
o3tl::make_unsigned(rFormula.getLength()) > nAlloc ?
4736 new FunctionStack[rFormula.getLength()] : &aFuncs[0]);
4737 pFunctionStack[0].eOp =
ocNone;
4738 pFunctionStack[0].nSep = 0;
4739 size_t nFunction = 0;
4740 short nBrackets = 0;
4741 bool bInArray =
false;
4754 if (bUseFunctionStack)
4757 pFunctionStack[ nFunction ].eOp =
eLastOp;
4758 pFunctionStack[ nFunction ].nSep = 0;
4766 SetError( FormulaError::PairExpected );
4775 if (bUseFunctionStack && nFunction)
4781 if (bUseFunctionStack)
4782 ++pFunctionStack[ nFunction ].nSep;
4788 SetError( FormulaError::NestedArray );
4792 if (bUseFunctionStack)
4795 pFunctionStack[ nFunction ].eOp = eOp;
4796 pFunctionStack[ nFunction ].nSep = 0;
4808 SetError( FormulaError::PairExpected );
4815 if (bUseFunctionStack && nFunction)
4822 if (bUseFunctionStack)
4825 pFunctionStack[ nFunction ].eOp = eOp;
4826 pFunctionStack[ nFunction ].nSep = 0;
4832 if (bUseFunctionStack && nFunction)
4840 aArr.SetShareable(
false);
4861 SetError(FormulaError::CodeOverflow);
break;
4868 size_t nFunc = nFunction + 1;
4870 (pFunctionStack[ nFunc ].eOp ==
ocWeek &&
4871 pFunctionStack[ nFunc ].nSep == 0))
4876 SetError(FormulaError::CodeOverflow);
break;
4886 pFunctionStack[ nFunction ].eOp ==
ocAddress &&
4887 pFunctionStack[ nFunction ].nSep == 3)
4892 SetError(FormulaError::CodeOverflow);
break;
4894 ++pFunctionStack[ nFunction ].nSep;
4903 SetError( FormulaError::BadArrayContent);
4905 else if (!pNewToken)
4907 SetError(FormulaError::CodeOverflow);
4924 FormulaTokenArray::ReplaceMode::CODE_ONLY);
4960 SetError(FormulaError::CodeOverflow);
4969 while( nBrackets-- )
4973 SetError(FormulaError::CodeOverflow);
4984 if (pFunctionStack != &aFuncs[0])
4985 delete [] pFunctionStack;
5008 OSL_ENSURE( (
GetGrammar() == FormulaGrammar::GRAM_EXTERNAL) || rFormulaNmsp.isEmpty(),
5009 "ScCompiler::CompileString - unexpected formula namespace for internal grammar" );
5010 if(
GetGrammar() == FormulaGrammar::GRAM_EXTERNAL )
try
5013 uno::Reference< sheet::XFormulaParser > xParser( rParserPool.
getFormulaParser( rFormulaNmsp ), uno::UNO_SET_THROW );
5014 table::CellAddress aReferencePos;
5016 uno::Sequence< sheet::FormulaToken > aTokenSeq = xParser->parseFormula( rFormula, aReferencePos );
5021 std::unique_ptr<ScTokenArray> pNew(
new ScTokenArray( aTokenArray ));
5028 catch( uno::Exception& )