[Libreoffice-commits] .: 2 commits - sw/source

Philipp Riemer priemer at kemper.freedesktop.org
Sun Jul 1 17:21:06 PDT 2012


 sw/source/core/bastyp/SwSmartTagMgr.cxx |    2 
 sw/source/core/bastyp/bparr.cxx         |  224 ++--
 sw/source/core/bastyp/breakit.cxx       |   43 
 sw/source/core/bastyp/calc.cxx          | 1542 +++++++++++++++-----------------
 sw/source/core/bastyp/index.cxx         |   92 -
 sw/source/core/bastyp/init.cxx          |  331 +++---
 sw/source/core/bastyp/ring.cxx          |   24 
 sw/source/core/bastyp/swcache.cxx       |  115 --
 sw/source/core/bastyp/swrect.cxx        |  105 --
 sw/source/core/bastyp/swregion.cxx      |  120 --
 sw/source/core/bastyp/swtypes.cxx       |   18 
 sw/source/core/bastyp/tabcol.cxx        |   16 
 12 files changed, 1185 insertions(+), 1447 deletions(-)

New commits:
commit 517d3875fef75c72768fbd9211d6480ec4b17355
Author: Philipp Riemer <ruderphilipp at gmail.com>
Date:   Mon Jul 2 02:20:33 2012 +0200

    Moving code for better readability in sw/source/core/bastyp/
    
    Change-Id: Ibee47704db9c4fa2a15004c1ba7566dae2aa1d1c

diff --git a/sw/source/core/bastyp/bparr.cxx b/sw/source/core/bastyp/bparr.cxx
index 1851cd6..015a0d7 100644
--- a/sw/source/core/bastyp/bparr.cxx
+++ b/sw/source/core/bastyp/bparr.cxx
@@ -330,8 +330,8 @@ void BigPtrArray::Insert( const ElementPtr& rElem, sal_uLong pos )
     if( pos != p->nElem )
     {
         int nCount = p->nElem - sal_uInt16(pos);
-        ElementPtr *pFrom = p->pData + p->nElem,
-                            *pTo = pFrom + 1;
+        ElementPtr *pFrom = p->pData + p->nElem;
+        ElementPtr *pTo   = pFrom + 1;
         while( nCount-- )
             ++( *--pTo = *--pFrom )->nOffset;
     }
@@ -368,8 +368,8 @@ void BigPtrArray::Remove( sal_uLong pos, sal_uLong n )
         // move elements if needed
         if( ( pos + nel ) < sal_uLong(p->nElem) )
         {
-            ElementPtr *pTo = p->pData + pos,
-                                *pFrom = pTo + nel;
+            ElementPtr *pTo = p->pData + pos;
+            ElementPtr *pFrom = pTo + nel;
             int nCount = p->nElem - nel - sal_uInt16(pos);
             while( nCount-- )
             {
diff --git a/sw/source/core/bastyp/index.cxx b/sw/source/core/bastyp/index.cxx
index 833cb16..787d421 100644
--- a/sw/source/core/bastyp/index.cxx
+++ b/sw/source/core/bastyp/index.cxx
@@ -278,6 +278,22 @@ void SwIndexReg::Update( SwIndex const & rIdx, const xub_StrLen nDiff,
     }
 }
 
+void SwIndexReg::MoveTo( SwIndexReg& rArr )
+{
+    if (this != &rArr && m_pFirst)
+    {
+        SwIndex * pIdx = const_cast<SwIndex*>(m_pFirst);
+        SwIndex * pNext;
+        while( pIdx )
+        {
+            pNext = pIdx->m_pNext;
+            pIdx->Assign( &rArr, pIdx->GetIndex() );
+            pIdx = pNext;
+        }
+        m_pFirst = 0, m_pLast = 0;
+    }
+}
+
 #ifdef DBG_UTIL
 
 // -------
@@ -378,20 +394,4 @@ SwIndex& SwIndex::operator= ( xub_StrLen const nVal )
 
 #endif
 
-void SwIndexReg::MoveTo( SwIndexReg& rArr )
-{
-    if (this != &rArr && m_pFirst)
-    {
-        SwIndex * pIdx = const_cast<SwIndex*>(m_pFirst);
-        SwIndex * pNext;
-        while( pIdx )
-        {
-            pNext = pIdx->m_pNext;
-            pIdx->Assign( &rArr, pIdx->GetIndex() );
-            pIdx = pNext;
-        }
-        m_pFirst = 0, m_pLast = 0;
-    }
-}
-
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sw/source/core/bastyp/swcache.cxx b/sw/source/core/bastyp/swcache.cxx
index 4aa3108..ab1854b 100644
--- a/sw/source/core/bastyp/swcache.cxx
+++ b/sw/source/core/bastyp/swcache.cxx
@@ -30,12 +30,6 @@
 #include <rtl/strbuf.hxx>
 
 #ifdef DBG_UTIL
-#define INCREMENT( nVar )   ++nVar
-#else
-#define INCREMENT( nVar )
-#endif
-
-#ifdef DBG_UTIL
 void SwCache::Check()
 {
     if ( !pRealFirst )
@@ -70,11 +64,12 @@ void SwCache::Check()
         size() == nCurMax && nCurMax != aFreePositions.size() + nCnt, "sw",
         "Lost FreePositions." );
 }
-#endif
 
-#ifdef DBG_UTIL
+#define INCREMENT( nVar )   ++nVar
 #define CHECK Check();
+
 #else
+#define INCREMENT( nVar )
 #define CHECK
 #endif
 
diff --git a/sw/source/core/bastyp/swrect.cxx b/sw/source/core/bastyp/swrect.cxx
index 4b8c4c4..a905dd3 100644
--- a/sw/source/core/bastyp/swrect.cxx
+++ b/sw/source/core/bastyp/swrect.cxx
@@ -129,20 +129,20 @@ sal_Bool SwRect::IsInside( const Point& rPoint ) const
 // mouse moving of table borders
 sal_Bool SwRect::IsNear( const Point& rPoint, long nTolerance ) const
 {
-    return    IsInside(rPoint) ||
-        (((Left() - nTolerance)  <= rPoint.X())
-           && ((Top()  - nTolerance)  <= rPoint.Y())
-           && ((Right() + nTolerance) >= rPoint.X())
-           && ((Bottom()  + nTolerance)>= rPoint.Y()));
+    sal_Bool InTolerance = (((Left()   - nTolerance) <= rPoint.X()) &&
+                            ((Top()    - nTolerance) <= rPoint.Y()) &&
+                            ((Right()  + nTolerance) >= rPoint.X()) &&
+                            ((Bottom() + nTolerance) >= rPoint.Y()));
+    return IsInside(rPoint) || InTolerance;
 }
 
 
 sal_Bool SwRect::IsOver( const SwRect& rRect ) const
 {
-    return    (Top()   <= rRect.Bottom())
-           && (Left()  <= rRect.Right())
-           && (Right() >= rRect.Left())
-           && (Bottom()>= rRect.Top()) ? sal_True : sal_False;
+    return (Top()   <= rRect.Bottom()) &&
+           (Left()  <= rRect.Right())  &&
+           (Right() >= rRect.Left())   &&
+           (Bottom()>= rRect.Top());
 }
 
 void SwRect::Justify()
commit e3865adb873baa862bfc53339a6867f30f83643a
Author: Philipp Riemer <ruderphilipp at gmail.com>
Date:   Mon Jul 2 02:16:30 2012 +0200

    Code cleanup and translation of German comments in "sw/source/core/bastyp/"
    
    Change-Id: I9ba6f198fbc0f1a4655a57116f53719ea7d38fbd

diff --git a/sw/source/core/bastyp/SwSmartTagMgr.cxx b/sw/source/core/bastyp/SwSmartTagMgr.cxx
index fefddd0..389deac 100644
--- a/sw/source/core/bastyp/SwSmartTagMgr.cxx
+++ b/sw/source/core/bastyp/SwSmartTagMgr.cxx
@@ -58,7 +58,6 @@ SwSmartTagMgr::~SwSmartTagMgr()
 {
 }
 
