1*efeef26fSAndrew Rist /**************************************************************
2cdf0e10cSrcweir *
3*efeef26fSAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one
4*efeef26fSAndrew Rist * or more contributor license agreements. See the NOTICE file
5*efeef26fSAndrew Rist * distributed with this work for additional information
6*efeef26fSAndrew Rist * regarding copyright ownership. The ASF licenses this file
7*efeef26fSAndrew Rist * to you under the Apache License, Version 2.0 (the
8*efeef26fSAndrew Rist * "License"); you may not use this file except in compliance
9*efeef26fSAndrew Rist * with the License. You may obtain a copy of the License at
10cdf0e10cSrcweir *
11*efeef26fSAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0
12cdf0e10cSrcweir *
13*efeef26fSAndrew Rist * Unless required by applicable law or agreed to in writing,
14*efeef26fSAndrew Rist * software distributed under the License is distributed on an
15*efeef26fSAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*efeef26fSAndrew Rist * KIND, either express or implied. See the License for the
17*efeef26fSAndrew Rist * specific language governing permissions and limitations
18*efeef26fSAndrew Rist * under the License.
19cdf0e10cSrcweir *
20*efeef26fSAndrew Rist *************************************************************/
21*efeef26fSAndrew Rist
22*efeef26fSAndrew Rist
23cdf0e10cSrcweir
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25cdf0e10cSrcweir #include "precompiled_sw.hxx"
26cdf0e10cSrcweir
27cdf0e10cSrcweir #include "SwGrammarMarkUp.hxx"
28cdf0e10cSrcweir
~SwGrammarMarkUp()29cdf0e10cSrcweir SwGrammarMarkUp::~SwGrammarMarkUp()
30cdf0e10cSrcweir {
31cdf0e10cSrcweir }
32cdf0e10cSrcweir
Clone()33cdf0e10cSrcweir SwWrongList* SwGrammarMarkUp::Clone()
34cdf0e10cSrcweir {
35cdf0e10cSrcweir SwWrongList* pClone = new SwGrammarMarkUp();
36cdf0e10cSrcweir pClone->CopyFrom( *this );
37cdf0e10cSrcweir return pClone;
38cdf0e10cSrcweir }
39cdf0e10cSrcweir
CopyFrom(const SwWrongList & rCopy)40cdf0e10cSrcweir void SwGrammarMarkUp::CopyFrom( const SwWrongList& rCopy )
41cdf0e10cSrcweir {
42cdf0e10cSrcweir maSentence = ((const SwGrammarMarkUp&)rCopy).maSentence;
43cdf0e10cSrcweir SwWrongList::CopyFrom( rCopy );
44cdf0e10cSrcweir }
45cdf0e10cSrcweir
46cdf0e10cSrcweir
MoveGrammar(xub_StrLen nPos,long nDiff)47cdf0e10cSrcweir void SwGrammarMarkUp::MoveGrammar( xub_StrLen nPos, long nDiff )
48cdf0e10cSrcweir {
49cdf0e10cSrcweir Move( nPos, nDiff );
50cdf0e10cSrcweir if( !maSentence.size() )
51cdf0e10cSrcweir return;
52cdf0e10cSrcweir std::vector< xub_StrLen >::iterator pIter = maSentence.begin();
53cdf0e10cSrcweir while( pIter != maSentence.end() && *pIter < nPos )
54cdf0e10cSrcweir ++pIter;
55cdf0e10cSrcweir xub_StrLen nEnd = nDiff < 0 ? xub_StrLen(nPos - nDiff) : nPos;
56cdf0e10cSrcweir while( pIter != maSentence.end() )
57cdf0e10cSrcweir {
58cdf0e10cSrcweir if( *pIter >= nEnd )
59cdf0e10cSrcweir *pIter = xub_StrLen( *pIter + nDiff );
60cdf0e10cSrcweir else
61cdf0e10cSrcweir *pIter = nPos;
62cdf0e10cSrcweir ++pIter;
63cdf0e10cSrcweir }
64cdf0e10cSrcweir }
65cdf0e10cSrcweir
SplitGrammarList(xub_StrLen nSplitPos)66cdf0e10cSrcweir SwGrammarMarkUp* SwGrammarMarkUp::SplitGrammarList( xub_StrLen nSplitPos )
67cdf0e10cSrcweir {
68cdf0e10cSrcweir SwGrammarMarkUp* pNew = (SwGrammarMarkUp*)SplitList( nSplitPos );
69cdf0e10cSrcweir if( !maSentence.size() )
70cdf0e10cSrcweir return pNew;
71cdf0e10cSrcweir std::vector< xub_StrLen >::iterator pIter = maSentence.begin();
72cdf0e10cSrcweir while( pIter != maSentence.end() && *pIter < nSplitPos )
73cdf0e10cSrcweir ++pIter;
74cdf0e10cSrcweir if( pIter != maSentence.begin() )
75cdf0e10cSrcweir {
76cdf0e10cSrcweir if( !pNew ) {
77cdf0e10cSrcweir pNew = new SwGrammarMarkUp();
78cdf0e10cSrcweir pNew->SetInvalid( 0, STRING_LEN );
79cdf0e10cSrcweir }
80cdf0e10cSrcweir pNew->maSentence.insert( pNew->maSentence.begin(), maSentence.begin(), pIter );
81cdf0e10cSrcweir maSentence.erase( maSentence.begin(), pIter );
82cdf0e10cSrcweir }
83cdf0e10cSrcweir return pNew;
84cdf0e10cSrcweir }
85cdf0e10cSrcweir
JoinGrammarList(SwGrammarMarkUp * pNext,xub_StrLen nInsertPos)86cdf0e10cSrcweir void SwGrammarMarkUp::JoinGrammarList( SwGrammarMarkUp* pNext, xub_StrLen nInsertPos )
87cdf0e10cSrcweir {
88cdf0e10cSrcweir JoinList( pNext, nInsertPos );
89cdf0e10cSrcweir if (pNext)
90cdf0e10cSrcweir {
91cdf0e10cSrcweir if( !pNext->maSentence.size() )
92cdf0e10cSrcweir return;
93cdf0e10cSrcweir std::vector< xub_StrLen >::iterator pIter = pNext->maSentence.begin();
94cdf0e10cSrcweir while( pIter != pNext->maSentence.end() )
95cdf0e10cSrcweir {
96cdf0e10cSrcweir *pIter = *pIter + nInsertPos;
97cdf0e10cSrcweir ++pIter;
98cdf0e10cSrcweir }
99cdf0e10cSrcweir maSentence.insert( maSentence.end(), pNext->maSentence.begin(), pNext->maSentence.end() );
100cdf0e10cSrcweir }
101cdf0e10cSrcweir }
102cdf0e10cSrcweir
ClearGrammarList(xub_StrLen nSentenceEnd)103cdf0e10cSrcweir void SwGrammarMarkUp::ClearGrammarList( xub_StrLen nSentenceEnd )
104cdf0e10cSrcweir {
105cdf0e10cSrcweir if( STRING_LEN == nSentenceEnd ) {
106cdf0e10cSrcweir ClearList();
107cdf0e10cSrcweir maSentence.clear();
108cdf0e10cSrcweir Validate();
109cdf0e10cSrcweir } else if( GetBeginInv() <= nSentenceEnd ) {
110cdf0e10cSrcweir std::vector< xub_StrLen >::iterator pIter = maSentence.begin();
111cdf0e10cSrcweir xub_StrLen nStart = 0;
112cdf0e10cSrcweir while( pIter != maSentence.end() && *pIter < GetBeginInv() )
113cdf0e10cSrcweir {
114cdf0e10cSrcweir nStart = *pIter;
115cdf0e10cSrcweir ++pIter;
116cdf0e10cSrcweir }
117cdf0e10cSrcweir std::vector< xub_StrLen >::iterator pLast = pIter;
118cdf0e10cSrcweir while( pLast != maSentence.end() && *pLast <= nSentenceEnd )
119cdf0e10cSrcweir ++pLast;
120cdf0e10cSrcweir maSentence.erase( pIter, pLast );
121cdf0e10cSrcweir RemoveEntry( nStart, nSentenceEnd );
122cdf0e10cSrcweir SetInvalid( nSentenceEnd + 1, STRING_LEN );
123cdf0e10cSrcweir }
124cdf0e10cSrcweir }
125cdf0e10cSrcweir
setSentence(xub_StrLen nStart)126cdf0e10cSrcweir void SwGrammarMarkUp::setSentence( xub_StrLen nStart )
127cdf0e10cSrcweir {
128cdf0e10cSrcweir std::vector< xub_StrLen >::iterator pIter = maSentence.begin();
129cdf0e10cSrcweir while( pIter != maSentence.end() && *pIter < nStart )
130cdf0e10cSrcweir ++pIter;
131cdf0e10cSrcweir if( pIter == maSentence.end() || *pIter > nStart )
132cdf0e10cSrcweir maSentence.insert( pIter, nStart );
133cdf0e10cSrcweir }
134cdf0e10cSrcweir
getSentenceStart(xub_StrLen nPos)135cdf0e10cSrcweir xub_StrLen SwGrammarMarkUp::getSentenceStart( xub_StrLen nPos )
136cdf0e10cSrcweir {
137cdf0e10cSrcweir if( !maSentence.size() )
138cdf0e10cSrcweir return 0;
139cdf0e10cSrcweir std::vector< xub_StrLen >::iterator pIter = maSentence.begin();
140cdf0e10cSrcweir while( pIter != maSentence.end() && *pIter < nPos )
141cdf0e10cSrcweir ++pIter;
142cdf0e10cSrcweir if( pIter != maSentence.begin() )
143cdf0e10cSrcweir --pIter;
144cdf0e10cSrcweir xub_StrLen nRet = 0;
145cdf0e10cSrcweir if( pIter != maSentence.end() && *pIter < nPos )
146cdf0e10cSrcweir nRet = *pIter;
147cdf0e10cSrcweir return nRet;
148cdf0e10cSrcweir }
149cdf0e10cSrcweir
getSentenceEnd(xub_StrLen nPos)150cdf0e10cSrcweir xub_StrLen SwGrammarMarkUp::getSentenceEnd( xub_StrLen nPos )
151cdf0e10cSrcweir {
152cdf0e10cSrcweir if( !maSentence.size() )
153cdf0e10cSrcweir return STRING_LEN;
154cdf0e10cSrcweir std::vector< xub_StrLen >::iterator pIter = maSentence.begin();
155cdf0e10cSrcweir while( pIter != maSentence.end() && *pIter <= nPos )
156cdf0e10cSrcweir ++pIter;
157cdf0e10cSrcweir xub_StrLen nRet = STRING_LEN;
158cdf0e10cSrcweir if( pIter != maSentence.end() )
159cdf0e10cSrcweir nRet = *pIter;
160cdf0e10cSrcweir return nRet;
161cdf0e10cSrcweir }
162cdf0e10cSrcweir
163