From dfbf0cabfa8310502e19642d56c746cc0d454d27 Mon Sep 17 00:00:00 2001 From: August Sodora Date: Fri, 23 Dec 2011 01:25:20 -0500 Subject: SV_DECL_VARARR->std::vector --- editeng/source/editeng/editeng.cxx | 4 +- editeng/source/editeng/editobj.cxx | 2 +- editeng/source/editeng/edtspell.cxx | 187 +++++++++++++++--------------------- editeng/source/editeng/edtspell.hxx | 21 +--- editeng/source/editeng/impedit2.cxx | 29 +++--- editeng/source/editeng/impedit3.cxx | 4 +- 6 files changed, 97 insertions(+), 150 deletions(-) (limited to 'editeng') diff --git a/editeng/source/editeng/editeng.cxx b/editeng/source/editeng/editeng.cxx index 0c7a746d044b..0ce3ff2a6ab9 100644 --- a/editeng/source/editeng/editeng.cxx +++ b/editeng/source/editeng/editeng.cxx @@ -1643,7 +1643,7 @@ void EditEngine::SetControlWord( sal_uInt32 nWord ) { ContentNode* pNode = pImpEditEngine->GetEditDoc().GetObject( n ); ParaPortion* pPortion = pImpEditEngine->GetParaPortions().GetObject( n ); - sal_Bool bWrongs = ( bSpellingChanged || ( nWord & EE_CNTRL_ONLINESPELLING ) ) ? pNode->GetWrongList()->HasWrongs() : sal_False; + sal_Bool bWrongs = ( bSpellingChanged || ( nWord & EE_CNTRL_ONLINESPELLING ) ) ? !pNode->GetWrongList()->empty() : sal_False; if ( bSpellingChanged ) pNode->DestroyWrongList(); if ( bWrongs ) @@ -2131,7 +2131,7 @@ sal_Bool EditEngine::HasOnlineSpellErrors() const for ( sal_uInt16 n = 0; n < nNodes; n++ ) { ContentNode* pNode = pImpEditEngine->GetEditDoc().GetObject( n ); - if ( pNode->GetWrongList() && pNode->GetWrongList()->Count() ) + if ( pNode->GetWrongList() && !pNode->GetWrongList()->empty() ) return sal_True; } return sal_False; diff --git a/editeng/source/editeng/editobj.cxx b/editeng/source/editeng/editobj.cxx index 51fb1d6d5b3b..a5a536d550e6 100644 --- a/editeng/source/editeng/editobj.cxx +++ b/editeng/source/editeng/editobj.cxx @@ -765,7 +765,7 @@ sal_Bool BinTextObject::HasOnlineSpellErrors() const for ( sal_uInt16 n = 0; n < aContents.Count(); n++ ) { ContentInfo* p = aContents.GetObject( n ); - if ( p->GetWrongList() && p->GetWrongList()->Count() ) + if ( p->GetWrongList() && !p->GetWrongList()->empty() ) return sal_True; } return sal_False; diff --git a/editeng/source/editeng/edtspell.cxx b/editeng/source/editeng/edtspell.cxx index 6dd989e7933c..a356257587c6 100644 --- a/editeng/source/editeng/edtspell.cxx +++ b/editeng/source/editeng/edtspell.cxx @@ -207,8 +207,6 @@ void EditSpellWrapper::CheckSpellTo() ////////////////////////////////////////////////////////////////////// -SV_IMPL_VARARR( WrongRanges, WrongRange ); - WrongList::WrongList() { nInvalidStart = 0; @@ -244,50 +242,48 @@ void WrongList::TextInserted( sal_uInt16 nPos, sal_uInt16 nNew, sal_Bool bPosIsS nInvalidEnd = nPos+nNew; } - for ( sal_uInt16 n = 0; n < Count(); n++ ) + for (WrongList::iterator i = begin(); i < end(); ++i) { - WrongRange& rWrong = GetObject( n ); sal_Bool bRefIsValid = sal_True; - if ( rWrong.nEnd >= nPos ) + if (i->nEnd >= nPos) { // Move all Wrongs after the insert position... - if ( rWrong.nStart > nPos ) + if (i->nStart > nPos) { - rWrong.nStart = rWrong.nStart + nNew; - rWrong.nEnd = rWrong.nEnd + nNew; + i->nStart += nNew; + i->nEnd += nNew; } // 1: Starts before and goes until nPos... - else if ( rWrong.nEnd == nPos ) + else if (i->nEnd == nPos) { // Should be halted at a blank! if ( !bPosIsSep ) - rWrong.nEnd = rWrong.nEnd + nNew; + i->nEnd += nNew; } // 2: Starts before and goes until after nPos... - else if ( ( rWrong.nStart < nPos ) && ( rWrong.nEnd > nPos ) ) + else if (i->nStart < nPos && i->nEnd > nPos) { - rWrong.nEnd = rWrong.nEnd + nNew; + i->nEnd += nNew; // When a separator remove and re-examine the Wrong if ( bPosIsSep ) { // Split Wrong... - WrongRange aNewWrong( rWrong.nStart, nPos ); - rWrong.nStart = nPos+1; - Insert( aNewWrong, n ); + WrongRange aNewWrong(i->nStart, nPos); + i->nStart = nPos + 1; + insert(i, aNewWrong); bRefIsValid = sal_False; // Reference no longer valid after Insert, the other was inserted in front of this position - n++; // This not again ... + ++i; // Not this again... } } // 3: Attribute starts at position .. - else if ( rWrong.nStart == nPos ) + else if (i->nStart == nPos) { - rWrong.nEnd = rWrong.nEnd + nNew; + i->nEnd += nNew; if ( bPosIsSep ) - rWrong.nStart++; + ++(i->nStart); } } - DBG_ASSERT( !bRefIsValid || ( rWrong.nStart < rWrong.nEnd ), - "TextInserted, WrongRange: Start >= End?!" ); + DBG_ASSERT(!bRefIsValid || i->nStart < i->nEnd, "TextInserted, WrongRange: Start >= End?!"); (void)bRefIsValid; } @@ -316,46 +312,40 @@ void WrongList::TextDeleted( sal_uInt16 nPos, sal_uInt16 nDeleted ) } } - for ( sal_uInt16 n = 0; n < Count(); n++ ) + for (WrongList::reverse_iterator i = rbegin(); i < rend(); ++i) { - WrongRange& rWrong = GetObject( n ); sal_Bool bDelWrong = sal_False; - if ( rWrong.nEnd >= nPos ) + if (i->nEnd >= nPos) { // Move all Wrongs after the insert position... - if ( rWrong.nStart >= nEndChanges ) + if (i->nStart >= nEndChanges) { - rWrong.nStart = rWrong.nStart - nDeleted; - rWrong.nEnd = rWrong.nEnd - nDeleted; + i->nStart -= nDeleted; + i->nEnd -= nDeleted; } // 1. Delete Internal Wrongs ... - else if ( ( rWrong.nStart >= nPos ) && ( rWrong.nEnd <= nEndChanges ) ) + else if (i->nStart >= nPos && i->nEnd <= nEndChanges) { bDelWrong = sal_True; } // 2. Wrong begins before, ends inside or behind it ... - else if ( ( rWrong.nStart <= nPos ) && ( rWrong.nEnd > nPos ) ) + else if (i->nStart <= nPos && i->nEnd > nPos) { - if ( rWrong.nEnd <= nEndChanges ) // ends inside - rWrong.nEnd = nPos; + if (i->nEnd <= nEndChanges) // ends inside + i->nEnd = nPos; else - rWrong.nEnd = rWrong.nEnd - nDeleted; // ends after + i->nEnd -= nDeleted; // ends after } // 3. Wrong begins inside, ending after ... - else if ( ( rWrong.nStart >= nPos ) && ( rWrong.nEnd > nEndChanges ) ) + else if (i->nStart >= nPos && i->nEnd > nEndChanges) { - rWrong.nStart = nEndChanges; - rWrong.nStart = rWrong.nStart - nDeleted; - rWrong.nEnd = rWrong.nEnd - nDeleted; + i->nStart = nEndChanges - nDeleted; + i->nEnd -= nDeleted; } } - DBG_ASSERT( rWrong.nStart < rWrong.nEnd, - "TextInserted, WrongRange: Start >= End?!" ); + DBG_ASSERT(i->nStart < i->nEnd, "TextInserted, WrongRange: Start >= End?!" ); if ( bDelWrong ) - { - Remove( n, 1 ); - n--; - } + erase(--(i.base())); } DBG_ASSERT( !DbgIsBuggy(), "InsertWrong: WrongList broken!" ); @@ -367,13 +357,12 @@ sal_Bool WrongList::NextWrong( sal_uInt16& rnStart, sal_uInt16& rnEnd ) const rnStart get the start position, is possibly adjusted wrt. Wrong start rnEnd does not have to be initialized. */ - for ( sal_uInt16 n = 0; n < Count(); n++ ) + for (WrongList::const_iterator i = begin(); i < end(); ++i) { - WrongRange& rWrong = GetObject( n ); - if ( rWrong.nEnd > rnStart ) + if ( i->nEnd > rnStart ) { - rnStart = rWrong.nStart; - rnEnd = rWrong.nEnd; + rnStart = i->nStart; + rnEnd = i->nEnd; return sal_True; } } @@ -382,12 +371,11 @@ sal_Bool WrongList::NextWrong( sal_uInt16& rnStart, sal_uInt16& rnEnd ) const sal_Bool WrongList::HasWrong( sal_uInt16 nStart, sal_uInt16 nEnd ) const { - for ( sal_uInt16 n = 0; n < Count(); n++ ) + for (WrongList::const_iterator i = begin(); i < end(); ++i) { - WrongRange& rWrong = GetObject( n ); - if ( ( rWrong.nStart == nStart ) && ( rWrong.nEnd == nEnd ) ) + if (i->nStart == nStart && i->nEnd == nEnd) return sal_True; - else if ( rWrong.nStart >= nStart ) + else if ( i->nStart >= nStart ) break; } return sal_False; @@ -395,12 +383,11 @@ sal_Bool WrongList::HasWrong( sal_uInt16 nStart, sal_uInt16 nEnd ) const sal_Bool WrongList::HasAnyWrong( sal_uInt16 nStart, sal_uInt16 nEnd ) const { - for ( sal_uInt16 n = 0; n < Count(); n++ ) + for (WrongList::const_iterator i = begin(); i < end(); ++i) { - WrongRange& rWrong = GetObject( n ); - if ( ( rWrong.nEnd >= nStart ) && ( rWrong.nStart < nEnd ) ) + if (i->nEnd >= nStart && i->nStart < nEnd) return sal_True; - else if ( rWrong.nStart >= nEnd ) + else if (i->nStart >= nEnd) break; } return sal_False; @@ -409,27 +396,21 @@ sal_Bool WrongList::HasAnyWrong( sal_uInt16 nStart, sal_uInt16 nEnd ) const void WrongList::ClearWrongs( sal_uInt16 nStart, sal_uInt16 nEnd, const ContentNode* pNode ) { - for ( sal_uInt16 n = 0; n < Count(); n++ ) + for (WrongList::reverse_iterator i = rbegin(); i < rend(); ++i) { - WrongRange& rWrong = GetObject( n ); - if ( ( rWrong.nEnd > nStart ) && ( rWrong.nStart < nEnd ) ) + if (i->nEnd > nStart && i->nStart < nEnd) { - if ( rWrong.nEnd > nEnd ) // Runs out + if (i->nEnd > nEnd) // Runs out { - rWrong.nStart = nEnd; + i->nStart = nEnd; // Blanks? - while ( ( rWrong.nStart < pNode->Len() ) && - ( ( pNode->GetChar( rWrong.nStart ) == ' ' ) || - ( pNode->IsFeature( rWrong.nStart ) ) ) ) - { - rWrong.nStart++; - } + while (i->nStart < pNode->Len() && + (pNode->GetChar(i->nStart) == ' ' || + pNode->IsFeature(i->nStart))) + ++(i->nStart); } else - { - Remove( n, 1 ); - n--; - } + erase(--(i.base())); } } @@ -439,47 +420,46 @@ void WrongList::ClearWrongs( sal_uInt16 nStart, sal_uInt16 nEnd, void WrongList::InsertWrong( sal_uInt16 nStart, sal_uInt16 nEnd, sal_Bool bClearRange ) { - sal_uInt16 nPos = Count(); - for ( sal_uInt16 n = 0; n < Count(); n++ ) + WrongList::iterator nPos = end(); + for (WrongList::iterator i = begin(); i < end(); ++i) { - WrongRange& rWrong = GetObject( n ); - if ( rWrong.nStart >= nStart ) + if (i->nStart >= nStart ) { - nPos = n; + nPos = i; if ( bClearRange ) { // It can really only happen that the Wrong starts exactly here // and runs along, but not that there are several ranges ... // Exactly in the range is no one allowed to be, otherwise this // Method can not be called! - DBG_ASSERT( ( ( rWrong.nStart == nStart ) && ( rWrong.nEnd > nEnd ) ) - || ( rWrong.nStart > nEnd ), "InsertWrong: RangeMismatch!" ); - if ( ( rWrong.nStart == nStart ) && ( rWrong.nEnd > nEnd ) ) - rWrong.nStart = nEnd+1; + DBG_ASSERT((i->nStart == nStart && i->nEnd > nEnd) || i->nStart > nEnd, "InsertWrong: RangeMismatch!"); + if (i->nStart == nStart && i->nEnd > nEnd) + i->nStart = nEnd + 1; } break; } } - Insert( WrongRange( nStart, nEnd ), nPos ); + + if(nPos < end()) + insert(nPos, WrongRange(nStart, nEnd)); + else + push_back(WrongRange(nStart, nEnd)); DBG_ASSERT( !DbgIsBuggy(), "InsertWrong: WrongList broken!" ); } void WrongList::MarkWrongsInvalid() { - if ( Count() ) - MarkInvalid( GetObject( 0 ).nStart, GetObject( Count()-1 ).nEnd ); + if (!empty()) + MarkInvalid(front().nStart, back().nEnd ); } -WrongList* WrongList::Clone() const +WrongList* WrongList::Clone() const { WrongList* pNew = new WrongList; - for ( sal_uInt16 n = 0; n < Count(); n++ ) - { - WrongRange& rWrong = GetObject( n ); - pNew->Insert( rWrong, pNew->Count() ); - } - + pNew->reserve(size()); + for (WrongList::const_iterator i = begin(); i < end(); ++i) + pNew->push_back(*i); return pNew; } @@ -489,22 +469,15 @@ bool WrongList::operator==(const WrongList& rCompare) const // cleck direct members if(GetInvalidStart() != rCompare.GetInvalidStart() || GetInvalidEnd() != rCompare.GetInvalidEnd() - || Count() != rCompare.Count()) - { + || size() != rCompare.size()) return false; - } - for(sal_uInt16 a(0); a < Count(); a++) - { - const WrongRange& rCandA(GetObject(a)); - const WrongRange& rCandB(rCompare.GetObject(a)); + WrongList::const_iterator rCA = begin(); + WrongList::const_iterator rCB = rCompare.begin(); - if(rCandA.nStart != rCandB.nStart - || rCandA.nEnd != rCandB.nEnd) - { + for(; rCA < end(); ++rCA) + if(rCA->nStart != rCB->nStart || rCA->nEnd != rCB->nEnd) return false; - } - } return true; } @@ -514,19 +487,15 @@ sal_Bool WrongList::DbgIsBuggy() const { // Check if the ranges overlap. sal_Bool bError = sal_False; - for ( sal_uInt16 _nA = 0; !bError && ( _nA < Count() ); _nA++ ) + for (WrongList::const_iterator i = begin(); !bError && (i < end()); ++i) { - WrongRange& rWrong = GetObject( _nA ); - for ( sal_uInt16 nB = _nA+1; !bError && ( nB < Count() ); nB++ ) + for (WrongList::const_iterator j = i + 1; !bError && (j < end()); ++j) { - WrongRange& rNextWrong = GetObject( nB ); // 1) Start before, End after the second Start - if ( ( rWrong.nStart <= rNextWrong.nStart ) - && ( rWrong.nEnd >= rNextWrong.nStart ) ) + if (i->nStart <= j->nStart && i->nEnd >= j->nStart) bError = sal_True; // 2) Start after the second Start, but still before the second End - else if ( ( rWrong.nStart >= rNextWrong.nStart) - && ( rWrong.nStart <= rNextWrong.nEnd ) ) + else if (i->nStart >= j->nStart && i->nStart <= j->nEnd) bError = sal_True; } } diff --git a/editeng/source/editeng/edtspell.hxx b/editeng/source/editeng/edtspell.hxx index 112276627367..edf2ec1ef6d2 100644 --- a/editeng/source/editeng/edtspell.hxx +++ b/editeng/source/editeng/edtspell.hxx @@ -81,10 +81,9 @@ struct WrongRange WrongRange( sal_uInt16 nS, sal_uInt16 nE ) { nStart = nS; nEnd = nE; } }; -SV_DECL_VARARR( WrongRanges, WrongRange, 4, 4 ) #define NOT_INVALID 0xFFFF -class WrongList : private WrongRanges +class WrongList : public std::vector { private: sal_uInt16 nInvalidStart; @@ -100,12 +99,6 @@ public: void SetValid() { nInvalidStart = NOT_INVALID; nInvalidEnd = 0; } void MarkInvalid( sal_uInt16 nS, sal_uInt16 nE ); - sal_uInt16 Count() const { return WrongRanges::Count(); } - - // When one knows what to do: - WrongRange& GetObject( sal_uInt16 n ) const { return WrongRanges::GetObject( n ); } - void InsertWrong( const WrongRange& rWrong, sal_uInt16 nPos ); - sal_uInt16 GetInvalidStart() const { return nInvalidStart; } sal_uInt16& GetInvalidStart() { return nInvalidStart; } @@ -115,8 +108,6 @@ public: void TextInserted( sal_uInt16 nPos, sal_uInt16 nChars, sal_Bool bPosIsSep ); void TextDeleted( sal_uInt16 nPos, sal_uInt16 nChars ); - void ResetRanges() { Remove( 0, Count() ); } - sal_Bool HasWrongs() const { return Count() != 0; } void InsertWrong( sal_uInt16 nStart, sal_uInt16 nEnd, sal_Bool bClearRange ); sal_Bool NextWrong( sal_uInt16& rnStart, sal_uInt16& rnEnd ) const; sal_Bool HasWrong( sal_uInt16 nStart, sal_uInt16 nEnd ) const; @@ -130,16 +121,6 @@ public: bool operator==(const WrongList& rCompare) const; }; -inline void WrongList::InsertWrong( const WrongRange& rWrong, sal_uInt16 nPos ) -{ - WrongRanges::Insert( rWrong, nPos ); -#ifdef DBG_UTIL - DBG_ASSERT( !DbgIsBuggy(), "Insert: WrongList broken!" ); -#endif -} - - - class EdtAutoCorrDoc : public SvxAutoCorrDoc { ImpEditEngine* pImpEE; diff --git a/editeng/source/editeng/impedit2.cxx b/editeng/source/editeng/impedit2.cxx index 0e326caf072b..eb36306909cf 100644 --- a/editeng/source/editeng/impedit2.cxx +++ b/editeng/source/editeng/impedit2.cxx @@ -2288,15 +2288,14 @@ EditPaM ImpEditEngine::ImpConnectParagraphs( ContentNode* pLeft, ContentNode* pR pLeft->GetWrongList()->ClearWrongs( nInv, 0xFFFF, pLeft ); // Possibly remove one pLeft->GetWrongList()->MarkInvalid( nInv, nEnd+1 ); // Take over misspelled words - sal_uInt16 nRWrongs = pRight->GetWrongList()->Count(); - for ( sal_uInt16 nW = 0; nW < nRWrongs; nW++ ) + WrongList* pRWrongs = pRight->GetWrongList(); + for (WrongList::iterator i = pRWrongs->begin(); i < pRWrongs->end(); ++i) { - WrongRange aWrong = pRight->GetWrongList()->GetObject( nW ); - if ( aWrong.nStart != 0 ) // Not a subsequent + if (i->nStart != 0) // Not a subsequent { - aWrong.nStart = aWrong.nStart + nEnd; - aWrong.nEnd = aWrong.nEnd + nEnd; - pLeft->GetWrongList()->InsertWrong( aWrong, pLeft->GetWrongList()->Count() ); + i->nStart = i->nStart + nEnd; + i->nEnd = i->nEnd + nEnd; + pLeft->GetWrongList()->push_back(*i); } } } @@ -2761,7 +2760,7 @@ EditPaM ImpEditEngine::ImpInsertText( EditSelection aCurSel, const XubString& rS { // now remove the Wrongs (red spell check marks) from both words... WrongList *pWrongs = aCurPaM.GetNode()->GetWrongList(); - if (pWrongs && pWrongs->HasWrongs()) + if (pWrongs && !pWrongs->empty()) pWrongs->ClearWrongs( aCurWord.Min().GetIndex(), aPaM.GetIndex(), aPaM.GetNode() ); // ... and mark both words as 'to be checked again' pPortion->MarkInvalid( aCurWord.Min().GetIndex(), aLine.Len() ); @@ -2858,21 +2857,19 @@ EditPaM ImpEditEngine::ImpInsertParaBreak( const EditPaM& rPaM, sal_Bool bKeepEn WrongList* pLWrongs = rPaM.GetNode()->GetWrongList(); WrongList* pRWrongs = aPaM.GetNode()->GetWrongList(); // take over misspelled words: - sal_uInt16 nLWrongs = pLWrongs->Count(); - for ( sal_uInt16 nW = 0; nW < nLWrongs; nW++ ) + for(WrongList::iterator i = pLWrongs->begin(); i < pLWrongs->end(); ++i) { - WrongRange& rWrong = pLWrongs->GetObject( nW ); // Correct only if really a word gets overlapped in the process of // Spell checking - if ( rWrong.nStart > nEnd ) + if (i->nStart > nEnd) { - pRWrongs->InsertWrong( rWrong, pRWrongs->Count() ); - WrongRange& rRWrong = pRWrongs->GetObject( pRWrongs->Count() - 1 ); + pRWrongs->push_back(*i); + WrongRange& rRWrong = pRWrongs->back(); rRWrong.nStart = rRWrong.nStart - nEnd; rRWrong.nEnd = rRWrong.nEnd - nEnd; } - else if ( ( rWrong.nStart < nEnd ) && ( rWrong.nEnd > nEnd ) ) - rWrong.nEnd = nEnd; + else if (i->nStart < nEnd && i->nEnd > nEnd) + i->nEnd = nEnd; } sal_uInt16 nInv = nEnd ? nEnd-1 : nEnd; if ( nEnd ) diff --git a/editeng/source/editeng/impedit3.cxx b/editeng/source/editeng/impedit3.cxx index ffdd294a9fe1..9c2a80033390 100644 --- a/editeng/source/editeng/impedit3.cxx +++ b/editeng/source/editeng/impedit3.cxx @@ -3143,7 +3143,7 @@ void ImpEditEngine::Paint( OutputDevice* pOutDev, Rectangle aClipRec, Point aSta { WrongList* pWrongs = pPortion->GetNode()->GetWrongList(); - if(pWrongs && pWrongs->HasWrongs()) + if(pWrongs && !pWrongs->empty()) { sal_uInt16 nStart(nIndex); sal_uInt16 nEnd(0); @@ -3367,7 +3367,7 @@ void ImpEditEngine::Paint( OutputDevice* pOutDev, Rectangle aClipRec, Point aSta } - if ( GetStatus().DoOnlineSpelling() && pPortion->GetNode()->GetWrongList()->HasWrongs() && pTextPortion->GetLen() ) + if ( GetStatus().DoOnlineSpelling() && !pPortion->GetNode()->GetWrongList()->empty() && pTextPortion->GetLen() ) { {//#105750# adjust LinePos for superscript or subscript text short _nEsc = aTmpFont.GetEscapement(); -- cgit