-// ::com::sun::star::util::XModifyListener
 void SwSmartTagMgr::modified( const lang::EventObject& rEO ) throw( RuntimeException )
 {
     SolarMutexGuard aGuard;
@@ -69,7 +68,6 @@ void SwSmartTagMgr::modified( const lang::EventObject& rEO ) throw( RuntimeExcep
     SmartTagMgr::modified( rEO );
 }
 
-// ::com::sun::star::util::XChangesListener
 void SwSmartTagMgr::changesOccurred( const util::ChangesEvent& rEvent ) throw( RuntimeException)
 {
     SolarMutexGuard aGuard;
diff --git a/sw/source/core/bastyp/bparr.cxx b/sw/source/core/bastyp/bparr.cxx
index aa6c5ed..1851cd6 100644
--- a/sw/source/core/bastyp/bparr.cxx
+++ b/sw/source/core/bastyp/bparr.cxx
@@ -30,45 +30,37 @@
 #include <limits.h>
 #include "bparr.hxx"
 
-// die Blockverwaltung waechst/schrumpft immer um 20 Bloecke, das sind dann
-// immer ~ 20 * MAXENTRY == 20000 Eintraege
+/** Resize block management by this constant.
+    As a result there are approx. 20 * MAXENTRY == 20000 entries available */
 const sal_uInt16 nBlockGrowSize = 20;
 
 #if OSL_DEBUG_LEVEL > 2
-
 #define CHECKIDX( p, n, i, c ) CheckIdx( p, n, i, c );
-
 void CheckIdx( BlockInfo** ppInf, sal_uInt16 nBlock, sal_uLong nSize, sal_uInt16 nCur )
 {
-    assert(!nSize || nCur < nBlock); // BigPtrArray: CurIndex invalid
+    assert( !nSize || nCur < nBlock ); // BigPtrArray: CurIndex invalid
 
     sal_uLong nIdx = 0;
     for( sal_uInt16 nCnt = 0; nCnt < nBlock; ++nCnt, ++ppInf )
     {
         nIdx += (*ppInf)->nElem;
         // Array with holes is not allowed
-        assert(!nCnt || (*(ppInf-1))->nEnd + 1 == (*ppInf)->nStart);
+        assert( !nCnt || (*(ppInf-1))->nEnd + 1 == (*ppInf)->nStart );
     }
     assert(nIdx == nSize); // invalid count in nSize
 }
-
 #else
-
 #define CHECKIDX( p, n, i, c )
-
 #endif
 
-
 BigPtrArray::BigPtrArray()
 {
     nBlock = nCur = 0;
     nSize = 0;
-    nMaxBlock = nBlockGrowSize;     // == 20 * 1000 Eintraege
+    nMaxBlock = nBlockGrowSize;
     ppInf = new BlockInfo* [ nMaxBlock ];
 }
 
-
-
 BigPtrArray::~BigPtrArray()
 {
     if( nBlock )
@@ -83,21 +75,24 @@ BigPtrArray::~BigPtrArray()
     delete[] ppInf;
 }
 
-// Auch der Move ist schlicht. Optimieren ist hier wg. der
-// Stueckelung des Feldes zwecklos!
-
+// Also moving is done simply here. Optimization is useless because of the
+// division of this field into multiple parts.
 void BigPtrArray::Move( sal_uLong from, sal_uLong to )
 {
     sal_uInt16 cur = Index2Block( from );
     BlockInfo* p = ppInf[ cur ];
     ElementPtr pElem = p->pData[ from - p->nStart ];
-    Insert( pElem, to );            // erst einfuegen, dann loeschen !!!!
+    Insert( pElem, to ); // insert first, then delete!
     Remove( ( to < from ) ? ( from + 1 ) : from );
 }
 
-// das Ende ist EXCLUSIV
-
+/** Apply function to every element.
 
+    @param nStart First element to start with
+    @param nEnd   Last element (exclusive!)
+    @param fn     Function
+    @param pArgs  Additional arguments for <fn>
+*/
 void BigPtrArray::ForEach( sal_uLong nStart, sal_uLong nEnd,
                             FnForEach fn, void* pArgs )
 {
@@ -117,10 +112,10 @@ void BigPtrArray::ForEach( sal_uLong nStart, sal_uLong nEnd,
             if( !(*fn)( *pElem++, pArgs ) || ++nStart >= nEnd )
                 break;
 
-            // naechstes Element
+            // next element
             if( !--nElem )
             {
-                // neuer Block
+                // new block
                 p = *++pp;
                 pElem = p->pData;
                 nElem = p->nElem;
@@ -129,11 +124,10 @@ void BigPtrArray::ForEach( sal_uLong nStart, sal_uLong nEnd,
     }
 }
 
-
 ElementPtr BigPtrArray::operator[]( sal_uLong idx ) const
 {
     assert(idx < nSize); // operator[]: Index out of bounds
-    // weil die Funktion eben doch nicht const ist:
+    // because this function is not <const>:
     BigPtrArray* pThis = (BigPtrArray*) this;
     sal_uInt16 cur = Index2Block( idx );
     BlockInfo* p = ppInf[ cur ];
@@ -141,45 +135,33 @@ ElementPtr BigPtrArray::operator[]( sal_uLong idx ) const
     return p->pData[ idx - p->nStart ];
 }
 
-///////////////////////////////////////////////////////////////////////////
-
-// private Methoden
-
-// Suchen des Blocks einer bestimmten Position
-// Algorithmus:
-// 1. Test, ob der letzte Block der gesuchte Block ist
-// 2. Sonderfall: Index = 0?
-// 3. Test der Nachbarbloecke
-
-// 4. Binaere Suche
-
-
-
+/** Search a block at a given position */
 sal_uInt16 BigPtrArray::Index2Block( sal_uLong pos ) const
 {
-    // zuletzt verwendeter Block?
+    // last used block?
     BlockInfo* p = ppInf[ nCur ];
     if( p->nStart <= pos && p->nEnd >= pos )
         return nCur;
     // Index = 0?
     if( !pos )
         return 0;
-    // Folgeblock?
+
+    // following one?
     if( nCur < ( nBlock - 1 ) )
     {
         p = ppInf[ nCur+1 ];
         if( p->nStart <= pos && p->nEnd >= pos )
             return nCur+1;
     }
-    // vorangehender Block?
+    // previous one?
     else if( pos < p->nStart && nCur > 0 )
     {
         p = ppInf[ nCur-1 ];
         if( p->nStart <= pos && p->nEnd >= pos )
             return nCur-1;
     }
-    // Binaere Suche:
-    // Diese fuehrt immer zum Erfolg
+
+    // binary search: always successful
     sal_uInt16 lower = 0, upper = nBlock - 1;
     sal_uInt16 cur = 0;
     for(;;)
@@ -189,6 +171,7 @@ sal_uInt16 BigPtrArray::Index2Block( sal_uLong pos ) const
         p = ppInf[ cur ];
         if( p->nStart <= pos && p->nEnd >= pos )
             return cur;
+
         if( p->nStart > pos )
             upper = cur;
         else
@@ -196,11 +179,10 @@ sal_uInt16 BigPtrArray::Index2Block( sal_uLong pos ) const
     }
 }
 
+/** Update all index areas
 
-// Update aller Indexbereiche ab einer bestimmten Position
-
-// pos bezeichnet den letzten korrekten Block
-
+    @param pos last correct block (starting point)
+*/
 void BigPtrArray::UpdIndex( sal_uInt16 pos )
 {
     BlockInfo** pp = ppInf + pos;
@@ -210,22 +192,22 @@ void BigPtrArray::UpdIndex( sal_uInt16 pos )
     {
         p = *++pp;
         p->nStart = idx;
-        idx       += p->nElem;
-        p->nEnd   = idx - 1;
+        idx += p->nElem;
+        p->nEnd = idx - 1;
     }
 }
 
-// Einrichten eines neuen Blocks an einer bestimmten Position
-
-// Vorhandene Blocks werden nach hinten verschoben
-
+/** Create and insert new block
 
+    Existing blocks will be moved rearward.
 
+    @param pos Position at which the new block should be created.
+*/
 BlockInfo* BigPtrArray::InsBlock( sal_uInt16 pos )
 {
     if( nBlock == nMaxBlock )
     {
-        // dann sollte wir mal das Array erweitern
+        // than extend the array first
         BlockInfo** ppNew = new BlockInfo* [ nMaxBlock + nBlockGrowSize ];
         memcpy( ppNew, ppInf, nMaxBlock * sizeof( BlockInfo* ));
         delete[] ppInf;
@@ -233,8 +215,10 @@ BlockInfo* BigPtrArray::InsBlock( sal_uInt16 pos )
         ppInf = ppNew;
     }
     if( pos != nBlock )
-        memmove( ppInf + pos+1, ppInf + pos ,
-                 ( nBlock - pos ) * sizeof (BlockInfo*) );
+    {
+        memmove( ppInf + pos+1, ppInf + pos,
+                 ( nBlock - pos ) * sizeof( BlockInfo* ));
+    }
     ++nBlock;
     BlockInfo* p = new BlockInfo;
     ppInf[ pos ] = p;
@@ -243,7 +227,8 @@ BlockInfo* BigPtrArray::InsBlock( sal_uInt16 pos )
         p->nStart = p->nEnd = ppInf[ pos-1 ]->nEnd + 1;
     else
         p->nStart = p->nEnd = 0;
-    p->nEnd--;  // keine Elemente
+
+    p->nEnd--;  // no elements
     p->nElem = 0;
     p->pData = new ElementPtr [ MAXENTRY ];
     p->pBigArr = this;
@@ -255,7 +240,7 @@ void BigPtrArray::BlockDel( sal_uInt16 nDel )
     nBlock = nBlock - nDel;
     if( nMaxBlock - nBlock > nBlockGrowSize )
     {
-        // dann koennen wir wieder schrumpfen
+        // than shrink array
         nDel = (( nBlock / nBlockGrowSize ) + 1 ) * nBlockGrowSize;
         BlockInfo** ppNew = new BlockInfo* [ nDel ];
         memcpy( ppNew, ppInf, nBlock * sizeof( BlockInfo* ));
@@ -265,7 +250,6 @@ void BigPtrArray::BlockDel( sal_uInt16 nDel )
     }
 }
 
-
 void BigPtrArray::Insert( const ElementPtr& rElem, sal_uLong pos )
 {
     CHECKIDX( ppInf, nBlock, nSize, nCur );
@@ -273,26 +257,29 @@ void BigPtrArray::Insert( const ElementPtr& rElem, sal_uLong pos )
     BlockInfo* p;
     sal_uInt16 cur;
     if( !nSize )
-        // Sonderfall: erstes Element einfuegen
+    {
+        // special case: insert first element
         p = InsBlock( cur = 0 );
+    }
     else if( pos == nSize )
     {
-        // Sonderfall: Einfuegen am Ende
+        // special case: insert at end
         cur = nBlock - 1;
         p = ppInf[ cur ];
         if( p->nElem == MAXENTRY )
-            // Der letzte Block ist voll, neuen anlegen
+            // the last block is full, create a new one
             p = InsBlock( ++cur );
     }
     else
     {
-        // Standardfall:
+        // standard case:
         cur = Index2Block( pos );
         p = ppInf[ cur ];
     }
+
     if( p->nElem == MAXENTRY )
     {
-        // passt der letzte Eintrag in den naechsten Block?
+        // does the last entry fit into the next block?
         BlockInfo* q;
         if( cur < ( nBlock - 1 ) && ppInf[ cur+1 ]->nElem < MAXENTRY )
         {
@@ -310,19 +297,14 @@ void BigPtrArray::Insert( const ElementPtr& rElem, sal_uLong pos )
         }
         else
         {
-            // Wenn er auch nicht in den Folgeblock passt, muss ein
-            // neuer Block eingefuegt werden
-            // erst mal bei Bedarf komprimieren
-
-            // wenn mehr als 50% "Luft" im Array ist, dann sollte man mal das
-            // Compress aufrufen
+            // If it does not fit, then insert a new block. But if there is more
+            // than 50% space in the array then compress first.
             if( /*nBlock == nMaxBlock &&*/
                 nBlock > ( nSize / ( MAXENTRY / 2 ) ) &&
                 cur >= Compress() )
             {
-                // es wurde vor der akt. Pos etwas verschoben und alle
-                // Pointer koennen ungueltig sein. Also das Insert
-                // nochmals aufsetzen
+                // Something was moved before the current position and all
+                // pointer might be invalid. Thus restart Insert.
                 Insert( rElem, pos );
                 return ;
             }
@@ -330,7 +312,7 @@ void BigPtrArray::Insert( const ElementPtr& rElem, sal_uLong pos )
             q = InsBlock( cur+1 );
         }
 
-        // Eintrag passt nicht mehr. Dann muss Platz gemacht werden
+        // entry does not fit anymore - clear space
         ElementPtr pLast = p->pData[ MAXENTRY-1 ];
         pLast->nOffset = 0;
         pLast->pBlock = q;
@@ -342,7 +324,7 @@ void BigPtrArray::Insert( const ElementPtr& rElem, sal_uLong pos )
         p->nEnd--;
         p->nElem--;
     }
-    // Nun haben wir einen freien Block am Wickel: eintragen
+    // now we have free space - insert
     pos -= p->nStart;
     assert(pos < MAXENTRY);
     if( pos != p->nElem )
@@ -353,7 +335,7 @@ void BigPtrArray::Insert( const ElementPtr& rElem, sal_uLong pos )
         while( nCount-- )
             ++( *--pTo = *--pFrom )->nOffset;
     }
-    // Element eintragen und Indexe updaten
+    // insert element and update indices
     ((ElementPtr&)rElem)->nOffset = sal_uInt16(pos);
     ((ElementPtr&)rElem)->pBlock = p;
     p->pData[ pos ] = rElem;
@@ -370,19 +352,20 @@ void BigPtrArray::Remove( sal_uLong pos, sal_uLong n )
 {
     CHECKIDX( ppInf, nBlock, nSize, nCur );
 
-    sal_uInt16 nBlkdel = 0;                 // entfernte Bloecke
-    sal_uInt16 cur = Index2Block( pos );    // aktuelle Blocknr
-    sal_uInt16 nBlk1 = cur;                 // 1. behandelter Block
-    sal_uInt16 nBlk1del = USHRT_MAX;        // 1. entfernter Block
+    sal_uInt16 nBlkdel = 0;              // deleted blocks
+    sal_uInt16 cur = Index2Block( pos ); // current block number
+    sal_uInt16 nBlk1 = cur;              // 1st treated block
+    sal_uInt16 nBlk1del = USHRT_MAX;     // 1st deleted block
     BlockInfo* p = ppInf[ cur ];
     pos -= p->nStart;
+
     sal_uLong nElem = n;
     while( nElem )
     {
         sal_uInt16 nel = p->nElem - sal_uInt16(pos);
         if( sal_uLong(nel) > nElem )
             nel = sal_uInt16(nElem);
-        // Eventuell Elemente verschieben
+        // move elements if needed
         if( ( pos + nel ) < sal_uLong(p->nElem) )
         {
             ElementPtr *pTo = p->pData + pos,
@@ -397,9 +380,9 @@ void BigPtrArray::Remove( sal_uLong pos, sal_uLong n )
         }
         p->nEnd -= nel;
         p->nElem = p->nElem - nel;
+        // possibly delete block completely
         if( !p->nElem )
         {
-            // eventuell Block ganz entfernen
             delete[] p->pData;
             nBlkdel++;
             if( USHRT_MAX == nBlk1del )
@@ -411,10 +394,10 @@ void BigPtrArray::Remove( sal_uLong pos, sal_uLong n )
         p = ppInf[ ++cur ];
         pos = 0;
     }
-    // Am Ende die Tabelle updaten, falls Bloecke geloescht waren
+
+    // update table if blocks were removed
     if( nBlkdel )
     {
-        // loeschen sollte man immer !!
         for( sal_uInt16 i = nBlk1del; i < ( nBlk1del + nBlkdel ); i++ )
             delete ppInf[ i ];
 
@@ -423,8 +406,7 @@ void BigPtrArray::Remove( sal_uLong pos, sal_uLong n )
             memmove( ppInf + nBlk1del, ppInf + nBlk1del + nBlkdel,
                      ( nBlock - nBlkdel - nBlk1del ) * sizeof( BlockInfo* ) );
 
-            // JP 19.07.95: nicht den ersten behandelten, sondern den davor!!
-            //              UpdateIdx updatet nur alle Nachfolgende!!
+            // UpdateIdx updates the successor thus start before first elem
             if( !nBlk1 )
             {
                 p = ppInf[ 0 ];
@@ -432,9 +414,11 @@ void BigPtrArray::Remove( sal_uLong pos, sal_uLong n )
                 p->nEnd = p->nElem-1;
             }
             else
+            {
                 --nBlk1;
+            }
         }
-        BlockDel( nBlkdel );            // es wurden Bloecke geloescht
+        BlockDel( nBlkdel ); // blocks were deleted
     }
 
     nSize -= n;
@@ -442,19 +426,17 @@ void BigPtrArray::Remove( sal_uLong pos, sal_uLong n )
         UpdIndex( nBlk1 );
     nCur = nBlk1;
 
-    // wenn mehr als 50% "Luft" im Array ist, dann sollte man mal das
-    // Compress aufrufen
+    // call Compress() if there is more than 50% space in the array
     if( nBlock > ( nSize / ( MAXENTRY / 2 ) ) )
         Compress();
 
     CHECKIDX( ppInf, nBlock, nSize, nCur );
 }
 
-
 void BigPtrArray::Replace( sal_uLong idx, const ElementPtr& rElem)
 {
     assert(idx < nSize); // Index out of bounds
-    // weil die Funktion eben doch nicht const ist:
+    // because this function ist not <const>:
     BigPtrArray* pThis = (BigPtrArray*) this;
     sal_uInt16 cur = Index2Block( idx );
     BlockInfo* p = ppInf[ cur ];
@@ -464,37 +446,32 @@ void BigPtrArray::Replace( sal_uLong idx, const ElementPtr& rElem)
     p->pData[ idx - p->nStart ] = rElem;
 }
 
-
-// Array komprimieren
-
+/** Compress the array */
 sal_uInt16 BigPtrArray::Compress( short nMax )
 {
     CHECKIDX( ppInf, nBlock, nSize, nCur );
 
-    // Es wird von vorne nach hinten ueber das InfoBlock Array iteriert.
-    // Wenn zwischen durch Block gel�scht werden, dann mussen alle
-    // nachfolgenden verschoben werden. Dazu werden die Pointer pp und qq
-    // benutzt; wobei pp das "alte" Array, qq das "neue" Array ist.
+    // Iterate over InfoBlock array from beginning to end. If there is a deleted
+    // block in between so move all following ones accordingly. The pointer <pp>
+    // represents the "old" and <qq> the "new" array.
     BlockInfo** pp = ppInf, **qq = pp;
     BlockInfo* p;
-    BlockInfo* pLast(0);                // letzter nicht voller Block
-    sal_uInt16 nLast = 0;                   // fehlende Elemente
-    sal_uInt16 nBlkdel = 0;                 // Anzahl der geloeschte Bloecke
-    sal_uInt16 nFirstChgPos = USHRT_MAX;    // ab welcher Pos gab es die 1. Aenderung?
+    BlockInfo* pLast(0);                 // last empty block
+    sal_uInt16 nLast = 0;                // missing elements
+    sal_uInt16 nBlkdel = 0;              // number of deleted blocks
+    sal_uInt16 nFirstChgPos = USHRT_MAX; // at which position was the 1st change?
 
-    // von Fuell-Prozenten auf uebrige Eintrage umrechnen
+    // convert fill percentage into number of remaining elements
     nMax = MAXENTRY - (long) MAXENTRY * nMax / 100;
 
     for( sal_uInt16 cur = 0; cur < nBlock; ++cur )
     {
         p = *pp++;
         sal_uInt16 n = p->nElem;
-        // Testen, ob der noch nicht volle Block so gelassen wird
-        // dies ist der Fall, wenn der aktuelle Block gesplittet
-        // werden muesste, der noch nicht volle Block aber bereits
-        // ueber dem uebergebenen Break-Wert voll ist. In diesem
-        // Fall wird von einer weiteren Fuellung (die ja wegen dem
-        // zweifachen memmove() zeitaufwendig ist) abgesehen.
+        // Check if a not completely full block will be ignored. This happens if
+        // the current block would have to be split but the filling of the
+        // inspected block is already over its threshold value. In this case we
+        // do not fill more (it's expensive because of a double memmove() call)
         if( nLast && ( n > nLast ) && ( nLast < nMax ) )
             nLast = 0;
         if( nLast )
@@ -502,28 +479,30 @@ sal_uInt16 BigPtrArray::Compress( short nMax )
             if( USHRT_MAX == nFirstChgPos )
                 nFirstChgPos = cur;
 
-            // ein nicht voller Block vorhanden: auffuellen
+            // Not full yet? Than fill up.
             if( n > nLast )
                 n = nLast;
 
-            // Elemente uebertragen, vom akt. in den letzten
+            // move elements from current to last block
             ElementPtr* pElem = pLast->pData + pLast->nElem;
             ElementPtr* pFrom = p->pData;
             for( sal_uInt16 nCount = n, nOff = pLast->nElem;
                             nCount; --nCount, ++pElem )
+            {
                 *pElem = *pFrom++,
                     (*pElem)->pBlock = pLast,
                     (*pElem)->nOffset = nOff++;
+            }
 
-            // korrigieren
+            // adjustment
             pLast->nElem = pLast->nElem + n;
             nLast = nLast - n;
             p->nElem = p->nElem - n;
 
-            // Ist der aktuelle Block dadurch leer geworden?
+            // Is the current block now empty as a result?
             if( !p->nElem )
             {
-                // dann kann der entfernt werden
+                // than remove
                 delete[] p->pData;
                 delete   p, p = 0;
                 ++nBlkdel;
@@ -541,11 +520,11 @@ sal_uInt16 BigPtrArray::Compress( short nMax )
             }
         }
 
-        if( p )     // die Blockinfo wurde nicht geloescht
+        if( p ) // BlockInfo was not deleted
         {
-            *qq++ = p;      // dann setze sie an die richtige neue Position
+            *qq++ = p; // adjust to correct position
 
-            // eventuell den letzten halbvollen Block festhalten
+            // keep the potentially existing last half-full block
             if( !nLast && p->nElem < MAXENTRY )
             {
                 pLast = p;
@@ -554,11 +533,11 @@ sal_uInt16 BigPtrArray::Compress( short nMax )
         }
     }
 
-    // Bloecke geloescht wurden, ggfs. das BlockInfo Array verkuerzen
+    // if blocks were deleted shrink BlockInfo array if needed
     if( nBlkdel )
         BlockDel( nBlkdel );
 
-    // Und neu durchindizieren
+    // and re-index
     p = ppInf[ 0 ];
     p->nEnd = p->nElem - 1;
     UpdIndex( 0 );
@@ -571,5 +550,4 @@ sal_uInt16 BigPtrArray::Compress( short nMax )
     return nFirstChgPos;
 }
 
-
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sw/source/core/bastyp/breakit.cxx b/sw/source/core/bastyp/breakit.cxx
index 21cb4a9..1e4d398 100644
--- a/sw/source/core/bastyp/breakit.cxx
+++ b/sw/source/core/bastyp/breakit.cxx
@@ -26,7 +26,6 @@
  *
  ************************************************************************/
 
-
 #include "breakit.hxx"
 #include <unicode/uchar.h>
 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
@@ -40,10 +39,9 @@
 
 using namespace com::sun::star;
 
-SwBreakIt * pBreakIt = 0;
+SwBreakIt* pBreakIt = 0;
 
-void SwBreakIt::_Create(
-    const uno::Reference< lang::XMultiServiceFactory > & rxMSF)
+void SwBreakIt::_Create( const uno::Reference<lang::XMultiServiceFactory> & rxMSF )
 {
     delete pBreakIt, pBreakIt = new SwBreakIt( rxMSF );
 }
@@ -58,13 +56,12 @@ SwBreakIt * SwBreakIt::Get()
     return pBreakIt;
 }
 
-SwBreakIt::SwBreakIt(
-    const uno::Reference< lang::XMultiServiceFactory > & rxMSF)
+SwBreakIt::SwBreakIt( const uno::Reference<lang::XMultiServiceFactory> & rxMSF )
     : m_xMSF( rxMSF ),
       m_pLocale( NULL ),
       m_pForbidden( NULL ),
       aLast( LANGUAGE_DONTKNOW ),
-      aForbiddenLang( LANGUAGE_DONTKNOW)
+      aForbiddenLang( LANGUAGE_DONTKNOW )
 {
     OSL_ENSURE( m_xMSF.is(), "SwBreakIt: no MultiServiceFactory" );
 }
@@ -78,7 +75,9 @@ SwBreakIt::~SwBreakIt()
 void SwBreakIt::createBreakIterator() const
 {
     if ( m_xMSF.is() && !xBreak.is() )
-        xBreak.set(m_xMSF->createInstance(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.i18n.BreakIterator"))),uno::UNO_QUERY);
+        xBreak.set(m_xMSF->createInstance(::rtl::OUString(
+                     RTL_CONSTASCII_USTRINGPARAM("com.sun.star.i18n.BreakIterator"))),
+                   uno::UNO_QUERY);
 }
 
 void SwBreakIt::_GetLocale( const LanguageType aLang )
@@ -120,14 +119,19 @@ sal_uInt16 SwBreakIt::GetRealScriptOfText( const rtl::OUString& rTxt, sal_Int32
                     break;
             }
         }
-        if( i18n::ScriptType::WEAK == nScript && nPos &&
-            0 < (nChgPos = xBreak->beginOfScript( rTxt, nPos, nScript )) )
+        if( i18n::ScriptType::WEAK == nScript &&
+            nPos &&
+            0 < ( nChgPos = xBreak->beginOfScript( rTxt, nPos, nScript ) ) )
+        {
             nScript = xBreak->getScriptType( rTxt, nChgPos-1 );
+        }
 
-        if( i18n::ScriptType::WEAK == nScript && rTxt.getLength() >
-            ( nChgPos = xBreak->endOfScript( rTxt, nPos, nScript ) ) &&
+        if( i18n::ScriptType::WEAK == nScript &&
+            rTxt.getLength() > ( nChgPos = xBreak->endOfScript( rTxt, nPos, nScript ) ) &&
             0 <= nChgPos )
+        {
             nScript = xBreak->getScriptType( rTxt, nChgPos );
+        }
     }
     if( i18n::ScriptType::WEAK == nScript )
         nScript = GetI18NScriptTypeOfLanguage( (sal_uInt16)GetAppLanguage() );
@@ -137,12 +141,14 @@ sal_uInt16 SwBreakIt::GetRealScriptOfText( const rtl::OUString& rTxt, sal_Int32
 sal_uInt16 SwBreakIt::GetAllScriptsOfText( const rtl::OUString& rTxt ) const
 {
     const sal_uInt16 coAllScripts = ( SCRIPTTYPE_LATIN |
-                                  SCRIPTTYPE_ASIAN |
-                                  SCRIPTTYPE_COMPLEX );
+                                      SCRIPTTYPE_ASIAN |
+                                      SCRIPTTYPE_COMPLEX );
     createBreakIterator();
     sal_uInt16 nRet = 0, nScript;
     if( !xBreak.is() )
+    {
         nRet = coAllScripts;
+    }
     else if( !rTxt.isEmpty() )
     {
         for( sal_Int32 n = 0, nEnd = rTxt.getLength(); n < nEnd;
@@ -165,17 +171,20 @@ sal_uInt16 SwBreakIt::GetAllScriptsOfText( const rtl::OUString& rTxt ) const
     return nRet;
 }
 
-sal_Int32 SwBreakIt::getGraphemeCount(const rtl::OUString& rText, sal_Int32 nStart, sal_Int32 nEnd) const
+sal_Int32 SwBreakIt::getGraphemeCount(const rtl::OUString& rText,
+                                      sal_Int32 nStart, sal_Int32 nEnd) const
 {
     sal_Int32 nGraphemeCount = 0;
 
     sal_Int32 nCurPos = nStart;
     while (nCurPos < nEnd)
     {
-        //fdo#49208 cheat and assume that nothing can combine with a space
-        //to form a single grapheme
+        // fdo#49208 cheat and assume that nothing can combine with a space
+        // to form a single grapheme
         if (rText[nCurPos] == ' ')
+        {
             ++nCurPos;
+        }
         else
         {
             sal_Int32 nCount2 = 1;
diff --git a/sw/source/core/bastyp/calc.cxx b/sw/source/core/bastyp/calc.cxx
index 73baaf1..6250178 100644
--- a/sw/source/core/bastyp/calc.cxx
+++ b/sw/source/core/bastyp/calc.cxx
@@ -61,7 +61,7 @@
 
 using namespace ::com::sun::star;
 
-// tippt sich schneller
+// shortcut
 #define RESOURCE ViewShell::GetShellRes()
 
 const sal_Char sCalc_Add[]  =   "add";
@@ -79,8 +79,8 @@ const sal_Char sCalc_Eq[]   =   "eq";
 const sal_Char sCalc_Neq[]  =   "neq";
 const sal_Char sCalc_Leq[]  =   "leq";
 const sal_Char sCalc_Geq[]  =   "geq";
-const sal_Char sCalc_L[]        =   "l";
-const sal_Char sCalc_G[]        =   "g";
+const sal_Char sCalc_L[]    =   "l";
+const sal_Char sCalc_G[]    =   "g";
 const sal_Char sCalc_Sum[]  =   "sum";
 const sal_Char sCalc_Mean[] =   "mean";
 const sal_Char sCalc_Min[]  =   "min";
@@ -91,12 +91,10 @@ const sal_Char sCalc_Tan[]  =   "tan";
 const sal_Char sCalc_Asin[] =   "asin";
 const sal_Char sCalc_Acos[] =   "acos";
 const sal_Char sCalc_Atan[] =   "atan";
-const sal_Char sCalc_Round[]    =   "round";
+const sal_Char sCalc_Round[]=   "round";
 const sal_Char sCalc_Date[] =   "date";
 
-
-
-//!!!!! ACHTUNG - Sortierte Liste aller Operatoren !!!!!
+// ATTENTION: sorted list of all operators
 struct _CalcOp
 {
     union{
@@ -107,35 +105,35 @@ struct _CalcOp
 };
 
 _CalcOp const aOpTable[] = {
-/* ACOS */    {{sCalc_Acos},       CALC_ACOS},  // Arcuscosinus
+/* ACOS */    {{sCalc_Acos},       CALC_ACOS},  // Arc cosine
 /* ADD */     {{sCalc_Add},        CALC_PLUS},  // Addition
-/* AND */     {{sCalc_And},        CALC_AND},   // log. und
-/* ASIN */    {{sCalc_Asin},       CALC_ASIN},  // Arcussinus
-/* ATAN */    {{sCalc_Atan},       CALC_ATAN},  // Arcustangens
-/* COS */     {{sCalc_Cos},        CALC_COS},   // Cosinus
+/* AND */     {{sCalc_And},        CALC_AND},   // log. AND
+/* ASIN */    {{sCalc_Asin},       CALC_ASIN},  // Arc sine
+/* ATAN */    {{sCalc_Atan},       CALC_ATAN},  // Arc tangent
+/* COS */     {{sCalc_Cos},        CALC_COS},   // Cosine
 /* DATE */    {{sCalc_Date},       CALC_DATE},  // Date
-/* DIV */     {{sCalc_Div},        CALC_DIV},   // Dividieren
-/* EQ */      {{sCalc_Eq},         CALC_EQ},    // gleich
-/* G */       {{sCalc_G},          CALC_GRE},   // groesser
-/* GEQ */     {{sCalc_Geq},        CALC_GEQ},   // groesser gleich
-/* L */       {{sCalc_L},          CALC_LES},   // kleiner
-/* LEQ */     {{sCalc_Leq},        CALC_LEQ},   // kleiner gleich
-/* MAX */     {{sCalc_Max},        CALC_MAX},   // Maximalwert
-/* MEAN */    {{sCalc_Mean},       CALC_MEAN},  // Mittelwert
-/* MIN */     {{sCalc_Min},        CALC_MIN},   // Minimalwert
-/* MUL */     {{sCalc_Mul},        CALC_MUL},   // Multiplizieren
-/* NEQ */     {{sCalc_Neq},        CALC_NEQ},   // nicht gleich
-/* NOT */     {{sCalc_Not},        CALC_NOT},   // log. nicht
-/* OR */      {{sCalc_Or},         CALC_OR},    // log. oder
-/* PHD */     {{sCalc_Phd},        CALC_PHD},   // Prozent
-/* POW */     {{sCalc_Pow},        CALC_POW},   // Potenzieren
-/* ROUND */   {{sCalc_Round},      CALC_ROUND}, // Runden
-/* SIN */     {{sCalc_Sin},        CALC_SIN},   // Sinus
-/* SQRT */    {{sCalc_Sqrt},       CALC_SQRT},  // Wurzel
-/* SUB */     {{sCalc_Sub},        CALC_MINUS}, // Subtraktion
-/* SUM */     {{sCalc_Sum},        CALC_SUM},   // Summe
-/* TAN */     {{sCalc_Tan},        CALC_TAN},   // Tangens
-/* XOR */     {{sCalc_Xor},        CALC_XOR}    // log. xoder
+/* DIV */     {{sCalc_Div},        CALC_DIV},   // Division
+/* EQ */      {{sCalc_Eq},         CALC_EQ},    // Equality
+/* G */       {{sCalc_G},          CALC_GRE},   // Greater than
+/* GEQ */     {{sCalc_Geq},        CALC_GEQ},   // Greater or equal
+/* L */       {{sCalc_L},          CALC_LES},   // Less than
+/* LEQ */     {{sCalc_Leq},        CALC_LEQ},   // Less or equal
+/* MAX */     {{sCalc_Max},        CALC_MAX},   // Maximum value
+/* MEAN */    {{sCalc_Mean},       CALC_MEAN},  // Mean
+/* MIN */     {{sCalc_Min},        CALC_MIN},   // Minimum value
+/* MUL */     {{sCalc_Mul},        CALC_MUL},   // Multiplication
+/* NEQ */     {{sCalc_Neq},        CALC_NEQ},   // Not equal
+/* NOT */     {{sCalc_Not},        CALC_NOT},   // log. NOT
+/* OR */      {{sCalc_Or},         CALC_OR},    // log. OR
+/* PHD */     {{sCalc_Phd},        CALC_PHD},   // Percentage
+/* POW */     {{sCalc_Pow},        CALC_POW},   // Exponentiation
+/* ROUND */   {{sCalc_Round},      CALC_ROUND}, // Rounding
+/* SIN */     {{sCalc_Sin},        CALC_SIN},   // Sine
+/* SQRT */    {{sCalc_Sqrt},       CALC_SQRT},  // Square root
+/* SUB */     {{sCalc_Sub},        CALC_MINUS}, // Subtraction
+/* SUM */     {{sCalc_Sum},        CALC_SUM},   // Sum
+/* TAN */     {{sCalc_Tan},        CALC_TAN},   // Tangent
+/* XOR */     {{sCalc_Xor},        CALC_XOR}    // log. XOR
 };
 
 double const nRoundVal[] = {
@@ -149,18 +147,17 @@ double const nKorrVal[] = {
     9e-9, 9e-10, 9e-11, 9e-12, 9e-13, 9e-14
 };
 
-    // First character may be any alphabetic or underscore.
+// First character may be any alphabetic or underscore.
 const sal_Int32 coStartFlags =
         i18n::KParseTokens::ANY_LETTER_OR_NUMBER |
         i18n::KParseTokens::ASC_UNDERSCORE |
         i18n::KParseTokens::IGNORE_LEADING_WS;
 
-    // Continuing characters may be any alphanumeric or underscore or dot.
+// Continuing characters may be any alphanumeric, underscore, or dot.
 const sal_Int32 coContFlags =
     ( coStartFlags | i18n::KParseTokens::ASC_DOT )
         & ~i18n::KParseTokens::IGNORE_LEADING_WS;
 
-
 extern "C" {
 static int SAL_CALL OperatorCompare( const void *pFirst, const void *pSecond)
 {
@@ -169,23 +166,22 @@ static int SAL_CALL OperatorCompare( const void *pFirst, const void *pSecond)
     {
         if( CALC_NAME == ((_CalcOp*)pSecond)->eOp )
             nRet = ((_CalcOp*)pFirst)->pUName->CompareTo(
-                            *((_CalcOp*)pSecond)->pUName );
+                   *((_CalcOp*)pSecond)->pUName );
         else
             nRet = ((_CalcOp*)pFirst)->pUName->CompareToAscii(
-                            ((_CalcOp*)pSecond)->pName );
+                   ((_CalcOp*)pSecond)->pName );
     }
     else
     {
         if( CALC_NAME == ((_CalcOp*)pSecond)->eOp )
             nRet = -1 * ((_CalcOp*)pSecond)->pUName->CompareToAscii(
-                            ((_CalcOp*)pFirst)->pName );
+                        ((_CalcOp*)pFirst)->pName );
         else
             nRet = strcmp( ((_CalcOp*)pFirst)->pName,
-                            ((_CalcOp*)pSecond)->pName );
+                           ((_CalcOp*)pSecond)->pName );
     }
     return nRet;
 }
-
 }// extern "C"
 
 _CalcOp* FindOperator( const String& rSrch )
@@ -194,38 +190,41 @@ _CalcOp* FindOperator( const String& rSrch )
     aSrch.pUName = &rSrch;
     aSrch.eOp = CALC_NAME;
 
-    return (_CalcOp*)bsearch(   (void*) &aSrch,
-                                (void*) aOpTable,
-                                sizeof( aOpTable ) / sizeof( _CalcOp ),
-                                sizeof( _CalcOp ),
-                                OperatorCompare );
+    return (_CalcOp*)bsearch( (void*) &aSrch,
+                              (void*) aOpTable,
+                              sizeof( aOpTable ) / sizeof( _CalcOp ),
+                              sizeof( _CalcOp ),
+                              OperatorCompare );
 }
 
-
-//-----------------------------------------------------------------------------
-
-SwHash* Find( const String& rStr, SwHash** ppTable, sal_uInt16 nTblSize,
-                sal_uInt16* pPos )
+SwHash* Find( const String& rStr, SwHash** ppTable,
+              sal_uInt16 nTblSize, sal_uInt16* pPos )
 {
     sal_uLong ii = 0;
     for( xub_StrLen n = 0; n < rStr.Len(); ++n )
+    {
         ii = ii << 1 ^ rStr.GetChar( n );
+    }
     ii %= nTblSize;
 
     if( pPos )
         *pPos = (sal_uInt16)ii;
 
     for( SwHash* pEntry = *(ppTable+ii); pEntry; pEntry = pEntry->pNext )
+    {
         if( rStr == pEntry->aStr )
+        {
             return pEntry;
+        }
+    }
     return 0;
 }
 
 inline LanguageType GetDocAppScriptLang( SwDoc& rDoc )
 {
     return ((SvxLanguageItem&)rDoc.GetDefault(
-                            GetWhichOfScript( RES_CHRATR_LANGUAGE,
-                                GetI18NScriptTypeOfLanguage( (sal_uInt16)GetAppLanguage() ))
+               GetWhichOfScript( RES_CHRATR_LANGUAGE,
+                                 GetI18NScriptTypeOfLanguage( (sal_uInt16)GetAppLanguage() ))
             )).GetLanguage();
 }
 
@@ -236,23 +235,14 @@ double lcl_ConvertToDateValue( SwDoc& rDoc, sal_Int32 nDate )
     if( pFormatter )
     {
         Date* pNull = pFormatter->GetNullDate();
-        Date aDate( nDate >> 24, (nDate & 0x00FF0000) >> 16, nDate & 0x0000FFFF );
+        Date aDate( nDate >> 24, (nDate& 0x00FF0000) >> 16, nDate& 0x0000FFFF );
         nRet = aDate - *pNull;
     }
     return nRet;
 }
 
-//-----------------------------------------------------------------------------
-
-/******************************************************************************
-|*
-|*  SwCalc::SwCalc( SwDoc* pD ) :
-|*
-|******************************************************************************/
-
 SwCalc::SwCalc( SwDoc& rD )
-    :
-    aErrExpr( aEmptyStr, SwSbxValue(), 0 ),
+    : aErrExpr( aEmptyStr, SwSbxValue(), 0 ),
     rDoc( rD ),
     pLclData( m_aSysLocale.GetLocaleDataPtr() ),
     pCharClass( &GetAppCharClass() ),
@@ -276,74 +266,73 @@ SwCalc::SwCalc( SwDoc& rD )
     sCurrSym = comphelper::string::strip(pLclData->getCurrSymbol(), ' ');
     sCurrSym  = pCharClass->lowercase( sCurrSym );
 
-static sal_Char const
-    sNType0[] = "false",
-    sNType1[] = "true",
-    sNType2[] = "pi",
-    sNType3[] = "e",
-    sNType4[] = "tables",
-    sNType5[] = "graf",
-    sNType6[] = "ole",
-    sNType7[] = "page",
-    sNType8[] = "para",
-    sNType9[] = "word",
-    sNType10[]= "char",
-
-    sNType11[] = "user_firstname" ,
-    sNType12[] = "user_lastname" ,
-    sNType13[] = "user_initials" ,
-    sNType14[] = "user_company" ,
-    sNType15[] = "user_street" ,
-    sNType16[] = "user_country" ,
-    sNType17[] = "user_zipcode" ,
-    sNType18[] = "user_city" ,
-    sNType19[] = "user_title" ,
-    sNType20[] = "user_position" ,
-    sNType21[] = "user_tel_work" ,
-    sNType22[] = "user_tel_home" ,
-    sNType23[] = "user_fax" ,
-    sNType24[] = "user_email" ,
-    sNType25[] = "user_state" ,
-    sNType26[] = "graph"
-    ;
-
-static const sal_Char* const sNTypeTab[ 27 ] =
-{
-    sNType0, sNType1, sNType2, sNType3, sNType4, sNType5,
-    sNType6, sNType7, sNType8, sNType9, sNType10, sNType11,
-    sNType12, sNType13, sNType14, sNType15, sNType16, sNType17,
-    sNType18, sNType19, sNType20, sNType21, sNType22, sNType23,
-    sNType24,
-
-    // diese sind mit doppelten HashIds
-    sNType25, sNType26
-};
-static sal_uInt16 const aHashValue[ 27 ] =
-{
-    34, 38, 43,  7, 18, 32, 22, 29, 30, 33,  3,
-    28, 24, 40,  9, 11, 26, 45,  4, 23, 36, 44, 19,  5,  1,
-    // diese sind mit doppelten HashIds
-    11, 38
-};
-static sal_uInt16 const aAdrToken[ 12 ] =
-{
-    USER_OPT_COMPANY, USER_OPT_STREET, USER_OPT_COUNTRY, USER_OPT_ZIP,
-    USER_OPT_CITY, USER_OPT_TITLE, USER_OPT_POSITION, USER_OPT_TELEPHONEWORK,
-    USER_OPT_TELEPHONEHOME, USER_OPT_FAX, USER_OPT_EMAIL, USER_OPT_STATE
-};
+    static sal_Char const
+        sNType0[] = "false",
+        sNType1[] = "true",
+        sNType2[] = "pi",
+        sNType3[] = "e",
+        sNType4[] = "tables",
+        sNType5[] = "graf",
+        sNType6[] = "ole",
+        sNType7[] = "page",
+        sNType8[] = "para",
+        sNType9[] = "word",
+        sNType10[]= "char",
+
+        sNType11[] = "user_firstname" ,
+        sNType12[] = "user_lastname" ,
+        sNType13[] = "user_initials" ,
+        sNType14[] = "user_company" ,
+        sNType15[] = "user_street" ,
+        sNType16[] = "user_country" ,
+        sNType17[] = "user_zipcode" ,
+        sNType18[] = "user_city" ,
+        sNType19[] = "user_title" ,
+        sNType20[] = "user_position" ,
+        sNType21[] = "user_tel_work" ,
+        sNType22[] = "user_tel_home" ,
+        sNType23[] = "user_fax" ,
+        sNType24[] = "user_email" ,
+        sNType25[] = "user_state" ,
+        sNType26[] = "graph"
+        ;
+    static const sal_Char* const sNTypeTab[ 27 ] =
+    {
+        sNType0, sNType1, sNType2, sNType3, sNType4, sNType5,
+        sNType6, sNType7, sNType8, sNType9, sNType10, sNType11,
+        sNType12, sNType13, sNType14, sNType15, sNType16, sNType17,
+        sNType18, sNType19, sNType20, sNType21, sNType22, sNType23,
+        sNType24,
+
+        // those have two HashIds
+        sNType25, sNType26
+    };
+    static sal_uInt16 const aHashValue[ 27 ] =
+    {
+        34, 38, 43,  7, 18, 32, 22, 29, 30, 33,  3,
+        28, 24, 40,  9, 11, 26, 45,  4, 23, 36, 44, 19,  5,  1,
+        // those have two HashIds
+        11, 38
+    };
+    static sal_uInt16 const aAdrToken[ 12 ] =
+    {
+        USER_OPT_COMPANY, USER_OPT_STREET, USER_OPT_COUNTRY, USER_OPT_ZIP,
+        USER_OPT_CITY, USER_OPT_TITLE, USER_OPT_POSITION, USER_OPT_TELEPHONEWORK,
+        USER_OPT_TELEPHONEHOME, USER_OPT_FAX, USER_OPT_EMAIL, USER_OPT_STATE
+    };
 
-static sal_uInt16 SwDocStat::* const aDocStat1[ 3 ] =
-{
-    &SwDocStat::nTbl, &SwDocStat::nGrf, &SwDocStat::nOLE
-};
-static sal_uLong SwDocStat::* const aDocStat2[ 4 ] =
-{
-    &SwDocStat::nPage, &SwDocStat::nPara,
-    &SwDocStat::nWord, &SwDocStat::nChar
-};
+    static sal_uInt16 SwDocStat::* const aDocStat1[ 3 ] =
+    {
+        &SwDocStat::nTbl, &SwDocStat::nGrf, &SwDocStat::nOLE
+    };
+    static sal_uLong SwDocStat::* const aDocStat2[ 4 ] =
+    {
+        &SwDocStat::nPage, &SwDocStat::nPara,
+        &SwDocStat::nWord, &SwDocStat::nChar
+    };
 
 #if TBLSZ != 47
-#error Alle Hashwerte angepasst?
+#error Did you adjust all hash values?
 #endif
 
     const SwDocStat& rDocStat = rDoc.GetDocStat();
@@ -382,30 +371,19 @@ static sal_uLong SwDocStat::* const aDocStat2[ 4 ] =
     sTmpStr.AssignAscii( sNTypeTab[ 25 ] );
     VarTable[ aHashValue[ 25 ] ]->pNext = new SwCalcExp( sTmpStr, nVal, 0 );
 
-}
-
-/******************************************************************************
-|*
-|*  SwCalc::~SwCalc()
-|*
-|******************************************************************************/
+} // SwCalc::SwCalc
 
 SwCalc::~SwCalc()
 {
     for( sal_uInt16 n = 0; n < TBLSZ; ++n )
         delete VarTable[n];
+
     if( pLclData != m_aSysLocale.GetLocaleDataPtr() )
         delete pLclData;
     if( pCharClass != &GetAppCharClass() )
         delete pCharClass;
 }
 
-/******************************************************************************
-|*
-|*  SwSbxValue SwCalc::Calculate( const String& rStr )
-|*
-|******************************************************************************/
-
 SwSbxValue SwCalc::Calculate( const String& rStr )
 {
     eError = CALC_NOERR;
@@ -415,7 +393,7 @@ SwSbxValue SwCalc::Calculate( const String& rStr )
         return nResult;
 
     nListPor = 0;
-    eCurrListOper = CALC_PLUS;          // defaulten auf Summe
+    eCurrListOper = CALC_PLUS; // default: sum
 
     sCommand = rStr;
     nCommandPos = 0;
@@ -429,16 +407,16 @@ SwSbxValue SwCalc::Calculate( const String& rStr )
     return nResult;
 }
 
-/******************************************************************************
-|*
-|*  String SwCalc::GetStrResult( SwSbxValue nValue, sal_Bool bRound = sal_True )
-|*  Beschreibung        Der Parameter bRound ist auf sal_True defaultet und darf
-|*                      nur beim errechnen von Tabellenzellen auf sal_False gesetzt
-|*                      werden, damit keine Rundungsfehler beim zusammenstellen
-|*                      der Formel entstehen.
-|*
-|******************************************************************************/
+//TODO: provide documentation
+/** ???
 
+  @param rVal ???
+  @param bRound In previous times <bRound> had a default value of <sal_True>.
+                There it should be only changed when calculating table cells,
+                so that no rounding errors would occur while composing a formula.
+                Now this parameter is ignored.
+  @return ???
+*/
 String SwCalc::GetStrResult( const SwSbxValue& rVal, sal_Bool bRound )
 {
     if( !rVal.IsDouble() )
@@ -447,49 +425,37 @@ String SwCalc::GetStrResult( const SwSbxValue& rVal, sal_Bool bRound )
     return GetStrResult( rVal.GetDouble(), bRound );
 }
 
-
 String SwCalc::GetStrResult( double nValue, sal_Bool )
 {
     if( nValue >= DBL_MAX )
         switch( eError )
         {
-            case CALC_SYNTAX    :   return RESOURCE->aCalc_Syntax;
-            case CALC_ZERODIV   :   return RESOURCE->aCalc_ZeroDiv;
-            case CALC_BRACK     :   return RESOURCE->aCalc_Brack;
-            case CALC_POWERR    :   return RESOURCE->aCalc_Pow;
-            case CALC_VARNFND   :   return RESOURCE->aCalc_VarNFnd;
-            case CALC_OVERFLOW  :   return RESOURCE->aCalc_Overflow;
-            case CALC_WRONGTIME :   return RESOURCE->aCalc_WrongTime;
-            default             :   return RESOURCE->aCalc_Default;
+        case CALC_SYNTAX    :   return RESOURCE->aCalc_Syntax;
+        case CALC_ZERODIV   :   return RESOURCE->aCalc_ZeroDiv;
+        case CALC_BRACK     :   return RESOURCE->aCalc_Brack;
+        case CALC_POWERR    :   return RESOURCE->aCalc_Pow;
+        case CALC_VARNFND   :   return RESOURCE->aCalc_VarNFnd;
+        case CALC_OVERFLOW  :   return RESOURCE->aCalc_Overflow;
+        case CALC_WRONGTIME :   return RESOURCE->aCalc_WrongTime;
+        default             :   return RESOURCE->aCalc_Default;
         }
 
-    sal_uInt16  nDec = 15; //pLclData->getNumDigits();
-    String  aRetStr( ::rtl::math::doubleToUString( nValue,
-                rtl_math_StringFormat_Automatic,
-                nDec,
-                pLclData->getNumDecimalSep()[0],
-                true ));
-
+    sal_uInt16  nDec = 15;
+    String aRetStr( ::rtl::math::doubleToUString(
+                        nValue,
+                        rtl_math_StringFormat_Automatic,
+                        nDec,
+                        pLclData->getNumDecimalSep()[0],
+                        true ));
     return aRetStr;
 }
 
-/******************************************************************************
-|*
-|*  SwCalcExp* SwCalc::VarLook( const String& )
-|*
-|******************************************************************************/
-
 SwCalcExp* SwCalc::VarInsert( const String &rStr )
 {
     String aStr = pCharClass->lowercase( rStr );
     return VarLook( aStr, 1 );
 }
 
-/******************************************************************************
-|*
-|*  SwCalcExp* SwCalc::VarLook( const String& , sal_uInt16 ins )
-|*
-|******************************************************************************/
 SwCalcExp* SwCalc::VarLook( const String& rStr, sal_uInt16 ins )
 {
     aErrExpr.nValue.SetVoidValue(false);
@@ -501,18 +467,20 @@ SwCalcExp* SwCalc::VarLook( const String& rStr, sal_uInt16 ins )
 
     if( !pFnd )
     {
-        // dann sehen wir mal im Doc nach:
+        // then check doc
         SwHash** ppDocTbl = rDoc.GetUpdtFlds().GetFldTypeTable();
         for( SwHash* pEntry = *(ppDocTbl+ii); pEntry; pEntry = pEntry->pNext )
+        {
             if( aStr == pEntry->aStr )
             {
-                // dann hier zufuegen
+                // then insert here
                 pFnd = new SwCalcExp( aStr, SwSbxValue(),
                                     ((SwCalcFldType*)pEntry)->pFldType );
                 pFnd->pNext = *(VarTable+ii);
                 *(VarTable+ii) = pFnd;
                 break;
             }
+        }
     }
 
     if( pFnd )
@@ -523,10 +491,12 @@ SwCalcExp* SwCalc::VarLook( const String& rStr, sal_uInt16 ins )
         {
             SwUserFieldType* pUFld = (SwUserFieldType*)pFndExp->pFldType;
             if( nsSwGetSetExpType::GSE_STRING & pUFld->GetType() )
+            {
                 pFndExp->nValue.PutString( pUFld->GetContent() );
+            }
             else if( !pUFld->IsValid() )
             {
-                // Die aktuellen Werte sichern . . .
+                // Save the current values...
                 sal_uInt16          nOld_ListPor        = nListPor;
                 SwSbxValue      nOld_LastLeft       = nLastLeft;
                 SwSbxValue      nOld_NumberValue    = nNumberValue;
@@ -536,7 +506,7 @@ SwCalcExp* SwCalc::VarLook( const String& rStr, sal_uInt16 ins )
 
                 pFndExp->nValue.PutDouble( pUFld->GetValue( *this ) );
 
-                // . . . und zurueck damit.
+                // ...and write them back.
                 nListPor        = nOld_ListPor;
                 nLastLeft       = nOld_LastLeft;
                 nNumberValue    = nOld_NumberValue;
@@ -545,13 +515,13 @@ SwCalcExp* SwCalc::VarLook( const String& rStr, sal_uInt16 ins )
                 eCurrListOper   = eOld_CurrListOper;
             }
             else
+            {
                 pFndExp->nValue.PutDouble( pUFld->GetValue() );
+            }
         }
         return pFndExp;
     }
 
-    // Name(p)=Adress.PLZ oder Adress.DATENSATZNUMMER
-    // DBSETNUMBERFLD = DatenSATZ-nummernfeld (NICHT "setze Datensatznummer!!!")
     // At this point the "real" case variable has to be used
     String sTmpName( rStr );
     ::ReplacePoint( sTmpName );
@@ -560,8 +530,6 @@ SwCalcExp* SwCalc::VarLook( const String& rStr, sal_uInt16 ins )
     {
         SwNewDBMgr *pMgr = rDoc.GetNewDBMgr();
 
-        // Name(p)=Adress.PLZ oder Adress.DATENSATZNUMMER
-        // DBSETNUMBERFLD = DatenSATZ-nummernfeld (NICHT "setze Datensatznummer!!!")
         String sDBName(GetDBName( sTmpName ));
         String sSourceName(sDBName.GetToken(0, DB_DELIM));
         String sTableName(sDBName.GetToken(0).GetToken(1, DB_DELIM));
@@ -569,14 +537,14 @@ SwCalcExp* SwCalc::VarLook( const String& rStr, sal_uInt16 ins )
             pMgr->OpenDataSource(sSourceName, sTableName, -1, false))
         {
             String sColumnName( GetColumnName( sTmpName ));
-           OSL_ENSURE(sColumnName.Len(), "DB-Spaltenname fehlt!");
+            OSL_ENSURE(sColumnName.Len(), "Missing DB column name");
 
             String sDBNum( SwFieldType::GetTypeStr(TYP_DBSETNUMBERFLD) );
             sDBNum = pCharClass->lowercase(sDBNum);
 
-            // Hier nochmal initialisieren, da das nicht mehr in docfld
-            // fuer Felder != RES_DBFLD geschieht. Z.B. wenn ein Expressionfield
-            // vor einem DB_Field in einem Dok vorkommt.
+            // Initialize again because this doesn't happen in docfld anymore for
+            // elements != RES_DBFLD. E.g. if there is an expression field before
+            // an DB_Field in a document.
             VarChange( sDBNum, pMgr->GetSelectedRecordId(sSourceName, sTableName));
 
             if( sDBNum.EqualsIgnoreCaseAscii(sColumnName) )
@@ -609,17 +577,16 @@ SwCalcExp* SwCalc::VarLook( const String& rStr, sal_uInt16 ins )
             //data source was not available - set return to "NoValue"
             aErrExpr.nValue.SetVoidValue(true);
         }
-        // auf keinen fall eintragen!!
+        // NEVER save!
         return &aErrExpr;
     }
 
-
     SwCalcExp* pNewExp = new SwCalcExp( aStr, SwSbxValue(), 0 );
     pNewExp->pNext = VarTable[ ii ];
     VarTable[ ii ] = pNewExp;
 
     String sColumnName( GetColumnName( sTmpName ));
-    OSL_ENSURE( sColumnName.Len(), "DB-Spaltenname fehlt!" );
+    OSL_ENSURE( sColumnName.Len(), "Missing DB column name" );
     if( sColumnName.EqualsIgnoreCaseAscii(
                             SwFieldType::GetTypeStr( TYP_DBSETNUMBERFLD ) ))
     {
@@ -630,20 +597,18 @@ SwCalcExp* SwCalc::VarLook( const String& rStr, sal_uInt16 ins )
         if( pMgr && sSourceName.Len() && sTableName.Len() &&
             pMgr->OpenDataSource(sSourceName, sTableName, -1, false) &&
             !pMgr->IsInMerge())
+        {
             pNewExp->nValue.PutULong( pMgr->GetSelectedRecordId(sSourceName, sTableName));
+        }
         else
+        {
             pNewExp->nValue.SetVoidValue(true);
+        }
     }
 
     return pNewExp;
 }
 
-/******************************************************************************
-|*
-|*  sal_Bool SwCalc::VarChange( const String& rStr, const SwSbxValue nValue )
-|*
-|******************************************************************************/
-
 void SwCalc::VarChange( const String& rStr, double nValue )
 {
     SwSbxValue aVal( nValue );
@@ -664,15 +629,11 @@ void SwCalc::VarChange( const String& rStr, const SwSbxValue& rValue )
         VarTable[ nPos ] = pFnd;
     }
     else
+    {
         pFnd->nValue = rValue;
+    }
 }
 
-/******************************************************************************
-|*
-|*  sal_Bool SwCalc::Push( const void* pPtr )
-|*
-|******************************************************************************/
-
 sal_Bool SwCalc::Push( const VoidPtr pPtr )
 {
     if( USHRT_MAX != aRekurStk.GetPos( pPtr ) )
@@ -682,34 +643,21 @@ sal_Bool SwCalc::Push( const VoidPtr pPtr )
     return sal_True;
 }
 
-/******************************************************************************
-|*
-|*  void SwCalc::Pop( const void* pPtr )
-|*
-|******************************************************************************/
-
 void SwCalc::Pop( const VoidPtr )
 {
-    OSL_ENSURE( aRekurStk.Count(), "SwCalc: Pop auf ungueltigen Ptr" );
+    OSL_ENSURE( aRekurStk.Count(), "SwCalc: Pop on an invalid pointer" );
 
     aRekurStk.Remove( aRekurStk.Count() - 1 );
 }
 
-
-/******************************************************************************
-|*
-|*  SwCalcOper SwCalc::GetToken()
-|*
-|******************************************************************************/
-
 SwCalcOper SwCalc::GetToken()
 {
 #if OSL_DEBUG_LEVEL > 1
-//static for switch back to the "old" implementation of the
-//calculator, which don't use the I18N routines.
-static int nUseOld = 0;
-if( !nUseOld )
-{
+    // static for switch back to the "old" implementation of the calculator
+    // which doesn't use the I18N routines.
+    static int nUseOld = 0;
+    if( !nUseOld )
+    {
 #endif
 
     if( nCommandPos >= sCommand.Len() )
@@ -719,8 +667,8 @@ if( !nUseOld )
     {
         // Parse any token.
         ParseResult aRes = pCharClass->parseAnyToken( sCommand, nCommandPos,
-                                                    coStartFlags, aEmptyStr,
-                                                    coContFlags, aEmptyStr );
+                                                      coStartFlags, aEmptyStr,
+                                                      coContFlags, aEmptyStr );
 
         sal_Bool bSetError = sal_True;
         xub_StrLen nRealStt = nCommandPos + (xub_StrLen)aRes.LeadingWhiteSpace;
@@ -732,38 +680,40 @@ if( !nUseOld )
         }
         else if( aRes.TokenType & KParseType::IDENTNAME )
         {
-            String aName( sCommand.Copy( nRealStt, static_cast<xub_StrLen>(aRes.EndPos) - nRealStt ));
-            //#101436#: the variable may contain a database name it must not be converted to lower case
-            // instead all further comparisons must be done case-insensitive
+            String aName( sCommand.Copy( nRealStt,
+                            static_cast<xub_StrLen>(aRes.EndPos) - nRealStt ));
+            //#101436#: The variable may contain a database name. It must not be
+            // converted to lower case! Instead all further comparisons must be
+            // done case-insensitive
             String sLowerCaseName = pCharClass->lowercase( aName );
-            // Currency-Symbol abfangen
+            // catch currency symbol
             if( sLowerCaseName == sCurrSym )
             {
                 nCommandPos = (xub_StrLen)aRes.EndPos;
-                return GetToken();  // also nochmal aufrufen
+                return GetToken(); // call again
             }
 
-            // Operations abfangen
+            // catch operators
             _CalcOp* pFnd = ::FindOperator( sLowerCaseName );
             if( pFnd )
             {
                 switch( ( eCurrOper = ((_CalcOp*)pFnd)->eOp ) )
                 {
-                    case CALC_SUM:
-                    case CALC_MEAN:
-                        eCurrListOper = CALC_PLUS;
-                        break;
-                    case CALC_MIN:
-                        eCurrListOper = CALC_MIN_IN;
-                        break;
-                    case CALC_MAX:
-                        eCurrListOper = CALC_MAX_IN;
-                        break;
-                    case CALC_DATE:
-                        eCurrListOper = CALC_MONTH;
-                        break;
-                    default:
-                        break;
+                case CALC_SUM:
+                case CALC_MEAN:
+                    eCurrListOper = CALC_PLUS;
+                    break;
+                case CALC_MIN:
+                    eCurrListOper = CALC_MIN_IN;
+                    break;
+                case CALC_MAX:
+                    eCurrListOper = CALC_MAX_IN;
+                    break;
+                case CALC_DATE:
+                    eCurrListOper = CALC_MONTH;
+                    break;
+                default:
+                    break;
                 }
                 nCommandPos = (xub_StrLen)aRes.EndPos;
                 return eCurrOper;
@@ -780,22 +730,25 @@ if( !nUseOld )
         }
         else if( aRes.TokenType & KParseType::ONE_SINGLE_CHAR )
         {
-            String aName( sCommand.Copy( nRealStt, static_cast<xub_StrLen>(aRes.EndPos) - nRealStt ));
+            String aName( sCommand.Copy( nRealStt,
+                              static_cast<xub_StrLen>(aRes.EndPos) - nRealStt ));
             if( 1 == aName.Len() )
             {
                 bSetError = sal_False;
                 sal_Unicode ch = aName.GetChar( 0 );
                 switch( ch )
                 {
-                case ';': if( CALC_MONTH == eCurrListOper ||
-                              CALC_DAY == eCurrListOper )
-                          {
-                              eCurrOper = eCurrListOper;
-                              break;
-                          }
+                case ';':
+                    if( CALC_MONTH == eCurrListOper || CALC_DAY == eCurrListOper )
+                    {
+                        eCurrOper = eCurrListOper;
+                        break;
+                    }
+
                 case '\n':
-                            eCurrOper = CALC_PRINT;
-                            break;
+                    eCurrOper = CALC_PRINT;
+                    break;
+
                 case '%':
                 case '^':
                 case '*':
@@ -803,68 +756,71 @@ if( !nUseOld )
                 case '+':
                 case '-':
                 case '(':
-                case ')':   eCurrOper = SwCalcOper(ch);
-                            break;
+                case ')':
+                    eCurrOper = SwCalcOper(ch);
+                    break;
 
                 case '=':
                 case '!':
+                    {
+                        SwCalcOper eTmp2;
+                        if( '=' == ch )
+                            eCurrOper = SwCalcOper('='), eTmp2 = CALC_EQ;
+                        else
+                            eCurrOper = CALC_NOT, eTmp2 = CALC_NEQ;
+
+                        if( aRes.EndPos < sCommand.Len() &&
+                            '=' == sCommand.GetChar( (xub_StrLen)aRes.EndPos ) )
                         {
-                            SwCalcOper eTmp2;
-                            if( '=' == ch )
-                                eCurrOper = SwCalcOper('='), eTmp2 = CALC_EQ;
-                            else
-                                eCurrOper = CALC_NOT, eTmp2 = CALC_NEQ;
-
-                            if( aRes.EndPos < sCommand.Len() &&
-                                '=' == sCommand.GetChar( (xub_StrLen)aRes.EndPos ) )
-                            {
-                                eCurrOper = eTmp2;
-                                ++aRes.EndPos;
-                            }
+                            eCurrOper = eTmp2;
+                            ++aRes.EndPos;
                         }
-                        break;
+                    }
+                    break;
 
-                case cListDelim :
-                        eCurrOper = eCurrListOper;
-                        break;
+                case cListDelim:
+                    eCurrOper = eCurrListOper;
+                    break;
 
                 case '[':
-                        if( aRes.EndPos < sCommand.Len() )
-                        {
-                            aVarName.Erase();
-                            xub_StrLen nFndPos = (xub_StrLen)aRes.EndPos,
-                                        nSttPos = nFndPos;
+                    if( aRes.EndPos < sCommand.Len() )
+                    {
+                        aVarName.Erase();
+                        xub_StrLen nFndPos = (xub_StrLen)aRes.EndPos,
+                                             nSttPos = nFndPos;
 
-                            do{
-                                if( STRING_NOTFOUND != ( nFndPos =
-                                    sCommand.Search( ']', nFndPos )) )
+                        do {
+                            if( STRING_NOTFOUND != ( nFndPos =
+                                sCommand.Search( ']', nFndPos )) )
+                            {
+                                // ignore the ]
+                                if( '\\' == sCommand.GetChar(nFndPos-1))
                                 {
-                                    // ignore the ]
-                                    if( '\\' == sCommand.GetChar(nFndPos-1))
-                                    {
-                                        aVarName += sCommand.Copy( nSttPos,
+                                    aVarName += sCommand.Copy( nSttPos,
                                                     nFndPos - nSttPos - 1 );
-                                        nSttPos = ++nFndPos;
-                                    }
-                                    else
-                                        break;
+                                    nSttPos = ++nFndPos;
                                 }
-                            } while( STRING_NOTFOUND != nFndPos );
+                                else
+                                    break;
+                            }
+                        } while( STRING_NOTFOUND != nFndPos );
 
-                            if( STRING_NOTFOUND != nFndPos )
-                            {
-                                if( nSttPos != nFndPos )
-                                    aVarName += sCommand.Copy( nSttPos,
+                        if( STRING_NOTFOUND != nFndPos )
+                        {
+                            if( nSttPos != nFndPos )
+                                aVarName += sCommand.Copy( nSttPos,
                                                     nFndPos - nSttPos );
-                                aRes.EndPos = nFndPos + 1;
-                                eCurrOper = CALC_NAME;
-                            }
-                            else
-                                bSetError = sal_True;
+                            aRes.EndPos = nFndPos + 1;
+                            eCurrOper = CALC_NAME;
                         }
                         else
                             bSetError = sal_True;
-                        break;
+                    }
+                    else
+                    {
+                        bSetError = sal_True;
+                    }
+                    break;
 
                 default:
                     bSetError = sal_True;
@@ -874,7 +830,8 @@ if( !nUseOld )
         }
         else if( aRes.TokenType & KParseType::BOOLEAN )
         {
-            String aName( sCommand.Copy( nRealStt, static_cast<xub_StrLen>(aRes.EndPos) - nRealStt ));
+            String aName( sCommand.Copy( nRealStt,
+                                         static_cast<xub_StrLen>(aRes.EndPos) - nRealStt ));
             if( aName.Len() )
             {
                 sal_Unicode ch = aName.GetChar(0);
@@ -909,41 +866,44 @@ if( !nUseOld )
     };
 
 #if OSL_DEBUG_LEVEL > 1
-
 #define NextCh( s, n )  (nCommandPos < sCommand.Len() ? sCommand.GetChar( nCommandPos++ ) : 0)
 
-}
-else
-{
-    sal_Unicode ch;
-    sal_Unicode cTSep = pLclData->getNumThousandSep()[0],
-                cDSep = pLclData->getNumDecimalSep()[0];
+    }
+    else
+    {
+        sal_Unicode ch;
+        sal_Unicode cTSep = pLclData->getNumThousandSep()[0],
+                    cDSep = pLclData->getNumDecimalSep()[0];
 
-    do {
-        if( 0 == ( ch = NextCh( sCommand, nCommandPos ) ) )
-            return eCurrOper = CALC_ENDCALC;
-    } while ( ch == '\t' || ch == ' ' || ch == cTSep );
+        do {
+            if( 0 == ( ch = NextCh( sCommand, nCommandPos ) ) )
+                return eCurrOper = CALC_ENDCALC;
+        } while ( ch == '\t' || ch == ' ' || ch == cTSep );
 
-    if( ch == cDSep )
-        ch = '.';
+        if( ch == cDSep )
+            ch = '.';
 
-    switch( ch )
-    {
-        case ';': if( CALC_MONTH == eCurrListOper || CALC_DAY == eCurrListOper )
-                  {
-                      eCurrOper = eCurrListOper;
-                      break;
-                  } // else .. no break
+        switch( ch )
+        {
+        case ';':
+            if( CALC_MONTH == eCurrListOper || CALC_DAY == eCurrListOper )
+            {
+                eCurrOper = eCurrListOper;
+                break;
+            } // else .. no break
         case '\n':
-                    {
-                        sal_Unicode c;
-                        while( nCommandPos < sCommand.Len() && ( ( c =
-                                sCommand.GetChar( nCommandPos ) ) == ' ' ||
-                                c == '\t' || c == '\x0a' || c == '\x0d' ))
-                            ++nCommandPos;
-                        eCurrOper = CALC_PRINT;
-                    }
-                    break;
+            {
+                sal_Unicode c;
+                while( nCommandPos < sCommand.Len() &&
+                       ( ( c = sCommand.GetChar( nCommandPos ) ) == ' ' ||
+                       c == '\t' || c == '\x0a' || c == '\x0d' ))
+                {
+                    ++nCommandPos;
+                }
+                eCurrOper = CALC_PRINT;
+            }
+            break;
+
         case '%':
         case '^':
         case '*':
@@ -951,166 +911,178 @@ else
         case '+':
         case '-':
         case '(':
-        case ')':   eCurrOper = SwCalcOper(ch);
-                    break;
+        case ')':
+            eCurrOper = SwCalcOper(ch);
+            break;
 
-        case '=':   if( '=' == sCommand.GetChar( nCommandPos ) )
-                    {
-                        ++nCommandPos;
-                        eCurrOper = CALC_EQ;
-                    }
-                    else
-                        eCurrOper = SwCalcOper(ch);
-                    break;
+        case '=':
+            if( '=' == sCommand.GetChar( nCommandPos ) )
+            {
+                ++nCommandPos;
+                eCurrOper = CALC_EQ;
+            }
+            else
+            {
+                eCurrOper = SwCalcOper(ch);
+            }
+            break;
 
-        case '!':   if( '=' == sCommand.GetChar( nCommandPos ) )
-                    {
-                        ++nCommandPos;
-                        eCurrOper = CALC_NEQ;
-                    }
-                    else
-                        eCurrOper = CALC_NOT;
-                    break;
+        case '!':
+            if( '=' == sCommand.GetChar( nCommandPos ) )
+            {
+                ++nCommandPos;
+                eCurrOper = CALC_NEQ;
+            }
+            else
+            {
+                eCurrOper = CALC_NOT;
+            }
+            break;
 
         case '>':
-        case '<':   eCurrOper = '>' == ch  ? CALC_GRE : CALC_LES;
-                    if( '=' == (ch = sCommand.GetChar( nCommandPos ) ) )
-                    {
-                        ++nCommandPos;
-                        eCurrOper = CALC_GRE == eCurrOper ? CALC_GEQ : CALC_LEQ;
-                    }
-                    else if( ' ' != ch )
-                    {
-                        eError = CALC_SYNTAX;
-                        eCurrOper = CALC_PRINT;
-                    }
-                    break;
+        case '<':
+            eCurrOper = '>' == ch  ? CALC_GRE : CALC_LES;
+            if( '=' == (ch = sCommand.GetChar( nCommandPos ) ) )
+            {
+                ++nCommandPos;
+                eCurrOper = CALC_GRE == eCurrOper ? CALC_GEQ : CALC_LEQ;
+            }
+            else if( ' ' != ch )
+            {
+                eError = CALC_SYNTAX;
+                eCurrOper = CALC_PRINT;
+            }
+            break;
 
         case cListDelim :
-                    eCurrOper = eCurrListOper;
-                    break;
+            eCurrOper = eCurrListOper;
+            break;
 
         case '0':   case '1':   case '2':   case '3':   case '4':
         case '5':   case '6':   case '7':   case '8':   case '9':
         case ',':
-        case '.':   {
-                        double nVal;
-                        --nCommandPos;      //  auf das 1. Zeichen zurueck
-                        if( Str2Double( sCommand, nCommandPos, nVal, pLclData ))
-                        {
-                            nNumberValue.PutDouble( nVal );
-                            eCurrOper = CALC_NUMBER;
-                        }
-                        else
-                        {
-                            // fehlerhafte Zahl
-                            eError = CALC_SYNTAX;
-                            eCurrOper = CALC_PRINT;
-                        }
-                    }
-                    break;
+        case '.':
+            {
+                double nVal;
+                --nCommandPos; //  back to the first char
+                if( Str2Double( sCommand, nCommandPos, nVal, pLclData ))
+                {
+                    nNumberValue.PutDouble( nVal );
+                    eCurrOper = CALC_NUMBER;
+                }
+                else
+                {
+                    // erroneous number
+                    eError = CALC_SYNTAX;
+                    eCurrOper = CALC_PRINT;
+                }
+            }
+            break;
 
-        case '[':   {
-                        String aStr;
-                        sal_Bool bIgnore = sal_False;
-                        do {
-                            while( 0 != ( ch = NextCh( sCommand, nCommandPos  ))
-                                    && ch != ']' )
-                            {
-                                if( !bIgnore && '\\' == ch )
-                                    bIgnore = sal_True;
-                                else if( bIgnore )
-                                    bIgnore = sal_False;
-                                aStr += ch;
-                            }
+        case '[':
+            {
+                String aStr;
+                sal_Bool bIgnore = sal_False;
+                do {
+                    while( 0 != ( ch = NextCh( sCommand, nCommandPos  )) &&
+                           ch != ']' )
+                    {
+                        if( !bIgnore && '\\' == ch )
+                            bIgnore = sal_True;
+                        else if( bIgnore )
+                            bIgnore = sal_False;
+                        aStr += ch;
+                    }
 
-                            if( !bIgnore )
-                                break;
+                    if( !bIgnore )
+                        break;
 
-                            aStr.SetChar( aStr.Len() - 1, ch );
-                        } while( ch );
+                    aStr.SetChar( aStr.Len() - 1, ch );
+                } while( ch );
 
-                        aVarName = aStr;
-                        eCurrOper = CALC_NAME;
-                    }
-                    break;
+                aVarName = aStr;
+                eCurrOper = CALC_NAME;
+            }
+            break;
 
-        case '"':   {
-                        xub_StrLen nStt = nCommandPos;
-                        while( 0 != ( ch = NextCh( sCommand, nCommandPos ) )
-                                && '"' != ch )
-                            ;
-
-                        xub_StrLen nLen = nCommandPos - nStt;
-                        if( '"' == ch )
-                            --nLen;
-                        nNumberValue.PutString( sCommand.Copy( nStt, nLen ));
-                        eCurrOper = CALC_NUMBER;
-                    }
-                    break;
+        case '"':
+            {
+                xub_StrLen nStt = nCommandPos;
+                while( 0 != ( ch = NextCh( sCommand, nCommandPos ) ) &&
+                       '"' != ch )
+                {
+                    ;
+                }
 
-        default:    if (ch && (pCharClass->isLetter( sCommand, nCommandPos - 1) || '_' == ch))
-                    {
-                        xub_StrLen nStt = nCommandPos-1;
-                        while( 0 != (ch = NextCh( sCommand, nCommandPos )) &&
-                               (pCharClass->isLetterNumeric(
-                                                   sCommand, nCommandPos - 1) ||
-                                ch == '_' || ch == '.' ) )
-                            ;
+                xub_StrLen nLen = nCommandPos - nStt;
+                if( '"' == ch )
+                    --nLen;
+                nNumberValue.PutString( sCommand.Copy( nStt, nLen ));
+                eCurrOper = CALC_NUMBER;
+            }
+            break;
 
-                        if( ch )
-                            --nCommandPos;
+        default:
+            if (ch && (pCharClass->isLetter( sCommand, nCommandPos - 1) ||
+                '_' == ch))
+            {
+                xub_StrLen nStt = nCommandPos-1;
+                while( 0 != (ch = NextCh( sCommand, nCommandPos )) &&
+                       (pCharClass->isLetterNumeric( sCommand, nCommandPos - 1) ||
+                       ch == '_' || ch == '.' ) )
+                {
+                    ;
+                }
 
-                        String aStr( sCommand.Copy( nStt, nCommandPos-nStt ));
-                        aStr = pCharClass->lowercase( aStr );
+                if( ch )
+                    --nCommandPos;
 
+                String aStr( sCommand.Copy( nStt, nCommandPos-nStt ));
+                aStr = pCharClass->lowercase( aStr );
 
-                        // Currency-Symbol abfangen
-                        if( aStr == sCurrSym )
-                            return GetToken();  // also nochmal aufrufen
+                // catch currency symbol
+                if( aStr == sCurrSym )
+                    return GetToken();  // call again
 
-                        // Operations abfangen
-                        _CalcOp* pFnd = ::FindOperator( aStr );
-                        if( pFnd )
-                        {
-                            switch( ( eCurrOper = ((_CalcOp*)pFnd)->eOp ) )
-                            {
-                                case CALC_SUM  :
-                                case CALC_MEAN : eCurrListOper = CALC_PLUS;
-                                                    break;
-                                case CALC_MIN  : eCurrListOper = CALC_MIN_IN;
-                                                    break;
-                                case CALC_MAX  : eCurrListOper = CALC_MAX_IN;
-                                                    break;
-                                case CALC_DATE  : eCurrListOper = CALC_MONTH;
-                                                    break;
-                                default :
-                                    break;
-                            }
-                            return eCurrOper;
-                        }
-                        aVarName = aStr;
-                        eCurrOper = CALC_NAME;
-                    }
-                    else
+                // catch operators
+                _CalcOp* pFnd = ::FindOperator( aStr );
+                if( pFnd )
+                {
+                    switch( ( eCurrOper = ((_CalcOp*)pFnd)->eOp ) )
                     {
-                        eError = CALC_SYNTAX;
-                        eCurrOper = CALC_PRINT;
+                    case CALC_SUM :
+                    case CALC_MEAN :
+                        eCurrListOper = CALC_PLUS;
+                        break;
+                    case CALC_MIN :
+                        eCurrListOper = CALC_MIN_IN;
+                        break;
+                    case CALC_MAX :
+                        eCurrListOper = CALC_MAX_IN;
+                        break;
+                    case CALC_DATE :
+                        eCurrListOper = CALC_MONTH;
+                        break;
+                    default :
+                        break;
                     }
-                    break;
+                    return eCurrOper;
+                }
+                aVarName = aStr;
+                eCurrOper = CALC_NAME;
+            }
+            else
+            {
+                eError = CALC_SYNTAX;
+                eCurrOper = CALC_PRINT;
+            }
+            break;
+        }
     }
-
-}
 #endif
     return eCurrOper;
 }
 
-/******************************************************************************
-|*
-|*  SwSbxValue SwCalc::Term()
-|*
-|******************************************************************************/
-
 SwSbxValue SwCalc::Term()
 {
     SwSbxValue left( Prim() );
@@ -1121,136 +1093,145 @@ SwSbxValue SwCalc::Term()
 
         switch( eCurrOper )
         {
-            case CALC_AND:  {
-                                GetToken();
-                                sal_Bool bB = Prim().GetBool();
-                                left.PutBool( left.GetBool() && bB );
-                            }
-                            break;
-            case CALC_OR:   {
-                                GetToken();
-                                sal_Bool bB = Prim().GetBool();
-                                left.PutBool( left.GetBool() || bB );
-                            }
-                            break;
-            case CALC_XOR:  {
-                                GetToken();
-                                sal_Bool bR = Prim().GetBool();
-                                sal_Bool bL = left.GetBool();
-                                left.PutBool( (bL && !bR) || (!bL && bR) );
-                            }
-                            break;
-
-            case CALC_EQ:   nSbxOper = SbxEQ;   break;
-            case CALC_NEQ:  nSbxOper = SbxNE;   break;
-            case CALC_LEQ:  nSbxOper = SbxLE;   break;
-            case CALC_GEQ:  nSbxOper = SbxGE;   break;
-            case CALC_GRE:  nSbxOper = SbxGT;   break;
-            case CALC_LES:  nSbxOper = SbxLT;   break;
+        case CALC_AND:
+            {
+                GetToken();
+                sal_Bool bB = Prim().GetBool();
+                left.PutBool( left.GetBool() && bB );
+            }
+            break;
+        case CALC_OR:
+            {
+                GetToken();
+                sal_Bool bB = Prim().GetBool();
+                left.PutBool( left.GetBool() || bB );
+            }
+            break;
+        case CALC_XOR:
+            {
+                GetToken();
+                sal_Bool bR = Prim().GetBool();
+                sal_Bool bL = left.GetBool();
+                left.PutBool( (bL && !bR) || (!bL && bR) );
+            }
+            break;
 
-            case CALC_MUL:  nSbxOper = SbxMUL;  break;
-            case CALC_DIV:  nSbxOper = SbxDIV;  break;
+        case CALC_EQ:   nSbxOper = SbxEQ;   break;
+        case CALC_NEQ:  nSbxOper = SbxNE;   break;
+        case CALC_LEQ:  nSbxOper = SbxLE;   break;
+        case CALC_GEQ:  nSbxOper = SbxGE;   break;
+        case CALC_GRE:  nSbxOper = SbxGT;   break;
+        case CALC_LES:  nSbxOper = SbxLT;   break;
 
-            case CALC_MIN_IN:
-                            {
-                                GetToken();
-                                SwSbxValue e = Prim();
-                                left = left.GetDouble() < e.GetDouble()
-                                            ? left : e;
-                            }
-                            break;
-            case CALC_MAX_IN:
-                            {
-                                GetToken();
-                                SwSbxValue e = Prim();
-                                left = left.GetDouble() > e.GetDouble()
-                                            ? left : e;
-                            }
-                            break;
-            case CALC_MONTH:
-                            {
-                                GetToken();
-                                SwSbxValue e = Prim();
-                                sal_Int32 nYear = (sal_Int32) floor( left.GetDouble() );
-                                nYear = nYear & 0x0000FFFF;
-                                sal_Int32 nMonth = (sal_Int32) floor( e.GetDouble() );
-                                nMonth = ( nMonth & 0x000000FF ) << 16;
-                                left.PutLong( nMonth + nYear );
-                                eCurrOper = CALC_DAY;
-                            }
-                            break;
-            case CALC_DAY:
-                            {
-                                GetToken();
-                                SwSbxValue e = Prim();
-                                sal_Int32 nYearMonth = (sal_Int32) floor( left.GetDouble() );
-                                nYearMonth = nYearMonth & 0x00FFFFFF;
-                                sal_Int32 nDay = (sal_Int32) floor( e.GetDouble() );
-                                nDay = ( nDay & 0x000000FF ) << 24;
-                                left = lcl_ConvertToDateValue( rDoc, nDay + nYearMonth );
-                            }
-                            break;
-            case CALC_ROUND:
-                            {
-                                GetToken();
-                                SwSbxValue e = Prim();
+        case CALC_MUL:  nSbxOper = SbxMUL;  break;
+        case CALC_DIV:  nSbxOper = SbxDIV;  break;
 
-                                double fVal = 0;
-                                double fFac = 1;
-                                sal_Int32 nDec = (sal_Int32) floor( e.GetDouble() );
-                                if( nDec < -20 || nDec > 20 )
-                                {
-                                    eError = CALC_OVERFLOW;
-                                    left.Clear();
-                                    return left;
-                                }
-                                fVal = left.GetDouble();
-                                sal_uInt16 i;
-                                if( nDec >= 0)
-                                    for (i = 0; i < (sal_uInt16) nDec; ++i )
-                                        fFac *= 10.0;
-                                else
-                                    for (i = 0; i < (sal_uInt16) -nDec; ++i )
-                                        fFac /= 10.0;
+        case CALC_MIN_IN:
+            {
+                GetToken();
+                SwSbxValue e = Prim();
+                left = left.GetDouble() < e.GetDouble() ? left : e;
+            }
+            break;
+        case CALC_MAX_IN:
+            {
+                GetToken();
+                SwSbxValue e = Prim();
+                left = left.GetDouble() > e.GetDouble() ? left : e;
+            }
+            break;
+        case CALC_MONTH:
+            {
+                GetToken();
+                SwSbxValue e = Prim();
+                sal_Int32 nYear = (sal_Int32) floor( left.GetDouble() );
+                nYear = nYear & 0x0000FFFF;
+                sal_Int32 nMonth = (sal_Int32) floor( e.GetDouble() );
+                nMonth = ( nMonth & 0x000000FF ) << 16;
+                left.PutLong( nMonth + nYear );
+                eCurrOper = CALC_DAY;
+            }
+            break;
+        case CALC_DAY:
+            {
+                GetToken();
+                SwSbxValue e = Prim();
+                sal_Int32 nYearMonth = (sal_Int32) floor( left.GetDouble() );
+                nYearMonth = nYearMonth & 0x00FFFFFF;
+                sal_Int32 nDay = (sal_Int32) floor( e.GetDouble() );
+                nDay = ( nDay & 0x000000FF ) << 24;
+                left = lcl_ConvertToDateValue( rDoc, nDay + nYearMonth );
+            }
+            break;
+        case CALC_ROUND:
+            {
+                GetToken();
+                SwSbxValue e = Prim();
 
-                                fVal *= fFac;
+                double fVal = 0;
+                double fFac = 1;
+                sal_Int32 nDec = (sal_Int32) floor( e.GetDouble() );
+                if( nDec < -20 || nDec > 20 )
+                {
+                    eError = CALC_OVERFLOW;
+                    left.Clear();
+                    return left;
+                }
+                fVal = left.GetDouble();
+                sal_uInt16 i;
+                if( nDec >= 0)
+                {
+                    for (i = 0; i < (sal_uInt16) nDec; ++i )
+                        fFac *= 10.0;
+                }
+                else
+                {
+                    for (i = 0; i < (sal_uInt16) -nDec; ++i )
+                        fFac /= 10.0;
+                }
 
-                                sal_Bool bSign;
-                                if (fVal < 0.0)
-                                {
-                                    fVal *= -1.0;
-                                    bSign = sal_True;
-                                }
-                                else
-                                    bSign = sal_False;
+                fVal *= fFac;
+                sal_Bool bSign;
+                if (fVal < 0.0)
+                {
+                    fVal *= -1.0;
+                    bSign = sal_True;
+                }
+                else
+                {
+                    bSign = sal_False;
+                }
 
-                                // runden
-                                double fNum = fVal;             // find the exponent
-                                int nExp = 0;
-                                if( fNum > 0 )
-                                {
-                                    while( fNum < 1.0 ) fNum *= 10.0, --nExp;
-                                    while( fNum >= 10.0 ) fNum /= 10.0, ++nExp;
-                                }
-                                nExp = 15 - nExp;
-                                if( nExp > 15 )
-                                    nExp = 15;
-                                else if( nExp <= 1 )
-                                    nExp = 0;
-                                fVal = floor( fVal+ 0.5 + nRoundVal[ nExp ] );
+                // rounding
+                double fNum = fVal; // find the exponent
+                int nExp = 0;
+                if( fNum > 0 )
+                {
+                    while( fNum < 1.0 )
+                        fNum *= 10.0, --nExp;
+                    while( fNum >= 10.0 )
+                        fNum /= 10.0, ++nExp;
+                }
+                nExp = 15 - nExp;
+                if( nExp > 15 )
+                    nExp = 15;
+                else if( nExp <= 1 )
+                    nExp = 0;
+                fVal = floor( fVal+ 0.5 + nRoundVal[ nExp ] );
 
-                                if (bSign)
-                                    fVal *= -1.0;
+                if (bSign)
+                    fVal *= -1.0;
 
-                                fVal /= fFac;
+                fVal /= fFac;
 
-                                left.PutDouble( fVal );
-                            }
-                            break;
+                left.PutDouble( fVal );
+            }
+            break;
 
 //#77448# (=2*3^2 != 18)
 
-            default:        return left;
+        default:
+            return left;
         }
 
         if( USHRT_MAX != nSbxOper )
@@ -1260,7 +1241,9 @@ SwSbxValue SwCalc::Term()
 
             GetToken();
             if( SbxEQ <= eSbxOper && eSbxOper <= SbxGE )
+            {
                 left.PutBool( left.Compare( eSbxOper, Prim() ));
+            }
             else
             {
                 SwSbxValue aRight( Prim() );
@@ -1276,12 +1259,6 @@ SwSbxValue SwCalc::Term()
     }
 }
 
-/******************************************************************************
-|*
-|*  SwSbxValue SwCalc::Prim()
-|*
-|******************************************************************************/
-
 extern "C" typedef double (*pfCalc)( double );
 
 SwSbxValue SwCalc::Prim()
@@ -1294,112 +1271,131 @@ SwSbxValue SwCalc::Prim()
 
     switch( eCurrOper )
     {
-        case CALC_SIN:      pFnc = &sin;                        break;
-        case CALC_COS:      pFnc = &cos;                        break;
-        case CALC_TAN:      pFnc = &tan;                        break;
-        case CALC_ATAN:     pFnc = &atan;                       break;
-        case CALC_ASIN:     pFnc = &asin;   bChkTrig = sal_True;    break;
-        case CALC_ACOS:     pFnc = &acos;   bChkTrig = sal_True;    break;
-
-        case CALC_NOT:      {
-                                GetToken();
-                                nErg = Prim();
-                                if( SbxSTRING == nErg.GetType() )
-                                    nErg.PutBool( 0 == nErg.GetString().Len() );
-                                else if(SbxBOOL == nErg.GetType() )
-                                    nErg.PutBool(!nErg.GetBool());
-                                // evaluate arguments manually so that the binary NOT below
-                                // does not get called.
-                                // We want a BOOLEAN NOT.
-                                else if (nErg.IsNumeric())
-                                    nErg.PutLong( nErg.GetDouble() == 0.0 ? 1 : 0 );
-                                else
-                                {
-                                    OSL_FAIL( "unexpected case. computing binary NOT" );
-                                    //!! computes a binary NOT
-                                    nErg.Compute( SbxNOT, nErg );
-                                }
-                            }
-                            break;
+    case CALC_SIN:  pFnc = &sin;  break;
+    case CALC_COS:  pFnc = &cos;  break;
+    case CALC_TAN:  pFnc = &tan;  break;
+    case CALC_ATAN: pFnc = &atan; break;
+    case CALC_ASIN: pFnc = &asin; bChkTrig = sal_True; break;
+    case CALC_ACOS: pFnc = &acos; bChkTrig = sal_True; break;
+
+    case CALC_NOT:
+        {
+            GetToken();
+            nErg = Prim();
+            if( SbxSTRING == nErg.GetType() )
+            {
+                nErg.PutBool( 0 == nErg.GetString().Len() );
+            }
+            else if(SbxBOOL == nErg.GetType() )
+            {
+                nErg.PutBool(!nErg.GetBool());
+            }
+            // Evaluate arguments manually so that the binary NOT below does not
+            // get called. We want a BOOLEAN NOT.
+            else if (nErg.IsNumeric())
+            {
+                nErg.PutLong( nErg.GetDouble() == 0.0 ? 1 : 0 );
+            }
+            else
+            {
+                OSL_FAIL( "unexpected case. computing binary NOT" );
+                //!! computes a binary NOT
+                nErg.Compute( SbxNOT, nErg );
+            }
+        }
+        break;
 
-        case CALC_NUMBER:   if( GetToken() == CALC_PHD )
-                            {
-                                double aTmp = nNumberValue.GetDouble();
-                                aTmp *= 0.01;
-                                nErg.PutDouble( aTmp );
-                                GetToken();
-                            }
-                            else if( eCurrOper == CALC_NAME )
-                                eError = CALC_SYNTAX;
-                            else
-                            {
-                                nErg = nNumberValue;
-                                bChkPow = sal_True;
-                            }
-                            break;
+    case CALC_NUMBER:
+        if( GetToken() == CALC_PHD )
+        {
+            double aTmp = nNumberValue.GetDouble();
+            aTmp *= 0.01;
+            nErg.PutDouble( aTmp );
+            GetToken();
+        }
+        else if( eCurrOper == CALC_NAME )
+        {
+            eError = CALC_SYNTAX;
+        }
+        else
+        {
+            nErg = nNumberValue;
+            bChkPow = sal_True;
+        }
+        break;
 
-        case CALC_NAME:     if( GetToken() == CALC_ASSIGN )
-                            {
-                                SwCalcExp* n = VarInsert( aVarName );
-                                GetToken();
-                                nErg = n->nValue = Expr();
-                            }
-                            else
-                            {
-                                nErg = VarLook( aVarName )->nValue;
-                                bChkPow = sal_True;
-                            }
-                            break;
+    case CALC_NAME:
+        if( GetToken() == CALC_ASSIGN )
+        {
+            SwCalcExp* n = VarInsert( aVarName );
+            GetToken();
+            nErg = n->nValue = Expr();
+        }
+        else
+        {
+            nErg = VarLook( aVarName )->nValue;
+            bChkPow = sal_True;
+        }
+        break;
 
-        case CALC_MINUS:    GetToken();
-                            nErg.PutDouble( -(Prim().GetDouble()) );
-                            break;
+    case CALC_MINUS:
+        GetToken();
+        nErg.PutDouble( -(Prim().GetDouble()) );
+        break;
 
-        case CALC_LP:       {
-                                GetToken();
-                                nErg = Expr();
-                                if( eCurrOper != CALC_RP )
-                                    eError = CALC_BRACK;
-                                else
-                                {
-                                    GetToken();
-                                    bChkPow = sal_True; // in order for =(7)^2 to work
-                                }
-                            }
-                            break;
-
-        case CALC_MEAN:     {
-                                nListPor = 1;
-                                GetToken();
-                                nErg = Expr();
-                                double aTmp = nErg.GetDouble();
-                                aTmp /= nListPor;
-                                nErg.PutDouble( aTmp );
-                            }
-                            break;
+    case CALC_LP:
+        {
+            GetToken();
+            nErg = Expr();
+            if( eCurrOper != CALC_RP )
+            {
+                eError = CALC_BRACK;
+            }
+            else
+            {
+                GetToken();
+                bChkPow = sal_True; // in order for =(7)^2 to work
+            }
+        }
+        break;
 
-        case CALC_SQRT:     {
-                                GetToken();
-                                nErg = Prim();
-                                if( nErg.GetDouble() < 0 )
-                                    eError = CALC_OVERFLOW;
-                                else
-                                    nErg.PutDouble( sqrt( nErg.GetDouble() ));
-                            }
-                            break;
+    case CALC_MEAN:
+        {
+            nListPor = 1;
+            GetToken();
+            nErg = Expr();
+            double aTmp = nErg.GetDouble();
+            aTmp /= nListPor;
+            nErg.PutDouble( aTmp );
+        }
+        break;
+
+    case CALC_SQRT:
+        {
+            GetToken();
+            nErg = Prim();
+            if( nErg.GetDouble() < 0 )
+                eError = CALC_OVERFLOW;
+            else
+                nErg.PutDouble( sqrt( nErg.GetDouble() ));
+        }
+        break;
 
-        case CALC_SUM:
-        case CALC_DATE:
-        case CALC_MIN:
-        case CALC_MAX:      GetToken();
-                            nErg = Expr();
-                            break;
+    case CALC_SUM:
+    case CALC_DATE:
+    case CALC_MIN:
+    case CALC_MAX:
+        GetToken();
+        nErg = Expr();
+        break;
 
-        case CALC_ENDCALC:  nErg.Clear();
-                            break;
+    case CALC_ENDCALC:
+        nErg.Clear();
+        break;
 
-        default:            eError = CALC_SYNTAX;
-                            break;
+    default:
+        eError = CALC_SYNTAX;
+        break;
     }
 
     if( pFnc )
@@ -1437,7 +1433,6 @@ SwSbxValue SwCalc::Prim()
             else
             {
                 nErg.PutDouble( dleft );
-//              GetToken();
             }
         }
     }
@@ -1445,42 +1440,35 @@ SwSbxValue SwCalc::Prim()
     return nErg;
 }
 
-/******************************************************************************
-|*
-|*  SwSbxValue  SwCalc::Expr()
-|*
-|******************************************************************************/
-
 SwSbxValue  SwCalc::Expr()
 {
     SwSbxValue left = Term(), right;
     nLastLeft = left;
     for(;;)
+    {
         switch(eCurrOper)
         {
-            case CALC_PLUS:     GetToken();
-                                // erzeuge zum addieren auf jedenfall einen
-                                // Double-Wert
-                                left.MakeDouble();
-                                ( right = Term() ).MakeDouble();

... etc. - the rest is truncated


More information about the Libreoffice-commits mailing list