LCOV - code coverage report
Current view: top level - usr/local/src/libreoffice/sw/source/core/text - wrong.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 183 317 57.7 %
Date: 2013-07-09 Functions: 16 26 61.5 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2             : /*
       3             :  * This file is part of the LibreOffice project.
       4             :  *
       5             :  * This Source Code Form is subject to the terms of the Mozilla Public
       6             :  * License, v. 2.0. If a copy of the MPL was not distributed with this
       7             :  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
       8             :  *
       9             :  * This file incorporates work covered by the following license notice:
      10             :  *
      11             :  *   Licensed to the Apache Software Foundation (ASF) under one or more
      12             :  *   contributor license agreements. See the NOTICE file distributed
      13             :  *   with this work for additional information regarding copyright
      14             :  *   ownership. The ASF licenses this file to you under the Apache
      15             :  *   License, Version 2.0 (the "License"); you may not use this file
      16             :  *   except in compliance with the License. You may obtain a copy of
      17             :  *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
      18             :  */
      19             : 
      20             : #include "swtypes.hxx"
      21             : #include "txttypes.hxx"
      22             : 
      23             : #include "SwGrammarMarkUp.hxx"
      24             : 
      25             : /*************************************************************************
      26             :  *SwWrongArea::SwWrongArea
      27             :  *************************************************************************/
      28             : 
      29         284 : SwWrongArea::SwWrongArea( const rtl::OUString& rType, WrongListType listType,
      30             :         com::sun::star::uno::Reference< com::sun::star::container::XStringKeyMap > xPropertyBag,
      31             :         xub_StrLen nPos,
      32             :         xub_StrLen nLen)
      33         284 : : maType(rType), mxPropertyBag(xPropertyBag), mnPos(nPos), mnLen(nLen), mpSubList(0)
      34             : {
      35         284 :     mColor =  getWrongAreaColor(listType, xPropertyBag);
      36         284 :     mLineType = getWrongAreaLineType(listType, xPropertyBag);
      37         284 : }
      38             : 
      39           0 : SwWrongArea::SwWrongArea( const rtl::OUString& rType,
      40             :         com::sun::star::uno::Reference< com::sun::star::container::XStringKeyMap > xPropertyBag,
      41             :         xub_StrLen nPos,
      42             :         xub_StrLen nLen,
      43             :         SwWrongList* pSubList)
      44           0 : : maType(rType), mxPropertyBag(xPropertyBag), mnPos(nPos), mnLen(nLen), mpSubList(pSubList), mLineType(WRONGAREA_NONE)
      45             : {
      46           0 :     if (pSubList != 0)
      47             :     {
      48           0 :         mColor =  getWrongAreaColor(pSubList->GetWrongListType(), xPropertyBag);
      49           0 :         mLineType = getWrongAreaLineType(pSubList->GetWrongListType(), xPropertyBag);
      50             :     }
      51           0 : }
      52             : 
      53             : /*************************************************************************
      54             :  * SwWrongList::SwWrongList()
      55             :  *************************************************************************/
      56         410 : SwWrongList::SwWrongList( WrongListType eType ) :
      57             :     meType       (eType),
      58             :     nBeginInvalid(STRING_LEN),  // everything correct... (the invalid area starts beyond the string)
      59         410 :     nEndInvalid  (STRING_LEN)
      60             : {
      61         410 :     maList.reserve( 5 );
      62         410 : }
      63             : 
      64        1227 : SwWrongList::~SwWrongList()
      65             : {
      66         409 :     ClearList();
      67         818 : }
      68             : 
      69             : /*************************************************************************
      70             :  * SwWrongList* SwWrongList::Clone()
      71             :  *************************************************************************/
      72             : 
      73           0 : SwWrongList* SwWrongList::Clone()
      74             : {
      75           0 :     SwWrongList* pClone = new SwWrongList( meType );
      76           0 :     pClone->CopyFrom( *this );
      77           0 :     return pClone;
      78             : }
      79             : 
      80             : /*************************************************************************
      81             :  * void SwWrongList::CopyFrom( const SwWrongList& rCopy )
      82             :  *************************************************************************/
      83             : 
      84           0 : void SwWrongList::CopyFrom( const SwWrongList& rCopy )
      85             : {
      86           0 :     maList = rCopy.maList;
      87           0 :     meType = rCopy.meType;
      88           0 :     nBeginInvalid = rCopy.nBeginInvalid;
      89           0 :     nEndInvalid = rCopy.nEndInvalid;
      90           0 :     for( size_t i = 0; i < maList.size(); ++i )
      91             :     {
      92           0 :         if( maList[i].mpSubList )
      93           0 :             maList[i].mpSubList = maList[i].mpSubList->Clone();
      94             :     }
      95           0 : }
      96             : 
      97             : /*************************************************************************
      98             :  * SwWrongList::ClearList()
      99             :  *************************************************************************/
     100         409 : void SwWrongList::ClearList()
     101             : {
     102         584 :     for ( size_t i = 0; i < maList.size(); ++i)
     103             :     {
     104         175 :         if (maList[i].mpSubList)
     105           0 :             delete maList[i].mpSubList;
     106         175 :         maList[i].mpSubList = NULL;
     107             :     }
     108         409 :     maList.clear();
     109         409 : }
     110             : 
     111             : /*************************************************************************
     112             :  * sal_Bool SwWrongList::InWrongWord() gibt den Anfang und die Laenge des
     113             :  * Wortes zurueck, wenn es als falsch markiert ist.
     114             :  *************************************************************************/
     115           0 : sal_Bool SwWrongList::InWrongWord( xub_StrLen &rChk, xub_StrLen &rLn ) const
     116             : {
     117           0 :     MSHORT nPos = GetWrongPos( rChk );
     118             :     xub_StrLen nWrPos;
     119           0 :     if( nPos < Count() && ( nWrPos = Pos( nPos ) ) <= rChk )
     120             :     {
     121           0 :         rLn = Len( nPos );
     122           0 :         if( nWrPos + rLn <= rChk )
     123           0 :             return sal_False;
     124           0 :         rChk = nWrPos;
     125           0 :         return sal_True;
     126             :     }
     127           0 :     return sal_False;
     128             : }
     129             : 
     130             : /*************************************************************************
     131             :  * sal_Bool SwWrongList::Check() liefert den ersten falschen Bereich
     132             :  *************************************************************************/
     133        6260 : sal_Bool SwWrongList::Check( xub_StrLen &rChk, xub_StrLen &rLn ) const
     134             : {
     135        6260 :     MSHORT nPos = GetWrongPos( rChk );
     136        6260 :     rLn = rLn + rChk;
     137             :     xub_StrLen nWrPos;
     138             : 
     139        6260 :     if( nPos == Count() )
     140        5618 :         return sal_False;
     141             : 
     142         642 :     xub_StrLen nEnd = Len( nPos );
     143         642 :     nEnd = nEnd + ( nWrPos = Pos( nPos ) );
     144         642 :     if( nEnd == rChk )
     145             :     {
     146         275 :         ++nPos;
     147         275 :         if( nPos == Count() )
     148          15 :             return sal_False;
     149             :         else
     150             :         {
     151         260 :             nEnd = Len( nPos );
     152         260 :             nEnd = nEnd + ( nWrPos = Pos( nPos ) );
     153             :         }
     154             :     }
     155         627 :     if( nEnd > rChk && nWrPos < rLn )
     156             :     {
     157         543 :         if( nWrPos > rChk )
     158         326 :             rChk = nWrPos;
     159         543 :         if( nEnd < rLn )
     160         270 :             rLn = nEnd;
     161         543 :         rLn = rLn - rChk;
     162         543 :         return 0 != rLn;
     163             :     }
     164          84 :     return sal_False;
     165             : }
     166             : 
     167             : /*************************************************************************
     168             :  * xub_StrLen SwWrongList::NextWrong() liefert die naechste Fehlerposition
     169             :  *************************************************************************/
     170             : 
     171           0 : xub_StrLen SwWrongList::NextWrong( xub_StrLen nChk ) const
     172             : {
     173             :     xub_StrLen nRet;
     174           0 :     xub_StrLen nPos = GetWrongPos( nChk );
     175           0 :     if( nPos < Count() )
     176             :     {
     177           0 :         nRet = Pos( nPos );
     178           0 :         if( nRet < nChk && nRet + Len( nPos ) <= nChk )
     179             :         {
     180           0 :             if( ++nPos < Count() )
     181           0 :                 nRet = Pos( nPos );
     182             :             else
     183           0 :                 nRet = STRING_LEN;
     184             :         }
     185             :     }
     186             :     else
     187           0 :         nRet = STRING_LEN;
     188           0 :     if( nRet > GetBeginInv() && nChk < GetEndInv() )
     189           0 :         nRet = nChk > GetBeginInv() ? nChk : GetBeginInv();
     190           0 :     return nRet;
     191             : }
     192             : 
     193             : /*************************************************************************
     194             :  *                 MSHORT SwWrongList::GetWrongPos( xub_StrLen nValue )
     195             :  *  sucht die erste Position im Array, die groessergleich nValue ist,
     196             :  * dies kann natuerlich auch hinter dem letzten Element sein!
     197             :  *************************************************************************/
     198             : 
     199       10570 : MSHORT SwWrongList::GetWrongPos( xub_StrLen nValue ) const
     200             : {
     201       10570 :     MSHORT nOben = Count(), nUnten = 0;
     202             : 
     203       10570 :     if( nOben > 0 )
     204             :     {
     205             :         // For smart tag lists, we may not use a binary search. We return the
     206             :         // position of the first smart tag which coveres nValue
     207        1220 :         if ( !maList[0].maType.isEmpty() || maList[0].mpSubList )
     208             :         {
     209           0 :             for (std::vector<SwWrongArea>::const_iterator aIter(maList.begin()), aEnd(maList.end()); aIter != aEnd; ++aIter)
     210             :             {
     211           0 :                 const xub_StrLen nSTPos = (*aIter).mnPos;
     212           0 :                 const xub_StrLen nSTLen = (*aIter).mnLen;
     213           0 :                 if ( nSTPos <= nValue && nValue < nSTPos + nSTLen )
     214             :                     break;
     215           0 :                 else if ( nSTPos > nValue )
     216           0 :                     break;
     217             : 
     218           0 :                 ++nUnten;
     219             :             }
     220           0 :             return nUnten;
     221             :         }
     222             : 
     223        1220 :         --nOben;
     224        1220 :         MSHORT nMitte = 0;
     225        4506 :         while( nUnten <= nOben )
     226             :         {
     227        3258 :             nMitte = nUnten + ( nOben - nUnten ) / 2;
     228        3258 :             xub_StrLen nTmp = Pos( nMitte );
     229        3258 :             if( nTmp == nValue )
     230             :             {
     231         477 :                 nUnten = nMitte;
     232         477 :                 break;
     233             :             }
     234        2781 :             else if( nTmp < nValue )
     235             :             {
     236        1709 :                 if( nTmp + Len( nMitte ) >= nValue )
     237             :                 {
     238         569 :                     nUnten = nMitte;
     239         569 :                     break;
     240             :                 }
     241        1140 :                 nUnten = nMitte + 1;
     242             :             }
     243        1072 :             else if( nMitte == 0 )
     244             :             {
     245         146 :                 break;
     246             :             }
     247             :             else
     248         926 :                 nOben = nMitte - 1;
     249             :         }
     250             :     }
     251             : 
     252             :     // nUnten now points to an index i into the wrong list which
     253             :     // 1. nValue is inside [ Area[i].pos, Area[i].pos + Area[i].len ] (inkl!!!)
     254             :     // 2. nValue < Area[i].pos
     255             : 
     256       10570 :     return nUnten;
     257             : }
     258             : 
     259             : /*************************************************************************
     260             :  *                 void SwWrongList::_Invalidate()
     261             :  *************************************************************************/
     262             : 
     263        3196 : void SwWrongList::_Invalidate( xub_StrLen nBegin, xub_StrLen nEnd )
     264             : {
     265        3196 :     if ( nBegin < GetBeginInv() )
     266          13 :         nBeginInvalid = nBegin;
     267        3196 :     if ( nEnd > GetEndInv() )
     268         582 :         nEndInvalid = nEnd;
     269        3196 : }
     270             : 
     271        1364 : void SwWrongList::SetInvalid( xub_StrLen nBegin, xub_StrLen nEnd )
     272             : {
     273        1364 :     nBeginInvalid = nBegin;
     274        1364 :     nEndInvalid = nEnd;
     275        1364 : }
     276             : 
     277             : 
     278             : /*************************************************************************
     279             :  *                      SwWrongList::Move( xub_StrLen nPos, long nDiff )
     280             :  *  veraendert alle Positionen ab nPos um den angegebenen Wert,
     281             :  *  wird nach Einfuegen oder Loeschen von Buchstaben benoetigt.
     282             :  *************************************************************************/
     283             : 
     284        2890 : void SwWrongList::Move( xub_StrLen nPos, long nDiff )
     285             : {
     286        2890 :     MSHORT i = GetWrongPos( nPos );
     287        2890 :     if( nDiff < 0 )
     288             :     {
     289         465 :         xub_StrLen nEnd = nPos + xub_StrLen( -nDiff );
     290         465 :         MSHORT nLst = i;
     291             :         xub_StrLen nWrPos;
     292             :         xub_StrLen nWrLen;
     293         465 :         bool bJump = false;
     294        1011 :         while( nLst < Count() && Pos( nLst ) < nEnd )
     295          81 :             ++nLst;
     296         465 :         if( nLst > i && ( nWrPos = Pos( nLst - 1 ) ) <= nPos )
     297             :         {
     298           1 :             nWrLen = Len( nLst - 1 );
     299             :             // calculate new length of word
     300           1 :             nWrLen = ( nEnd > nWrPos + nWrLen ) ?
     301             :                        nPos - nWrPos :
     302           1 :                        static_cast<xub_StrLen>(nWrLen + nDiff);
     303           1 :             if( nWrLen )
     304             :             {
     305           0 :                 maList[--nLst].mnLen = nWrLen;
     306           0 :                 bJump = true;
     307             :             }
     308             :         }
     309         465 :         Remove( i, nLst - i );
     310             : 
     311         465 :         if ( bJump )
     312           0 :             ++i;
     313         465 :         if( STRING_LEN == GetBeginInv() )
     314           2 :             SetInvalid( nPos ? nPos - 1 : nPos, nPos + 1 );
     315             :         else
     316             :         {
     317         463 :             ShiftLeft( nBeginInvalid, nPos, nEnd );
     318         463 :             ShiftLeft( nEndInvalid, nPos, nEnd );
     319         463 :             _Invalidate( nPos ? nPos - 1 : nPos, nPos + 1 );
     320             :         }
     321             :     }
     322             :     else
     323             :     {
     324             :         xub_StrLen nWrPos;
     325        2425 :         xub_StrLen nEnd = nPos + xub_StrLen( nDiff );
     326        2425 :         if( STRING_LEN != GetBeginInv() )
     327             :         {
     328        2421 :             if( nBeginInvalid > nPos )
     329           1 :                 nBeginInvalid = nBeginInvalid + xub_StrLen( nDiff );
     330        2421 :             if( nEndInvalid >= nPos )
     331        2207 :                 nEndInvalid = nEndInvalid + xub_StrLen( nDiff );
     332             :         }
     333             :         // Wenn wir mitten in einem falschen Wort stehen, muss vom Wortanfang
     334             :         // invalidiert werden.
     335        2425 :         if( i < Count() && nPos >= ( nWrPos = Pos( i ) ) )
     336             :         {
     337           3 :             Invalidate( nWrPos, nEnd );
     338           3 :             xub_StrLen nWrLen = Len( i ) + xub_StrLen( nDiff );
     339           3 :             maList[i++].mnLen = nWrLen;
     340           3 :             nWrLen = nWrLen + nWrPos;
     341           3 :             Invalidate( nWrPos, nWrLen );
     342             :         }
     343             :         else
     344        2422 :             Invalidate( nPos, nEnd );
     345             :     }
     346        5785 :     while( i < Count() )
     347             :     {
     348           5 :         const xub_StrLen nTmp = static_cast<xub_StrLen>(nDiff + maList[i].mnPos);
     349           5 :         maList[i++].mnPos = nTmp;
     350             :     }
     351        2890 : }
     352             : 
     353             : /*************************************************************************
     354             :  *                      SwWrongList::Fresh
     355             :  *
     356             :  * For a given range [nPos, nPos + nLen[ and an index nIndex, this function
     357             :  * basically counts the number of SwWrongArea entries starting with nIndex
     358             :  * up to nPos + nLen. All these entries are removed.
     359             :  *************************************************************************/
     360        1827 : sal_Bool SwWrongList::Fresh( xub_StrLen &rStart, xub_StrLen &rEnd, xub_StrLen nPos,
     361             :                              xub_StrLen nLen, MSHORT nIndex, xub_StrLen nCursorPos )
     362             : {
     363             :     // length of word must be greater than 0 and cursor position must be outside the word
     364        1827 :     sal_Bool bRet = nLen && ( nCursorPos > nPos + nLen || nCursorPos < nPos );
     365             : 
     366        1827 :     xub_StrLen nWrPos = 0;
     367        1827 :     xub_StrLen nWrEnd = rEnd;
     368        1827 :     MSHORT nCnt = nIndex;
     369        1827 :     if( nCnt < Count() && ( nWrPos = Pos( nIndex ) ) < nPos )
     370             :     {
     371           0 :         if( rStart > nWrPos )
     372           0 :             rStart = nWrPos;
     373             :     }
     374             : 
     375        3654 :     while( nCnt < Count() && ( nWrPos = Pos( nCnt ) ) < nPos )
     376           0 :         nWrEnd = nWrPos + Len( nCnt++ );
     377             : 
     378        1827 :     if( nCnt < Count() && nWrPos == nPos && Len( nCnt ) == nLen )
     379             :     {
     380          28 :         ++nCnt;
     381          28 :         bRet = sal_True;
     382             :     }
     383             :     else
     384             :     {
     385        1799 :         if( bRet )
     386             :         {
     387         256 :             if( rStart > nPos )
     388          54 :                 rStart = nPos;
     389         256 :             nWrEnd = nPos + nLen;
     390             :         }
     391             :     }
     392             : 
     393        1827 :     nPos = nPos + nLen;
     394             : 
     395        1827 :     if( nCnt < Count() && ( nWrPos = Pos( nCnt ) ) < nPos )
     396             :     {
     397           0 :         if( rStart > nWrPos )
     398           0 :             rStart = nWrPos;
     399             :     }
     400             : 
     401        3654 :     while( nCnt < Count() && ( nWrPos = Pos( nCnt ) ) < nPos )
     402           0 :         nWrEnd = nWrPos + Len( nCnt++ );
     403             : 
     404        1827 :     if( rEnd < nWrEnd )
     405         256 :         rEnd = nWrEnd;
     406             : 
     407        1827 :     Remove( nIndex, nCnt - nIndex );
     408             : 
     409        1827 :     return bRet;
     410             : }
     411             : 
     412        2688 : void SwWrongList::Invalidate( xub_StrLen nBegin, xub_StrLen nEnd )
     413             : {
     414        2688 :     if (STRING_LEN == GetBeginInv())
     415          14 :         SetInvalid( nBegin, nEnd );
     416             :     else
     417        2674 :         _Invalidate( nBegin, nEnd );
     418        2688 : }
     419             : 
     420           0 : sal_Bool SwWrongList::InvalidateWrong( )
     421             : {
     422           0 :     if( Count() )
     423             :     {
     424           0 :         xub_StrLen nFirst = Pos( 0 );
     425           0 :         xub_StrLen nLast = Pos( Count() - 1 ) + Len( Count() - 1 );
     426           0 :         Invalidate( nFirst, nLast );
     427           0 :         return sal_True;
     428             :     }
     429             :     else
     430           0 :         return sal_False;
     431             : }
     432             : 
     433          60 : SwWrongList* SwWrongList::SplitList( xub_StrLen nSplitPos )
     434             : {
     435          60 :     SwWrongList *pRet = NULL;
     436          60 :     MSHORT nLst = 0;
     437             :     xub_StrLen nWrPos;
     438             :     xub_StrLen nWrLen;
     439         121 :     while( nLst < Count() && Pos( nLst ) < nSplitPos )
     440           1 :         ++nLst;
     441          62 :     if( nLst && ( nWrPos = Pos( nLst - 1 ) )
     442           2 :         + ( nWrLen = Len( nLst - 1 ) ) > nSplitPos )
     443             :     {
     444           1 :         nWrLen += nWrPos - nSplitPos;
     445           1 :         maList[--nLst].mnPos = nSplitPos;
     446           1 :         maList[nLst].mnLen = nWrLen;
     447             :     }
     448          60 :     if( nLst )
     449             :     {
     450           0 :         if( WRONGLIST_GRAMMAR == GetWrongListType() )
     451           0 :             pRet = new SwGrammarMarkUp();
     452             :         else
     453           0 :             pRet = new SwWrongList( GetWrongListType() );
     454           0 :         pRet->Insert(0, maList.begin(), ( nLst >= maList.size() ? maList.end() : maList.begin() + nLst ) );
     455           0 :         pRet->SetInvalid( GetBeginInv(), GetEndInv() );
     456           0 :         pRet->_Invalidate( nSplitPos ? nSplitPos - 1 : nSplitPos, nSplitPos );
     457           0 :         Remove( 0, nLst );
     458             :     }
     459          60 :     if( STRING_LEN == GetBeginInv() )
     460           1 :         SetInvalid( 0, 1 );
     461             :     else
     462             :     {
     463          59 :         ShiftLeft( nBeginInvalid, 0, nSplitPos );
     464          59 :         ShiftLeft( nEndInvalid, 0, nSplitPos );
     465          59 :         _Invalidate( 0, 1 );
     466             :     }
     467          60 :     nLst = 0;
     468         125 :     while( nLst < Count() )
     469             :     {
     470           5 :         nWrPos = maList[nLst].mnPos - nSplitPos;
     471           5 :         maList[nLst++].mnPos = nWrPos;
     472             :     }
     473          60 :     return pRet;
     474             : }
     475             : 
     476           7 : void SwWrongList::JoinList( SwWrongList* pNext, xub_StrLen nInsertPos )
     477             : {
     478             :     if (pNext)
     479             :     {
     480             :         OSL_ENSURE( GetWrongListType() == pNext->GetWrongListType(), "type mismatch with next list" );
     481             :     }
     482           7 :     if( pNext )
     483             :     {
     484           6 :         sal_uInt16 nCnt = Count();
     485           6 :         pNext->Move( 0, nInsertPos );
     486           6 :         Insert(nCnt, pNext->maList.begin(), pNext->maList.end());
     487             : 
     488           6 :         Invalidate( pNext->GetBeginInv(), pNext->GetEndInv() );
     489           6 :         if( nCnt && Count() > nCnt )
     490             :         {
     491           0 :             xub_StrLen nWrPos = Pos( nCnt );
     492           0 :             xub_StrLen nWrLen = Len( nCnt );
     493           0 :             if( !nWrPos )
     494             :             {
     495           0 :                 nWrPos = nWrPos + nInsertPos;
     496           0 :                 nWrLen = nWrLen - nInsertPos;
     497           0 :                 maList[nCnt].mnPos = nWrPos;
     498           0 :                 maList[nCnt].mnLen = nWrLen;
     499             :             }
     500           0 :             if( nWrPos == Pos( nCnt - 1 ) + Len( nCnt - 1 ) )
     501             :             {
     502           0 :                 nWrLen = nWrLen + Len( nCnt - 1 );
     503           0 :                 maList[nCnt - 1].mnLen = nWrLen;
     504           0 :                 Remove( nCnt, 1 );
     505             :             }
     506             :         }
     507             :     }
     508           7 :     Invalidate( nInsertPos ? nInsertPos - 1 : nInsertPos, nInsertPos + 1 );
     509           7 : }
     510             : 
     511             : 
     512           0 : void SwWrongList::InsertSubList( xub_StrLen nNewPos, xub_StrLen nNewLen, sal_uInt16 nWhere, SwWrongList* pSubList )
     513             : {
     514             :     if (pSubList)
     515             :     {
     516             :         OSL_ENSURE( GetWrongListType() == pSubList->GetWrongListType(), "type mismatch with sub list" );
     517             :     }
     518           0 :     std::vector<SwWrongArea>::iterator i = maList.begin();
     519           0 :     if ( nWhere >= maList.size() )
     520           0 :         i = maList.end(); // robust
     521             :     else
     522           0 :         i += nWhere;
     523           0 :     maList.insert(i, SwWrongArea( OUString(), 0, nNewPos, nNewLen, pSubList ) );
     524           0 : }
     525             : 
     526             : 
     527             : // New functions: Necessary because SwWrongList has been changed to use std::vector
     528           6 : void SwWrongList::Insert(sal_uInt16 nWhere, std::vector<SwWrongArea>::iterator startPos, std::vector<SwWrongArea>::iterator endPos)
     529             : {
     530           6 :     std::vector<SwWrongArea>::iterator i = maList.begin();
     531           6 :     if ( nWhere >= maList.size() )
     532           6 :         i = maList.end(); // robust
     533             :     else
     534           0 :         i += nWhere;
     535           6 :     maList.insert(i, startPos, endPos); // insert [startPos, endPos[ before i
     536             : 
     537             :     // ownership of the sublist is passed to maList, therefore we have to set the
     538             :     // pSubList-Pointers to 0
     539          12 :     while ( startPos != endPos )
     540             :     {
     541           0 :         (*startPos).mpSubList = 0;
     542           0 :         ++startPos;
     543             :     }
     544           6 : }
     545             : 
     546        2292 : void SwWrongList::Remove(sal_uInt16 nIdx, sal_uInt16 nLen )
     547             : {
     548        4584 :     if ( nIdx >= maList.size() ) return;
     549          34 :     std::vector<SwWrongArea>::iterator i1 = maList.begin();
     550          34 :     i1 += nIdx;
     551             : 
     552          34 :     std::vector<SwWrongArea>::iterator i2 = i1;
     553          34 :     if ( nIdx + nLen >= static_cast<sal_uInt16>(maList.size()) )
     554          18 :         i2 = maList.end(); // robust
     555             :     else
     556          16 :         i2 += nLen;
     557             : 
     558          34 :     std::vector<SwWrongArea>::iterator iLoop = i1;
     559         177 :     while ( iLoop != i2 )
     560             :     {
     561         109 :         if ( (*iLoop).mpSubList )
     562           0 :             delete (*iLoop).mpSubList;
     563         109 :         ++iLoop;
     564             :     }
     565             : 
     566             : #if OSL_DEBUG_LEVEL > 0
     567             :     const int nOldSize = Count();
     568             :     (void) nOldSize;
     569             : #endif
     570             : 
     571          34 :     maList.erase(i1, i2);
     572             : 
     573             : #if OSL_DEBUG_LEVEL > 0
     574             :     OSL_ENSURE( Count() + nLen == nOldSize, "SwWrongList::Remove() trouble" );
     575             : #endif
     576             : }
     577             : 
     578           0 : void SwWrongList::RemoveEntry( xub_StrLen nBegin, xub_StrLen nEnd ) {
     579           0 :     sal_uInt16 nDelPos = 0;
     580           0 :     sal_uInt16 nDel = 0;
     581           0 :     std::vector<SwWrongArea>::const_iterator aIter(maList.begin()), aEnd(maList.end());
     582           0 :     while( aIter != aEnd && (*aIter).mnPos < nBegin )
     583             :     {
     584           0 :         ++aIter;
     585           0 :         ++nDelPos;
     586             :     }
     587           0 :     if( WRONGLIST_GRAMMAR == GetWrongListType() )
     588             :     {
     589           0 :         while( aIter != aEnd && nBegin < nEnd && nEnd > (*aIter).mnPos )
     590             :         {
     591           0 :             ++aIter;
     592           0 :             ++nDel;
     593             :         }
     594             :     }
     595             :     else
     596             :     {
     597           0 :         while( aIter != aEnd && nBegin == (*aIter).mnPos && nEnd == (*aIter).mnPos +(*aIter).mnLen )
     598             :         {
     599           0 :             ++aIter;
     600           0 :             ++nDel;
     601             :         }
     602             :     }
     603           0 :     if( nDel )
     604           0 :         Remove( nDelPos, nDel );
     605           0 : }
     606             : 
     607           0 : bool SwWrongList::LookForEntry( xub_StrLen nBegin, xub_StrLen nEnd ) {
     608           0 :     std::vector<SwWrongArea>::iterator aIter = maList.begin();
     609           0 :     while( aIter != maList.end() && (*aIter).mnPos < nBegin )
     610           0 :         ++aIter;
     611           0 :     if( aIter != maList.end() && nBegin == (*aIter).mnPos && nEnd == (*aIter).mnPos +(*aIter).mnLen )
     612           0 :         return true;
     613           0 :     return false;
     614             : }
     615             : 
     616           0 : void SwWrongList::Insert( const OUString& rType,
     617             :                           com::sun::star::uno::Reference< com::sun::star::container::XStringKeyMap > xPropertyBag,
     618             :                           xub_StrLen nNewPos, xub_StrLen nNewLen )
     619             : {
     620           0 :     std::vector<SwWrongArea>::iterator aIter = maList.begin();
     621             : 
     622           0 :     while ( aIter != maList.end() )
     623             :     {
     624           0 :         const xub_StrLen nSTPos = (*aIter).mnPos;
     625             : 
     626           0 :         if ( nNewPos < nSTPos )
     627             :         {
     628             :             // insert at current position
     629           0 :             break;
     630             :         }
     631           0 :         else if ( nNewPos == nSTPos )
     632             :         {
     633           0 :             while ( aIter != maList.end() && (*aIter).mnPos == nSTPos )
     634             :             {
     635           0 :                 const xub_StrLen nSTLen = (*aIter).mnLen;
     636             : 
     637           0 :                 if ( nNewLen < nSTLen )
     638             :                 {
     639             :                     // insert at current position
     640           0 :                     break;
     641             :                 }
     642             : 
     643           0 :                 ++aIter;
     644             :             }
     645             : 
     646           0 :             break;
     647             :         }
     648             : 
     649           0 :         ++aIter;
     650             :     }
     651             : 
     652           0 :     maList.insert(aIter, SwWrongArea( rType, meType, xPropertyBag, nNewPos, nNewLen) );
     653           0 : }
     654             : 
     655             : 
     656             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10