diff options
author | Noel Grandin <noel@peralex.com> | 2013-09-12 16:21:34 +0200 |
---|---|---|
committer | Noel Grandin <noel@peralex.com> | 2013-09-17 08:06:13 +0200 |
commit | 12d44973d96f5cad4b99386c8a281f8427d304e4 (patch) | |
tree | d7e811bd689256ff57c90401779e1b045fe38de1 | |
parent | e42e0efe504b95b3b3127b437cdf40621d1dafd8 (diff) |
convert aCorrectedSymbol in formula::FormulaCompiler from String to OUString
Change-Id: I426b305fb8befffe0452e280d2097b6560843eef
-rw-r--r-- | formula/source/core/api/FormulaCompiler.cxx | 29 | ||||
-rw-r--r-- | include/formula/FormulaCompiler.hxx | 4 | ||||
-rw-r--r-- | sc/source/core/tool/compiler.cxx | 36 |
3 files changed, 36 insertions, 33 deletions
diff --git a/formula/source/core/api/FormulaCompiler.cxx b/formula/source/core/api/FormulaCompiler.cxx index 638931304937..5586791da39e 100644 --- a/formula/source/core/api/FormulaCompiler.cxx +++ b/formula/source/core/api/FormulaCompiler.cxx @@ -978,7 +978,7 @@ bool FormulaCompiler::GetToken() if ( bAutoCorrect && !pStack ) { // don't merge stacked subroutine code into entered formula aCorrectedFormula += aCorrectedSymbol; - aCorrectedSymbol.Erase(); + aCorrectedSymbol = ""; } bool bStop = false; if( pArr->GetCodeError() && !bIgnoreErrors ) @@ -1361,7 +1361,7 @@ void FormulaCompiler::Factor() SetError( errParameterExpected ); if ( bAutoCorrect && !pStack ) { - aCorrectedSymbol.Erase(); + aCorrectedSymbol = ""; bCorrected = true; } } @@ -1380,7 +1380,7 @@ void FormulaCompiler::Factor() xub_StrLen nLen = aCorrectedFormula.Len(); if ( nLen ) aCorrectedFormula.Erase( nLen - 1 ); - aCorrectedSymbol.Erase(); + aCorrectedSymbol = ""; bCorrected = true; } } @@ -1588,7 +1588,7 @@ bool FormulaCompiler::CompileTokenArray() if ( bAutoCorrect ) { aCorrectedFormula.Erase(); - aCorrectedSymbol.Erase(); + aCorrectedSymbol = ""; } pArr->nRefs = 0; // count from start pArr->DelRPN(); @@ -1707,6 +1707,13 @@ FormulaToken* FormulaCompiler::CreateStringFromToken( String& rFormula, FormulaT rFormula += aBuffer.makeStringAndClear(); return p; } +FormulaToken* FormulaCompiler::CreateStringFromToken( OUString& rFormula, FormulaToken* pTokenP,bool bAllowArrAdvance ) +{ + OUStringBuffer aBuffer; + FormulaToken* p = CreateStringFromToken( aBuffer, pTokenP, bAllowArrAdvance ); + rFormula += aBuffer.makeStringAndClear(); + return p; +} FormulaToken* FormulaCompiler::CreateStringFromToken( OUStringBuffer& rBuffer, FormulaToken* pTokenP, bool bAllowArrAdvance ) { @@ -1930,7 +1937,7 @@ OpCode FormulaCompiler::NextToken() { if ( eOp == eLastOp || eLastOp == ocOpen ) { // throw away duplicated operator - aCorrectedSymbol.Erase(); + aCorrectedSymbol = ""; bCorrected = true; } else @@ -1947,7 +1954,7 @@ OpCode FormulaCompiler::NextToken() { // >= instead of => aCorrectedFormula.SetChar( nPos, mxSymbols->getSymbol( ocGreater).GetChar(0) ); - aCorrectedSymbol = c; + aCorrectedSymbol = OUString(c); bCorrected = true; } break; @@ -1956,14 +1963,14 @@ OpCode FormulaCompiler::NextToken() { // <= instead of =< aCorrectedFormula.SetChar( nPos, mxSymbols->getSymbol( ocLess).GetChar(0) ); - aCorrectedSymbol = c; + aCorrectedSymbol = OUString(c); bCorrected = true; } else if ( c == mxSymbols->getSymbol( ocGreater).GetChar(0) ) { // <> instead of >< aCorrectedFormula.SetChar( nPos, mxSymbols->getSymbol( ocLess).GetChar(0) ); - aCorrectedSymbol = c; + aCorrectedSymbol = OUString(c); bCorrected = true; } break; @@ -1972,7 +1979,7 @@ OpCode FormulaCompiler::NextToken() { // *- instead of -* aCorrectedFormula.SetChar( nPos, mxSymbols->getSymbol( ocMul).GetChar(0) ); - aCorrectedSymbol = c; + aCorrectedSymbol = OUString(c); bCorrected = true; } break; @@ -1981,7 +1988,7 @@ OpCode FormulaCompiler::NextToken() { // /- instead of -/ aCorrectedFormula.SetChar( nPos, mxSymbols->getSymbol( ocDiv).GetChar(0) ); - aCorrectedSymbol = c; + aCorrectedSymbol = OUString(c); bCorrected = true; } break; @@ -2067,7 +2074,7 @@ void FormulaCompiler::PushTokenArray( FormulaTokenArray* pa, bool bTemp ) if ( bAutoCorrect && !pStack ) { // don't merge stacked subroutine code into entered formula aCorrectedFormula += aCorrectedSymbol; - aCorrectedSymbol.Erase(); + aCorrectedSymbol = ""; } FormulaArrayStack* p = new FormulaArrayStack; p->pNext = pStack; diff --git a/include/formula/FormulaCompiler.hxx b/include/formula/FormulaCompiler.hxx index 28bf5f928075..0328e39f4048 100644 --- a/include/formula/FormulaCompiler.hxx +++ b/include/formula/FormulaCompiler.hxx @@ -245,6 +245,8 @@ public: void CreateStringFromTokenArray( String& rFormula ); void CreateStringFromTokenArray( OUStringBuffer& rBuffer ); + FormulaToken* CreateStringFromToken( OUString& rFormula, FormulaToken* pToken, + bool bAllowArrAdvance = false ); FormulaToken* CreateStringFromToken( String& rFormula, FormulaToken* pToken, bool bAllowArrAdvance = false ); FormulaToken* CreateStringFromToken( OUStringBuffer& rBuffer, FormulaToken* pToken, @@ -306,7 +308,7 @@ protected: bool MergeRangeReference( FormulaToken * * const pCode1, FormulaToken * const * const pCode2 ); String aCorrectedFormula; // autocorrected Formula - String aCorrectedSymbol; // autocorrected Symbol + OUString aCorrectedSymbol; // autocorrected Symbol OpCodeMapPtr mxSymbols; // which symbols are used diff --git a/sc/source/core/tool/compiler.cxx b/sc/source/core/tool/compiler.cxx index a6b3e196cd77..01e6077ca8e9 100644 --- a/sc/source/core/tool/compiler.cxx +++ b/sc/source/core/tool/compiler.cxx @@ -3232,33 +3232,33 @@ bool ScCompiler::IsErrorConstant( const String& rName ) const void ScCompiler::AutoCorrectParsedSymbol() { - xub_StrLen nPos = aCorrectedSymbol.Len(); + sal_Int32 nPos = aCorrectedSymbol.getLength(); if ( nPos ) { nPos--; const sal_Unicode cQuote = '\"'; const sal_Unicode cx = 'x'; const sal_Unicode cX = 'X'; - sal_Unicode c1 = aCorrectedSymbol.GetChar( 0 ); - sal_Unicode c2 = aCorrectedSymbol.GetChar( nPos ); - sal_Unicode c2p = nPos > 0 ? aCorrectedSymbol.GetChar( nPos-1 ) : 0; + sal_Unicode c1 = aCorrectedSymbol[0]; + sal_Unicode c2 = aCorrectedSymbol[nPos]; + sal_Unicode c2p = nPos > 0 ? aCorrectedSymbol[nPos-1] : 0; if ( c1 == cQuote && c2 != cQuote ) { // "... // What's not a word doesn't belong to it. // Don't be pedantic: c < 128 should be sufficient here. - while ( nPos && ((aCorrectedSymbol.GetChar(nPos) < 128) && - ((GetCharTableFlags(aCorrectedSymbol.GetChar(nPos), aCorrectedSymbol.GetChar(nPos-1)) & + while ( nPos && ((aCorrectedSymbol[nPos] < 128) && + ((GetCharTableFlags(aCorrectedSymbol[nPos], aCorrectedSymbol[nPos-1]) & (SC_COMPILER_C_WORD | SC_COMPILER_C_CHAR_DONTCARE)) == 0)) ) nPos--; if ( nPos == MAXSTRLEN - 2 ) - aCorrectedSymbol.SetChar( nPos, cQuote ); // '"' the 255th character + aCorrectedSymbol = aCorrectedSymbol.replaceAt( nPos, 1, OUString(cQuote) ); // '"' the 255th character else - aCorrectedSymbol.Insert( cQuote, nPos + 1 ); + aCorrectedSymbol = aCorrectedSymbol.replaceAt( nPos + 1, 0, OUString(cQuote) ); bCorrected = true; } else if ( c1 != cQuote && c2 == cQuote ) { // ..." - aCorrectedSymbol.Insert( cQuote, 0 ); + aCorrectedSymbol = OUString(cQuote) + aCorrectedSymbol; bCorrected = true; } else if ( nPos == 0 && (c1 == cx || c1 == cX) ) @@ -3272,20 +3272,14 @@ void ScCompiler::AutoCorrectParsedSymbol() xub_StrLen nXcount; if ( (nXcount = comphelper::string::getTokenCount(aCorrectedSymbol, cx)) > 1 ) { // x => * - xub_StrLen nIndex = 0; sal_Unicode c = mxSymbols->getSymbol(ocMul).GetChar(0); - while ( (nIndex = aCorrectedSymbol.SearchAndReplace( - cx, c, nIndex )) != STRING_NOTFOUND ) - nIndex++; + aCorrectedSymbol = aCorrectedSymbol.replaceAll(OUString(cx), OUString(c)); bCorrected = true; } if ( (nXcount = comphelper::string::getTokenCount(aCorrectedSymbol, cX)) > 1 ) { // X => * - xub_StrLen nIndex = 0; sal_Unicode c = mxSymbols->getSymbol(ocMul).GetChar(0); - while ( (nIndex = aCorrectedSymbol.SearchAndReplace( - cX, c, nIndex )) != STRING_NOTFOUND ) - nIndex++; + aCorrectedSymbol = aCorrectedSymbol.replaceAll(OUString(cX), OUString(c)); bCorrected = true; } } @@ -3412,7 +3406,7 @@ void ScCompiler::AutoCorrectParsedSymbol() aCorrectedSymbol += aRef[0]; if ( nRefs == 2 ) { - aCorrectedSymbol += ':'; + aCorrectedSymbol += ":"; aCorrectedSymbol += aTab[1]; aCorrectedSymbol += aRef[1]; } @@ -3671,7 +3665,7 @@ ScTokenArray* ScCompiler::CompileString( const OUString& rFormula ) if ( bAutoCorrect ) { aCorrectedFormula.Erase(); - aCorrectedSymbol.Erase(); + aCorrectedSymbol = ""; } sal_uInt8 nForced = 0; // ==formula forces recalc even if cell is not visible if( aFormula.GetChar(nSrcPos) == '=' ) @@ -3732,7 +3726,7 @@ ScTokenArray* ScCompiler::CompileString( const OUString& rFormula ) if ( bAutoCorrect ) { bCorrected = true; - aCorrectedSymbol.Erase(); + aCorrectedSymbol = ""; } } else @@ -3774,7 +3768,7 @@ ScTokenArray* ScCompiler::CompileString( const OUString& rFormula ) if ( bAutoCorrect ) { bCorrected = true; - aCorrectedSymbol.Erase(); + aCorrectedSymbol = ""; } } if (bPODF && nFunction) |