diff options
author | Eike Rathke <erack@redhat.com> | 2015-06-15 14:51:52 +0200 |
---|---|---|
committer | Eike Rathke <erack@redhat.com> | 2015-06-15 17:52:16 +0200 |
commit | 1d463600f4db2993838c7660da2cb87aa19218fd (patch) | |
tree | 9679701e0ab6da444e912abf48f02e59c8cafbd8 /formula/source | |
parent | 09c5a9d41e03b3137ce47b9f9419290525458337 (diff) |
prepare ReplaceToken() to replace also in RPN
Change-Id: I98fbcb9849f2c2b1f26109a54ecbf5347cdd8b4e
Diffstat (limited to 'formula/source')
-rw-r--r-- | formula/source/core/api/token.cxx | 26 |
1 files changed, 22 insertions, 4 deletions
diff --git a/formula/source/core/api/token.cxx b/formula/source/core/api/token.cxx index a5e93923e971..0d272fb1baf2 100644 --- a/formula/source/core/api/token.cxx +++ b/formula/source/core/api/token.cxx @@ -848,15 +848,33 @@ FormulaToken* FormulaTokenArray::MergeArray( ) return NULL; } -FormulaToken* FormulaTokenArray::ReplaceToken( sal_uInt16 nOffset, FormulaToken* t ) +FormulaToken* FormulaTokenArray::ReplaceToken( sal_uInt16 nOffset, FormulaToken* t, + FormulaTokenArray::ReplaceMode eMode ) { + if (eMode == BACKWARD_CODE_ONLY) + nOffset = nLen - nOffset - 1; + if (nOffset < nLen) { CheckToken(*t); - sal_uInt16 nPos = nLen - nOffset - 1; t->IncRef(); - pCode[nPos]->DecRef(); - pCode[nPos] = t; + FormulaToken* p = pCode[nOffset]; + pCode[nOffset] = t; + if (eMode == FORWARD_CODE_AND_RPN && p->GetRef() > 1) + { + for (sal_uInt16 i=0; i < nRPN; ++i) + { + if (pRPN[i] == p) + { + t->IncRef(); + pRPN[i] = t; + p->DecRef(); + if (p->GetRef() == 1) + break; // for + } + } + } + p->DecRef(); // may be dead now return t; } else |