diff options
Diffstat (limited to 'starmath/source/parse.cxx')
-rw-r--r-- | starmath/source/parse.cxx | 79 |
1 files changed, 56 insertions, 23 deletions
diff --git a/starmath/source/parse.cxx b/starmath/source/parse.cxx index 7a39233a762b..67512e4a44eb 100644 --- a/starmath/source/parse.cxx +++ b/starmath/source/parse.cxx @@ -64,7 +64,7 @@ SmToken::SmToken(SmTokenType eTokenType, { } - +//Definition of math keywords static const SmTokenTableEntry aTokenTable[] = { { "abs", TABS, '\0', TG::UnOper, 13 }, @@ -159,6 +159,7 @@ static const SmTokenTableEntry aTokenTable[] = { "italic", TITALIC, '\0', TG::FontAttr, 5}, { "lambdabar" , TLAMBDABAR, MS_LAMBDABAR, TG::Standalone, 5}, { "langle", TLANGLE, MS_LMATHANGLE, TG::LBrace, 5}, + { "laplace", TLAPLACE, MS_LAPLACE, TG::Standalone, 5}, { "lbrace", TLBRACE, MS_LBRACE, TG::LBrace, 5}, { "lceil", TLCEIL, MS_LCEIL, TG::LBrace, 5}, { "ldbracket", TLDBRACKET, MS_LDBRACKET, TG::LBrace, 5}, @@ -239,6 +240,7 @@ static const SmTokenTableEntry aTokenTable[] = { "re" , TRE, MS_RE, TG::Standalone, 5 }, { "red", TRED, '\0', TG::Color, 0}, { "rfloor", TRFLOOR, MS_RFLOOR, TG::RBrace, 0}, //! 0 to terminate expression + { "rgb", TRGB, '\0', TG::Color, 0}, { "right", TRIGHT, '\0', TG::NONE, 0}, { "rightarrow" , TRIGHTARROW, MS_RIGHTARROW, TG::Standalone, 5}, { "rline", TRLINE, MS_VERTLINE, TG::RBrace, 0}, //! 0 to terminate expression @@ -297,33 +299,37 @@ static const SmTokenTableEntry aTokenTable[] = { "yellow", TYELLOW, '\0', TG::Color, 0} }; +//Checks if keyword is in the list by SmTokenTableEntry. #if !defined NDEBUG static bool sortCompare(const SmTokenTableEntry & lhs, const SmTokenTableEntry & rhs) { return OUString::createFromAscii(lhs.pIdent).compareToIgnoreAsciiCase(OUString::createFromAscii(rhs.pIdent)) < 0; } #endif + +//Checks if keyword is in the list. static bool findCompare(const SmTokenTableEntry & lhs, const OUString & s) { return s.compareToIgnoreAsciiCaseAscii(lhs.pIdent) > 0; } + +//Returns the SmTokenTableEntry for a keyword const SmTokenTableEntry * SmParser::GetTokenTableEntry( const OUString &rName ) { - static bool bSortKeyWords = false; - if( !bSortKeyWords ) + static bool bSortKeyWords = false; // Flag: RTF-token table has been sorted. + if( !bSortKeyWords ) //First time sorts it. { assert( std::is_sorted( std::begin(aTokenTable), std::end(aTokenTable), sortCompare ) ); bSortKeyWords = true; } - if (rName.isEmpty()) - return nullptr; + if (rName.isEmpty())return nullptr; //avoid null pointer exceptions + //Looks for the first keyword after or equal to rName in alphabetical order. auto findIter = std::lower_bound( std::begin(aTokenTable), std::end(aTokenTable), rName, findCompare ); - if ( findIter != std::end(aTokenTable) && rName.equalsIgnoreAsciiCaseAscii( findIter->pIdent )) - return &*findIter; + if ( findIter != std::end(aTokenTable) && rName.equalsIgnoreAsciiCaseAscii( findIter->pIdent ))return &*findIter; //check is equal - return nullptr; + return nullptr; //not found } namespace { @@ -333,42 +339,44 @@ bool IsDelimiter( const OUString &rTxt, sal_Int32 nPos ) { assert(nPos <= rTxt.getLength()); //index out of range - if (nPos == rTxt.getLength()) - return true; + if (nPos == rTxt.getLength())return true; //This is EOF sal_Unicode cChar = rTxt[nPos]; // check if 'cChar' is in the delimiter table static const sal_Unicode aDelimiterTable[] = { - ' ', '\t', '\n', '\r', '+', '-', '*', '/', '=', '#', - '%', '\\', '"', '~', '`', '>', '<', '&', '|', '(', - ')', '{', '}', '[', ']', '^', '_' - }; + ' ', '{', '}', '(', ')', '\t', '\n', '\r', '+', '-', + '*', '/', '=', '[', ']', '^', '_', '#', + '%', '>', '<', '&', '|', '\\', '"', '~', '`' + };//reordered by usage (by eye) for nanoseconds saving. + + //checks the array for (auto const &cDelimiter : aDelimiterTable) { - if (cDelimiter == cChar) - return true; + if (cDelimiter == cChar)return true; } + //special chars support sal_Int16 nTypJp = SM_MOD()->GetSysLocale().GetCharClass().getType( rTxt, nPos ); return ( nTypJp == css::i18n::UnicodeType::SPACE_SEPARATOR || nTypJp == css::i18n::UnicodeType::CONTROL); } -} +}//end namespace +//Text replace onto m_aBufferString void SmParser::Replace( sal_Int32 nPos, sal_Int32 nLen, const OUString &rText ) { - assert( nPos + nLen <= m_aBufferString.getLength() ); + assert( nPos + nLen <= m_aBufferString.getLength() ); //checks if length allows text replace - m_aBufferString = m_aBufferString.replaceAt( nPos, nLen, rText ); + m_aBufferString = m_aBufferString.replaceAt( nPos, nLen, rText ); //replace and reindex sal_Int32 nChg = rText.getLength() - nLen; m_nBufferIndex = m_nBufferIndex + nChg; m_nTokenIndex = m_nTokenIndex + nChg; } -void SmParser::NextToken() +void SmParser::NextToken() //Central part of the parser { // First character may be any alphabetic static const sal_Int32 coStartFlags = @@ -979,7 +987,7 @@ namespace aSubArray[i] = rSubNodes[i].release(); return aSubArray; } -} +} //end namespace // grammar @@ -1474,6 +1482,7 @@ std::unique_ptr<SmNode> SmParser::DoTerm(bool bGroupNumberIdent) case TFORALL : case TPARTIAL : case TNABLA : + case TLAPLACE : case TTOWARD : case TDOTSAXIS : case TDOTSDIAG : @@ -1860,10 +1869,34 @@ std::unique_ptr<SmStructureNode> SmParser::DoColor() // last color rules, get that one SmToken aToken; do - { NextToken(); + { + + NextToken(); if (TokenInGroup(TG::Color)) - { aToken = m_aCurToken; + { + aToken = m_aCurToken; + if(m_aCurToken.eType==TRGB){ + SmToken r,g,b; + sal_Int32 nr, ng, nb, nc; + NextToken(); + if(m_aCurToken.eType!=TNUMBER)return DoError(SmParseError::ColorExpected); + r = m_aCurToken; + NextToken(); + if(m_aCurToken.eType!=TNUMBER)return DoError(SmParseError::ColorExpected); + g = m_aCurToken; + NextToken(); + if(m_aCurToken.eType!=TNUMBER)return DoError(SmParseError::ColorExpected); + b = m_aCurToken; + nr = r.aText.toInt32(); + if( nr < 0 || nr > 255 )return DoError(SmParseError::ColorExpected); + ng = g.aText.toInt32(); + if( ng < 0 || ng > 255 )return DoError(SmParseError::ColorExpected); + nb = b.aText.toInt32(); + if( nb < 0 || nb > 255 )return DoError(SmParseError::ColorExpected); + nc = nb + 256 * ( ng + nr*256 ); + aToken.aText = OUString::number(nc); + } NextToken(); } else |