update credits
[LibreOffice.git] / sw / source / core / text / SwGrammarMarkUp.cxx
blobf40ed7d50c791979c702a3272fa40aad525dc0d4
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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 );
31 return pClone;
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 )
43 Move( nPos, nDiff );
44 if( !maSentence.size() )
45 return;
46 std::vector< xub_StrLen >::iterator pIter = maSentence.begin();
47 while( pIter != maSentence.end() && *pIter < nPos )
48 ++pIter;
49 xub_StrLen nEnd = nDiff < 0 ? xub_StrLen(nPos - nDiff) : nPos;
50 while( pIter != maSentence.end() )
52 if( *pIter >= nEnd )
53 *pIter = xub_StrLen( *pIter + nDiff );
54 else
55 *pIter = nPos;
56 ++pIter;
60 SwGrammarMarkUp* SwGrammarMarkUp::SplitGrammarList( xub_StrLen nSplitPos )
62 SwGrammarMarkUp* pNew = (SwGrammarMarkUp*)SplitList( nSplitPos );
63 if( !maSentence.size() )
64 return pNew;
65 std::vector< xub_StrLen >::iterator pIter = maSentence.begin();
66 while( pIter != maSentence.end() && *pIter < nSplitPos )
67 ++pIter;
68 if( pIter != maSentence.begin() )
70 if( !pNew ) {
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 );
77 return pNew;
80 void SwGrammarMarkUp::JoinGrammarList( SwGrammarMarkUp* pNext, xub_StrLen nInsertPos )
82 JoinList( pNext, nInsertPos );
83 if (pNext)
85 if( !pNext->maSentence.size() )
86 return;
87 std::vector< xub_StrLen >::iterator pIter = pNext->maSentence.begin();
88 while( pIter != pNext->maSentence.end() )
90 *pIter = *pIter + nInsertPos;
91 ++pIter;
93 maSentence.insert( maSentence.end(), pNext->maSentence.begin(), pNext->maSentence.end() );
97 void SwGrammarMarkUp::ClearGrammarList( xub_StrLen nSentenceEnd )
99 if( STRING_LEN == nSentenceEnd ) {
100 ClearList();
101 maSentence.clear();
102 Validate();
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() )
108 nStart = *pIter;
109 ++pIter;
111 std::vector< xub_StrLen >::iterator pLast = pIter;
112 while( pLast != maSentence.end() && *pLast <= nSentenceEnd )
113 ++pLast;
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 )
124 ++pIter;
125 if( pIter == maSentence.end() || *pIter > nStart )
126 maSentence.insert( pIter, nStart );
129 xub_StrLen SwGrammarMarkUp::getSentenceStart( xub_StrLen nPos )
131 if( !maSentence.size() )
132 return 0;
133 std::vector< xub_StrLen >::iterator pIter = maSentence.begin();
134 while( pIter != maSentence.end() && *pIter < nPos )
135 ++pIter;
136 if( pIter != maSentence.begin() )
137 --pIter;
138 xub_StrLen nRet = 0;
139 if( pIter != maSentence.end() && *pIter < nPos )
140 nRet = *pIter;
141 return nRet;
144 xub_StrLen SwGrammarMarkUp::getSentenceEnd( xub_StrLen nPos )
146 if( !maSentence.size() )
147 return STRING_LEN;
148 std::vector< xub_StrLen >::iterator pIter = maSentence.begin();
149 while( pIter != maSentence.end() && *pIter <= nPos )
150 ++pIter;
151 xub_StrLen nRet = STRING_LEN;
152 if( pIter != maSentence.end() )
153 nRet = *pIter;
154 return nRet;
157 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */