Branch data 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 : 2396 : SwGrammarMarkUp::~SwGrammarMarkUp()
24 : : {
25 [ - + ]: 4792 : }
26 : :
27 : 235 : SwWrongList* SwGrammarMarkUp::Clone()
28 : : {
29 [ + - ]: 235 : SwWrongList* pClone = new SwGrammarMarkUp();
30 : 235 : pClone->CopyFrom( *this );
31 : 235 : return pClone;
32 : : }
33 : :
34 : 235 : void SwGrammarMarkUp::CopyFrom( const SwWrongList& rCopy )
35 : : {
36 : 235 : maSentence = ((const SwGrammarMarkUp&)rCopy).maSentence;
37 : 235 : SwWrongList::CopyFrom( rCopy );
38 : 235 : }
39 : :
40 : :
41 : 10274 : void SwGrammarMarkUp::MoveGrammar( xub_StrLen nPos, long nDiff )
42 : : {
43 [ + - ]: 10274 : Move( nPos, nDiff );
44 [ + + ]: 10274 : if( !maSentence.size() )
45 : 10274 : return;
46 : 10270 : std::vector< xub_StrLen >::iterator pIter = maSentence.begin();
47 [ + - ][ + + ]: 10689 : while( pIter != maSentence.end() && *pIter < nPos )
[ + - ][ + + ]
[ + - ]
[ + + # # ]
48 [ + - ]: 419 : ++pIter;
49 [ + + ]: 10270 : xub_StrLen nEnd = nDiff < 0 ? xub_StrLen(nPos - nDiff) : nPos;
50 [ + - ][ + + ]: 20971 : while( pIter != maSentence.end() )
51 : : {
52 [ + - ][ + + ]: 10697 : if( *pIter >= nEnd )
53 [ + - ][ + - ]: 10591 : *pIter = xub_StrLen( *pIter + nDiff );
54 : : else
55 [ + - ]: 106 : *pIter = nPos;
56 [ + - ]: 10697 : ++pIter;
57 : : }
58 : : }
59 : :
60 : 133 : SwGrammarMarkUp* SwGrammarMarkUp::SplitGrammarList( xub_StrLen nSplitPos )
61 : : {
62 [ + - ]: 133 : SwGrammarMarkUp* pNew = (SwGrammarMarkUp*)SplitList( nSplitPos );
63 [ - + ]: 133 : if( !maSentence.size() )
64 : 0 : return pNew;
65 : 133 : std::vector< xub_StrLen >::iterator pIter = maSentence.begin();
66 [ + - ][ + - ]: 133 : while( pIter != maSentence.end() && *pIter < nSplitPos )
[ + - ][ - + ]
[ + - ]
[ - + # # ]
67 [ # # ]: 0 : ++pIter;
68 [ + - ][ - + ]: 133 : 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 : 133 : return pNew;
78 : : }
79 : :
80 : 14 : void SwGrammarMarkUp::JoinGrammarList( SwGrammarMarkUp* pNext, xub_StrLen nInsertPos )
81 : : {
82 : 14 : JoinList( pNext, nInsertPos );
83 [ + + ]: 14 : if (pNext)
84 : : {
85 [ + - ]: 11 : if( !pNext->maSentence.size() )
86 : 14 : return;
87 : 11 : std::vector< xub_StrLen >::iterator pIter = pNext->maSentence.begin();
88 [ + - ][ + + ]: 24 : while( pIter != pNext->maSentence.end() )
89 : : {
90 [ + - ][ + - ]: 13 : *pIter = *pIter + nInsertPos;
91 [ + - ]: 13 : ++pIter;
92 : : }
93 [ + - ]: 11 : maSentence.insert( maSentence.end(), pNext->maSentence.begin(), pNext->maSentence.end() );
94 : : }
95 : : }
96 : :
97 : 2892 : void SwGrammarMarkUp::ClearGrammarList( xub_StrLen nSentenceEnd )
98 : : {
99 [ - + ]: 2892 : if( STRING_LEN == nSentenceEnd ) {
100 : 0 : ClearList();
101 : 0 : maSentence.clear();
102 : 0 : Validate();
103 [ + + ]: 2892 : } else if( GetBeginInv() <= nSentenceEnd ) {
104 : 2891 : std::vector< xub_StrLen >::iterator pIter = maSentence.begin();
105 : 2891 : xub_StrLen nStart = 0;
106 [ + - ][ + + ]: 2937 : while( pIter != maSentence.end() && *pIter < GetBeginInv() )
[ + - ][ + + ]
[ + - ]
[ + + # # ]
107 : : {
108 [ + - ]: 46 : nStart = *pIter;
109 [ + - ]: 46 : ++pIter;
110 : : }
111 : 2891 : std::vector< xub_StrLen >::iterator pLast = pIter;
112 [ + - ][ + + ]: 3549 : while( pLast != maSentence.end() && *pLast <= nSentenceEnd )
[ + - ][ + + ]
[ + - ]
[ + + # # ]
113 [ + - ]: 658 : ++pLast;
114 [ + - ]: 2891 : maSentence.erase( pIter, pLast );
115 [ + - ]: 2891 : RemoveEntry( nStart, nSentenceEnd );
116 [ + - ]: 2891 : SetInvalid( nSentenceEnd + 1, STRING_LEN );
117 : : }
118 : 2892 : }
119 : :
120 : 2892 : void SwGrammarMarkUp::setSentence( xub_StrLen nStart )
121 : : {
122 : 2892 : std::vector< xub_StrLen >::iterator pIter = maSentence.begin();
123 [ + - ][ + + ]: 2892 : while( pIter != maSentence.end() && *pIter < nStart )
[ + - ][ - + ]
[ + - ]
[ - + # # ]
124 [ # # ]: 0 : ++pIter;
125 [ + - ][ + + ]: 2892 : if( pIter == maSentence.end() || *pIter > nStart )
[ + - ][ + + ]
[ + - ]
[ + + # # ]
126 [ + - ]: 2846 : maSentence.insert( pIter, nStart );
127 : 2892 : }
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: */
|