1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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 );
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
)
42 if( maSentence
.empty() )
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() )
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() )
62 auto pIter
= std::find_if(maSentence
.begin(), maSentence
.end(),
63 [nSplitPos
](const sal_Int32
& rPos
) { return rPos
>= nSplitPos
; });
64 if( pIter
!= maSentence
.begin() )
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
);
76 void SwGrammarMarkUp::JoinGrammarList( SwGrammarMarkUp
* pNext
, sal_Int32 nInsertPos
)
78 JoinList( pNext
, nInsertPos
);
81 if( pNext
->maSentence
.empty() )
83 for( auto& rPos
: pNext
->maSentence
)
87 maSentence
.insert( maSentence
.end(), pNext
->maSentence
.begin(), pNext
->maSentence
.end() );
91 void SwGrammarMarkUp::ClearGrammarList( sal_Int32 nSentenceEnd
)
93 if( COMPLETE_STRING
== nSentenceEnd
) {
97 } else if( GetBeginInv() <= nSentenceEnd
) {
98 std::vector
< sal_Int32
>::iterator pIter
= maSentence
.begin();
100 while( pIter
!= maSentence
.end() && *pIter
< GetBeginInv() )
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() )
125 auto pIter
= std::find_if(maSentence
.begin(), maSentence
.end(),
126 [nPos
](const sal_Int32
& rPos
) { return rPos
>= nPos
; });
127 if( pIter
!= maSentence
.begin() )
129 if( pIter
!= maSentence
.end() && *pIter
< nPos
)
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() )
142 return COMPLETE_STRING
;
145 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */