LCOV - code coverage report
Current view: top level - sw/source/core/inc - wrong.hxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 22 25 88.0 %
Date: 2012-08-25 Functions: 13 15 86.7 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 14 20 70.0 %

           Branch data     Line data    Source code
       1                 :            : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2                 :            : /*************************************************************************
       3                 :            :  *
       4                 :            :  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
       5                 :            :  *
       6                 :            :  * Copyright 2000, 2010 Oracle and/or its affiliates.
       7                 :            :  *
       8                 :            :  * OpenOffice.org - a multi-platform office productivity suite
       9                 :            :  *
      10                 :            :  * This file is part of OpenOffice.org.
      11                 :            :  *
      12                 :            :  * OpenOffice.org is free software: you can redistribute it and/or modify
      13                 :            :  * it under the terms of the GNU Lesser General Public License version 3
      14                 :            :  * only, as published by the Free Software Foundation.
      15                 :            :  *
      16                 :            :  * OpenOffice.org is distributed in the hope that it will be useful,
      17                 :            :  * but WITHOUT ANY WARRANTY; without even the implied warranty of
      18                 :            :  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
      19                 :            :  * GNU Lesser General Public License version 3 for more details
      20                 :            :  * (a copy is included in the LICENSE file that accompanied this code).
      21                 :            :  *
      22                 :            :  * You should have received a copy of the GNU Lesser General Public License
      23                 :            :  * version 3 along with OpenOffice.org.  If not, see
      24                 :            :  * <http://www.openoffice.org/license.html>
      25                 :            :  * for a copy of the LGPLv3 License.
      26                 :            :  *
      27                 :            :  ************************************************************************/
      28                 :            : 
      29                 :            : #ifndef _WRONG_HXX
      30                 :            : #define _WRONG_HXX
      31                 :            : 
      32                 :            : #include <com/sun/star/container/XStringKeyMap.hpp>
      33                 :            : 
      34                 :            : #include <vector>
      35                 :            : 
      36                 :            : #include <tools/string.hxx>
      37                 :            : 
      38                 :            : class SwWrongList;
      39                 :            : 
      40                 :            : // ST2
      41                 :       5661 : class SwWrongArea
      42                 :            : {
      43                 :            : public:
      44                 :            :     rtl::OUString maType;
      45                 :            :     com::sun::star::uno::Reference< com::sun::star::container::XStringKeyMap > mxPropertyBag;
      46                 :            :     xub_StrLen mnPos;
      47                 :            :     xub_StrLen mnLen;
      48                 :            :     SwWrongList* mpSubList;
      49                 :            : 
      50                 :            :     SwWrongArea() : mnPos(0), mnLen(0), mpSubList(NULL) {}
      51                 :       1174 :     SwWrongArea( const rtl::OUString& rType,
      52                 :            :                  com::sun::star::uno::Reference< com::sun::star::container::XStringKeyMap > xPropertyBag,
      53                 :            :                  xub_StrLen nPos,
      54                 :            :                  xub_StrLen nLen,
      55                 :            :                  SwWrongList* pSubList )
      56                 :       1174 :         : maType(rType), mxPropertyBag(xPropertyBag), mnPos(nPos), mnLen(nLen), mpSubList(pSubList) {}
      57                 :            : };
      58                 :            : 
      59                 :            : enum WrongListType
      60                 :            : {
      61                 :            :     WRONGLIST_SPELL,
      62                 :            :     WRONGLIST_GRAMMAR,
      63                 :            :     WRONGLIST_SMARTTAG,
      64                 :            :     WRONGLIST_CHANGETRACKING
      65                 :            : };
      66                 :            : 
      67                 :            : class SwWrongList
      68                 :            : {
      69                 :            :     std::vector<SwWrongArea> maList;
      70                 :            :     WrongListType            meType;
      71                 :            : 
      72                 :            :     xub_StrLen nBeginInvalid;   // Start of the invalid range
      73                 :            :     xub_StrLen nEndInvalid;     // End of the invalid range
      74                 :            : 
      75                 :       4864 :     void ShiftLeft( xub_StrLen &rPos, xub_StrLen nStart, xub_StrLen nEnd )
      76 [ +  + ][ +  + ]:       4864 :     { if( rPos > nStart ) rPos = rPos > nEnd ? rPos - nEnd + nStart : nStart; }
      77                 :            :     void ShiftRight( xub_StrLen &rPos, xub_StrLen nStart, xub_StrLen nEnd )
      78                 :            :     { if( rPos >= nStart ) rPos += nStart - nEnd; }
      79                 :            :     void _Invalidate( xub_StrLen nBegin, xub_StrLen nEnd );
      80                 :            : 
      81                 :            :     void Insert(sal_uInt16 nWhere, std::vector<SwWrongArea>::iterator startPos, std::vector<SwWrongArea>::iterator endPos);
      82                 :            :     void Remove( sal_uInt16 nIdx, sal_uInt16 nLen );
      83                 :            : 
      84                 :            :     // forbidden and not implemented
      85                 :            :     SwWrongList& operator= (const SwWrongList &);
      86                 :            :     SwWrongList( const SwWrongList& rCpy );
      87                 :            : 
      88                 :            : public:
      89                 :            :     SwWrongList( WrongListType eType );
      90                 :            : 
      91                 :            :     virtual ~SwWrongList();
      92                 :            :     virtual SwWrongList* Clone();
      93                 :            :     virtual void CopyFrom( const SwWrongList& rCopy );
      94                 :            : 
      95                 :       2961 :     inline WrongListType GetWrongListType() const { return meType; }
      96                 :      73012 :     inline xub_StrLen GetBeginInv() const { return nBeginInvalid; }
      97                 :      23804 :     inline xub_StrLen GetEndInv() const { return nEndInvalid; }
      98                 :            :     inline sal_Bool InsideInvalid( xub_StrLen nChk ) const
      99                 :            :         { return nChk >= nBeginInvalid && nChk <= nEndInvalid; }
     100                 :            :     void SetInvalid( xub_StrLen nBegin, xub_StrLen nEnd );
     101                 :          0 :     inline void Validate(){ nBeginInvalid = STRING_LEN; }
     102                 :            :     void Invalidate( xub_StrLen nBegin, xub_StrLen nEnd );
     103                 :            :     sal_Bool InvalidateWrong();
     104                 :            :     sal_Bool Fresh( xub_StrLen &rStart, xub_StrLen &rEnd, xub_StrLen nPos,
     105                 :            :             xub_StrLen nLen, sal_uInt16 nIndex, xub_StrLen nCursorPos );
     106                 :            :     sal_uInt16 GetWrongPos( xub_StrLen nValue ) const;
     107                 :            : 
     108                 :            :     sal_Bool Check( xub_StrLen &rChk, xub_StrLen &rLn ) const;
     109                 :            :     sal_Bool InWrongWord( xub_StrLen &rChk, xub_StrLen &rLn ) const;
     110                 :            :     xub_StrLen NextWrong( xub_StrLen nChk ) const;
     111                 :            : 
     112                 :            :     void Move( xub_StrLen nPos, long nDiff );
     113                 :            :     void ClearList();
     114                 :            : 
     115                 :            :     // Divide the list into two part, the wrong words until nSplitPos will be
     116                 :            :     // removed and transferred to a new SwWrongList.
     117                 :            :     SwWrongList* SplitList( xub_StrLen nSplitPos );
     118                 :            :     // Join the next SwWrongList, nInsertPos is my own text length, where
     119                 :            :     // the other wrong list has to be inserted.
     120                 :            :     void JoinList( SwWrongList* pNext, xub_StrLen nInsertPos );
     121                 :            : 
     122                 :      20314 :     inline xub_StrLen Len( sal_uInt16 nIdx ) const
     123                 :            :     {
     124         [ +  - ]:      20314 :         return nIdx < maList.size() ? maList[nIdx].mnLen : 0;
     125                 :            :     }
     126                 :            : 
     127                 :      28405 :     inline xub_StrLen Pos( sal_uInt16 nIdx ) const
     128                 :            :     {
     129         [ +  + ]:      28405 :         return nIdx < maList.size() ? maList[nIdx].mnPos : 0;
     130                 :            :     }
     131                 :            : 
     132                 :     186000 :     inline sal_uInt16 Count() const { return (sal_uInt16)maList.size(); }
     133                 :            : 
     134                 :        960 :     inline void Insert( const rtl::OUString& rType,
     135                 :            :                         com::sun::star::uno::Reference< com::sun::star::container::XStringKeyMap > xPropertyBag,
     136                 :            :                         xub_StrLen nNewPos, xub_StrLen nNewLen, sal_uInt16 nWhere )
     137                 :            :     {
     138                 :        960 :         std::vector<SwWrongArea>::iterator i = maList.begin();
     139         [ +  + ]:        960 :         if ( nWhere >= maList.size() )
     140                 :        922 :             i = maList.end(); // robust
     141                 :            :         else
     142                 :         38 :             i += nWhere;
     143 [ +  - ][ +  - ]:        960 :         maList.insert(i, SwWrongArea( rType, xPropertyBag, nNewPos, nNewLen, 0 ) );
                 [ +  - ]
     144                 :        960 :     }
     145                 :            : 
     146                 :            :     void Insert( const rtl::OUString& rType,
     147                 :            :                  com::sun::star::uno::Reference< com::sun::star::container::XStringKeyMap > xPropertyBag,
     148                 :            :                  xub_StrLen nNewPos, xub_StrLen nNewLen );
     149                 :            : 
     150                 :        197 :     inline SwWrongList* SubList( sal_uInt16 nIdx ) const
     151                 :            :     {
     152         [ +  + ]:        197 :         return nIdx < maList.size() ? maList[nIdx].mpSubList : 0;
     153                 :            :     }
     154                 :            : 
     155                 :            :     void InsertSubList( xub_StrLen nNewPos, xub_StrLen nNewLen, sal_uInt16 nWhere, SwWrongList* pSubList );
     156                 :            : 
     157                 :          0 :     inline const SwWrongArea* GetElement( sal_uInt16 nIdx ) const
     158                 :            :     {
     159         [ #  # ]:          0 :         return nIdx < maList.size() ? &maList[nIdx] : 0;
     160                 :            :     }
     161                 :            :     void RemoveEntry( xub_StrLen nBegin, xub_StrLen nEnd );
     162                 :            :     bool LookForEntry( xub_StrLen nBegin, xub_StrLen nEnd );
     163                 :            : };
     164                 :            : 
     165                 :            : #endif
     166                 :            : 
     167                 :            : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10