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