1 /************************************************************************* 2 * 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * Copyright 2000, 2010 Oracle and/or its affiliates. 6 * 7 * OpenOffice.org - a multi-platform office productivity suite 8 * 9 * This file is part of OpenOffice.org. 10 * 11 * OpenOffice.org is free software: you can redistribute it and/or modify 12 * it under the terms of the GNU Lesser General Public License version 3 13 * only, as published by the Free Software Foundation. 14 * 15 * OpenOffice.org is distributed in the hope that it will be useful, 16 * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 * GNU Lesser General Public License version 3 for more details 19 * (a copy is included in the LICENSE file that accompanied this code). 20 * 21 * You should have received a copy of the GNU Lesser General Public License 22 * version 3 along with OpenOffice.org. If not, see 23 * <http://www.openoffice.org/license.html> 24 * for a copy of the LGPLv3 License. 25 * 26 ************************************************************************/ 27 28 // MARKER(update_precomp.py): autogen include statement, do not remove 29 #include "precompiled_sw.hxx" 30 31 #include "SwGrammarMarkUp.hxx" 32 33 SwGrammarMarkUp::~SwGrammarMarkUp() 34 { 35 } 36 37 SwWrongList* SwGrammarMarkUp::Clone() 38 { 39 SwWrongList* pClone = new SwGrammarMarkUp(); 40 pClone->CopyFrom( *this ); 41 return pClone; 42 } 43 44 void SwGrammarMarkUp::CopyFrom( const SwWrongList& rCopy ) 45 { 46 maSentence = ((const SwGrammarMarkUp&)rCopy).maSentence; 47 SwWrongList::CopyFrom( rCopy ); 48 } 49 50 51 void SwGrammarMarkUp::MoveGrammar( xub_StrLen nPos, long nDiff ) 52 { 53 Move( nPos, nDiff ); 54 if( !maSentence.size() ) 55 return; 56 std::vector< xub_StrLen >::iterator pIter = maSentence.begin(); 57 while( pIter != maSentence.end() && *pIter < nPos ) 58 ++pIter; 59 xub_StrLen nEnd = nDiff < 0 ? xub_StrLen(nPos - nDiff) : nPos; 60 while( pIter != maSentence.end() ) 61 { 62 if( *pIter >= nEnd ) 63 *pIter = xub_StrLen( *pIter + nDiff ); 64 else 65 *pIter = nPos; 66 ++pIter; 67 } 68 } 69 70 SwGrammarMarkUp* SwGrammarMarkUp::SplitGrammarList( xub_StrLen nSplitPos ) 71 { 72 SwGrammarMarkUp* pNew = (SwGrammarMarkUp*)SplitList( nSplitPos ); 73 if( !maSentence.size() ) 74 return pNew; 75 std::vector< xub_StrLen >::iterator pIter = maSentence.begin(); 76 while( pIter != maSentence.end() && *pIter < nSplitPos ) 77 ++pIter; 78 if( pIter != maSentence.begin() ) 79 { 80 if( !pNew ) { 81 pNew = new SwGrammarMarkUp(); 82 pNew->SetInvalid( 0, STRING_LEN ); 83 } 84 pNew->maSentence.insert( pNew->maSentence.begin(), maSentence.begin(), pIter ); 85 maSentence.erase( maSentence.begin(), pIter ); 86 } 87 return pNew; 88 } 89 90 void SwGrammarMarkUp::JoinGrammarList( SwGrammarMarkUp* pNext, xub_StrLen nInsertPos ) 91 { 92 JoinList( pNext, nInsertPos ); 93 if (pNext) 94 { 95 if( !pNext->maSentence.size() ) 96 return; 97 std::vector< xub_StrLen >::iterator pIter = pNext->maSentence.begin(); 98 while( pIter != pNext->maSentence.end() ) 99 { 100 *pIter = *pIter + nInsertPos; 101 ++pIter; 102 } 103 maSentence.insert( maSentence.end(), pNext->maSentence.begin(), pNext->maSentence.end() ); 104 } 105 } 106 107 void SwGrammarMarkUp::ClearGrammarList( xub_StrLen nSentenceEnd ) 108 { 109 if( STRING_LEN == nSentenceEnd ) { 110 ClearList(); 111 maSentence.clear(); 112 Validate(); 113 } else if( GetBeginInv() <= nSentenceEnd ) { 114 std::vector< xub_StrLen >::iterator pIter = maSentence.begin(); 115 xub_StrLen nStart = 0; 116 while( pIter != maSentence.end() && *pIter < GetBeginInv() ) 117 { 118 nStart = *pIter; 119 ++pIter; 120 } 121 std::vector< xub_StrLen >::iterator pLast = pIter; 122 while( pLast != maSentence.end() && *pLast <= nSentenceEnd ) 123 ++pLast; 124 maSentence.erase( pIter, pLast ); 125 RemoveEntry( nStart, nSentenceEnd ); 126 SetInvalid( nSentenceEnd + 1, STRING_LEN ); 127 } 128 } 129 130 void SwGrammarMarkUp::setSentence( xub_StrLen nStart ) 131 { 132 std::vector< xub_StrLen >::iterator pIter = maSentence.begin(); 133 while( pIter != maSentence.end() && *pIter < nStart ) 134 ++pIter; 135 if( pIter == maSentence.end() || *pIter > nStart ) 136 maSentence.insert( pIter, nStart ); 137 } 138 139 xub_StrLen SwGrammarMarkUp::getSentenceStart( xub_StrLen nPos ) 140 { 141 if( !maSentence.size() ) 142 return 0; 143 std::vector< xub_StrLen >::iterator pIter = maSentence.begin(); 144 while( pIter != maSentence.end() && *pIter < nPos ) 145 ++pIter; 146 if( pIter != maSentence.begin() ) 147 --pIter; 148 xub_StrLen nRet = 0; 149 if( pIter != maSentence.end() && *pIter < nPos ) 150 nRet = *pIter; 151 return nRet; 152 } 153 154 xub_StrLen SwGrammarMarkUp::getSentenceEnd( xub_StrLen nPos ) 155 { 156 if( !maSentence.size() ) 157 return STRING_LEN; 158 std::vector< xub_StrLen >::iterator pIter = maSentence.begin(); 159 while( pIter != maSentence.end() && *pIter <= nPos ) 160 ++pIter; 161 xub_StrLen nRet = STRING_LEN; 162 if( pIter != maSentence.end() ) 163 nRet = *pIter; 164 return nRet; 165 } 166 167