1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: SwGrammarMarkUp.cxx,v $
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 );
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
)
57 if( !maSentence
.size() )
59 std::vector
< xub_StrLen
>::iterator pIter
= maSentence
.begin();
60 while( pIter
!= maSentence
.end() && *pIter
< nPos
)
62 xub_StrLen nEnd
= nDiff
< 0 ? xub_StrLen(nPos
- nDiff
) : nPos
;
63 while( pIter
!= maSentence
.end() )
66 *pIter
= xub_StrLen( *pIter
+ nDiff
);
73 SwGrammarMarkUp
* SwGrammarMarkUp::SplitGrammarList( xub_StrLen nSplitPos
)
75 SwGrammarMarkUp
* pNew
= (SwGrammarMarkUp
*)SplitList( nSplitPos
);
76 if( !maSentence
.size() )
78 std::vector
< xub_StrLen
>::iterator pIter
= maSentence
.begin();
79 while( pIter
!= maSentence
.end() && *pIter
< nSplitPos
)
81 if( pIter
!= maSentence
.begin() )
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
);
93 void SwGrammarMarkUp::JoinGrammarList( SwGrammarMarkUp
* pNext
, xub_StrLen nInsertPos
)
95 JoinList( pNext
, nInsertPos
);
98 if( !pNext
->maSentence
.size() )
100 std::vector
< xub_StrLen
>::iterator pIter
= pNext
->maSentence
.begin();
101 while( pIter
!= pNext
->maSentence
.end() )
103 *pIter
= *pIter
+ nInsertPos
;
106 maSentence
.insert( maSentence
.end(), pNext
->maSentence
.begin(), pNext
->maSentence
.end() );
110 void SwGrammarMarkUp::ClearGrammarList( xub_StrLen nSentenceEnd
)
112 if( STRING_LEN
== nSentenceEnd
) {
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() )
124 std::vector
< xub_StrLen
>::iterator pLast
= pIter
;
125 while( pLast
!= maSentence
.end() && *pLast
<= nSentenceEnd
)
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
)
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
)
147 if( nLength
== STRING_LEN
)
151 std::vector
< xub_StrLen
>::iterator pLast
= pIter
;
152 while( pLast
!= maSentence
.end() && *pLast
< nStart
)
154 maSentence
.erase( pIter
, pLast
);
157 xub_StrLen
SwGrammarMarkUp::getSentenceStart( xub_StrLen nPos
)
159 if( !maSentence
.size() )
161 std::vector
< xub_StrLen
>::iterator pIter
= maSentence
.begin();
162 while( pIter
!= maSentence
.end() && *pIter
< nPos
)
164 if( pIter
!= maSentence
.begin() )
167 if( pIter
!= maSentence
.end() && *pIter
< nPos
)
172 xub_StrLen
SwGrammarMarkUp::getSentenceEnd( xub_StrLen nPos
)
174 if( !maSentence
.size() )
176 std::vector
< xub_StrLen
>::iterator pIter
= maSentence
.begin();
177 while( pIter
!= maSentence
.end() && *pIter
<= nPos
)
179 xub_StrLen nRet
= STRING_LEN
;
180 if( pIter
!= maSentence
.end() )