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