/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ /* * This file is part of the LibreOffice project. * * This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. * * This file incorporates work covered by the following license notice: * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed * with this work for additional information regarding copyright * ownership. The ASF licenses this file to you under the Apache * License, Version 2.0 (the "License"); you may not use this file * except in compliance with the License. You may obtain a copy of * the License at http://www.apache.org/licenses/LICENSE-2.0 .
*/
// Include colon; addresses in range reference are handled individually. const sal_Unicode pDelimiters[] = { '=','(',')','+','-','*','/','^','&',' ','{','}','<','>',':', 0
};
bool IsText( sal_Unicode c )
{ bool bFound = ScGlobal::UnicodeStrChr( pDelimiters, c ); if (bFound) // This is one of delimiters, therefore not text. returnfalse;
// argument separator is configurable. const sal_Unicode sep = ScCompiler::GetNativeSymbolChar(ocSep); return c != sep;
}
bool IsText( bool& bQuote, sal_Unicode c )
{ if (c == '\'')
{
bQuote = !bQuote; returntrue;
} if (bQuote) returntrue;
return IsText(c);
}
/** * Find first character position that is considered text. A character is * considered a text when it's within the ascii range and when it's not a * delimiter.
*/
sal_Int32 FindStartPos(const sal_Unicode* p, sal_Int32 nStartPos, sal_Int32 nEndPos)
{ while (nStartPos <= nEndPos && !IsText(p[nStartPos]))
++nStartPos;
sal_Int32 FindEndPosR1C1(const sal_Unicode* p, sal_Int32 nStartPos, sal_Int32 nEndPos)
{
sal_Int32 nNewEnd = nStartPos;
p = &p[nStartPos]; for (; nNewEnd <= nEndPos; ++p, ++nNewEnd)
{ if (*p == '\'')
{ // Skip until the closing quote. for (++p, ++nNewEnd; nNewEnd <= nEndPos; ++p, ++nNewEnd) if (*p == '\'') break; if (nNewEnd > nEndPos) break;
} elseif (*p == '[')
{ // Skip until the closing bracket. for (++p, ++nNewEnd; nNewEnd <= nEndPos; ++p, ++nNewEnd) if (*p == ']') break; if (nNewEnd > nEndPos) break;
} elseif (!IsText(*p)) break;
}
return nNewEnd;
}
/** * Find last character position that is considered text, from the specified * start position.
*/
sal_Int32 FindEndPos(const sal_Unicode* p, sal_Int32 nStartPos, sal_Int32 nEndPos,
formula::FormulaGrammar::AddressConvention eConv)
{ switch (eConv)
{ case formula::FormulaGrammar::CONV_XL_R1C1: return FindEndPosR1C1(p, nStartPos, nEndPos); case formula::FormulaGrammar::CONV_OOO: case formula::FormulaGrammar::CONV_XL_A1: default: return FindEndPosA1(p, nStartPos, nEndPos);
}
}
void ExpandToTextR1C1(const sal_Unicode* p, sal_Int32 nLen, sal_Int32& rStartPos, sal_Int32& rEndPos)
{ // move back the start position to the first text character. if (rStartPos > 0)
{ for (--rStartPos; rStartPos > 0; --rStartPos)
{
sal_Unicode c = p[rStartPos]; if (c == '\'')
{ // Skip until the opening quote. for (--rStartPos; rStartPos > 0; --rStartPos)
{
c = p[rStartPos]; if (c == '\'') break;
} if (rStartPos == 0) break;
} elseif (c == ']')
{ // Skip until the opening bracket. for (--rStartPos; rStartPos > 0; --rStartPos)
{
c = p[rStartPos]; if (c == '[') break;
} if (rStartPos == 0) break;
} elseif (!IsText(c))
{
++rStartPos; break;
}
}
}
// move forward the end position to the last text character.
rEndPos = FindEndPosR1C1(p, rEndPos, nLen-1);
}
sal_Int32 nLoopStart = nStartPos; while ( nLoopStart <= nEndPos )
{ // Determine the start and end positions of a text segment. Note that // the end position returned from FindEndPos may be one position after // the last character position in case of the last segment.
sal_Int32 nEStart = FindStartPos(pSource, nLoopStart, nEndPos);
sal_Int32 nEEnd = FindEndPos(pSource, nEStart, nEndPos, meConv);
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.