android: Update app-specific/MIME type icons
[LibreOffice.git] / sw / source / core / text / SwGrammarMarkUp.cxx
blob53fd4b13c0134b5771566d31b68e24fb7bc2ba0d
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 .
20 #include <SwGrammarMarkUp.hxx>
22 SwGrammarMarkUp::~SwGrammarMarkUp()
26 SwWrongList* SwGrammarMarkUp::Clone()
28 SwWrongList* pClone = new SwGrammarMarkUp();
29 pClone->CopyFrom( *this );
30 return pClone;
33 void SwGrammarMarkUp::CopyFrom( const SwWrongList& rCopy )
35 maSentence = static_cast<const SwGrammarMarkUp&>(rCopy).maSentence;
36 SwWrongList::CopyFrom( rCopy );
39 void SwGrammarMarkUp::MoveGrammar( sal_Int32 nPos, sal_Int32 nDiff )
41 Move( nPos, nDiff );
42 if( maSentence.empty() )
43 return;
44 auto pIter = std::find_if(maSentence.begin(), maSentence.end(),
45 [nPos](const sal_Int32& rPos) { return rPos >= nPos; });
46 const sal_Int32 nEnd = nDiff < 0 ? nPos-nDiff : nPos;
47 while( pIter != maSentence.end() )
49 if( *pIter >= nEnd )
50 *pIter += nDiff;
51 else
52 *pIter = nPos;
53 ++pIter;
57 std::unique_ptr<SwGrammarMarkUp> SwGrammarMarkUp::SplitGrammarList( sal_Int32 nSplitPos )
59 std::unique_ptr<SwGrammarMarkUp> pNew( static_cast<SwGrammarMarkUp*>(SplitList( nSplitPos ).release()) );
60 if( maSentence.empty() )
61 return pNew;
62 auto pIter = std::find_if(maSentence.begin(), maSentence.end(),
63 [nSplitPos](const sal_Int32& rPos) { return rPos >= nSplitPos; });
64 if( pIter != maSentence.begin() )
66 if( !pNew ) {
67 pNew.reset(new SwGrammarMarkUp());
68 pNew->SetInvalid( 0, COMPLETE_STRING );
70 pNew->maSentence.insert( pNew->maSentence.begin(), maSentence.begin(), pIter );
71 maSentence.erase( maSentence.begin(), pIter );
73 return pNew;
76 void SwGrammarMarkUp::JoinGrammarList( SwGrammarMarkUp* pNext, sal_Int32 nInsertPos )
78 JoinList( pNext, nInsertPos );
79 if (pNext)
81 if( pNext->maSentence.empty() )
82 return;
83 for( auto& rPos : pNext->maSentence )
85 rPos += nInsertPos;
87 maSentence.insert( maSentence.end(), pNext->maSentence.begin(), pNext->maSentence.end() );
91 void SwGrammarMarkUp::ClearGrammarList( sal_Int32 nSentenceEnd )
93 if( COMPLETE_STRING == nSentenceEnd ) {
94 ClearList();
95 maSentence.clear();
96 Validate();
97 } else if( GetBeginInv() <= nSentenceEnd ) {
98 std::vector< sal_Int32 >::iterator pIter = maSentence.begin();
99 sal_Int32 nStart = 0;
100 while( pIter != maSentence.end() && *pIter < GetBeginInv() )
102 nStart = *pIter;
103 ++pIter;
105 auto pLast = std::find_if(pIter, maSentence.end(),
106 [nSentenceEnd](const sal_Int32& rPos) { return rPos > nSentenceEnd; });
107 maSentence.erase( pIter, pLast );
108 RemoveEntry( nStart, nSentenceEnd );
109 SetInvalid( nSentenceEnd + 1, COMPLETE_STRING );
113 void SwGrammarMarkUp::setSentence( sal_Int32 nStart )
115 auto pIter = std::find_if(maSentence.begin(), maSentence.end(),
116 [nStart](const sal_Int32& rPos) { return rPos >= nStart; });
117 if( pIter == maSentence.end() || *pIter > nStart )
118 maSentence.insert( pIter, nStart );
121 sal_Int32 SwGrammarMarkUp::getSentenceStart( sal_Int32 nPos )
123 if( maSentence.empty() )
124 return 0;
125 auto pIter = std::find_if(maSentence.begin(), maSentence.end(),
126 [nPos](const sal_Int32& rPos) { return rPos >= nPos; });
127 if( pIter != maSentence.begin() )
128 --pIter;
129 if( pIter != maSentence.end() && *pIter < nPos )
130 return *pIter;
131 return 0;
134 sal_Int32 SwGrammarMarkUp::getSentenceEnd( sal_Int32 nPos )
136 if( maSentence.empty() )
137 return COMPLETE_STRING;
138 auto pIter = std::find_if(maSentence.begin(), maSentence.end(),
139 [nPos](const sal_Int32& rPos) { return rPos > nPos; });
140 if( pIter != maSentence.end() )
141 return *pIter;
142 return COMPLETE_STRING;
145 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */