26#include <compiler.hxx>
27#include <document.hxx>
34 '=',
'(',
')',
'+',
'-',
'*',
'/',
'^',
'&',
' ',
'{',
'}',
'<',
'>',
':', 0
67sal_Int32 FindStartPos(
const sal_Unicode* p, sal_Int32 nStartPos, sal_Int32 nEndPos)
69 while (nStartPos <= nEndPos && !IsText(p[nStartPos]))
75sal_Int32 FindEndPosA1(
const sal_Unicode* p, sal_Int32 nStartPos, sal_Int32 nEndPos)
78 sal_Int32 nNewEnd = nStartPos;
79 while (nNewEnd <= nEndPos && IsText(bQuote, p[nNewEnd]))
85sal_Int32 FindEndPosR1C1(
const sal_Unicode* p, sal_Int32 nStartPos, sal_Int32 nEndPos)
87 sal_Int32 nNewEnd = nStartPos;
89 for (; nNewEnd <= nEndPos; ++
p, ++nNewEnd)
94 for (++p, ++nNewEnd; nNewEnd <= nEndPos; ++
p, ++nNewEnd)
97 if (nNewEnd > nEndPos)
103 for (++p, ++nNewEnd; nNewEnd <= nEndPos; ++
p, ++nNewEnd)
106 if (nNewEnd > nEndPos)
109 else if (!IsText(*p))
120sal_Int32 FindEndPos(
const sal_Unicode* p, sal_Int32 nStartPos, sal_Int32 nEndPos,
126 return FindEndPosR1C1(p, nStartPos, nEndPos);
130 return FindEndPosA1(p, nStartPos, nEndPos);
134void ExpandToTextA1(
const sal_Unicode* p, sal_Int32 nLen, sal_Int32& rStartPos, sal_Int32& rEndPos)
137 while (rStartPos > 0 && IsText(bQuote, p[rStartPos - 1]) )
141 while (rEndPos+1 < nLen && IsText(p[rEndPos + 1]) )
145void ExpandToTextR1C1(
const sal_Unicode* p, sal_Int32 nLen, sal_Int32& rStartPos, sal_Int32& rEndPos)
150 for (--rStartPos; rStartPos > 0; --rStartPos)
156 for (--rStartPos; rStartPos > 0; --rStartPos)
168 for (--rStartPos; rStartPos > 0; --rStartPos)
186 rEndPos = FindEndPosR1C1(p, rEndPos, nLen-1);
189void ExpandToText(
const sal_Unicode* p, sal_Int32 nLen, sal_Int32& rStartPos, sal_Int32& rEndPos,
195 ExpandToTextR1C1(p, nLen, rStartPos, rEndPos);
200 ExpandToTextA1(p, nLen, rStartPos, rEndPos);
207 OUString aFormula,
const ScAddress& rPos,
232 return (nOld & ~Mask_ABS) | nNew;
244 if ( nEndPos < nStartPos )
245 ::std::swap(nEndPos, nStartPos);
247 ExpandToText(pSource, nLen, nStartPos, nEndPos,
meConv);
249 OUStringBuffer aResult;
255 sal_Int32 nLoopStart = nStartPos;
256 while ( nLoopStart <= nEndPos )
261 sal_Int32 nEStart = FindStartPos(pSource, nLoopStart, nEndPos);
262 sal_Int32 nEEnd = FindEndPos(pSource, nEStart, nEndPos,
meConv);
264 aSep =
maFormula.copy(nLoopStart, nEStart-nLoopStart);
266 aExpr =
maFormula.copy(nEStart, nEEnd-nEStart);
285 nSep = aExpr.lastIndexOf(
'!');
289 nSep = aExpr.lastIndexOf(
'.');
294 OUString aRef = aExpr.copy(nSep+1);
295 std::u16string_view aExtDocNameTabName = aExpr.subView(0, nSep+1);
299 aExpr = aExtDocNameTabName + aAddr.
Format(nFlags, &
mrDoc, aDetails);
303 assert(!
"Invalid syntax according to address convention.");
312 sal_Int32 nAbsStart = nStartPos+aResult.getLength()+aSep.getLength();
316 mnSelEnd = nAbsStart + aExpr.getLength();
322 aResult.append(aSep + aExpr);
327 OUString aTotal =
maFormula.subView(0, nStartPos) + aResult;
SC_DLLPUBLIC void Format(OStringBuffer &r, ScRefFlags nFlags, const ScDocument *pDocument=nullptr, const Details &rDetails=detailsOOOa1) const
SC_DLLPUBLIC ScRefFlags Parse(const OUString &, const ScDocument &, const Details &rDetails=detailsOOOa1, ExternalInfo *pExtInfo=nullptr, const css::uno::Sequence< css::sheet::ExternalLinkInfo > *pExternalLinks=nullptr, sal_Int32 *pSheetEndPos=nullptr, const OUString *pErrRef=nullptr)
static const sal_Unicode * UnicodeStrChr(const sal_Unicode *pStr, sal_Unicode c)
strchr() functionality on unicode, as long as we need it for FormulaToken etc.
ScRefFinder(OUString aFormula, const ScAddress &rPos, ScDocument &rDoc, formula::FormulaGrammar::AddressConvention eConvP=formula::FormulaGrammar::CONV_OOO)
void ToggleRel(sal_Int32 nStartPos, sal_Int32 nEndPos)
formula::FormulaGrammar::AddressConvention meConv
constexpr std::underlying_type_t< T > to_underlying(T e)
static ScRefFlags lcl_NextFlags(ScRefFlags nOld)