26 #include <compiler.hxx>
27 #include <document.hxx>
33 '=',
'(',
')',
'+',
'-',
'*',
'/',
'^',
'&',
' ',
'{',
'}',
'<',
'>',
':', 0
66 sal_Int32 FindStartPos(
const sal_Unicode* p, sal_Int32 nStartPos, sal_Int32 nEndPos)
68 while (nStartPos <= nEndPos && !IsText(p[nStartPos]))
74 sal_Int32 FindEndPosA1(
const sal_Unicode* p, sal_Int32 nStartPos, sal_Int32 nEndPos)
77 sal_Int32 nNewEnd = nStartPos;
78 while (nNewEnd <= nEndPos && IsText(bQuote, p[nNewEnd]))
84 sal_Int32 FindEndPosR1C1(
const sal_Unicode* p, sal_Int32 nStartPos, sal_Int32 nEndPos)
86 sal_Int32 nNewEnd = nStartPos;
88 for (; nNewEnd <= nEndPos; ++p, ++nNewEnd)
93 for (; nNewEnd <= nEndPos; ++p, ++nNewEnd)
96 if (nNewEnd > nEndPos)
102 for (; nNewEnd <= nEndPos; ++p, ++nNewEnd)
105 if (nNewEnd > nEndPos)
108 else if (!IsText(*p))
119 sal_Int32 FindEndPos(
const sal_Unicode* p, sal_Int32 nStartPos, sal_Int32 nEndPos,
125 return FindEndPosR1C1(p, nStartPos, nEndPos);
129 return FindEndPosA1(p, nStartPos, nEndPos);
133 void ExpandToTextA1(
const sal_Unicode* p, sal_Int32 nLen, sal_Int32& rStartPos, sal_Int32& rEndPos)
136 while (rStartPos > 0 && IsText(bQuote, p[rStartPos - 1]) )
140 while (rEndPos+1 < nLen && IsText(p[rEndPos + 1]) )
144 void ExpandToTextR1C1(
const sal_Unicode* p, sal_Int32 nLen, sal_Int32& rStartPos, sal_Int32& rEndPos)
149 for (--rStartPos; rStartPos > 0; --rStartPos)
155 for (--rStartPos; rStartPos > 0; --rStartPos)
167 for (--rStartPos; rStartPos > 0; --rStartPos)
185 rEndPos = FindEndPosR1C1(p, rEndPos, nLen-1);
188 void ExpandToText(
const sal_Unicode* p, sal_Int32 nLen, sal_Int32& rStartPos, sal_Int32& rEndPos,
194 ExpandToTextR1C1(p, nLen, rStartPos, rEndPos);
199 ExpandToTextA1(p, nLen, rStartPos, rEndPos);
206 const OUString& rFormula,
const ScAddress& rPos,
231 return (nOld & ~Mask_ABS) | nNew;
243 if ( nEndPos < nStartPos )
244 ::std::swap(nEndPos, nStartPos);
246 ExpandToText(pSource, nLen, nStartPos, nEndPos,
meConv);
248 OUStringBuffer aResult;
254 sal_Int32 nLoopStart = nStartPos;
255 while ( nLoopStart <= nEndPos )
260 sal_Int32 nEStart = FindStartPos(pSource, nLoopStart, nEndPos);
261 sal_Int32 nEEnd = FindEndPos(pSource, nEStart, nEndPos,
meConv);
263 aSep =
maFormula.copy(nLoopStart, nEStart-nLoopStart);
265 aExpr =
maFormula.copy(nEStart, nEEnd-nEStart);
276 if( aExtInfo.mbExternal )
284 nSep = aExpr.lastIndexOf(
'!');
288 nSep = aExpr.lastIndexOf(
'.');
293 OUString aRef = aExpr.copy(nSep+1);
294 OUString aExtDocNameTabName = aExpr.copy(0, nSep+1);
298 aExpr = aExtDocNameTabName + aAddr.
Format(nFlags, &
mrDoc, aDetails);
302 assert(!
"Invalid syntax according to address convention.");
311 sal_Int32 nAbsStart = nStartPos+aResult.getLength()+aSep.getLength();
315 mnSelEnd = nAbsStart + aExpr.getLength();
321 aResult.append(aSep);
322 aResult.append(aExpr);
327 OUString aTotal =
maFormula.subView(0, nStartPos) + aResult.makeStringAndClear();
SC_DLLPUBLIC void Format(OStringBuffer &r, ScRefFlags nFlags, const ScDocument *pDocument=nullptr, const Details &rDetails=detailsOOOa1) const
formula::FormulaGrammar::AddressConvention meConv
constexpr std::underlying_type_t< T > underlyingEnumValue(T e)
void ToggleRel(sal_Int32 nStartPos, sal_Int32 nEndPos)
static ScRefFlags lcl_NextFlags(ScRefFlags nOld)
const BorderLinePrimitive2D *pCandidateB assert(pCandidateA)
ScRefFinder(const OUString &rFormula, const ScAddress &rPos, ScDocument &rDoc, formula::FormulaGrammar::AddressConvention eConvP=formula::FormulaGrammar::CONV_OOO)
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.
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)