1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
21 #include "SwGrammarMarkUp.hxx"
23 SwGrammarMarkUp::~SwGrammarMarkUp()
27 SwWrongList
* SwGrammarMarkUp::Clone()
29 SwWrongList
* pClone
= new SwGrammarMarkUp();
30 pClone
->CopyFrom( *this );
34 void SwGrammarMarkUp::CopyFrom( const SwWrongList
& rCopy
)
36 maSentence
= ((const SwGrammarMarkUp
&)rCopy
).maSentence
;
37 SwWrongList::CopyFrom( rCopy
);
41 void SwGrammarMarkUp::MoveGrammar( xub_StrLen nPos
, long nDiff
)
44 if( !maSentence
.size() )
46 std::vector
< xub_StrLen
>::iterator pIter
= maSentence
.begin();
47 while( pIter
!= maSentence
.end() && *pIter
< nPos
)
49 xub_StrLen nEnd
= nDiff
< 0 ? xub_StrLen(nPos
- nDiff
) : nPos
;
50 while( pIter
!= maSentence
.end() )
53 *pIter
= xub_StrLen( *pIter
+ nDiff
);
60 SwGrammarMarkUp
* SwGrammarMarkUp::SplitGrammarList( xub_StrLen nSplitPos
)
62 SwGrammarMarkUp
* pNew
= (SwGrammarMarkUp
*)SplitList( nSplitPos
);
63 if( !maSentence
.size() )
65 std::vector
< xub_StrLen
>::iterator pIter
= maSentence
.begin();
66 while( pIter
!= maSentence
.end() && *pIter
< nSplitPos
)
68 if( pIter
!= maSentence
.begin() )
71 pNew
= new SwGrammarMarkUp();
72 pNew
->SetInvalid( 0, STRING_LEN
);
74 pNew
->maSentence
.insert( pNew
->maSentence
.begin(), maSentence
.begin(), pIter
);
75 maSentence
.erase( maSentence
.begin(), pIter
);
80 void SwGrammarMarkUp::JoinGrammarList( SwGrammarMarkUp
* pNext
, xub_StrLen nInsertPos
)
82 JoinList( pNext
, nInsertPos
);
85 if( !pNext
->maSentence
.size() )
87 std::vector
< xub_StrLen
>::iterator pIter
= pNext
->maSentence
.begin();
88 while( pIter
!= pNext
->maSentence
.end() )
90 *pIter
= *pIter
+ nInsertPos
;
93 maSentence
.insert( maSentence
.end(), pNext
->maSentence
.begin(), pNext
->maSentence
.end() );
97 void SwGrammarMarkUp::ClearGrammarList( xub_StrLen nSentenceEnd
)
99 if( STRING_LEN
== nSentenceEnd
) {
103 } else if( GetBeginInv() <= nSentenceEnd
) {
104 std::vector
< xub_StrLen
>::iterator pIter
= maSentence
.begin();
105 xub_StrLen nStart
= 0;
106 while( pIter
!= maSentence
.end() && *pIter
< GetBeginInv() )
111 std::vector
< xub_StrLen
>::iterator pLast
= pIter
;
112 while( pLast
!= maSentence
.end() && *pLast
<= nSentenceEnd
)
114 maSentence
.erase( pIter
, pLast
);
115 RemoveEntry( nStart
, nSentenceEnd
);
116 SetInvalid( nSentenceEnd
+ 1, STRING_LEN
);
120 void SwGrammarMarkUp::setSentence( xub_StrLen nStart
)
122 std::vector
< xub_StrLen
>::iterator pIter
= maSentence
.begin();
123 while( pIter
!= maSentence
.end() && *pIter
< nStart
)
125 if( pIter
== maSentence
.end() || *pIter
> nStart
)
126 maSentence
.insert( pIter
, nStart
);
129 xub_StrLen
SwGrammarMarkUp::getSentenceStart( xub_StrLen nPos
)
131 if( !maSentence
.size() )
133 std::vector
< xub_StrLen
>::iterator pIter
= maSentence
.begin();
134 while( pIter
!= maSentence
.end() && *pIter
< nPos
)
136 if( pIter
!= maSentence
.begin() )
139 if( pIter
!= maSentence
.end() && *pIter
< nPos
)
144 xub_StrLen
SwGrammarMarkUp::getSentenceEnd( xub_StrLen nPos
)
146 if( !maSentence
.size() )
148 std::vector
< xub_StrLen
>::iterator pIter
= maSentence
.begin();
149 while( pIter
!= maSentence
.end() && *pIter
<= nPos
)
151 xub_StrLen nRet
= STRING_LEN
;
152 if( pIter
!= maSentence
.end() )
157 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */