Update ooo320-m1
[ooovba.git] / sw / source / core / text / SwGrammarMarkUp.cxx
blobe060f4f59c72cb783fd8ec7695561d589cd72a06
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: SwGrammarMarkUp.cxx,v $
10 * $Revision: 1.2 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_sw.hxx"
34 #include "SwGrammarMarkUp.hxx"
36 SwGrammarMarkUp::~SwGrammarMarkUp()
40 SwWrongList* SwGrammarMarkUp::Clone()
42 SwWrongList* pClone = new SwGrammarMarkUp();
43 pClone->CopyFrom( *this );
44 return pClone;
47 void SwGrammarMarkUp::CopyFrom( const SwWrongList& rCopy )
49 maSentence = ((const SwGrammarMarkUp&)rCopy).maSentence;
50 SwWrongList::CopyFrom( rCopy );
54 void SwGrammarMarkUp::MoveGrammar( xub_StrLen nPos, long nDiff )
56 Move( nPos, nDiff );
57 if( !maSentence.size() )
58 return;
59 std::vector< xub_StrLen >::iterator pIter = maSentence.begin();
60 while( pIter != maSentence.end() && *pIter < nPos )
61 ++pIter;
62 xub_StrLen nEnd = nDiff < 0 ? xub_StrLen(nPos - nDiff) : nPos;
63 while( pIter != maSentence.end() )
65 if( *pIter >= nEnd )
66 *pIter = xub_StrLen( *pIter + nDiff );
67 else
68 *pIter = nPos;
69 ++pIter;
73 SwGrammarMarkUp* SwGrammarMarkUp::SplitGrammarList( xub_StrLen nSplitPos )
75 SwGrammarMarkUp* pNew = (SwGrammarMarkUp*)SplitList( nSplitPos );
76 if( !maSentence.size() )
77 return pNew;
78 std::vector< xub_StrLen >::iterator pIter = maSentence.begin();
79 while( pIter != maSentence.end() && *pIter < nSplitPos )
80 ++pIter;
81 if( pIter != maSentence.begin() )
83 if( !pNew ) {
84 pNew = new SwGrammarMarkUp();
85 pNew->SetInvalid( 0, STRING_LEN );
87 pNew->maSentence.insert( pNew->maSentence.begin(), maSentence.begin(), pIter );
88 maSentence.erase( maSentence.begin(), pIter );
90 return pNew;
93 void SwGrammarMarkUp::JoinGrammarList( SwGrammarMarkUp* pNext, xub_StrLen nInsertPos )
95 JoinList( pNext, nInsertPos );
96 if (pNext)
98 if( !pNext->maSentence.size() )
99 return;
100 std::vector< xub_StrLen >::iterator pIter = pNext->maSentence.begin();
101 while( pIter != pNext->maSentence.end() )
103 *pIter = *pIter + nInsertPos;
104 ++pIter;
106 maSentence.insert( maSentence.end(), pNext->maSentence.begin(), pNext->maSentence.end() );
110 void SwGrammarMarkUp::ClearGrammarList( xub_StrLen nSentenceEnd )
112 if( STRING_LEN == nSentenceEnd ) {
113 ClearList();
114 maSentence.clear();
115 Validate();
116 } else if( GetBeginInv() <= nSentenceEnd ) {
117 std::vector< xub_StrLen >::iterator pIter = maSentence.begin();
118 xub_StrLen nStart = 0;
119 while( pIter != maSentence.end() && *pIter < GetBeginInv() )
121 nStart = *pIter;
122 ++pIter;
124 std::vector< xub_StrLen >::iterator pLast = pIter;
125 while( pLast != maSentence.end() && *pLast <= nSentenceEnd )
126 ++pLast;
127 maSentence.erase( pIter, pLast );
128 RemoveEntry( nStart, nSentenceEnd );
129 SetInvalid( nSentenceEnd + 1, STRING_LEN );
133 void SwGrammarMarkUp::setSentence( xub_StrLen nStart )
135 std::vector< xub_StrLen >::iterator pIter = maSentence.begin();
136 while( pIter != maSentence.end() && *pIter < nStart )
137 ++pIter;
138 if( pIter == maSentence.end() || *pIter > nStart )
139 maSentence.insert( pIter, nStart );
142 void SwGrammarMarkUp::removeSentence(xub_StrLen nStart, xub_StrLen nLength )
144 std::vector< xub_StrLen >::iterator pIter = maSentence.begin();
145 while( pIter != maSentence.end() && *pIter < nStart )
146 ++pIter;
147 if( nLength == STRING_LEN )
148 nStart = STRING_LEN;
149 else
150 nStart += nLength;
151 std::vector< xub_StrLen >::iterator pLast = pIter;
152 while( pLast != maSentence.end() && *pLast < nStart )
153 ++pLast;
154 maSentence.erase( pIter, pLast );
157 xub_StrLen SwGrammarMarkUp::getSentenceStart( xub_StrLen nPos )
159 if( !maSentence.size() )
160 return 0;
161 std::vector< xub_StrLen >::iterator pIter = maSentence.begin();
162 while( pIter != maSentence.end() && *pIter < nPos )
163 ++pIter;
164 if( pIter != maSentence.begin() )
165 --pIter;
166 xub_StrLen nRet = 0;
167 if( pIter != maSentence.end() && *pIter < nPos )
168 nRet = *pIter;
169 return nRet;
172 xub_StrLen SwGrammarMarkUp::getSentenceEnd( xub_StrLen nPos )
174 if( !maSentence.size() )
175 return STRING_LEN;
176 std::vector< xub_StrLen >::iterator pIter = maSentence.begin();
177 while( pIter != maSentence.end() && *pIter <= nPos )
178 ++pIter;
179 xub_StrLen nRet = STRING_LEN;
180 if( pIter != maSentence.end() )
181 nRet = *pIter;
182 return nRet;