20#include <config_features.h>
22#include <compiler.hxx>
36#include <osl/diagnose.h>
37#include <rtl/character.hxx>
40#include <com/sun/star/lang/Locale.hpp>
41#include <com/sun/star/sheet/FormulaOpCodeMapEntry.hpp>
42#include <com/sun/star/sheet/FormulaLanguage.hpp>
43#include <com/sun/star/i18n/KParseTokens.hpp>
44#include <com/sun/star/i18n/KParseType.hpp>
49#include <rtl/math.hxx>
50#include <rtl/ustring.hxx>
54#include <document.hxx>
71#include <tokenarray.hxx>
74#include <officecfg/Office/Common.hxx>
104static const char*
pInternal[2] = {
"TTT",
"__DEBUG_VAR" };
110 size_t nSymbolOffset;
113 case FormulaGrammar::GRAM_PODF:
114 nSymbolOffset = offsetof(
AddInMap, pUpper);
117 case FormulaGrammar::GRAM_ODFF:
118 nSymbolOffset = offsetof(
AddInMap, pODFF);
120 case FormulaGrammar::GRAM_ENGLISH:
121 nSymbolOffset = offsetof(
AddInMap, pEnglish);
126 for ( ; pMap < pStop; ++pMap)
128 char const *
const * ppSymbol =
129 reinterpret_cast< char const *
const *
>(
130 reinterpret_cast< char const *
>(pMap) + nSymbolOffset);
131 xMap->putExternal( OUString::createFromAscii( *ppSymbol),
132 OUString::createFromAscii( pMap->
pOriginal));
202 return !aIntName.isEmpty();
209 css::lang::Locale aLocale(
"en",
"US",
"");
211 ::comphelper::getProcessComponentContext(),
LanguageTag( aLocale));
230 assert( eGrammar != FormulaGrammar::GRAM_UNSPECIFIED &&
"ScCompiler::SetGrammar: don't pass FormulaGrammar::GRAM_UNSPECIFIED");
234 if( eGrammar == FormulaGrammar::GRAM_EXTERNAL )
242 const sal_Int32 nFormulaLanguage = FormulaGrammar::extractFormulaLanguage( eMyGrammar);
244 OSL_ENSURE( xMap,
"ScCompiler::SetGrammar: unknown formula language");
247 xMap =
GetOpCodeMap( css::sheet::FormulaLanguage::NATIVE);
248 eMyGrammar = xMap->getGrammar();
269 if (rTabNames.empty())
272 for (
auto& rTabName : rTabNames)
312 if (eConv == FormulaGrammar::CONV_UNSPECIFIED && eOldGrammar == FormulaGrammar::GRAM_UNSPECIFIED)
337 for (
i = 0;
i < 128;
i++)
348 if (FormulaGrammar::CONV_ODF ==
meConv)
353 if (FormulaGrammar::CONV_ODF ==
meConv)
367 for (
i = 48;
i < 58;
i++)
378 for (
i = 65;
i < 91;
i++)
381 if (FormulaGrammar::CONV_ODF ==
meConv)
387 else if (FormulaGrammar::CONV_OOO ==
meConv)
393 else if (FormulaGrammar::CONV_XL_OOX ==
meConv)
399 else if (FormulaGrammar::CONV_XL_A1 ==
meConv)
405 else if( FormulaGrammar::CONV_XL_R1C1 ==
meConv )
422 for (
i = 97;
i < 123;
i++)
431 if( !(FormulaGrammar::CONV_XL_A1 ==
meConv || FormulaGrammar::CONV_XL_R1C1 ==
meConv || FormulaGrammar::CONV_XL_OOX ==
meConv) )
479 while (
nPos < rFormula.getLength())
481 if (rFormula[
nPos] ==
'\'')
483 if ( (
nPos+1 == rFormula.getLength()) || (rFormula[
nPos+1] !=
'\'') )
485 rRes.TokenType = KParseType::SINGLE_QUOTE_NAME;
486 rRes.EndPos =
nPos+1;
499 const OUString& rSymbol,
504 const uno::Sequence<sheet::ExternalLinkInfo>* pExternalLinks )
508 const sal_Unicode*
const pStart = rSymbol.getStr();
510 sal_Int32 nLen = rSymbol.getLength();
512 OUStringBuffer aTmpName;
514 bool bInName =
false;
520 OUString aStartTabName, aEndTabName;
523 aEndTabName, nFlags,
true, pExternalLinks );
524 if (!
p ||
p == pStart)
526 i = sal_Int32(
p - pStart);
528 for ( ;
i < nLen; ++
i, ++
p)
533 if (c ==
'.' || c == cSep)
542 for (sal_Int32 j =
i; j < nLen; ++j, ++
p)
557 aTmpFile += OUStringChar(c);
566 if (cPrev ==
'\'' && j !=
i)
578 aTmpFile += OUStringChar(c);
618 if (rtl::isAsciiAlphanumeric(c))
642 aTmpFile += OUStringChar(c);
653 sal_Int32 nNameLen = aTmpName.getLength();
660 if (aTmpName[0] != cSep)
666 if (aTmpName[nNameLen-1] ==
'!')
674 rName = aTmpName.makeStringAndClear().copy(1);
681 OUString aEscQuote(
"''");
682 OUString aFile(rFile.replaceAll(
"'", aEscQuote));
683 OUString
aName(rName);
686 OUStringBuffer
aBuf(aFile.getLength() +
aName.getLength() + 9);
689 aBuf.append(
"'" + aFile +
"'" + OUStringChar(cSep) );
691 aBuf.append(
"$$'" );
695 return aBuf.makeStringAndClear();
699 const vector<OUString>& rTabNames,
const ScRange& rRef )
704 size_t nCount = rTabNames.size();
705 vector<OUString>::const_iterator itrBeg = rTabNames.begin(), itrEnd = rTabNames.end();
706 vector<OUString>::const_iterator itr = ::std::find(itrBeg, itrEnd, rTabName1);
707 if (itr == rTabNames.end())
709 rTabName2 =
ScResId(STR_NO_REF_TABLE);
713 size_t nDist = ::std::distance(itrBeg, itr);
714 if (nDist +
static_cast<size_t>(nTabSpan) >=
nCount)
716 rTabName2 =
ScResId(STR_NO_REF_TABLE);
720 rTabName2 = rTabNames[nDist+nTabSpan];
723 rTabName2 = rTabName1;
733 static void MakeColStr(
const ScSheetLimits& rLimits, OUStringBuffer& rBuffer,
SCCOL nCol );
734 static void MakeRowStr(
const ScSheetLimits& rLimits, OUStringBuffer& rBuffer,
SCROW nRow );
736 ParseResult parseAnyToken(
const OUString& rFormula,
739 bool bGroupSeparator)
const override
745 constexpr sal_Int32 nStartFlags = KParseTokens::ANY_LETTER_OR_NUMBER |
746 KParseTokens::ASC_UNDERSCORE | KParseTokens::ASC_DOLLAR;
747 constexpr sal_Int32 nContFlags = nStartFlags | KParseTokens::ASC_DOT;
749 static constexpr OUStringLiteral aAddAllowed(u
"?#");
751 nSrcPos, nStartFlags, aAddAllowed,
752 (bGroupSeparator ? nContFlags | KParseTokens::GROUP_SEPARATOR_IN_NUMBER : nContFlags),
758 return mpCharTable[
static_cast<sal_uInt8>(c)];
764void Convention_A1::MakeColStr(
const ScSheetLimits& rLimits, OUStringBuffer& rBuffer,
SCCOL nCol )
767 rBuffer.append(
ScResId(STR_NO_REF_TABLE));
772void Convention_A1::MakeRowStr(
const ScSheetLimits& rLimits, OUStringBuffer& rBuffer,
SCROW nRow )
775 rBuffer.append(
ScResId(STR_NO_REF_TABLE));
777 rBuffer.append(sal_Int32(nRow + 1));
782struct ConventionOOO_A1 :
public Convention_A1
787 static void MakeTabStr( OUStringBuffer &rBuf,
const std::vector<OUString>& rTabNames,
SCTAB nTab )
790 rBuf.append(
ScResId(STR_NO_REF_TABLE));
792 rBuf.append(rTabNames[nTab]);
796 enum SingletonDisplay
803 static void MakeOneRefStrImpl(
805 std::u16string_view rErrRef,
const std::vector<OUString>& rTabNames,
807 bool bForceTab,
bool bODF, SingletonDisplay eSingletonDisplay )
815 rBuffer.append(rErrRef);
822 MakeTabStr(rBuffer, rTabNames, rAbsRef.
Tab());
828 if (eSingletonDisplay != SINGLETON_ROW)
833 rBuffer.append(rErrRef);
835 MakeColStr(rLimits, rBuffer, rAbsRef.
Col());
838 if (eSingletonDisplay != SINGLETON_COL)
843 rBuffer.append(rErrRef);
845 MakeRowStr(rLimits, rBuffer, rAbsRef.
Row());
855 return SINGLETON_NONE;
859 return SINGLETON_COL;
863 if (!bFromRangeName && rAbs1.
Row() == 0 && rAbs2.
Row() == rLimits.
mnMaxRow &&
865 return SINGLETON_COL;
869 return SINGLETON_ROW;
873 if (!bFromRangeName && rAbs1.
Col() == 0 && rAbs2.
Col() == rLimits.
mnMaxCol &&
875 return SINGLETON_ROW;
877 return SINGLETON_NONE;
880 virtual void makeRefStr(
882 OUStringBuffer& rBuffer,
885 const OUString& rErrRef,
const std::vector<OUString>& rTabNames,
888 bool bFromRangeName )
const override
896 SingletonDisplay eSingleton = bSingleRef ? SINGLETON_NONE :
897 getSingletonDisplay( rLimits, aAbs1, aAbs2, rRef, bFromRangeName);
898 MakeOneRefStrImpl(rLimits, rBuffer, rErrRef, rTabNames, rRef.
Ref1, aAbs1,
false,
false, eSingleton);
902 MakeOneRefStrImpl(rLimits, rBuffer, rErrRef, rTabNames, rRef.
Ref2, aAbs2, aAbs1.
Tab() != aAbs2.Tab(),
false,
907 virtual sal_Unicode getSpecialSymbol( SpecialSymbolType eSymType )
const override
920 virtual bool parseExternalName(
const OUString& rSymbol, OUString& rFile, OUString& rName,
922 const uno::Sequence<sheet::ExternalLinkInfo>* pExternalLinks )
const override
927 virtual OUString makeExternalNameStr( sal_uInt16 ,
const OUString& rFile,
928 const OUString& rName )
const override
933 static bool makeExternalSingleRefStr(
935 OUStringBuffer& rBuffer,
const OUString& rFileName,
const OUString& rTabName,
947 rBuffer.append(
"'" + aFile.replaceAll(
"'",
"''") +
"'#");
958 MakeColStr( rLimits, rBuffer, aAbsRef.
Col());
961 MakeRowStr( rLimits, rBuffer, aAbsRef.
Row());
966 static void makeExternalRefStrImpl(
968 OUStringBuffer& rBuffer,
const ScAddress& rPos,
const OUString& rFileName,
972 rBuffer.append(
'[');
974 bool bEncodeUrl = bODF;
975 makeExternalSingleRefStr(rLimits, rBuffer, rFileName, rTabName, rRef, rPos,
true, bEncodeUrl);
977 rBuffer.append(
']');
980 virtual void makeExternalRefStr(
982 OUStringBuffer& rBuffer,
const ScAddress& rPos, sal_uInt16 ,
const OUString& rFileName,
985 makeExternalRefStrImpl(rLimits, rBuffer, rPos, rFileName, rTabName, rRef,
false);
988 static void makeExternalRefStrImpl(
990 OUStringBuffer& rBuffer,
const ScAddress& rPos,
const OUString& rFileName,
991 const std::vector<OUString>& rTabNames,
const OUString& rTabName,
997 rBuffer.append(
'[');
999 bool bEncodeUrl = bODF;
1003 if (!makeExternalSingleRefStr(rLimits, rBuffer, rFileName, rTabName, rRef.
Ref1, rPos,
true, bEncodeUrl))
1006 rBuffer.append(
':');
1008 OUString aLastTabName;
1010 if (bDisplayTabName)
1015 OSL_FAIL(
"ConventionOOO_A1::makeExternalRefStrImpl: sheet name not found");
1020 rBuffer.append(
'.');
1021 makeExternalSingleRefStr(rLimits,
1022 rBuffer, rFileName, aLastTabName, rRef.
Ref2, rPos, bDisplayTabName, bEncodeUrl);
1026 rBuffer.append(
']');
1029 virtual void makeExternalRefStr(
1031 OUStringBuffer& rBuffer,
const ScAddress& rPos, sal_uInt16 ,
const OUString& rFileName,
1032 const std::vector<OUString>& rTabNames,
const OUString& rTabName,
1035 makeExternalRefStrImpl(rLimits, rBuffer, rPos, rFileName, rTabNames, rTabName, rRef,
false);
1039struct ConventionOOO_A1_ODF :
public ConventionOOO_A1
1041 ConventionOOO_A1_ODF() : ConventionOOO_A1 (
FormulaGrammar::CONV_ODF) { }
1043 virtual void makeRefStr(
1045 OUStringBuffer& rBuffer,
1048 const OUString& rErrRef,
const std::vector<OUString>& rTabNames,
1051 bool bFromRangeName )
const override
1053 rBuffer.append(
'[');
1063 rBuffer.append(rErrRef);
1070 SingletonDisplay eSingleton = bSingleRef ? SINGLETON_NONE :
1071 getSingletonDisplay( rLimits, aAbs1, aAbs2, rRef, bFromRangeName);
1072 MakeOneRefStrImpl(rLimits, rBuffer, rErrRef, rTabNames, rRef.
Ref1, aAbs1,
false,
true, eSingleton);
1075 rBuffer.append(
':');
1076 MakeOneRefStrImpl(rLimits, rBuffer, rErrRef, rTabNames, rRef.
Ref2, aAbs2, aAbs1.
Tab() != aAbs2.Tab(),
true,
1080 rBuffer.append(
']');
1083 virtual OUString makeExternalNameStr( sal_uInt16 ,
const OUString& rFile,
1084 const OUString& rName )
const override
1089 virtual void makeExternalRefStr(
1091 OUStringBuffer& rBuffer,
const ScAddress& rPos, sal_uInt16 ,
const OUString& rFileName,
1092 const OUString& rTabName,
const ScSingleRefData& rRef )
const override
1094 makeExternalRefStrImpl(rLimits, rBuffer, rPos, rFileName, rTabName, rRef,
true);
1097 virtual void makeExternalRefStr(
1099 OUStringBuffer& rBuffer,
const ScAddress& rPos, sal_uInt16 ,
const OUString& rFileName,
1100 const std::vector<OUString>& rTabNames,
1103 makeExternalRefStrImpl(rLimits, rBuffer, rPos, rFileName, rTabNames, rTabName, rRef,
true);
1109 virtual ~ConventionXL()
1115 const ScAddress& rPos,
const std::vector<OUString>& rTabNames,
1121 rTabName =
ScResId( STR_NO_REF_TABLE );
1124 rTabName = rTabNames[aAbs.
Tab()];
1127 static void MakeTabStr(
const ScSheetLimits& rLimits, OUStringBuffer& rBuf,
1129 const std::vector<OUString>& rTabNames,
1136 OUString aStartTabName, aEndTabName;
1138 GetTab(rLimits, rPos, rTabNames, rRef.
Ref1, aStartTabName);
1142 GetTab(rLimits, rPos, rTabNames, rRef.
Ref2, aEndTabName);
1145 rBuf.append( aStartTabName );
1146 if( !bSingleRef && rRef.
Ref2.
IsFlag3D() && aStartTabName != aEndTabName )
1149 rBuf.append( aEndTabName );
1167 static bool parseExternalName(
const OUString& rSymbol, OUString& rFile, OUString& rName,
1169 const uno::Sequence<sheet::ExternalLinkInfo>* pExternalLinks )
1174 static OUString makeExternalNameStr(
const OUString& rFile,
const OUString& rName )
1179 static void makeExternalDocStr( OUStringBuffer& rBuffer, std::u16string_view rFullName )
1188 rBuffer.append(
'[');
1189 rBuffer.append(
'\'');
1193 sal_Int32 nLen = aFullName.getLength();
1194 for (sal_Int32 i = 0;
i < nLen; ++
i)
1201 rBuffer.append(
'\'');
1202 rBuffer.append(
']');
1205 static void makeExternalTabNameRange( OUStringBuffer& rBuf,
const OUString& rTabName,
1206 const vector<OUString>& rTabNames,
1209 OUString aLastTabName;
1217 if (rTabName != aLastTabName)
1224 virtual void parseExternalDocName(
const OUString& rFormula, sal_Int32& rSrcPos )
const
1226 sal_Int32 nLen = rFormula.getLength();
1229 for (sal_Int32 i = rSrcPos;
i < nLen; ++
i)
1238 else if (i == rSrcPos + 1)
1258 if (rSrcPos >= nLen)
1268 if (i > rSrcPos + 2 && cPrev ==
'\'')
1278struct ConventionXL_A1 :
public Convention_A1,
public ConventionXL
1280 ConventionXL_A1() : Convention_A1(
FormulaGrammar::CONV_XL_A1 ) { }
1287 MakeColStr(rLimits, rBuf, rAbs.
Col());
1290 MakeRowStr(rLimits, rBuf, rAbs.
Row());
1293 virtual void makeRefStr(
1295 OUStringBuffer& rBuf,
1298 const OUString& rErrRef,
const std::vector<OUString>& rTabNames,
1301 bool )
const override
1307 ScAddress aAbs1 = aRef.Ref1.toAbs(rLimits, rPos), aAbs2;
1309 MakeTabStr(rLimits, rBuf, rPos, rTabNames, aRef, bSingleRef);
1313 rBuf.append(rErrRef);
1319 aAbs2 = aRef.Ref2.toAbs(rLimits, rPos);
1322 rBuf.append(rErrRef);
1326 if (aAbs1.
Col() == 0 && aAbs2.Col() >= rLimits.
mnMaxCol)
1328 if (!aRef.Ref1.IsRowRel())
1330 MakeRowStr(rLimits, rBuf, aAbs1.
Row());
1332 if (!aRef.Ref2.IsRowRel())
1334 MakeRowStr(rLimits, rBuf, aAbs2.Row());
1338 if (aAbs1.
Row() == 0 && aAbs2.Row() >= rLimits.
mnMaxRow)
1340 if (!aRef.Ref1.IsColRel())
1342 MakeColStr(rLimits, rBuf, aAbs1.
Col());
1344 if (!aRef.Ref2.IsColRel())
1346 MakeColStr(rLimits, rBuf, aAbs2.Col());
1351 makeSingleCellStr(rLimits, rBuf, aRef.Ref1, aAbs1);
1355 makeSingleCellStr(rLimits, rBuf, aRef.Ref2, aAbs2);
1359 virtual ParseResult parseAnyToken(
const OUString& rFormula,
1362 bool bGroupSeparator)
const override
1364 parseExternalDocName(rFormula,
nSrcPos);
1370 constexpr sal_Int32 nStartFlags = KParseTokens::ANY_LETTER_OR_NUMBER |
1371 KParseTokens::ASC_UNDERSCORE | KParseTokens::ASC_DOLLAR;
1372 constexpr sal_Int32 nContFlags = nStartFlags | KParseTokens::ASC_DOT;
1374 static constexpr OUStringLiteral aAddAllowed(u
"?!");
1376 nSrcPos, nStartFlags, aAddAllowed,
1377 (bGroupSeparator ? nContFlags | KParseTokens::GROUP_SEPARATOR_IN_NUMBER : nContFlags),
1381 virtual sal_Unicode getSpecialSymbol( SpecialSymbolType eSymType )
const override
1383 return ConventionXL::getSpecialSymbol(eSymType);
1386 virtual bool parseExternalName(
const OUString& rSymbol, OUString& rFile, OUString& rName,
1388 const uno::Sequence<sheet::ExternalLinkInfo>* pExternalLinks )
const override
1390 return ConventionXL::parseExternalName( rSymbol, rFile, rName,
rDoc, pExternalLinks);
1393 virtual OUString makeExternalNameStr( sal_uInt16 ,
const OUString& rFile,
1394 const OUString& rName )
const override
1396 return ConventionXL::makeExternalNameStr(rFile, rName);
1399 virtual void makeExternalRefStr(
1401 OUStringBuffer& rBuffer,
const ScAddress& rPos, sal_uInt16 ,
const OUString& rFileName,
1402 const OUString& rTabName,
const ScSingleRefData& rRef )
const override
1410 ConventionXL::makeExternalDocStr(rBuffer, rFileName);
1412 rBuffer.append(
'!');
1414 makeSingleCellStr(rLimits, rBuffer, rRef, rRef.
toAbs(rLimits, rPos));
1417 virtual void makeExternalRefStr(
1419 OUStringBuffer& rBuffer,
const ScAddress& rPos, sal_uInt16 ,
const OUString& rFileName,
1420 const std::vector<OUString>& rTabNames,
const OUString& rTabName,
1425 ConventionXL::makeExternalDocStr(rBuffer, rFileName);
1426 ConventionXL::makeExternalTabNameRange(rBuffer, rTabName, rTabNames, aAbsRef);
1427 rBuffer.append(
'!');
1429 makeSingleCellStr(rLimits, rBuffer, rRef.
Ref1, aAbsRef.
aStart);
1432 rBuffer.append(
':');
1433 makeSingleCellStr(rLimits, rBuffer, rRef.
Ref2, aAbsRef.
aEnd);
1438struct ConventionXL_OOX :
public ConventionXL_A1
1440 ConventionXL_OOX() : ConventionXL_A1(
FormulaGrammar::CONV_XL_OOX ) { }
1443 OUStringBuffer& rBuf,
1446 const OUString& rErrRef,
const std::vector<OUString>& rTabNames,
1449 bool bFromRangeName )
const override
1470 rBuf.append(rErrRef);
1479 rBuf.append(rErrRef);
1490 rBuf.append(rErrRef);
1495 ConventionXL_A1::makeRefStr( rLimits, rBuf, eGram,
aPos, rErrRef, rTabNames, rRef, bSingleRef, bFromRangeName);
1498 virtual OUString makeExternalNameStr( sal_uInt16 nFileId,
const OUString& ,
1499 const OUString& rName )
const override
1502 return OUString(
"[" + OUString::number(nFileId+1) +
"]!" + rName );
1510 virtual void parseExternalDocName(
const OUString& rFormula, sal_Int32& rSrcPos)
const override
1512 sal_Int32 nLen = rFormula.getLength();
1514 for (sal_Int32 i = rSrcPos;
i < nLen; ++
i)
1531 virtual void makeExternalRefStr(
1533 OUStringBuffer& rBuffer,
const ScAddress& rPos, sal_uInt16 nFileId,
const OUString& ,
1534 const OUString& rTabName,
const ScSingleRefData& rRef )
const override
1540 OUString aQuotedTab( rTabName);
1542 if (!aQuotedTab.isEmpty() && aQuotedTab[0] ==
'\'')
1544 rBuffer.append(
'\'');
1545 ConventionXL_OOX::makeExternalDocStr( rBuffer, nFileId);
1546 rBuffer.append( aQuotedTab.subView(1));
1550 ConventionXL_OOX::makeExternalDocStr( rBuffer, nFileId);
1551 rBuffer.append( aQuotedTab);
1553 rBuffer.append(
'!');
1555 makeSingleCellStr(rLimits, rBuffer, rRef, rRef.
toAbs(rLimits, rPos));
1558 virtual void makeExternalRefStr(
1560 OUStringBuffer& rBuffer,
const ScAddress& rPos, sal_uInt16 nFileId,
const OUString& ,
1561 const std::vector<OUString>& rTabNames,
const OUString& rTabName,
1572 OUStringBuffer
aBuf;
1573 ConventionXL::makeExternalTabNameRange( aBuf, rTabName, rTabNames, aAbsRef);
1574 if (!
aBuf.isEmpty() && aBuf[0] ==
'\'')
1576 rBuffer.append(
'\'');
1577 ConventionXL_OOX::makeExternalDocStr( rBuffer, nFileId);
1578 rBuffer.append(
aBuf.subView(1));
1582 ConventionXL_OOX::makeExternalDocStr( rBuffer, nFileId);
1583 rBuffer.append( aBuf);
1585 rBuffer.append(
'!');
1587 makeSingleCellStr(rLimits, rBuffer, rRef.
Ref1, aAbsRef.
aStart);
1590 rBuffer.append(
':');
1591 makeSingleCellStr(rLimits, rBuffer, rRef.
Ref2, aAbsRef.
aEnd);
1595 static void makeExternalDocStr( OUStringBuffer& rBuffer, sal_uInt16 nFileId )
1597 rBuffer.append(
'[').append(
static_cast<sal_Int32
>(nFileId+1) ).append(
']');
1611 rBuf.append(
"[" + OUString::number(nCol) +
"]");
1614 rBuf.append(
static_cast<sal_Int32
>(rAbsRef.
Col() + 1) );
1622 if (rRef.
Row() != 0)
1624 rBuf.append(
"[" + OUString::number(rRef.
Row()) +
"]");
1628 rBuf.append( rAbsRef.
Row() + 1 );
1638 OUStringBuffer& rBuf,
1641 const OUString& rErrRef,
const std::vector<OUString>& rTabNames,
1644 bool )
const override
1649 MakeTabStr(rLimits, rBuf, rPos, rTabNames, aRef, bSingleRef);
1655 rBuf.append(rErrRef);
1663 rBuf.append(rErrRef);
1703 ParseResult parseAnyToken(
const OUString& rFormula,
1706 bool bGroupSeparator)
const override
1708 parseExternalDocName(rFormula,
nSrcPos);
1714 constexpr sal_Int32 nStartFlags = KParseTokens::ANY_LETTER_OR_NUMBER |
1715 KParseTokens::ASC_UNDERSCORE ;
1716 constexpr sal_Int32 nContFlags = nStartFlags | KParseTokens::ASC_DOT;
1718 static constexpr OUStringLiteral aAddAllowed(u
"?-[]!");
1721 nSrcPos, nStartFlags, aAddAllowed,
1722 (bGroupSeparator ? nContFlags | KParseTokens::GROUP_SEPARATOR_IN_NUMBER : nContFlags),
1726 virtual sal_Unicode getSpecialSymbol( SpecialSymbolType eSymType )
const override
1728 return ConventionXL::getSpecialSymbol(eSymType);
1731 virtual bool parseExternalName(
const OUString& rSymbol, OUString& rFile, OUString& rName,
1733 const uno::Sequence<sheet::ExternalLinkInfo>* pExternalLinks )
const override
1735 return ConventionXL::parseExternalName( rSymbol, rFile, rName,
rDoc, pExternalLinks);
1738 virtual OUString makeExternalNameStr( sal_uInt16 ,
const OUString& rFile,
1739 const OUString& rName )
const override
1741 return ConventionXL::makeExternalNameStr(rFile, rName);
1744 virtual void makeExternalRefStr(
1746 OUStringBuffer& rBuffer,
const ScAddress& rPos, sal_uInt16 ,
const OUString& rFileName,
1747 const OUString& rTabName,
const ScSingleRefData& rRef )
const override
1756 ConventionXL::makeExternalDocStr(rBuffer, rFileName);
1758 rBuffer.append(
'!');
1764 virtual void makeExternalRefStr(
1766 OUStringBuffer& rBuffer,
const ScAddress& rPos, sal_uInt16 ,
const OUString& rFileName,
1767 const std::vector<OUString>& rTabNames,
const OUString& rTabName,
1772 ConventionXL::makeExternalDocStr(rBuffer, rFileName);
1773 ConventionXL::makeExternalTabNameRange(rBuffer, rTabName, rTabNames, aAbsRef);
1774 rBuffer.append(
'!');
1778 rBuffer.append(
ScResId(STR_NO_REF_TABLE));
1787 rBuffer.append(
':');
1798 rBuffer.append(
':');
1806 rBuffer.append(
':');
1814 if (c ==
'-' && cLast ==
'[')
1826 rDoc(rCxt.getDoc()),
1828 mpFormatter(pContext ? pContext->GetFormatTable() :
rDoc.GetFormatTable()),
1852 mpFormatter(pContext ? pContext->GetFormatTable() : rDoc.GetFormatTable()),
1853 mpInterpreterContext(pContext),
1854 mnCurrentSheetTab(-1),
1855 mnCurrentSheetEndPos(0),
1858 mbCharClassesDiffer(false),
1859 mnPredetectedReference(0),
1860 mnRangeOpPosInSymbol(-1),
1862 meExtendedErrorDetection( EXTENDED_ERROR_DETECTION_NONE ),
1863 mbCloseBrackets( true ),
1865 mbRefConventionChartOOXML( false )
1875 rDoc(rCxt.getDoc()),
1877 mpFormatter(pContext ? pContext->GetFormatTable() : rDoc.GetFormatTable()),
1878 mpInterpreterContext(pContext),
1879 mnCurrentSheetTab(-1),
1880 mnCurrentSheetEndPos(0),
1882 mbCharClassesDiffer(false),
1883 mnPredetectedReference(0),
1884 mnRangeOpPosInSymbol(-1),
1886 meExtendedErrorDetection(EXTENDED_ERROR_DETECTION_NONE),
1887 mbCloseBrackets(true),
1889 mbRefConventionChartOOXML(false),
1890 maTabNames(rCxt.getTabNames())
1901 mpFormatter(pContext ? pContext->GetFormatTable() : rDoc.GetFormatTable()),
1902 mpInterpreterContext(pContext),
1903 mnCurrentSheetTab(-1),
1904 mnCurrentSheetEndPos(0),
1907 mbCharClassesDiffer(false),
1908 mnPredetectedReference(0),
1909 mnRangeOpPosInSymbol(-1),
1911 meExtendedErrorDetection( EXTENDED_ERROR_DETECTION_NONE ),
1912 mbCloseBrackets( true ),
1914 mbRefConventionChartOOXML( false )
1928 sal_Int32 nStartFlags = KParseTokens::ANY_LETTER_OR_NUMBER | KParseTokens::ASC_UNDERSCORE;
1929 sal_Int32 nContFlags = nStartFlags;
1931 KParseType::IDENTNAME, rString, 0, nStartFlags, OUString(), nContFlags, OUString());
1932 bool bNeedsQuote = !((aRes.TokenType & KParseType::IDENTNAME) && aRes.EndPos == rString.getLength());
1937 case FormulaGrammar::CONV_UNSPECIFIED :
1939 case FormulaGrammar::CONV_OOO :
1940 case FormulaGrammar::CONV_XL_A1 :
1941 case FormulaGrammar::CONV_XL_R1C1 :
1942 case FormulaGrammar::CONV_XL_OOX :
1943 case FormulaGrammar::CONV_ODF :
1947 rString = rString.replaceAll(
"'",
"''" );
1960 rString =
"'" + rString +
"'";
1966 if (rString[0] !=
'\'')
1970 if (
nPos != -1 && rString[
nPos-1] !=
'\'')
1987 case FormulaGrammar::CONV_OOO:
1989 static const ConventionOOO_A1 ConvOOO_A1;
1992 case FormulaGrammar::CONV_ODF:
1994 static const ConventionOOO_A1_ODF ConvOOO_A1_ODF;
1995 return &ConvOOO_A1_ODF;
1997 case FormulaGrammar::CONV_XL_A1:
1999 static const ConventionXL_A1 ConvXL_A1;
2002 case FormulaGrammar::CONV_XL_R1C1:
2004 static const ConventionXL_R1C1 ConvXL_R1C1;
2005 return &ConvXL_R1C1;
2007 case FormulaGrammar::CONV_XL_OOX:
2009 static const ConventionXL_OOX ConvXL_OOX;
2012 case FormulaGrammar::CONV_UNSPECIFIED:
2024 assert( FormulaGrammar::isSupported(
meGrammar));
2036 while ( pDst < pStop )
2049 for (
size_t i=0;
i<
n; ++
i)
2055 if (p1[
i] <
'a' ||
'z' < p1[
i])
2057 if (p2[
i] <
'A' ||
'Z' < p2[
i])
2059 if (p1[
i] != p2[
i] + 0x20)
2070 if (rSpace.
cChar != c)
2073 rvSpaces.emplace_back(rSpace);
2118 std::vector<Whitespace> vSpaces;
2126 bool bQuote =
false;
2128 ScanState eState = ssGetChar;
2141 bool bAutoIntersection =
false;
2142 size_t nAutoIntersectionSpacesPos = 0;
2144 bool bErrorConstantHadSlash =
false;
2147 while ((c != 0) && (eState != ssStop) )
2154 if (c == cSep || (bInArray && (c == cArrayColSep || c == cArrayRowSep)))
2161 case ssGetReference:
2162 case ssSkipReference:
2163 case ssGetTableRefItem:
2164 case ssGetTableRefColumn:
2167 if (eState == ssGetChar)
2174Label_MaskStateMachine:
2183 eState = ssGetTableRefColumn;
2198 if (!bAutoIntersection)
2206 nAutoIntersectionSpacesPos = vSpaces.size();
2207 bAutoIntersection =
true;
2218 goto Label_MaskStateMachine;
2232 goto Label_MaskStateMachine;
2243 if (c ==
'[' && FormulaGrammar::isExcelSyntax(
meGrammar)
2250 if (FormulaGrammar::isRefConventionOOXML(
meGrammar) &&
2251 pSrc[0] ==
'0' && pSrc[1] ==
']' && pSrc[2] ==
'!')
2259 goto Label_MaskStateMachine;
2270 eState = ssGetReference;
2281 eState = ssGetValue;
2286 eState = ssGetString;
2292 eState = ssGetTableRefItem;
2294 eState = ssGetErrorConstant;
2304 eState = ssGetIdent;
2319 SetError(FormulaError::StringOverflow);
2339 SetError(FormulaError::StringOverflow);
2358 SetError(FormulaError::StringOverflow);
2367 else if ( 128 <= c ||
'\'' == c )
2399 SetError(FormulaError::StringOverflow);
2402 else if (c == cDecSep || (cDecSepAlt && c == cDecSepAlt))
2420 else if (c ==
'E' || c ==
'e')
2433 if (((cLast ==
'E') || (cLast ==
'e')) &&
2470 SetError(FormulaError::StringOverflow);
2471 eState = ssSkipString;
2482 case ssGetErrorConstant:
2502 eState = ssGetIdent;
2508 if (!bErrorConstantHadSlash)
2509 bErrorConstantHadSlash =
true;
2517 (c < 128 && !rtl::isAsciiAlphanumeric( c)))
2528 SetError( FormulaError::StringOverflow);
2536 case ssGetTableRefItem:
2543 SetError( FormulaError::StringOverflow);
2556 case ssGetTableRefColumn:
2559 if (c !=
']' || cLast ==
'\'')
2563 SetError( FormulaError::StringOverflow);
2576 case ssGetReference:
2579 SetError( FormulaError::StringOverflow);
2580 eState = ssSkipReference;
2583 case ssSkipReference:
2602 constexpr int kDollar = (1 << 1);
2605 constexpr int kOpen = (1 << 2);
2607 constexpr int kName = (1 << 3);
2611 constexpr int kQuote = (1 << 4);
2613 constexpr int kClose = (1 << 5);
2615 constexpr int kFileSep = (1 << 6);
2617 constexpr int kPast = (1 << 7);
2621 constexpr int kMarkAhead = (1 << 8);
2623 constexpr int kDefName = (1 << 9);
2625 constexpr int kRefErr = (1 << 10);
2627 bool bAddToSymbol =
true;
2630 OSL_ENSURE( nRefInName & (kPast | kDefName | kRefErr),
2631 "ScCompiler::NextSymbol: reference: "
2632 "closing bracket ']' without prior sheet name separator '.' violates ODF spec");
2634 bAddToSymbol =
false;
2637 else if (cSheetSep == c && nRefInName == 0)
2640 bAddToSymbol =
false;
2641 nRefInName |= kPast;
2642 if (
'$' == pSrc[0] &&
'$' == pSrc[1])
2643 nRefInName |= kMarkAhead;
2645 else if (!(nRefInName & kPast) || (nRefInName & (kMarkAhead | kDefName)))
2651 else if (
'$' == c &&
'$' == pSrc[0] && !(nRefInName & kOpen))
2653 nRefInName &= ~kMarkAhead;
2654 if (!(nRefInName & kDefName))
2657 bAddToSymbol =
false;
2659 nRefInName &= kPast;
2660 nRefInName |= kDefName;
2666 if (eState != ssSkipReference)
2672 SetError( FormulaError::StringOverflow);
2678 bAddToSymbol =
false;
2681 else if (cSheetPrefix == c && nRefInName == 0)
2682 nRefInName |= kDollar;
2688 if (!(nRefInName & kName))
2690 nRefInName |= (kOpen | kName);
2691 bAddToSymbol = !(nRefInName & kDefName);
2693 else if (!(nRefInName & kOpen))
2695 OSL_FAIL(
"ScCompiler::NextSymbol: reference: "
2696 "a ''' without the name being enclosed in '...' violates ODF spec");
2698 else if (nRefInName & kQuote)
2701 nRefInName &= ~kQuote;
2709 nRefInName |= kQuote;
2713 nRefInName |= kFileSep;
2717 nRefInName |= kClose;
2718 nRefInName &= ~kOpen;
2720 bAddToSymbol = !(nRefInName & kDefName);
2723 else if (
'#' == c && nRefInName == 0)
2724 nRefInName |= kRefErr;
2725 else if (cSheetSep == c && !(nRefInName & kOpen))
2728 nRefInName |= kPast;
2729 if (
'$' == pSrc[0] &&
'$' == pSrc[1])
2730 nRefInName |= kMarkAhead;
2732 else if (
':' == c && !(nRefInName & kOpen))
2734 OSL_FAIL(
"ScCompiler::NextSymbol: reference: "
2735 "range operator ':' without prior sheet name separator '.' violates ODF spec");
2739 else if (!(nRefInName & kName))
2742 nRefInName |= kName;
2751 if (bAddToSymbol && eState != ssSkipReference)
2764 vSpaces.emplace_back(aSpace);
2768 const sal_Int32 nOldSrcPos =
nSrcPos;
2769 for (
const auto& r : vSpaces)
2778 const bool bGroupSeparator = (128 <= cGroupSep && cGroupSep != cSep &&
2779 cGroupSep != cArrayColSep && cGroupSep != cArrayRowSep &&
2780 cGroupSep != cDecSep && cGroupSep != cDecSepAlt &&
2781 cGroupSep != cSheetPrefix && cGroupSep != cSheetSep);
2786 OUStringBuffer aSymbol;
2793 if ( pStart[
nSrcPos] == cSheetPrefix && pStart[
nSrcPos+1] ==
'\'' )
2794 aSymbol.append(pStart[
nSrcPos++]);
2798 if ( !aRes.TokenType )
2800 nErr = FormulaError::IllegalChar;
2806 assert(!aRes.TokenType);
2807 nErr = FormulaError::IllegalChar;
2812 aSymbol.setLength(0);
2822 for (sal_Int32
i =
nSrcPos;
i < aRes.EndPos; ++
i)
2824 if (pStart[
i] == cSep)
2831 if ( aRes.TokenType & KParseType::SINGLE_QUOTE_NAME )
2842 aSymbol.append(pStart[
nSrcPos++]);
2844 }
while ( bi18n && nErr == FormulaError::NONE );
2845 sal_Int32 nLen = aSymbol.getLength();
2848 SetError( FormulaError::StringOverflow );
2871 if (bAutoIntersection && vSpaces[nAutoIntersectionSpacesPos].
nCount > 1)
2872 --vSpaces[nAutoIntersectionSpacesPos].nCount;
2880 OpCodeHashMap::const_iterator iLook(
mxSymbols->getHashMap().find( rName));
2881 bool bFound = (iLook !=
mxSymbols->getHashMap().end());
2884 OpCode eOp = iLook->second;
2896 else if (rName ==
";")
2898 switch (FormulaGrammar::extractFormulaLanguage(
meGrammar))
2902 case css::sheet::FormulaLanguage::NATIVE:
2903 case css::sheet::FormulaLanguage::ENGLISH:
2904 case css::sheet::FormulaLanguage::ODFF:
2905 case css::sheet::FormulaLanguage::ODF_11:
2936 static const FunctionName aOdffAliases[] = {
2949 for (
const FunctionName& rOdffAlias : aOdffAliases)
2951 if (rName.equalsIgnoreAsciiCaseAscii( rOdffAlias.pName))
2968 static const FunctionName aOoxmlAliases[] = {
2977 for (
const FunctionName& rOoxmlAlias : aOoxmlAliases)
2979 if (rName.equalsIgnoreAsciiCaseAscii( rOoxmlAlias.pName))
2999 static const FunctionName aPodfAliases[] = {
3002 for (
const FunctionName& rPodfAlias : aPodfAliases)
3004 if (rName.equalsIgnoreAsciiCaseAscii( rPodfAlias.pName))
3019 ExternalHashMap::const_iterator iExt(
3020 mxSymbols->getExternalHashMap().find( rName));
3021 if (iExt !=
mxSymbols->getExternalHashMap().end())
3024 aIntName = (*iExt).second;
3040 if (!aIntName.isEmpty())
3051 bool bShouldBeNegSub =
3056 if (bShouldBeNegSub && eOp ==
ocSub)
3059 else if (!bShouldBeNegSub && eOp ==
ocNegSub)
3067 bool bFound =
false;
3089 const sal_Int32 nFormulaLanguage = FormulaGrammar::extractFormulaLanguage(
GetGrammar());
3090 if (nFormulaLanguage == css::sheet::FormulaLanguage::ODFF || nFormulaLanguage == css::sheet::FormulaLanguage::OOXML)
3094 rtl_math_ConversionStatus eStatus;
3095 sal_Int32 nParseEnd;
3096 double fVal = rtl::math::stringToDouble( rSym,
'.', 0, &eStatus, &nParseEnd);
3097 if (nParseEnd != rSym.getLength())
3109 if (rSym.equalsIgnoreAsciiCase(
"TRUE"))
3111 else if (rSym.equalsIgnoreAsciiCase(
"FALSE"))
3123 if (eStatus == rtl_math_ConversionStatus_OutOfRange)
3129 if (!std::isfinite(fVal) && rSym ==
"INF")
3140 SetError( FormulaError::IllegalArgument );
3159 if (
nType & (SvNumFormatType::TIME | SvNumFormatType::DATE))
3162 if (
nType == SvNumFormatType::LOGICAL)
3168 if(
nType == SvNumFormatType::TEXT )
3170 SetError( FormulaError::IllegalArgument );
3182 sal_Int32 nLen = sal::static_int_cast<sal_Int32>(
p -
cSymbol - 1 );
3183 if (!nLen ||
cSymbol[nLen] !=
'"')
3209 const OUString aErrRef(
"#REF!");
3210 sal_Int32
nPos = rName.indexOf( aErrRef);
3224 if (rName.getLength() == 5)
3243 if (
'$' == c2 ||
'#' == c2 || (
'0' <= c2 && c2 <=
'9'))
3251 (
'.' == c2 ||
'$' == c2 ||
'#' == c2 ||
3252 (
'0' <= c2 && c2 <=
'9')))
3259 if (rtl::isAsciiAlpha(c) &&
3405 if ( ch1 == cDecSep )
3412 if ( ch1 == cDecSep )
3433 if ( !(ch2 ==
'$' || rtl::isAsciiAlpha( ch2 )) )
3435 if ( cDecSep ==
'.' && (ch2 ==
'E' || ch2 ==
'e')
3448 OUString aTabName( rName.copy( 0,
nPos ) );
3486 case FormulaGrammar::CONV_XL_A1:
3487 case FormulaGrammar::CONV_XL_OOX:
3491 if (rName[0] !=
'\'')
3494 case FormulaGrammar::CONV_XL_R1C1:
3508#if !HAVE_FEATURE_SCRIPTING
3523 SAL_WARN(
"sc.core",
"ScCompiler::ParseMacro - SolarMutex would deadlock, not obtaining Basic");
3527 OUString
aName( rName);
3550 if (FormulaGrammar::isODFF(
GetGrammar()) &&
aName.startsWithIgnoreAsciiCase(
"USER."))
3561 ||
dynamic_cast<const SbMethod*
>( pMeth) == nullptr )
3642 rbInvalidExternalNameRange =
false;
3647 OUString aFile,
aName;
3655 OUString aTmp = aFile;
3661 rbInvalidExternalNameRange =
true;
3686 bool bInList =
false;
3687 bool bFound =
false;
3689 OUString
aName( rName );
3692 for (
short jThisTab = 1; jThisTab >= 0 && !bInList; jThisTab-- )
3694 for (
short jRow=0; jRow<2 && !bInList; jRow++ )
3701 for (
size_t iPair = 0, nPairs = pRL->
size(); iPair < nPairs && !bInList; ++iPair )
3705 if ( jThisTab && (rNameRange.
aStart.
Tab() > nThisTab ||
3706 nThisTab > rNameRange.
aEnd.
Tab()) )
3709 for (
bool bHas = aIter.
first(); bHas && !bInList; bHas = aIter.
next())
3737 bInList = bFound =
true;
3764 for (
const ScAddress& aAddress : rAddresses )
3768 if ( nMax <
static_cast<tools::Long>(aAddress.Col()) )
3771 if ( aAddress !=
aPos )
3775 SCCOL nCol = aAddress.Col();
3776 SCROW nRow = aAddress.Row();
3782 if ( nD < nDistance )
3784 if ( nC < 0 || nR < 0 )
3787 aTwo.
Set( nCol, nRow, aAddress.Tab() );
3788 nMax = std::max( nMyCol + std::abs( nC ), nMyRow + std::abs( nR ) );
3797 aOne.
Set( nCol, nRow, aAddress.Tab() );
3798 nMax = std::max( nMyCol + nC, nMyRow + nR );
3805 aOne.
Set( nCol, nRow, aAddress.Tab() );
3806 nDistance = nC * nC + nR * nR;
3807 nMax = std::max( nMyCol + std::abs( nC ), nMyRow + std::abs( nR ) );
3817 for (
bool bHas = aIter.
first(); bHas; bHas = aIter.
next())
3846 if ( nD < nDistance )
3848 if ( nC < 0 || nR < 0 )
3852 nMax = std::max( nMyCol + std::abs( nC ), nMyRow + std::abs( nR ) );
3862 nMax = std::max( nMyCol + nC, nMyRow + nR );
3870 nDistance = nC * nC + nR * nR;
3871 nMax = std::max( nMyCol + std::abs( nC ), nMyRow + std::abs( nR ) );
3901 if ( nC1 * nC1 + nR1 * nR1 <= nC2 * nC2 + nR2 * nR2 )
3916 aAdr.
Col(), aAdr.
Row() + 1, aAdr.
Tab()))
3918 aAdr.
Col(), aAdr.
Row() - 1, aAdr.
Tab()))
3941 OpCodeHashMap::const_iterator iLook(
mxSymbols->getHashMap().find( rName ) );
3942 if( iLook !=
mxSymbols->getHashMap().end() &&
3943 ((*iLook).second ==
ocTrue ||
3956 if (nError != FormulaError::NONE)
3968 OpCodeHashMap::const_iterator iLook(
mxSymbols->getHashMap().find( rName));
3969 if (iLook !=
mxSymbols->getHashMap().end())
3976 switch ((*iLook).second)
4008OUString unescapeTableRefColumnSpecifier(
const OUString& rStr )
4012 if (rStr.indexOf(
'\'' ) < 0)
4015 const sal_Int32
n = rStr.getLength();
4016 OUStringBuffer
aBuf( n );
4019 bool bEscaped =
false;
4020 for ( ;
p < pStop; ++
p)
4033 return aBuf.makeStringAndClear();
4048 OUString
aName( unescapeTableRefColumnSpecifier( rName));
4080 for (
bool bHas = aIter.
first(); bHas; bHas = aIter.
next())
4099 SAL_WARN(
"sc.core",
"ScCompiler::IsTableRefColumn - falling back to cell lookup");
4139 if ( c1 == cQuote && c2 != cQuote )
4153 else if ( c1 != cQuote && c2 == cQuote )
4158 else if (
nPos == 0 && (c1 == cx || c1 == cX) )
4183 if ( aSymbol[0] ==
'\'' )
4185 sal_Int32 nPosition = aSymbol.indexOf(
"'#" );
4186 if (nPosition != -1)
4188 aDoc = aSymbol.copy(0, nPosition + 2);
4189 aSymbol = aSymbol.copy(nPosition + 2);
4198 OUString aTmp1( aSymbol.getToken( 0,
':',
nIndex ) );
4199 sal_Int32 nLen1 = aTmp1.getLength();
4200 OUStringBuffer aSym;
4202 bool bLastAlp =
true;
4203 sal_Int32 nStrip = 0;
4204 sal_Int32
nCount = nRefs;
4205 for ( sal_Int32 j=1; j<
nCount; j++ )
4207 aTmp2 = aSymbol.getToken( 0,
':',
nIndex );
4208 sal_Int32 nLen2 = aTmp2.getLength();
4209 if ( nLen1 || nLen2 )
4219 if ( bLastAlp == bNextNum && nStrip < 1 )
4228 if ( !aSym.isEmpty() && aSym[aSym.getLength()-1] !=
':')
4232 bLastAlp = !bNextNum;
4249 aSymbol = aSym + aTmp1;
4254 if ( nRefs && nRefs <= 2 )
4256 OUString aTab[2], aRef[2];
4260 sal_Int32 nIdx{ 0 };
4261 aRef[0] = aSymbol.getToken( 0,
':', nIdx );
4262 aRef[1] = aSymbol.getToken( 0,
':', nIdx );
4267 bool bChanged =
false;
4270 for (
int j=0; j<nRefs; j++ )
4273 sal_Int32 nDotPos = -1;
4274 while ( (nTmp = aRef[j].indexOf(
'.', nTmp )) != -1 )
4276 if ( nDotPos != -1 )
4278 aTab[j] = aRef[j].copy( 0, nDotPos + 1 );
4279 aRef[j] = aRef[j].copy( nDotPos + 1 );
4281 OUString aOld( aRef[j] );
4282 OUStringBuffer aStr2;
4284 while ( *
p && rtl::isAsciiDigit( *
p ) )
4286 aRef[j] = OUString(
p );
4288 if ( bColons || aRef[j] != aOld )
4292 bOk &= ((aAdr.
Parse( aRef[j],
rDoc, aDetails ) & nMask) == nMask);
4295 if ( bChanged && bOk )
4318 rUpper = rOrg.toAsciiUpperCase();
4338 bool bAllowBooleans = bInArray;
4339 const std::vector<Whitespace> & vSpaces =
NextSymbol(bInArray);
4359 if (!vSpaces.empty())
4362 for (
const auto& rSpace : vSpaces)
4364 if (rSpace.cChar == 0x20)
4381 SetError(FormulaError::CodeOverflow);
4391 bool bInvalidExternalNameRange;
4419 bool bMayBeFuncName;
4420 bool bAsciiNonAlnum;
4423 bMayBeFuncName = rtl::isAsciiAlpha(
cSymbol[0] );
4426 bMayBeFuncName = officecfg::Office::Common::Misc::ExperimentalMode::get();
4429 bAsciiNonAlnum = !bMayBeFuncName && !rtl::isAsciiDigit(
cSymbol[0] );
4433 OUString aTmpStr(
cSymbol[0] );
4435 bAsciiNonAlnum =
false;
4451 if ( bMayBeFuncName )
4457 bMayBeFuncName = ( *
p ==
'(' );
4464 bool bAsciiUpper =
false;
4470 const OUString aOrg(
cSymbol );
4484 bAsciiUpper =
false;
4513 if (aUpper.isEmpty())
4537 if (aUpper.isEmpty())
4572 bool bInvalidExternalNameRange;
4577 if (bInvalidExternalNameRange)
4602 if (aUpper.indexOf( aErrRef) >= 0 &&
ParseReference( aUpper, &aErrRef))
4632 bool bExternal =
GetGrammar() == FormulaGrammar::GRAM_EXTERNAL;
4633 sal_uInt16 nExpectedCount = bExternal ? 2 : 1;
4634 OSL_ENSURE(
pArr->
GetLen() == nExpectedCount,
"ScCompiler::CreateStringFromXMLTokenArray - wrong number of tokens" );
4647class ExternalFileInserter
4653 maPos(rPos), mrRefMgr(rRefMgr) {}
4655 void operator() (sal_uInt16 nFileId)
const
4665 OSL_ENSURE(
meGrammar != FormulaGrammar::GRAM_EXTERNAL,
"ScCompiler::CompileString - unexpected grammar GRAM_EXTERNAL" );
4666 if(
meGrammar == FormulaGrammar::GRAM_EXTERNAL )
4696 struct FunctionStack
4702 bool bPODF = FormulaGrammar::isPODF(
meGrammar);
4703 bool bOOXML = FormulaGrammar::isOOXML(
meGrammar);
4704 bool bUseFunctionStack = (bPODF || bOOXML);
4705 const size_t nAlloc = 512;
4706 FunctionStack aFuncs[ nAlloc ];
4707 FunctionStack* pFunctionStack = (bUseFunctionStack &&
o3tl::make_unsigned(rFormula.getLength()) > nAlloc ?
4708 new FunctionStack[rFormula.getLength()] : &aFuncs[0]);
4709 pFunctionStack[0].eOp =
ocNone;
4710 pFunctionStack[0].nSep = 0;
4711 size_t nFunction = 0;
4712 short nBrackets = 0;
4713 bool bInArray =
false;
4726 if (bUseFunctionStack)
4729 pFunctionStack[ nFunction ].eOp =
eLastOp;
4730 pFunctionStack[ nFunction ].nSep = 0;
4738 SetError( FormulaError::PairExpected );
4747 if (bUseFunctionStack && nFunction)
4753 if (bUseFunctionStack)
4754 ++pFunctionStack[ nFunction ].nSep;
4760 SetError( FormulaError::NestedArray );
4764 if (bUseFunctionStack)
4767 pFunctionStack[ nFunction ].eOp = eOp;
4768 pFunctionStack[ nFunction ].nSep = 0;
4780 SetError( FormulaError::PairExpected );
4787 if (bUseFunctionStack && nFunction)
4794 if (bUseFunctionStack)
4797 pFunctionStack[ nFunction ].eOp = eOp;
4798 pFunctionStack[ nFunction ].nSep = 0;
4804 if (bUseFunctionStack && nFunction)
4812 aArr.SetShareable(
false);
4833 SetError(FormulaError::CodeOverflow);
break;
4840 size_t nFunc = nFunction + 1;
4842 (pFunctionStack[ nFunc ].eOp ==
ocWeek &&
4843 pFunctionStack[ nFunc ].nSep == 0))
4848 SetError(FormulaError::CodeOverflow);
break;
4858 pFunctionStack[ nFunction ].eOp ==
ocAddress &&
4859 pFunctionStack[ nFunction ].nSep == 3)
4864 SetError(FormulaError::CodeOverflow);
break;
4866 ++pFunctionStack[ nFunction ].nSep;
4875 SetError( FormulaError::BadArrayContent);
4877 else if (!pNewToken)
4879 SetError(FormulaError::CodeOverflow);
4896 FormulaTokenArray::ReplaceMode::CODE_ONLY);
4932 SetError(FormulaError::CodeOverflow);
4941 while( nBrackets-- )
4945 SetError(FormulaError::CodeOverflow);
4956 if (pFunctionStack != &aFuncs[0])
4957 delete [] pFunctionStack;
4980 OSL_ENSURE( (
GetGrammar() == FormulaGrammar::GRAM_EXTERNAL) || rFormulaNmsp.isEmpty(),
4981 "ScCompiler::CompileString - unexpected formula namespace for internal grammar" );
4982 if(
GetGrammar() == FormulaGrammar::GRAM_EXTERNAL )
try
4985 uno::Reference< sheet::XFormulaParser > xParser( rParserPool.
getFormulaParser( rFormulaNmsp ), uno::UNO_SET_THROW );
4986 table::CellAddress aReferencePos;
4988 uno::Sequence< sheet::FormulaToken > aTokenSeq = xParser->parseFormula( rFormula, aReferencePos );
4993 std::unique_ptr<ScTokenArray> pNew(
new ScTokenArray( aTokenArray ));
5000 catch( uno::Exception& )
5019 if( nErr != FormulaError::NONE )