OpenCoverage

qtextboundaryfinder.cpp

Absolute File Name:/home/qt/qt5_coco/qt5/qtbase/src/corelib/tools/qtextboundaryfinder.cpp
Source codeSwitch to Preprocessed file
LineSourceCount
1/****************************************************************************-
2**-
3** Copyright (C) 2016 The Qt Company Ltd.-
4** Contact: https://www.qt.io/licensing/-
5**-
6** This file is part of the QtCore module of the Qt Toolkit.-
7**-
8** $QT_BEGIN_LICENSE:LGPL$-
9** Commercial License Usage-
10** Licensees holding valid commercial Qt licenses may use this file in-
11** accordance with the commercial license agreement provided with the-
12** Software or, alternatively, in accordance with the terms contained in-
13** a written agreement between you and The Qt Company. For licensing terms-
14** and conditions see https://www.qt.io/terms-conditions. For further-
15** information use the contact form at https://www.qt.io/contact-us.-
16**-
17** GNU Lesser General Public License Usage-
18** Alternatively, this file may be used under the terms of the GNU Lesser-
19** General Public License version 3 as published by the Free Software-
20** Foundation and appearing in the file LICENSE.LGPL3 included in the-
21** packaging of this file. Please review the following information to-
22** ensure the GNU Lesser General Public License version 3 requirements-
23** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.-
24**-
25** GNU General Public License Usage-
26** Alternatively, this file may be used under the terms of the GNU-
27** General Public License version 2.0 or (at your option) the GNU General-
28** Public license version 3 or any later version approved by the KDE Free-
29** Qt Foundation. The licenses are as published by the Free Software-
30** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3-
31** included in the packaging of this file. Please review the following-
32** information to ensure the GNU General Public License requirements will-
33** be met: https://www.gnu.org/licenses/gpl-2.0.html and-
34** https://www.gnu.org/licenses/gpl-3.0.html.-
35**-
36** $QT_END_LICENSE$-
37**-
38****************************************************************************/-
39#include <QtCore/qtextboundaryfinder.h>-
40#include <QtCore/qvarlengtharray.h>-
41-
42#include <private/qunicodetools_p.h>-
43-
44QT_BEGIN_NAMESPACE-
45-
46class QTextBoundaryFinderPrivate-
47{-
48public:-
49 QCharAttributes attributes[1];-
50};-
51-
52static void init(QTextBoundaryFinder::BoundaryType type, const QChar *chars, int length, QCharAttributes *attributes)-
53{-
54 const ushort *string = reinterpret_cast<const ushort *>(chars);-
55-
56 QVarLengthArray<QUnicodeTools::ScriptItem> scriptItems;-
57 {-
58 QVarLengthArray<uchar> scripts(length);-
59-
60 QUnicodeTools::initScripts(string, length, scripts.data());-
61-
62 int start = 0;-
63 for (int i = start + 1; i <= length; ++i) {
i <= lengthDescription
TRUEevaluated 160347 times by 3 tests
Evaluated by:
  • tst_QAccessibility
  • tst_QTextBoundaryFinder
  • tst_QTextLayout
FALSEevaluated 8846 times by 3 tests
Evaluated by:
  • tst_QAccessibility
  • tst_QTextBoundaryFinder
  • tst_QTextLayout
8846-160347
64 if (i == length || scripts[i] != scripts[start]) {
i == lengthDescription
TRUEevaluated 8846 times by 3 tests
Evaluated by:
  • tst_QAccessibility
  • tst_QTextBoundaryFinder
  • tst_QTextLayout
FALSEevaluated 151501 times by 3 tests
Evaluated by:
  • tst_QAccessibility
  • tst_QTextBoundaryFinder
  • tst_QTextLayout
scripts[i] != scripts[start]Description
TRUEevaluated 373 times by 1 test
Evaluated by:
  • tst_QTextBoundaryFinder
FALSEevaluated 151128 times by 3 tests
Evaluated by:
  • tst_QAccessibility
  • tst_QTextBoundaryFinder
  • tst_QTextLayout
373-151501
65 QUnicodeTools::ScriptItem item;-
66 item.position = start;-
67 item.script = scripts[start];-
68 scriptItems.append(item);-
69 start = i;-
70 }
executed 9219 times by 3 tests: end of block
Executed by:
  • tst_QAccessibility
  • tst_QTextBoundaryFinder
  • tst_QTextLayout
9219
71 }
executed 160347 times by 3 tests: end of block
Executed by:
  • tst_QAccessibility
  • tst_QTextBoundaryFinder
  • tst_QTextLayout
160347
72 }-
73-
74 QUnicodeTools::CharAttributeOptions options = 0;-
75 switch (type) {-
76 case QTextBoundaryFinder::Grapheme: options |= QUnicodeTools::GraphemeBreaks; break;
executed 434 times by 2 tests: break;
Executed by:
  • tst_QAccessibility
  • tst_QTextBoundaryFinder
executed 434 times by 2 tests: case QTextBoundaryFinder::Grapheme:
Executed by:
  • tst_QAccessibility
  • tst_QTextBoundaryFinder
434
77 case QTextBoundaryFinder::Word: options |= QUnicodeTools::WordBreaks; break;
executed 1553 times by 3 tests: break;
Executed by:
  • tst_QAccessibility
  • tst_QTextBoundaryFinder
  • tst_QTextLayout
executed 1553 times by 3 tests: case QTextBoundaryFinder::Word:
Executed by:
  • tst_QAccessibility
  • tst_QTextBoundaryFinder
  • tst_QTextLayout
1553
78 case QTextBoundaryFinder::Sentence: options |= QUnicodeTools::SentenceBreaks; break;
executed 521 times by 2 tests: break;
Executed by:
  • tst_QAccessibility
  • tst_QTextBoundaryFinder
executed 521 times by 2 tests: case QTextBoundaryFinder::Sentence:
Executed by:
  • tst_QAccessibility
  • tst_QTextBoundaryFinder
521
79 case QTextBoundaryFinder::Line: options |= QUnicodeTools::LineBreaks; break;
executed 6338 times by 1 test: break;
Executed by:
  • tst_QTextBoundaryFinder
executed 6338 times by 1 test: case QTextBoundaryFinder::Line:
Executed by:
  • tst_QTextBoundaryFinder
6338
80 default: break;
never executed: break;
never executed: default:
0
81 }-
82 QUnicodeTools::initCharAttributes(string, length, scriptItems.data(), scriptItems.count(), attributes, options);-
83}
executed 8846 times by 3 tests: end of block
Executed by:
  • tst_QAccessibility
  • tst_QTextBoundaryFinder
  • tst_QTextLayout
8846
84-
85/*!-
86 \class QTextBoundaryFinder-
87 \inmodule QtCore-
88-
89 \brief The QTextBoundaryFinder class provides a way of finding Unicode text boundaries in a string.-
90-
91 \since 4.4-
92 \ingroup tools-
93 \ingroup shared-
94 \ingroup string-processing-
95 \reentrant-
96-
97 QTextBoundaryFinder allows to find Unicode text boundaries in a-
98 string, accordingly to the Unicode text boundary specification (see-
99 \l{http://www.unicode.org/reports/tr14/}{Unicode Standard Annex #14} and-
100 \l{http://www.unicode.org/reports/tr29/}{Unicode Standard Annex #29}).-
101-
102 QTextBoundaryFinder can operate on a QString in four possible-
103 modes depending on the value of \a BoundaryType.-
104-
105 Units of Unicode characters that make up what the user thinks of-
106 as a character or basic unit of the language are here called-
107 Grapheme clusters. The two unicode characters 'A' + diaeresis do-
108 for example form one grapheme cluster as the user thinks of them-
109 as one character, yet it is in this case represented by two-
110 unicode code points-
111 (see \l{http://www.unicode.org/reports/tr29/#Grapheme_Cluster_Boundaries}).-
112-
113 Word boundaries are there to locate the start and end of what a-
114 language considers to be a word-
115 (see \l{http://www.unicode.org/reports/tr29/#Word_Boundaries}).-
116-
117 Line break boundaries give possible places where a line break-
118 might happen and sentence boundaries will show the beginning and-
119 end of whole sentences-
120 (see \l{http://www.unicode.org/reports/tr29/#Sentence_Boundaries} and-
121 \l{http://www.unicode.org/reports/tr14/}).-
122-
123 The first position in a string is always a valid boundary and-
124 refers to the position before the first character. The last-
125 position at the length of the string is also valid and refers-
126 to the position after the last character.-
127*/-
128-
129/*!-
130 \enum QTextBoundaryFinder::BoundaryType-
131-
132 \value Grapheme Finds a grapheme which is the smallest boundary. It-
133 including letters, punctuation marks, numerals and more.-
134 \value Word Finds a word.-
135 \value Line Finds possible positions for breaking the text into multiple-
136 lines.-
137 \value Sentence Finds sentence boundaries. These include periods, question-
138 marks etc.-
139*/-
140-
141/*!-
142 \enum QTextBoundaryFinder::BoundaryReason-
143-
144 \value NotAtBoundary The boundary finder is not at a boundary position.-
145 \value BreakOpportunity The boundary finder is at a break opportunity position.-
146 Such a break opportunity might also be an item boundary-
147 (either StartOfItem, EndOfItem, or combination of both),-
148 a mandatory line break, or a soft hyphen.-
149 \value StartOfItem Since 5.0. The boundary finder is at the start of-
150 a grapheme, a word, a sentence, or a line.-
151 \value EndOfItem Since 5.0. The boundary finder is at the end of-
152 a grapheme, a word, a sentence, or a line.-
153 \value MandatoryBreak Since 5.0. The boundary finder is at the end of line-
154 (can occur for a Line boundary type only).-
155 \value SoftHyphen The boundary finder is at the soft hyphen-
156 (can occur for a Line boundary type only).-
157*/-
158-
159/*!-
160 Constructs an invalid QTextBoundaryFinder object.-
161*/-
162QTextBoundaryFinder::QTextBoundaryFinder()-
163 : t(Grapheme)-
164 , chars(0)-
165 , length(0)-
166 , freePrivate(true)-
167 , d(0)-
168{-
169}
executed 1 time by 1 test: end of block
Executed by:
  • tst_QTextBoundaryFinder
1
170-
171/*!-
172 Copies the QTextBoundaryFinder object, \a other.-
173*/-
174QTextBoundaryFinder::QTextBoundaryFinder(const QTextBoundaryFinder &other)-
175 : t(other.t)-
176 , s(other.s)-
177 , chars(other.chars)-
178 , length(other.length)-
179 , pos(other.pos)-
180 , freePrivate(true)-
181 , d(0)-
182{-
183 if (other.d) {
other.dDescription
TRUEnever evaluated
FALSEevaluated 15 times by 1 test
Evaluated by:
  • tst_QTextBoundaryFinder
0-15
184 Q_ASSERT(length > 0);-
185 d = (QTextBoundaryFinderPrivate *) malloc((length + 1) * sizeof(QCharAttributes));-
186 Q_CHECK_PTR(d);
never executed: qBadAlloc();
!(d)Description
TRUEnever evaluated
FALSEnever evaluated
0
187 memcpy(d, other.d, (length + 1) * sizeof(QCharAttributes));-
188 }
never executed: end of block
0
189}
executed 15 times by 1 test: end of block
Executed by:
  • tst_QTextBoundaryFinder
15
190-
191/*!-
192 Assigns the object, \a other, to another QTextBoundaryFinder object.-
193*/-
194QTextBoundaryFinder &QTextBoundaryFinder::operator=(const QTextBoundaryFinder &other)-
195{-
196 if (&other == this)
&other == thisDescription
TRUEnever evaluated
FALSEevaluated 4 times by 1 test
Evaluated by:
  • tst_QTextBoundaryFinder
0-4
197 return *this;
never executed: return *this;
0
198-
199 if (other.d) {
other.dDescription
TRUEevaluated 2 times by 1 test
Evaluated by:
  • tst_QTextBoundaryFinder
FALSEevaluated 2 times by 1 test
Evaluated by:
  • tst_QTextBoundaryFinder
2
200 Q_ASSERT(other.length > 0);-
201 uint newCapacity = (other.length + 1) * sizeof(QCharAttributes);-
202 QTextBoundaryFinderPrivate *newD = (QTextBoundaryFinderPrivate *) realloc(freePrivate ? d : 0, newCapacity);-
203 Q_CHECK_PTR(newD);
never executed: qBadAlloc();
!(newD)Description
TRUEnever evaluated
FALSEevaluated 2 times by 1 test
Evaluated by:
  • tst_QTextBoundaryFinder
0-2
204 freePrivate = true;-
205 d = newD;-
206 }
executed 2 times by 1 test: end of block
Executed by:
  • tst_QTextBoundaryFinder
2
207-
208 t = other.t;-
209 s = other.s;-
210 chars = other.chars;-
211 length = other.length;-
212 pos = other.pos;-
213-
214 if (other.d) {
other.dDescription
TRUEevaluated 2 times by 1 test
Evaluated by:
  • tst_QTextBoundaryFinder
FALSEevaluated 2 times by 1 test
Evaluated by:
  • tst_QTextBoundaryFinder
2
215 memcpy(d, other.d, (length + 1) * sizeof(QCharAttributes));-
216 } else {
executed 2 times by 1 test: end of block
Executed by:
  • tst_QTextBoundaryFinder
2
217 if (freePrivate)
freePrivateDescription
TRUEevaluated 2 times by 1 test
Evaluated by:
  • tst_QTextBoundaryFinder
FALSEnever evaluated
0-2
218 free(d);
executed 2 times by 1 test: free(d);
Executed by:
  • tst_QTextBoundaryFinder
2
219 d = 0;-
220 }
executed 2 times by 1 test: end of block
Executed by:
  • tst_QTextBoundaryFinder
2
221-
222 return *this;
executed 4 times by 1 test: return *this;
Executed by:
  • tst_QTextBoundaryFinder
4
223}-
224-
225/*!-
226 Destructs the QTextBoundaryFinder object.-
227*/-
228QTextBoundaryFinder::~QTextBoundaryFinder()-
229{-
230 Q_UNUSED(unused);-
231 if (freePrivate)
freePrivateDescription
TRUEevaluated 8867 times by 3 tests
Evaluated by:
  • tst_QAccessibility
  • tst_QTextBoundaryFinder
  • tst_QTextLayout
FALSEnever evaluated
0-8867
232 free(d);
executed 8867 times by 3 tests: free(d);
Executed by:
  • tst_QAccessibility
  • tst_QTextBoundaryFinder
  • tst_QTextLayout
8867
233}
executed 8867 times by 3 tests: end of block
Executed by:
  • tst_QAccessibility
  • tst_QTextBoundaryFinder
  • tst_QTextLayout
8867
234-
235/*!-
236 Creates a QTextBoundaryFinder object of \a type operating on \a string.-
237*/-
238QTextBoundaryFinder::QTextBoundaryFinder(BoundaryType type, const QString &string)-
239 : t(type)-
240 , s(string)-
241 , chars(string.unicode())-
242 , length(string.length())-
243 , pos(0)-
244 , freePrivate(true)-
245 , d(0)-
246{-
247 if (length > 0) {
length > 0Description
TRUEevaluated 8843 times by 2 tests
Evaluated by:
  • tst_QAccessibility
  • tst_QTextBoundaryFinder
FALSEevaluated 1 time by 1 test
Evaluated by:
  • tst_QTextBoundaryFinder
1-8843
248 d = (QTextBoundaryFinderPrivate *) malloc((length + 1) * sizeof(QCharAttributes));-
249 Q_CHECK_PTR(d);
never executed: qBadAlloc();
!(d)Description
TRUEnever evaluated
FALSEevaluated 8843 times by 2 tests
Evaluated by:
  • tst_QAccessibility
  • tst_QTextBoundaryFinder
0-8843
250 init(t, chars, length, d->attributes);-
251 }
executed 8843 times by 2 tests: end of block
Executed by:
  • tst_QAccessibility
  • tst_QTextBoundaryFinder
8843
252}
executed 8844 times by 2 tests: end of block
Executed by:
  • tst_QAccessibility
  • tst_QTextBoundaryFinder
8844
253-
254/*!-
255 Creates a QTextBoundaryFinder object of \a type operating on \a chars-
256 with \a length.-
257-
258 \a buffer is an optional working buffer of size \a bufferSize you can pass to-
259 the QTextBoundaryFinder. If the buffer is large enough to hold the working-
260 data required (bufferSize >= length + 1), it will use this-
261 instead of allocating its own buffer.-
262-
263 \warning QTextBoundaryFinder does not create a copy of \a chars. It is the-
264 application programmer's responsibility to ensure the array is allocated for-
265 as long as the QTextBoundaryFinder object stays alive. The same applies to-
266 \a buffer.-
267*/-
268QTextBoundaryFinder::QTextBoundaryFinder(BoundaryType type, const QChar *chars, int length, unsigned char *buffer, int bufferSize)-
269 : t(type)-
270 , chars(chars)-
271 , length(length)-
272 , pos(0)-
273 , freePrivate(true)-
274 , d(0)-
275{-
276 if (!chars) {
!charsDescription
TRUEevaluated 2 times by 1 test
Evaluated by:
  • tst_QTextBoundaryFinder
FALSEevaluated 5 times by 2 tests
Evaluated by:
  • tst_QTextBoundaryFinder
  • tst_QTextLayout
2-5
277 length = 0;-
278 } else if (length > 0) {
executed 2 times by 1 test: end of block
Executed by:
  • tst_QTextBoundaryFinder
length > 0Description
TRUEevaluated 3 times by 2 tests
Evaluated by:
  • tst_QTextBoundaryFinder
  • tst_QTextLayout
FALSEevaluated 2 times by 1 test
Evaluated by:
  • tst_QTextBoundaryFinder
2-3
279 if (buffer && (uint)bufferSize >= (length + 1) * sizeof(QCharAttributes)) {
bufferDescription
TRUEnever evaluated
FALSEevaluated 3 times by 2 tests
Evaluated by:
  • tst_QTextBoundaryFinder
  • tst_QTextLayout
(uint)bufferSi...harAttributes)Description
TRUEnever evaluated
FALSEnever evaluated
0-3
280 d = (QTextBoundaryFinderPrivate *)buffer;-
281 freePrivate = false;-
282 } else {
never executed: end of block
0
283 d = (QTextBoundaryFinderPrivate *) malloc((length + 1) * sizeof(QCharAttributes));-
284 Q_CHECK_PTR(d);
never executed: qBadAlloc();
!(d)Description
TRUEnever evaluated
FALSEevaluated 3 times by 2 tests
Evaluated by:
  • tst_QTextBoundaryFinder
  • tst_QTextLayout
0-3
285 }
executed 3 times by 2 tests: end of block
Executed by:
  • tst_QTextBoundaryFinder
  • tst_QTextLayout
3
286 init(t, chars, length, d->attributes);-
287 }
executed 3 times by 2 tests: end of block
Executed by:
  • tst_QTextBoundaryFinder
  • tst_QTextLayout
3
288}
executed 7 times by 2 tests: end of block
Executed by:
  • tst_QTextBoundaryFinder
  • tst_QTextLayout
7
289-
290/*!-
291 Moves the finder to the start of the string. This is equivalent to setPosition(0).-
292-
293 \sa setPosition(), position()-
294*/-
295void QTextBoundaryFinder::toStart()-
296{-
297 pos = 0;-
298}
never executed: end of block
0
299-
300/*!-
301 Moves the finder to the end of the string. This is equivalent to setPosition(string.length()).-
302-
303 \sa setPosition(), position()-
304*/-
305void QTextBoundaryFinder::toEnd()-
306{-
307 pos = length;-
308}
executed 8797 times by 1 test: end of block
Executed by:
  • tst_QTextBoundaryFinder
8797
309-
310/*!-
311 Returns the current position of the QTextBoundaryFinder.-
312-
313 The range is from 0 (the beginning of the string) to the length of-
314 the string inclusive.-
315-
316 \sa setPosition()-
317*/-
318int QTextBoundaryFinder::position() const-
319{-
320 return pos;
executed 195130 times by 3 tests: return pos;
Executed by:
  • tst_QAccessibility
  • tst_QTextBoundaryFinder
  • tst_QTextLayout
195130
321}-
322-
323/*!-
324 Sets the current position of the QTextBoundaryFinder to \a position.-
325-
326 If \a position is out of bounds, it will be bound to only valid-
327 positions. In this case, valid positions are from 0 to the length of-
328 the string inclusive.-
329-
330 \sa position()-
331*/-
332void QTextBoundaryFinder::setPosition(int position)-
333{-
334 pos = qBound(0, position, length);-
335}
executed 39074 times by 3 tests: end of block
Executed by:
  • tst_QAccessibility
  • tst_QTextBoundaryFinder
  • tst_QTextLayout
39074
336-
337/*! \fn QTextBoundaryFinder::BoundaryType QTextBoundaryFinder::type() const-
338-
339 Returns the type of the QTextBoundaryFinder.-
340*/-
341-
342/*! \fn bool QTextBoundaryFinder::isValid() const-
343-
344 Returns \c true if the text boundary finder is valid; otherwise returns \c false.-
345 A default QTextBoundaryFinder is invalid.-
346*/-
347-
348/*!-
349 Returns the string the QTextBoundaryFinder object operates on.-
350*/-
351QString QTextBoundaryFinder::string() const-
352{-
353 if (chars == s.unicode() && length == s.length())
chars == s.unicode()Description
TRUEevaluated 2 times by 1 test
Evaluated by:
  • tst_QTextBoundaryFinder
FALSEevaluated 2 times by 1 test
Evaluated by:
  • tst_QTextBoundaryFinder
length == s.length()Description
TRUEevaluated 2 times by 1 test
Evaluated by:
  • tst_QTextBoundaryFinder
FALSEnever evaluated
0-2
354 return s;
executed 2 times by 1 test: return s;
Executed by:
  • tst_QTextBoundaryFinder
2
355 return QString(chars, length);
executed 2 times by 1 test: return QString(chars, length);
Executed by:
  • tst_QTextBoundaryFinder
2
356}-
357-
358-
359/*!-
360 Moves the QTextBoundaryFinder to the next boundary position and returns that position.-
361-
362 Returns -1 if there is no next boundary.-
363*/-
364int QTextBoundaryFinder::toNextBoundary()-
365{-
366 if (!d || pos < 0 || pos >= length) {
!dDescription
TRUEevaluated 7 times by 1 test
Evaluated by:
  • tst_QTextBoundaryFinder
FALSEevaluated 24931 times by 3 tests
Evaluated by:
  • tst_QAccessibility
  • tst_QTextBoundaryFinder
  • tst_QTextLayout
pos < 0Description
TRUEnever evaluated
FALSEevaluated 24931 times by 3 tests
Evaluated by:
  • tst_QAccessibility
  • tst_QTextBoundaryFinder
  • tst_QTextLayout
pos >= lengthDescription
TRUEevaluated 8800 times by 2 tests
Evaluated by:
  • tst_QAccessibility
  • tst_QTextBoundaryFinder
FALSEevaluated 16131 times by 3 tests
Evaluated by:
  • tst_QAccessibility
  • tst_QTextBoundaryFinder
  • tst_QTextLayout
0-24931
367 pos = -1;-
368 return pos;
executed 8807 times by 2 tests: return pos;
Executed by:
  • tst_QAccessibility
  • tst_QTextBoundaryFinder
8807
369 }-
370-
371 ++pos;-
372 switch(t) {-
373 case Grapheme:
executed 826 times by 2 tests: case Grapheme:
Executed by:
  • tst_QAccessibility
  • tst_QTextBoundaryFinder
826
374 while (pos < length && !d->attributes[pos].graphemeBoundary)
pos < lengthDescription
TRUEevaluated 713 times by 2 tests
Evaluated by:
  • tst_QAccessibility
  • tst_QTextBoundaryFinder
FALSEevaluated 408 times by 2 tests
Evaluated by:
  • tst_QAccessibility
  • tst_QTextBoundaryFinder
!d->attributes...aphemeBoundaryDescription
TRUEevaluated 295 times by 1 test
Evaluated by:
  • tst_QTextBoundaryFinder
FALSEevaluated 418 times by 2 tests
Evaluated by:
  • tst_QAccessibility
  • tst_QTextBoundaryFinder
295-713
375 ++pos;
executed 295 times by 1 test: ++pos;
Executed by:
  • tst_QTextBoundaryFinder
295
376 break;
executed 826 times by 2 tests: break;
Executed by:
  • tst_QAccessibility
  • tst_QTextBoundaryFinder
826
377 case Word:
executed 4027 times by 3 tests: case Word:
Executed by:
  • tst_QAccessibility
  • tst_QTextBoundaryFinder
  • tst_QTextLayout
4027
378 while (pos < length && !d->attributes[pos].wordBreak)
pos < lengthDescription
TRUEevaluated 132701 times by 3 tests
Evaluated by:
  • tst_QAccessibility
  • tst_QTextBoundaryFinder
  • tst_QTextLayout
FALSEevaluated 1543 times by 2 tests
Evaluated by:
  • tst_QTextBoundaryFinder
  • tst_QTextLayout
!d->attributes[pos].wordBreakDescription
TRUEevaluated 130217 times by 3 tests
Evaluated by:
  • tst_QAccessibility
  • tst_QTextBoundaryFinder
  • tst_QTextLayout
FALSEevaluated 2484 times by 3 tests
Evaluated by:
  • tst_QAccessibility
  • tst_QTextBoundaryFinder
  • tst_QTextLayout
1543-132701
379 ++pos;
executed 130217 times by 3 tests: ++pos;
Executed by:
  • tst_QAccessibility
  • tst_QTextBoundaryFinder
  • tst_QTextLayout
130217
380 break;
executed 4027 times by 3 tests: break;
Executed by:
  • tst_QAccessibility
  • tst_QTextBoundaryFinder
  • tst_QTextLayout
4027
381 case Sentence:
executed 663 times by 2 tests: case Sentence:
Executed by:
  • tst_QAccessibility
  • tst_QTextBoundaryFinder
663
382 while (pos < length && !d->attributes[pos].sentenceBoundary)
pos < lengthDescription
TRUEevaluated 1585 times by 2 tests
Evaluated by:
  • tst_QAccessibility
  • tst_QTextBoundaryFinder
FALSEevaluated 518 times by 1 test
Evaluated by:
  • tst_QTextBoundaryFinder
!d->attributes...ntenceBoundaryDescription
TRUEevaluated 1440 times by 2 tests
Evaluated by:
  • tst_QAccessibility
  • tst_QTextBoundaryFinder
FALSEevaluated 145 times by 2 tests
Evaluated by:
  • tst_QAccessibility
  • tst_QTextBoundaryFinder
145-1585
383 ++pos;
executed 1440 times by 2 tests: ++pos;
Executed by:
  • tst_QAccessibility
  • tst_QTextBoundaryFinder
1440
384 break;
executed 663 times by 2 tests: break;
Executed by:
  • tst_QAccessibility
  • tst_QTextBoundaryFinder
663
385 case Line:
executed 10615 times by 1 test: case Line:
Executed by:
  • tst_QTextBoundaryFinder
10615
386 while (pos < length && !d->attributes[pos].lineBreak)
pos < lengthDescription
TRUEevaluated 14608 times by 1 test
Evaluated by:
  • tst_QTextBoundaryFinder
FALSEevaluated 6337 times by 1 test
Evaluated by:
  • tst_QTextBoundaryFinder
!d->attributes[pos].lineBreakDescription
TRUEevaluated 10330 times by 1 test
Evaluated by:
  • tst_QTextBoundaryFinder
FALSEevaluated 4278 times by 1 test
Evaluated by:
  • tst_QTextBoundaryFinder
4278-14608
387 ++pos;
executed 10330 times by 1 test: ++pos;
Executed by:
  • tst_QTextBoundaryFinder
10330
388 break;
executed 10615 times by 1 test: break;
Executed by:
  • tst_QTextBoundaryFinder
10615
389 }-
390-
391 return pos;
executed 16131 times by 3 tests: return pos;
Executed by:
  • tst_QAccessibility
  • tst_QTextBoundaryFinder
  • tst_QTextLayout
16131
392}-
393-
394/*!-
395 Moves the QTextBoundaryFinder to the previous boundary position and returns that position.-
396-
397 Returns -1 if there is no previous boundary.-
398*/-
399int QTextBoundaryFinder::toPreviousBoundary()-
400{-
401 if (!d || pos <= 0 || pos > length) {
!dDescription
TRUEnever evaluated
FALSEevaluated 24899 times by 2 tests
Evaluated by:
  • tst_QAccessibility
  • tst_QTextBoundaryFinder
pos <= 0Description
TRUEevaluated 8797 times by 1 test
Evaluated by:
  • tst_QTextBoundaryFinder
FALSEevaluated 16102 times by 2 tests
Evaluated by:
  • tst_QAccessibility
  • tst_QTextBoundaryFinder
pos > lengthDescription
TRUEnever evaluated
FALSEevaluated 16102 times by 2 tests
Evaluated by:
  • tst_QAccessibility
  • tst_QTextBoundaryFinder
0-24899
402 pos = -1;-
403 return pos;
executed 8797 times by 1 test: return pos;
Executed by:
  • tst_QTextBoundaryFinder
8797
404 }-
405-
406 --pos;-
407 switch(t) {-
408 case Grapheme:
executed 809 times by 2 tests: case Grapheme:
Executed by:
  • tst_QAccessibility
  • tst_QTextBoundaryFinder
809
409 while (pos > 0 && !d->attributes[pos].graphemeBoundary)
pos > 0Description
TRUEevaluated 700 times by 2 tests
Evaluated by:
  • tst_QAccessibility
  • tst_QTextBoundaryFinder
FALSEevaluated 404 times by 2 tests
Evaluated by:
  • tst_QAccessibility
  • tst_QTextBoundaryFinder
!d->attributes...aphemeBoundaryDescription
TRUEevaluated 295 times by 1 test
Evaluated by:
  • tst_QTextBoundaryFinder
FALSEevaluated 405 times by 2 tests
Evaluated by:
  • tst_QAccessibility
  • tst_QTextBoundaryFinder
295-700
410 --pos;
executed 295 times by 1 test: --pos;
Executed by:
  • tst_QTextBoundaryFinder
295
411 break;
executed 809 times by 2 tests: break;
Executed by:
  • tst_QAccessibility
  • tst_QTextBoundaryFinder
809
412 case Word:
executed 4015 times by 2 tests: case Word:
Executed by:
  • tst_QAccessibility
  • tst_QTextBoundaryFinder
4015
413 while (pos > 0 && !d->attributes[pos].wordBreak)
pos > 0Description
TRUEevaluated 4659 times by 2 tests
Evaluated by:
  • tst_QAccessibility
  • tst_QTextBoundaryFinder
FALSEevaluated 1540 times by 1 test
Evaluated by:
  • tst_QTextBoundaryFinder
!d->attributes[pos].wordBreakDescription
TRUEevaluated 2184 times by 2 tests
Evaluated by:
  • tst_QAccessibility
  • tst_QTextBoundaryFinder
FALSEevaluated 2475 times by 2 tests
Evaluated by:
  • tst_QAccessibility
  • tst_QTextBoundaryFinder
1540-4659
414 --pos;
executed 2184 times by 2 tests: --pos;
Executed by:
  • tst_QAccessibility
  • tst_QTextBoundaryFinder
2184
415 break;
executed 4015 times by 2 tests: break;
Executed by:
  • tst_QAccessibility
  • tst_QTextBoundaryFinder
4015
416 case Sentence:
executed 663 times by 2 tests: case Sentence:
Executed by:
  • tst_QAccessibility
  • tst_QTextBoundaryFinder
663
417 while (pos > 0 && !d->attributes[pos].sentenceBoundary)
pos > 0Description
TRUEevaluated 1537 times by 2 tests
Evaluated by:
  • tst_QAccessibility
  • tst_QTextBoundaryFinder
FALSEevaluated 520 times by 2 tests
Evaluated by:
  • tst_QAccessibility
  • tst_QTextBoundaryFinder
!d->attributes...ntenceBoundaryDescription
TRUEevaluated 1394 times by 2 tests
Evaluated by:
  • tst_QAccessibility
  • tst_QTextBoundaryFinder
FALSEevaluated 143 times by 2 tests
Evaluated by:
  • tst_QAccessibility
  • tst_QTextBoundaryFinder
143-1537
418 --pos;
executed 1394 times by 2 tests: --pos;
Executed by:
  • tst_QAccessibility
  • tst_QTextBoundaryFinder
1394
419 break;
executed 663 times by 2 tests: break;
Executed by:
  • tst_QAccessibility
  • tst_QTextBoundaryFinder
663
420 case Line:
executed 10615 times by 1 test: case Line:
Executed by:
  • tst_QTextBoundaryFinder
10615
421 while (pos > 0 && !d->attributes[pos].lineBreak)
pos > 0Description
TRUEevaluated 14608 times by 1 test
Evaluated by:
  • tst_QTextBoundaryFinder
FALSEevaluated 6337 times by 1 test
Evaluated by:
  • tst_QTextBoundaryFinder
!d->attributes[pos].lineBreakDescription
TRUEevaluated 10330 times by 1 test
Evaluated by:
  • tst_QTextBoundaryFinder
FALSEevaluated 4278 times by 1 test
Evaluated by:
  • tst_QTextBoundaryFinder
4278-14608
422 --pos;
executed 10330 times by 1 test: --pos;
Executed by:
  • tst_QTextBoundaryFinder
10330
423 break;
executed 10615 times by 1 test: break;
Executed by:
  • tst_QTextBoundaryFinder
10615
424 }-
425-
426 return pos;
executed 16102 times by 2 tests: return pos;
Executed by:
  • tst_QAccessibility
  • tst_QTextBoundaryFinder
16102
427}-
428-
429/*!-
430 Returns \c true if the object's position() is currently at a valid text boundary.-
431*/-
432bool QTextBoundaryFinder::isAtBoundary() const-
433{-
434 if (!d || pos < 0 || pos > length)
!dDescription
TRUEnever evaluated
FALSEevaluated 67350 times by 1 test
Evaluated by:
  • tst_QTextBoundaryFinder
pos < 0Description
TRUEevaluated 17594 times by 1 test
Evaluated by:
  • tst_QTextBoundaryFinder
FALSEevaluated 49756 times by 1 test
Evaluated by:
  • tst_QTextBoundaryFinder
pos > lengthDescription
TRUEnever evaluated
FALSEevaluated 49756 times by 1 test
Evaluated by:
  • tst_QTextBoundaryFinder
0-67350
435 return false;
executed 17594 times by 1 test: return false;
Executed by:
  • tst_QTextBoundaryFinder
17594
436-
437 switch(t) {-
438 case Grapheme:
executed 2400 times by 1 test: case Grapheme:
Executed by:
  • tst_QTextBoundaryFinder
2400
439 return d->attributes[pos].graphemeBoundary;
executed 2400 times by 1 test: return d->attributes[pos].graphemeBoundary;
Executed by:
  • tst_QTextBoundaryFinder
2400
440 case Word:
executed 11096 times by 1 test: case Word:
Executed by:
  • tst_QTextBoundaryFinder
11096
441 return d->attributes[pos].wordBreak;
executed 11096 times by 1 test: return d->attributes[pos].wordBreak;
Executed by:
  • tst_QTextBoundaryFinder
11096
442 case Sentence:
executed 2356 times by 1 test: case Sentence:
Executed by:
  • tst_QTextBoundaryFinder
2356
443 return d->attributes[pos].sentenceBoundary;
executed 2356 times by 1 test: return d->attributes[pos].sentenceBoundary;
Executed by:
  • tst_QTextBoundaryFinder
2356
444 case Line:
executed 33904 times by 1 test: case Line:
Executed by:
  • tst_QTextBoundaryFinder
33904
445 // ### TR#14 LB2 prohibits break at sot-
446 return d->attributes[pos].lineBreak || pos == 0;
executed 33904 times by 1 test: return d->attributes[pos].lineBreak || pos == 0;
Executed by:
  • tst_QTextBoundaryFinder
33904
447 }-
448 return false;
never executed: return false;
0
449}-
450-
451/*!-
452 Returns the reasons for the boundary finder to have chosen the current position as a boundary.-
453*/-
454QTextBoundaryFinder::BoundaryReasons QTextBoundaryFinder::boundaryReasons() const-
455{-
456 BoundaryReasons reasons = NotAtBoundary;-
457 if (!d || pos < 0 || pos > length)
!dDescription
TRUEevaluated 14 times by 1 test
Evaluated by:
  • tst_QTextBoundaryFinder
FALSEevaluated 106479 times by 3 tests
Evaluated by:
  • tst_QAccessibility
  • tst_QTextBoundaryFinder
  • tst_QTextLayout
pos < 0Description
TRUEevaluated 17597 times by 2 tests
Evaluated by:
  • tst_QAccessibility
  • tst_QTextBoundaryFinder
FALSEevaluated 88882 times by 3 tests
Evaluated by:
  • tst_QAccessibility
  • tst_QTextBoundaryFinder
  • tst_QTextLayout
pos > lengthDescription
TRUEnever evaluated
FALSEevaluated 88882 times by 3 tests
Evaluated by:
  • tst_QAccessibility
  • tst_QTextBoundaryFinder
  • tst_QTextLayout
0-106479
458 return reasons;
executed 17611 times by 2 tests: return reasons;
Executed by:
  • tst_QAccessibility
  • tst_QTextBoundaryFinder
17611
459-
460 const QCharAttributes attr = d->attributes[pos];-
461 switch (t) {-
462 case Grapheme:
executed 3951 times by 2 tests: case Grapheme:
Executed by:
  • tst_QAccessibility
  • tst_QTextBoundaryFinder
3951
463 if (attr.graphemeBoundary) {
attr.graphemeBoundaryDescription
TRUEevaluated 3656 times by 2 tests
Evaluated by:
  • tst_QAccessibility
  • tst_QTextBoundaryFinder
FALSEevaluated 295 times by 1 test
Evaluated by:
  • tst_QTextBoundaryFinder
295-3656
464 reasons |= BreakOpportunity | StartOfItem | EndOfItem;-
465 if (pos == 0)
pos == 0Description
TRUEevaluated 1209 times by 2 tests
Evaluated by:
  • tst_QAccessibility
  • tst_QTextBoundaryFinder
FALSEevaluated 2447 times by 2 tests
Evaluated by:
  • tst_QAccessibility
  • tst_QTextBoundaryFinder
1209-2447
466 reasons &= (~EndOfItem);
executed 1209 times by 2 tests: reasons &= (~EndOfItem);
Executed by:
  • tst_QAccessibility
  • tst_QTextBoundaryFinder
1209
467 else if (pos == length)
pos == lengthDescription
TRUEevaluated 1214 times by 2 tests
Evaluated by:
  • tst_QAccessibility
  • tst_QTextBoundaryFinder
FALSEevaluated 1233 times by 2 tests
Evaluated by:
  • tst_QAccessibility
  • tst_QTextBoundaryFinder
1214-1233
468 reasons &= (~StartOfItem);
executed 1214 times by 2 tests: reasons &= (~StartOfItem);
Executed by:
  • tst_QAccessibility
  • tst_QTextBoundaryFinder
1214
469 }
executed 3656 times by 2 tests: end of block
Executed by:
  • tst_QAccessibility
  • tst_QTextBoundaryFinder
3656
470 break;
executed 3951 times by 2 tests: break;
Executed by:
  • tst_QAccessibility
  • tst_QTextBoundaryFinder
3951
471 case Word:
executed 18853 times by 3 tests: case Word:
Executed by:
  • tst_QAccessibility
  • tst_QTextBoundaryFinder
  • tst_QTextLayout
18853
472 if (attr.wordBreak) {
attr.wordBreakDescription
TRUEevaluated 16675 times by 3 tests
Evaluated by:
  • tst_QAccessibility
  • tst_QTextBoundaryFinder
  • tst_QTextLayout
FALSEevaluated 2178 times by 2 tests
Evaluated by:
  • tst_QAccessibility
  • tst_QTextBoundaryFinder
2178-16675
473 reasons |= BreakOpportunity;-
474 if (attr.wordStart)
attr.wordStartDescription
TRUEevaluated 4571 times by 3 tests
Evaluated by:
  • tst_QAccessibility
  • tst_QTextBoundaryFinder
  • tst_QTextLayout
FALSEevaluated 12104 times by 3 tests
Evaluated by:
  • tst_QAccessibility
  • tst_QTextBoundaryFinder
  • tst_QTextLayout
4571-12104
475 reasons |= StartOfItem;
executed 4571 times by 3 tests: reasons |= StartOfItem;
Executed by:
  • tst_QAccessibility
  • tst_QTextBoundaryFinder
  • tst_QTextLayout
4571
476 if (attr.wordEnd)
attr.wordEndDescription
TRUEevaluated 4569 times by 3 tests
Evaluated by:
  • tst_QAccessibility
  • tst_QTextBoundaryFinder
  • tst_QTextLayout
FALSEevaluated 12106 times by 3 tests
Evaluated by:
  • tst_QAccessibility
  • tst_QTextBoundaryFinder
  • tst_QTextLayout
4569-12106
477 reasons |= EndOfItem;
executed 4569 times by 3 tests: reasons |= EndOfItem;
Executed by:
  • tst_QAccessibility
  • tst_QTextBoundaryFinder
  • tst_QTextLayout
4569
478 }
executed 16675 times by 3 tests: end of block
Executed by:
  • tst_QAccessibility
  • tst_QTextBoundaryFinder
  • tst_QTextLayout
16675
479 break;
executed 18853 times by 3 tests: break;
Executed by:
  • tst_QAccessibility
  • tst_QTextBoundaryFinder
  • tst_QTextLayout
18853
480 case Sentence:
executed 4892 times by 2 tests: case Sentence:
Executed by:
  • tst_QAccessibility
  • tst_QTextBoundaryFinder
4892
481 if (attr.sentenceBoundary) {
attr.sentenceBoundaryDescription
TRUEevaluated 3538 times by 2 tests
Evaluated by:
  • tst_QAccessibility
  • tst_QTextBoundaryFinder
FALSEevaluated 1354 times by 2 tests
Evaluated by:
  • tst_QAccessibility
  • tst_QTextBoundaryFinder
1354-3538
482 reasons |= BreakOpportunity | StartOfItem | EndOfItem;-
483 if (pos == 0)
pos == 0Description
TRUEevaluated 1554 times by 1 test
Evaluated by:
  • tst_QTextBoundaryFinder
FALSEevaluated 1984 times by 2 tests
Evaluated by:
  • tst_QAccessibility
  • tst_QTextBoundaryFinder
1554-1984
484 reasons &= (~EndOfItem);
executed 1554 times by 1 test: reasons &= (~EndOfItem);
Executed by:
  • tst_QTextBoundaryFinder
1554
485 else if (pos == length)
pos == lengthDescription
TRUEevaluated 1554 times by 1 test
Evaluated by:
  • tst_QTextBoundaryFinder
FALSEevaluated 430 times by 2 tests
Evaluated by:
  • tst_QAccessibility
  • tst_QTextBoundaryFinder
430-1554
486 reasons &= (~StartOfItem);
executed 1554 times by 1 test: reasons &= (~StartOfItem);
Executed by:
  • tst_QTextBoundaryFinder
1554
487 }
executed 3538 times by 2 tests: end of block
Executed by:
  • tst_QAccessibility
  • tst_QTextBoundaryFinder
3538
488 break;
executed 4892 times by 2 tests: break;
Executed by:
  • tst_QAccessibility
  • tst_QTextBoundaryFinder
4892
489 case Line:
executed 61186 times by 1 test: case Line:
Executed by:
  • tst_QTextBoundaryFinder
61186
490 // ### TR#14 LB2 prohibits break at sot-
491 if (attr.lineBreak || pos == 0) {
attr.lineBreakDescription
TRUEevaluated 31845 times by 1 test
Evaluated by:
  • tst_QTextBoundaryFinder
FALSEevaluated 29341 times by 1 test
Evaluated by:
  • tst_QTextBoundaryFinder
pos == 0Description
TRUEevaluated 19011 times by 1 test
Evaluated by:
  • tst_QTextBoundaryFinder
FALSEevaluated 10330 times by 1 test
Evaluated by:
  • tst_QTextBoundaryFinder
10330-31845
492 reasons |= BreakOpportunity;-
493 if (attr.mandatoryBreak || pos == 0) {
attr.mandatoryBreakDescription
TRUEevaluated 20952 times by 1 test
Evaluated by:
  • tst_QTextBoundaryFinder
FALSEevaluated 29904 times by 1 test
Evaluated by:
  • tst_QTextBoundaryFinder
pos == 0Description
TRUEevaluated 19011 times by 1 test
Evaluated by:
  • tst_QTextBoundaryFinder
FALSEevaluated 10893 times by 1 test
Evaluated by:
  • tst_QTextBoundaryFinder
10893-29904
494 reasons |= MandatoryBreak | StartOfItem | EndOfItem;-
495 if (pos == 0)
pos == 0Description
TRUEevaluated 19011 times by 1 test
Evaluated by:
  • tst_QTextBoundaryFinder
FALSEevaluated 20952 times by 1 test
Evaluated by:
  • tst_QTextBoundaryFinder
19011-20952
496 reasons &= (~EndOfItem);
executed 19011 times by 1 test: reasons &= (~EndOfItem);
Executed by:
  • tst_QTextBoundaryFinder
19011
497 else if (pos == length)
pos == lengthDescription
TRUEevaluated 19011 times by 1 test
Evaluated by:
  • tst_QTextBoundaryFinder
FALSEevaluated 1941 times by 1 test
Evaluated by:
  • tst_QTextBoundaryFinder
1941-19011
498 reasons &= (~StartOfItem);
executed 19011 times by 1 test: reasons &= (~StartOfItem);
Executed by:
  • tst_QTextBoundaryFinder
19011
499 } else if (pos > 0 && chars[pos - 1].unicode() == QChar::SoftHyphen) {
executed 39963 times by 1 test: end of block
Executed by:
  • tst_QTextBoundaryFinder
pos > 0Description
TRUEevaluated 10893 times by 1 test
Evaluated by:
  • tst_QTextBoundaryFinder
FALSEnever evaluated
chars[pos - 1]...ar::SoftHyphenDescription
TRUEevaluated 45 times by 1 test
Evaluated by:
  • tst_QTextBoundaryFinder
FALSEevaluated 10848 times by 1 test
Evaluated by:
  • tst_QTextBoundaryFinder
0-39963
500 reasons |= SoftHyphen;-
501 }
executed 45 times by 1 test: end of block
Executed by:
  • tst_QTextBoundaryFinder
45
502 }
executed 50856 times by 1 test: end of block
Executed by:
  • tst_QTextBoundaryFinder
50856
503 break;
executed 61186 times by 1 test: break;
Executed by:
  • tst_QTextBoundaryFinder
61186
504 default:
never executed: default:
0
505 break;
never executed: break;
0
506 }-
507-
508 return reasons;
executed 88882 times by 3 tests: return reasons;
Executed by:
  • tst_QAccessibility
  • tst_QTextBoundaryFinder
  • tst_QTextLayout
88882
509}-
510-
511QT_END_NAMESPACE-
Source codeSwitch to Preprocessed file

Generated by Squish Coco Non-Commercial 4.3.0-BETA-master-30-08-2018-4cb69e9