Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
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/.
8 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
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 .
18 : */
19 :
20 :
21 : #include "SwGrammarMarkUp.hxx"
22 :
23 0 : SwGrammarMarkUp::~SwGrammarMarkUp()
24 : {
25 0 : }
26 :
27 0 : SwWrongList* SwGrammarMarkUp::Clone()
28 : {
29 0 : SwWrongList* pClone = new SwGrammarMarkUp();
30 0 : pClone->CopyFrom( *this );
31 0 : return pClone;
32 : }
33 :
34 0 : void SwGrammarMarkUp::CopyFrom( const SwWrongList& rCopy )
35 : {
36 0 : maSentence = ((const SwGrammarMarkUp&)rCopy).maSentence;
37 0 : SwWrongList::CopyFrom( rCopy );
38 0 : }
39 :
40 :
41 0 : void SwGrammarMarkUp::MoveGrammar( xub_StrLen nPos, long nDiff )
42 : {
43 0 : Move( nPos, nDiff );
44 0 : if( !maSentence.size() )
45 0 : return;
46 0 : std::vector< xub_StrLen >::iterator pIter = maSentence.begin();
47 0 : while( pIter != maSentence.end() && *pIter < nPos )
48 0 : ++pIter;
49 0 : xub_StrLen nEnd = nDiff < 0 ? xub_StrLen(nPos - nDiff) : nPos;
50 0 : while( pIter != maSentence.end() )
51 : {
52 0 : if( *pIter >= nEnd )
53 0 : *pIter = xub_StrLen( *pIter + nDiff );
54 : else
55 0 : *pIter = nPos;
56 0 : ++pIter;
57 : }
58 : }
59 :
60 0 : SwGrammarMarkUp* SwGrammarMarkUp::SplitGrammarList( xub_StrLen nSplitPos )
61 : {
62 0 : SwGrammarMarkUp* pNew = (SwGrammarMarkUp*)SplitList( nSplitPos );
63 0 : if( !maSentence.size() )
64 0 : return pNew;
65 0 : std::vector< xub_StrLen >::iterator pIter = maSentence.begin();
66 0 : while( pIter != maSentence.end() && *pIter < nSplitPos )
67 0 : ++pIter;
68 0 : if( pIter != maSentence.begin() )
69 : {
70 0 : if( !pNew ) {
71 0 : pNew = new SwGrammarMarkUp();
72 0 : pNew->SetInvalid( 0, STRING_LEN );
73 : }
74 0 : pNew->maSentence.insert( pNew->maSentence.begin(), maSentence.begin(), pIter );
75 0 : maSentence.erase( maSentence.begin(), pIter );
76 : }
77 0 : return pNew;
78 : }
79 :
80 0 : void SwGrammarMarkUp::JoinGrammarList( SwGrammarMarkUp* pNext, xub_StrLen nInsertPos )
81 : {
82 0 : JoinList( pNext, nInsertPos );
83 0 : if (pNext)
84 : {
85 0 : if( !pNext->maSentence.size() )
86 0 : return;
87 0 : std::vector< xub_StrLen >::iterator pIter = pNext->maSentence.begin();
88 0 : while( pIter != pNext->maSentence.end() )
89 : {
90 0 : *pIter = *pIter + nInsertPos;
91 0 : ++pIter;
92 : }
93 0 : maSentence.insert( maSentence.end(), pNext->maSentence.begin(), pNext->maSentence.end() );
94 : }
95 : }
96 :
97 0 : void SwGrammarMarkUp::ClearGrammarList( xub_StrLen nSentenceEnd )
98 : {
99 0 : if( STRING_LEN == nSentenceEnd ) {
100 0 : ClearList();
101 0 : maSentence.clear();
102 0 : Validate();
103 0 : } else if( GetBeginInv() <= nSentenceEnd ) {
104 0 : std::vector< xub_StrLen >::iterator pIter = maSentence.begin();
105 0 : xub_StrLen nStart = 0;
106 0 : while( pIter != maSentence.end() && *pIter < GetBeginInv() )
107 : {
108 0 : nStart = *pIter;
109 0 : ++pIter;
110 : }
111 0 : std::vector< xub_StrLen >::iterator pLast = pIter;
112 0 : while( pLast != maSentence.end() && *pLast <= nSentenceEnd )
113 0 : ++pLast;
114 0 : maSentence.erase( pIter, pLast );
115 0 : RemoveEntry( nStart, nSentenceEnd );
116 0 : SetInvalid( nSentenceEnd + 1, STRING_LEN );
117 : }
118 0 : }
119 :
120 0 : void SwGrammarMarkUp::setSentence( xub_StrLen nStart )
121 : {
122 0 : std::vector< xub_StrLen >::iterator pIter = maSentence.begin();
123 0 : while( pIter != maSentence.end() && *pIter < nStart )
124 0 : ++pIter;
125 0 : if( pIter == maSentence.end() || *pIter > nStart )
126 0 : maSentence.insert( pIter, nStart );
127 0 : }
128 :
129 0 : xub_StrLen SwGrammarMarkUp::getSentenceStart( xub_StrLen nPos )
130 : {
131 0 : if( !maSentence.size() )
132 0 : return 0;
133 0 : std::vector< xub_StrLen >::iterator pIter = maSentence.begin();
134 0 : while( pIter != maSentence.end() && *pIter < nPos )
135 0 : ++pIter;
136 0 : if( pIter != maSentence.begin() )
137 0 : --pIter;
138 0 : xub_StrLen nRet = 0;
139 0 : if( pIter != maSentence.end() && *pIter < nPos )
140 0 : nRet = *pIter;
141 0 : return nRet;
142 : }
143 :
144 0 : xub_StrLen SwGrammarMarkUp::getSentenceEnd( xub_StrLen nPos )
145 : {
146 0 : if( !maSentence.size() )
147 0 : return STRING_LEN;
148 0 : std::vector< xub_StrLen >::iterator pIter = maSentence.begin();
149 0 : while( pIter != maSentence.end() && *pIter <= nPos )
150 0 : ++pIter;
151 0 : xub_StrLen nRet = STRING_LEN;
152 0 : if( pIter != maSentence.end() )
153 0 : nRet = *pIter;
154 0 : return nRet;
155 : }
156 :
157 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|