tools/qtextboundaryfinder.cpp

Source codeSwitch to Preprocessed file
LineSource CodeCoverage
1/**************************************************************************** -
2** -
3** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). -
4** Contact: http://www.qt-project.org/legal -
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 Digia. For licensing terms and -
14** conditions see http://qt.digia.com/licensing. For further information -
15** use the contact form at http://qt.digia.com/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 2.1 as published by the Free Software -
20** Foundation and appearing in the file LICENSE.LGPL included in the -
21** packaging of this file. Please review the following information to -
22** ensure the GNU Lesser General Public License version 2.1 requirements -
23** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -
24** -
25** In addition, as a special exception, Digia gives you certain additional -
26** rights. These rights are described in the Digia Qt LGPL Exception -
27** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -
28** -
29** GNU General Public License Usage -
30** Alternatively, this file may be used under the terms of the GNU -
31** General Public License version 3.0 as published by the Free Software -
32** Foundation and appearing in the file LICENSE.GPL included in the -
33** packaging of this file. Please review the following information to -
34** ensure the GNU General Public License version 3.0 requirements will be -
35** met: http://www.gnu.org/copyleft/gpl.html. -
36** -
37** -
38** $QT_END_LICENSE$ -
39** -
40****************************************************************************/ -
41#include <QtCore/qtextboundaryfinder.h> -
42#include <QtCore/qvarlengtharray.h> -
43 -
44#include <private/qunicodetables_p.h> -
45#include <private/qunicodetools_p.h> -
46 -
47QT_BEGIN_NAMESPACE -
48 -
49class QTextBoundaryFinderPrivate -
50{ -
51public: -
52 QCharAttributes attributes[1]; -
53}; -
54 -
55static void init(QTextBoundaryFinder::BoundaryType type, const QChar *chars, int length, QCharAttributes *attributes) -
56{ -
57 QVarLengthArray<QUnicodeTools::ScriptItem> scriptItems;
executed (the execution status of this line is deduced): QVarLengthArray<QUnicodeTools::ScriptItem> scriptItems;
-
58 -
59 const ushort *string = reinterpret_cast<const ushort *>(chars);
executed (the execution status of this line is deduced): const ushort *string = reinterpret_cast<const ushort *>(chars);
-
60 const ushort *unicode = string;
executed (the execution status of this line is deduced): const ushort *unicode = string;
-
61 // correctly assign script, isTab and isObject to the script analysis -
62 const ushort *uc = unicode;
executed (the execution status of this line is deduced): const ushort *uc = unicode;
-
63 const ushort *e = uc + length;
executed (the execution status of this line is deduced): const ushort *e = uc + length;
-
64 int script = QUnicodeTables::Common;
executed (the execution status of this line is deduced): int script = QUnicodeTables::Common;
-
65 int lastScript = QUnicodeTables::Common;
executed (the execution status of this line is deduced): int lastScript = QUnicodeTables::Common;
-
66 const ushort *start = uc;
executed (the execution status of this line is deduced): const ushort *start = uc;
-
67 while (uc < e) {
evaluated: uc < e
TRUEFALSE
yes
Evaluation Count:3286
yes
Evaluation Count:113
113-3286
68 int s = QUnicodeTables::script(*uc);
executed (the execution status of this line is deduced): int s = QUnicodeTables::script(*uc);
-
69 if (s != QUnicodeTables::Inherited)
evaluated: s != QUnicodeTables::Inherited
TRUEFALSE
yes
Evaluation Count:3268
yes
Evaluation Count:18
18-3268
70 script = s;
executed: script = s;
Execution Count:3268
3268
71 if (*uc == QChar::ObjectReplacementCharacter || *uc == QChar::LineSeparator || *uc == 9)
partially evaluated: *uc == QChar::ObjectReplacementCharacter
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:3286
partially evaluated: *uc == QChar::LineSeparator
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:3286
evaluated: *uc == 9
TRUEFALSE
yes
Evaluation Count:4
yes
Evaluation Count:3282
0-3286
72 script = QUnicodeTables::Common;
executed: script = QUnicodeTables::Common;
Execution Count:4
4
73 if (script != lastScript) {
partially evaluated: script != lastScript
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:3286
0-3286
74 if (uc != start) {
never evaluated: uc != start
0
75 QUnicodeTools::ScriptItem item;
never executed (the execution status of this line is deduced): QUnicodeTools::ScriptItem item;
-
76 item.position = start - string;
never executed (the execution status of this line is deduced): item.position = start - string;
-
77 item.script = lastScript;
never executed (the execution status of this line is deduced): item.script = lastScript;
-
78 scriptItems.append(item);
never executed (the execution status of this line is deduced): scriptItems.append(item);
-
79 start = uc;
never executed (the execution status of this line is deduced): start = uc;
-
80 }
never executed: }
0
81 lastScript = script;
never executed (the execution status of this line is deduced): lastScript = script;
-
82 }
never executed: }
0
83 ++uc;
executed (the execution status of this line is deduced): ++uc;
-
84 }
executed: }
Execution Count:3286
3286
85 if (uc != start) {
partially evaluated: uc != start
TRUEFALSE
yes
Evaluation Count:113
no
Evaluation Count:0
0-113
86 QUnicodeTools::ScriptItem item;
executed (the execution status of this line is deduced): QUnicodeTools::ScriptItem item;
-
87 item.position = start - string;
executed (the execution status of this line is deduced): item.position = start - string;
-
88 item.script = lastScript;
executed (the execution status of this line is deduced): item.script = lastScript;
-
89 scriptItems.append(item);
executed (the execution status of this line is deduced): scriptItems.append(item);
-
90 }
executed: }
Execution Count:113
113
91 -
92 QUnicodeTools::CharAttributeOptions options = 0;
executed (the execution status of this line is deduced): QUnicodeTools::CharAttributeOptions options = 0;
-
93 switch (type) { -
94 case QTextBoundaryFinder::Grapheme: options |= QUnicodeTools::GraphemeBreaks; break;
executed: break;
Execution Count:6
6
95 case QTextBoundaryFinder::Word: options |= QUnicodeTools::WordBreaks; break;
executed: break;
Execution Count:62
62
96 case QTextBoundaryFinder::Sentence: options |= QUnicodeTools::SentenceBreaks; break;
executed: break;
Execution Count:18
18
97 case QTextBoundaryFinder::Line: options |= QUnicodeTools::LineBreaks; break;
executed: break;
Execution Count:27
27
98 default: break;
never executed: break;
0
99 } -
100 QUnicodeTools::initCharAttributes(string, length, scriptItems.data(), scriptItems.count(), attributes, options);
executed (the execution status of this line is deduced): QUnicodeTools::initCharAttributes(string, length, scriptItems.data(), scriptItems.count(), attributes, options);
-
101}
executed: }
Execution Count:113
113
102 -
103/*! -
104 \class QTextBoundaryFinder -
105 \inmodule QtCore -
106 -
107 \brief The QTextBoundaryFinder class provides a way of finding Unicode text boundaries in a string. -
108 -
109 \since 4.4 -
110 \ingroup tools -
111 \ingroup shared -
112 \ingroup string-processing -
113 \reentrant -
114 -
115 QTextBoundaryFinder allows to find Unicode text boundaries in a -
116 string, accordingly to the Unicode text boundary specification (see -
117 \l{http://www.unicode.org/reports/tr14/}{Unicode Standard Annex #14} and -
118 \l{http://www.unicode.org/reports/tr29/}{Unicode Standard Annex #29}). -
119 -
120 QTextBoundaryFinder can operate on a QString in four possible -
121 modes depending on the value of \a BoundaryType. -
122 -
123 Units of Unicode characters that make up what the user thinks of -
124 as a character or basic unit of the language are here called -
125 Grapheme clusters. The two unicode characters 'A' + diaeresis do -
126 for example form one grapheme cluster as the user thinks of them -
127 as one character, yet it is in this case represented by two -
128 unicode code points -
129 (see \l{http://www.unicode.org/reports/tr29/#Grapheme_Cluster_Boundaries}). -
130 -
131 Word boundaries are there to locate the start and end of what a -
132 language considers to be a word -
133 (see \l{http://www.unicode.org/reports/tr29/#Word_Boundaries}). -
134 -
135 Line break boundaries give possible places where a line break -
136 might happen and sentence boundaries will show the beginning and -
137 end of whole sentences -
138 (see \l{http://www.unicode.org/reports/tr29/#Sentence_Boundaries} and -
139 \l{http://www.unicode.org/reports/tr14/}). -
140 -
141 The first position in a string is always a valid boundary and -
142 refers to the position before the first character. The last -
143 position at the length of the string is also valid and refers -
144 to the position after the last character. -
145*/ -
146 -
147/*! -
148 \enum QTextBoundaryFinder::BoundaryType -
149 -
150 \value Grapheme Finds a grapheme which is the smallest boundary. It -
151 including letters, punctuation marks, numerals and more. -
152 \value Word Finds a word. -
153 \value Line Finds possible positions for breaking the text into multiple -
154 lines. -
155 \value Sentence Finds sentence boundaries. These include periods, question -
156 marks etc. -
157*/ -
158 -
159/*! -
160 \enum QTextBoundaryFinder::BoundaryReason -
161 -
162 \value NotAtBoundary The boundary finder is not at a boundary position. -
163 \value BreakOpportunity The boundary finder is at a break opportunity position. -
164 Such a break opportunity might also be an item boundary -
165 (either StartOfItem, EndOfItem, or combination of both), -
166 a mandatory line break, or a soft hyphen. -
167 \value StartOfItem Since 5.0. The boundary finder is at the start of -
168 a grapheme, a word, a sentence, or a line. -
169 \value EndOfItem Since 5.0. The boundary finder is at the end of -
170 a grapheme, a word, a sentence, or a line. -
171 \value MandatoryBreak Since 5.0. The boundary finder is at the end of line -
172 (can occur for a Line boundary type only). -
173 \value SoftHyphen The boundary finder is at the soft hyphen -
174 (can occur for a Line boundary type only). -
175*/ -
176 -
177/*! -
178 Constructs an invalid QTextBoundaryFinder object. -
179*/ -
180QTextBoundaryFinder::QTextBoundaryFinder() -
181 : t(Grapheme) -
182 , chars(0) -
183 , length(0) -
184 , freePrivate(true) -
185 , d(0) -
186{ -
187}
executed: }
Execution Count:1
1
188 -
189/*! -
190 Copies the QTextBoundaryFinder object, \a other. -
191*/ -
192QTextBoundaryFinder::QTextBoundaryFinder(const QTextBoundaryFinder &other) -
193 : t(other.t) -
194 , s(other.s) -
195 , chars(other.chars) -
196 , length(other.length) -
197 , pos(other.pos) -
198 , freePrivate(true) -
199 , d(0) -
200{ -
201 if (other.d) {
partially evaluated: other.d
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:15
0-15
202 Q_ASSERT(length > 0);
never executed (the execution status of this line is deduced): qt_noop();
-
203 d = (QTextBoundaryFinderPrivate *) malloc((length + 1) * sizeof(QCharAttributes));
never executed (the execution status of this line is deduced): d = (QTextBoundaryFinderPrivate *) malloc((length + 1) * sizeof(QCharAttributes));
-
204 Q_CHECK_PTR(d);
never executed: qBadAlloc();
never executed: }
never evaluated: !(d)
never evaluated: 0
0
205 memcpy(d, other.d, (length + 1) * sizeof(QCharAttributes));
never executed (the execution status of this line is deduced): memcpy(d, other.d, (length + 1) * sizeof(QCharAttributes));
-
206 }
never executed: }
0
207}
executed: }
Execution Count:15
15
208 -
209/*! -
210 Assigns the object, \a other, to another QTextBoundaryFinder object. -
211*/ -
212QTextBoundaryFinder &QTextBoundaryFinder::operator=(const QTextBoundaryFinder &other) -
213{ -
214 if (&other == this)
partially evaluated: &other == this
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:4
0-4
215 return *this;
never executed: return *this;
0
216 -
217 if (other.d) {
evaluated: other.d
TRUEFALSE
yes
Evaluation Count:2
yes
Evaluation Count:2
2
218 Q_ASSERT(other.length > 0);
executed (the execution status of this line is deduced): qt_noop();
-
219 uint newCapacity = (other.length + 1) * sizeof(QCharAttributes);
executed (the execution status of this line is deduced): uint newCapacity = (other.length + 1) * sizeof(QCharAttributes);
-
220 QTextBoundaryFinderPrivate *newD = (QTextBoundaryFinderPrivate *) realloc(freePrivate ? d : 0, newCapacity);
executed (the execution status of this line is deduced): QTextBoundaryFinderPrivate *newD = (QTextBoundaryFinderPrivate *) realloc(freePrivate ? d : 0, newCapacity);
-
221 Q_CHECK_PTR(newD);
never executed: qBadAlloc();
executed: }
Execution Count:2
partially evaluated: !(newD)
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:2
partially evaluated: 0
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:2
0-2
222 freePrivate = true;
executed (the execution status of this line is deduced): freePrivate = true;
-
223 d = newD;
executed (the execution status of this line is deduced): d = newD;
-
224 }
executed: }
Execution Count:2
2
225 -
226 t = other.t;
executed (the execution status of this line is deduced): t = other.t;
-
227 s = other.s;
executed (the execution status of this line is deduced): s = other.s;
-
228 chars = other.chars;
executed (the execution status of this line is deduced): chars = other.chars;
-
229 length = other.length;
executed (the execution status of this line is deduced): length = other.length;
-
230 pos = other.pos;
executed (the execution status of this line is deduced): pos = other.pos;
-
231 -
232 if (other.d) {
evaluated: other.d
TRUEFALSE
yes
Evaluation Count:2
yes
Evaluation Count:2
2
233 memcpy(d, other.d, (length + 1) * sizeof(QCharAttributes));
executed (the execution status of this line is deduced): memcpy(d, other.d, (length + 1) * sizeof(QCharAttributes));
-
234 } else {
executed: }
Execution Count:2
2
235 if (freePrivate)
partially evaluated: freePrivate
TRUEFALSE
yes
Evaluation Count:2
no
Evaluation Count:0
0-2
236 free(d);
executed: free(d);
Execution Count:2
2
237 d = 0;
executed (the execution status of this line is deduced): d = 0;
-
238 }
executed: }
Execution Count:2
2
239 -
240 return *this;
executed: return *this;
Execution Count:4
4
241} -
242 -
243/*! -
244 Destructs the QTextBoundaryFinder object. -
245*/ -
246QTextBoundaryFinder::~QTextBoundaryFinder() -
247{ -
248 if (freePrivate)
partially evaluated: freePrivate
TRUEFALSE
yes
Evaluation Count:134
no
Evaluation Count:0
0-134
249 free(d);
executed: free(d);
Execution Count:134
134
250}
executed: }
Execution Count:134
134
251 -
252/*! -
253 Creates a QTextBoundaryFinder object of \a type operating on \a string. -
254*/ -
255QTextBoundaryFinder::QTextBoundaryFinder(BoundaryType type, const QString &string) -
256 : t(type) -
257 , s(string) -
258 , chars(string.unicode()) -
259 , length(string.length()) -
260 , pos(0) -
261 , freePrivate(true) -
262 , d(0) -
263{ -
264 if (length > 0) {
evaluated: length > 0
TRUEFALSE
yes
Evaluation Count:112
yes
Evaluation Count:1
1-112
265 d = (QTextBoundaryFinderPrivate *) malloc((length + 1) * sizeof(QCharAttributes));
executed (the execution status of this line is deduced): d = (QTextBoundaryFinderPrivate *) malloc((length + 1) * sizeof(QCharAttributes));
-
266 Q_CHECK_PTR(d);
never executed: qBadAlloc();
executed: }
Execution Count:112
partially evaluated: !(d)
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:112
partially evaluated: 0
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:112
0-112
267 init(t, chars, length, d->attributes);
executed (the execution status of this line is deduced): init(t, chars, length, d->attributes);
-
268 }
executed: }
Execution Count:112
112
269}
executed: }
Execution Count:113
113
270 -
271/*! -
272 Creates a QTextBoundaryFinder object of \a type operating on \a chars -
273 with \a length. -
274 -
275 \a buffer is an optional working buffer of size \a bufferSize you can pass to -
276 the QTextBoundaryFinder. If the buffer is large enough to hold the working -
277 data required (bufferSize >= length + 1), it will use this -
278 instead of allocating its own buffer. -
279 -
280 \warning QTextBoundaryFinder does not create a copy of \a chars. It is the -
281 application programmer's responsibility to ensure the array is allocated for -
282 as long as the QTextBoundaryFinder object stays alive. The same applies to -
283 \a buffer. -
284*/ -
285QTextBoundaryFinder::QTextBoundaryFinder(BoundaryType type, const QChar *chars, int length, unsigned char *buffer, int bufferSize) -
286 : t(type) -
287 , chars(chars) -
288 , length(length) -
289 , pos(0) -
290 , freePrivate(true) -
291 , d(0) -
292{ -
293 if (!chars) {
evaluated: !chars
TRUEFALSE
yes
Evaluation Count:2
yes
Evaluation Count:3
2-3
294 length = 0;
executed (the execution status of this line is deduced): length = 0;
-
295 } else if (length > 0) {
executed: }
Execution Count:2
evaluated: length > 0
TRUEFALSE
yes
Evaluation Count:1
yes
Evaluation Count:2
1-2
296 if (buffer && (uint)bufferSize >= (length + 1) * sizeof(QCharAttributes)) {
partially evaluated: buffer
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:1
never evaluated: (uint)bufferSize >= (length + 1) * sizeof(QCharAttributes)
0-1
297 d = (QTextBoundaryFinderPrivate *)buffer;
never executed (the execution status of this line is deduced): d = (QTextBoundaryFinderPrivate *)buffer;
-
298 freePrivate = false;
never executed (the execution status of this line is deduced): freePrivate = false;
-
299 } else {
never executed: }
0
300 d = (QTextBoundaryFinderPrivate *) malloc((length + 1) * sizeof(QCharAttributes));
executed (the execution status of this line is deduced): d = (QTextBoundaryFinderPrivate *) malloc((length + 1) * sizeof(QCharAttributes));
-
301 Q_CHECK_PTR(d);
never executed: qBadAlloc();
executed: }
Execution Count:1
partially evaluated: !(d)
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:1
partially evaluated: 0
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:1
0-1
302 }
executed: }
Execution Count:1
1
303 init(t, chars, length, d->attributes);
executed (the execution status of this line is deduced): init(t, chars, length, d->attributes);
-
304 }
executed: }
Execution Count:1
1
305} -
306 -
307/*! -
308 Moves the finder to the start of the string. This is equivalent to setPosition(0). -
309 -
310 \sa setPosition(), position() -
311*/ -
312void QTextBoundaryFinder::toStart() -
313{ -
314 pos = 0;
never executed (the execution status of this line is deduced): pos = 0;
-
315}
never executed: }
0
316 -
317/*! -
318 Moves the finder to the end of the string. This is equivalent to setPosition(string.length()). -
319 -
320 \sa setPosition(), position() -
321*/ -
322void QTextBoundaryFinder::toEnd() -
323{ -
324 pos = length;
executed (the execution status of this line is deduced): pos = length;
-
325}
executed: }
Execution Count:92
92
326 -
327/*! -
328 Returns the current position of the QTextBoundaryFinder. -
329 -
330 The range is from 0 (the beginning of the string) to the length of -
331 the string inclusive. -
332 -
333 \sa setPosition() -
334*/ -
335int QTextBoundaryFinder::position() const -
336{ -
337 return pos;
executed: return pos;
Execution Count:855
855
338} -
339 -
340/*! -
341 Sets the current position of the QTextBoundaryFinder to \a position. -
342 -
343 If \a position is out of bounds, it will be bound to only valid -
344 positions. In this case, valid positions are from 0 to the length of -
345 the string inclusive. -
346 -
347 \sa position() -
348*/ -
349void QTextBoundaryFinder::setPosition(int position) -
350{ -
351 pos = qBound(0, position, length);
executed (the execution status of this line is deduced): pos = qBound(0, position, length);
-
352}
executed: }
Execution Count:1421
1421
353 -
354/*! \fn QTextBoundaryFinder::BoundaryType QTextBoundaryFinder::type() const -
355 -
356 Returns the type of the QTextBoundaryFinder. -
357*/ -
358 -
359/*! \fn bool QTextBoundaryFinder::isValid() const -
360 -
361 Returns true if the text boundary finder is valid; otherwise returns false. -
362 A default QTextBoundaryFinder is invalid. -
363*/ -
364 -
365/*! -
366 Returns the string the QTextBoundaryFinder object operates on. -
367*/ -
368QString QTextBoundaryFinder::string() const -
369{ -
370 if (chars == s.unicode() && length == s.length())
evaluated: chars == s.unicode()
TRUEFALSE
yes
Evaluation Count:2
yes
Evaluation Count:2
partially evaluated: length == s.length()
TRUEFALSE
yes
Evaluation Count:2
no
Evaluation Count:0
0-2
371 return s;
executed: return s;
Execution Count:2
2
372 return QString(chars, length);
executed: return QString(chars, length);
Execution Count:2
2
373} -
374 -
375 -
376/*! -
377 Moves the QTextBoundaryFinder to the next boundary position and returns that position. -
378 -
379 Returns -1 if there is no next boundary. -
380*/ -
381int QTextBoundaryFinder::toNextBoundary() -
382{ -
383 if (!d || pos < 0 || pos >= length) {
evaluated: !d
TRUEFALSE
yes
Evaluation Count:7
yes
Evaluation Count:544
partially evaluated: pos < 0
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:544
evaluated: pos >= length
TRUEFALSE
yes
Evaluation Count:93
yes
Evaluation Count:451
0-544
384 pos = -1;
executed (the execution status of this line is deduced): pos = -1;
-
385 return pos;
executed: return pos;
Execution Count:100
100
386 } -
387 -
388 ++pos;
executed (the execution status of this line is deduced): ++pos;
-
389 switch(t) { -
390 case Grapheme: -
391 while (pos < length && !d->attributes[pos].graphemeBoundary)
partially evaluated: pos < length
TRUEFALSE
yes
Evaluation Count:6
no
Evaluation Count:0
partially evaluated: !d->attributes[pos].graphemeBoundary
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:6
0-6
392 ++pos;
never executed: ++pos;
0
393 break;
executed: break;
Execution Count:6
6
394 case Word: -
395 while (pos < length && !d->attributes[pos].wordBreak)
evaluated: pos < length
TRUEFALSE
yes
Evaluation Count:770
yes
Evaluation Count:52
evaluated: !d->attributes[pos].wordBreak
TRUEFALSE
yes
Evaluation Count:516
yes
Evaluation Count:254
52-770
396 ++pos;
executed: ++pos;
Execution Count:516
516
397 break;
executed: break;
Execution Count:306
306
398 case Sentence: -
399 while (pos < length && !d->attributes[pos].sentenceBoundary)
evaluated: pos < length
TRUEFALSE
yes
Evaluation Count:289
yes
Evaluation Count:15
evaluated: !d->attributes[pos].sentenceBoundary
TRUEFALSE
yes
Evaluation Count:271
yes
Evaluation Count:18
15-289
400 ++pos;
executed: ++pos;
Execution Count:271
271
401 break;
executed: break;
Execution Count:33
33
402 case Line: -
403 while (pos < length && !d->attributes[pos].lineBreak)
evaluated: pos < length
TRUEFALSE
yes
Evaluation Count:302
yes
Evaluation Count:26
evaluated: !d->attributes[pos].lineBreak
TRUEFALSE
yes
Evaluation Count:222
yes
Evaluation Count:80
26-302
404 ++pos;
executed: ++pos;
Execution Count:222
222
405 break;
executed: break;
Execution Count:106
106
406 } -
407 -
408 return pos;
executed: return pos;
Execution Count:451
451
409} -
410 -
411/*! -
412 Moves the QTextBoundaryFinder to the previous boundary position and returns that position. -
413 -
414 Returns -1 if there is no previous boundary. -
415*/ -
416int QTextBoundaryFinder::toPreviousBoundary() -
417{ -
418 if (!d || pos <= 0 || pos > length) {
partially evaluated: !d
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:530
evaluated: pos <= 0
TRUEFALSE
yes
Evaluation Count:92
yes
Evaluation Count:438
partially evaluated: pos > length
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:438
0-530
419 pos = -1;
executed (the execution status of this line is deduced): pos = -1;
-
420 return pos;
executed: return pos;
Execution Count:92
92
421 } -
422 -
423 --pos;
executed (the execution status of this line is deduced): --pos;
-
424 switch(t) { -
425 case Grapheme: -
426 while (pos > 0 && !d->attributes[pos].graphemeBoundary)
partially evaluated: pos > 0
TRUEFALSE
yes
Evaluation Count:1
no
Evaluation Count:0
partially evaluated: !d->attributes[pos].graphemeBoundary
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:1
0-1
427 --pos;
never executed: --pos;
0
428 break;
executed: break;
Execution Count:1
1
429 case Word: -
430 while (pos > 0 && !d->attributes[pos].wordBreak)
evaluated: pos > 0
TRUEFALSE
yes
Evaluation Count:737
yes
Evaluation Count:51
evaluated: !d->attributes[pos].wordBreak
TRUEFALSE
yes
Evaluation Count:490
yes
Evaluation Count:247
51-737
431 --pos;
executed: --pos;
Execution Count:490
490
432 break;
executed: break;
Execution Count:298
298
433 case Sentence: -
434 while (pos > 0 && !d->attributes[pos].sentenceBoundary)
evaluated: pos > 0
TRUEFALSE
yes
Evaluation Count:241
yes
Evaluation Count:17
evaluated: !d->attributes[pos].sentenceBoundary
TRUEFALSE
yes
Evaluation Count:225
yes
Evaluation Count:16
16-241
435 --pos;
executed: --pos;
Execution Count:225
225
436 break;
executed: break;
Execution Count:33
33
437 case Line: -
438 while (pos > 0 && !d->attributes[pos].lineBreak)
evaluated: pos > 0
TRUEFALSE
yes
Evaluation Count:302
yes
Evaluation Count:26
evaluated: !d->attributes[pos].lineBreak
TRUEFALSE
yes
Evaluation Count:222
yes
Evaluation Count:80
26-302
439 --pos;
executed: --pos;
Execution Count:222
222
440 break;
executed: break;
Execution Count:106
106
441 } -
442 -
443 return pos;
executed: return pos;
Execution Count:438
438
444} -
445 -
446/*! -
447 Returns true if the object's position() is currently at a valid text boundary. -
448*/ -
449bool QTextBoundaryFinder::isAtBoundary() const -
450{ -
451 if (!d || pos < 0 || pos > length)
partially evaluated: !d
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:1222
evaluated: pos < 0
TRUEFALSE
yes
Evaluation Count:184
yes
Evaluation Count:1038
partially evaluated: pos > length
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:1038
0-1222
452 return false;
executed: return false;
Execution Count:184
184
453 -
454 switch(t) { -
455 case Grapheme: -
456 return d->attributes[pos].graphemeBoundary;
never executed: return d->attributes[pos].graphemeBoundary;
0
457 case Word: -
458 return d->attributes[pos].wordBreak;
executed: return d->attributes[pos].wordBreak;
Execution Count:684
684
459 case Sentence: -
460 return d->attributes[pos].sentenceBoundary;
executed: return d->attributes[pos].sentenceBoundary;
Execution Count:90
90
461 case Line: -
462 // ### TR#14 LB2 prohibits break at sot -
463 return d->attributes[pos].lineBreak || pos == 0;
executed: return d->attributes[pos].lineBreak || pos == 0;
Execution Count:264
264
464 } -
465 return false;
never executed: return false;
0
466} -
467 -
468/*! -
469 Returns the reasons for the boundary finder to have chosen the current position as a boundary. -
470*/ -
471QTextBoundaryFinder::BoundaryReasons QTextBoundaryFinder::boundaryReasons() const -
472{ -
473 BoundaryReasons reasons = NotAtBoundary;
executed (the execution status of this line is deduced): BoundaryReasons reasons = NotAtBoundary;
-
474 if (!d || pos < 0 || pos > length)
evaluated: !d
TRUEFALSE
yes
Evaluation Count:14
yes
Evaluation Count:2674
evaluated: pos < 0
TRUEFALSE
yes
Evaluation Count:185
yes
Evaluation Count:2489
partially evaluated: pos > length
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:2489
0-2674
475 return reasons;
executed: return reasons;
Execution Count:199
199
476 -
477 const QCharAttributes attr = d->attributes[pos];
executed (the execution status of this line is deduced): const QCharAttributes attr = d->attributes[pos];
-
478 switch (t) { -
479 case Grapheme: -
480 if (attr.graphemeBoundary) {
partially evaluated: attr.graphemeBoundary
TRUEFALSE
yes
Evaluation Count:10
no
Evaluation Count:0
0-10
481 reasons |= BreakOpportunity | StartOfItem | EndOfItem;
executed (the execution status of this line is deduced): reasons |= BreakOpportunity | StartOfItem | EndOfItem;
-
482 if (pos == 0)
evaluated: pos == 0
TRUEFALSE
yes
Evaluation Count:1
yes
Evaluation Count:9
1-9
483 reasons &= (~EndOfItem);
executed: reasons &= (~EndOfItem);
Execution Count:1
1
484 else if (pos == length)
partially evaluated: pos == length
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:9
0-9
485 reasons &= (~StartOfItem);
never executed: reasons &= (~StartOfItem);
0
486 } -
487 break;
executed: break;
Execution Count:10
10
488 case Word: -
489 if (attr.wordBreak) {
evaluated: attr.wordBreak
TRUEFALSE
yes
Evaluation Count:1053
yes
Evaluation Count:484
484-1053
490 reasons |= BreakOpportunity;
executed (the execution status of this line is deduced): reasons |= BreakOpportunity;
-
491 if (attr.wordStart)
evaluated: attr.wordStart
TRUEFALSE
yes
Evaluation Count:371
yes
Evaluation Count:682
371-682
492 reasons |= StartOfItem;
executed: reasons |= StartOfItem;
Execution Count:371
371
493 if (attr.wordEnd)
evaluated: attr.wordEnd
TRUEFALSE
yes
Evaluation Count:371
yes
Evaluation Count:682
371-682
494 reasons |= EndOfItem;
executed: reasons |= EndOfItem;
Execution Count:371
371
495 }
executed: }
Execution Count:1053
1053
496 break;
executed: break;
Execution Count:1537
1537
497 case Sentence: -
498 if (attr.sentenceBoundary) {
evaluated: attr.sentenceBoundary
TRUEFALSE
yes
Evaluation Count:139
yes
Evaluation Count:185
139-185
499 reasons |= BreakOpportunity | StartOfItem | EndOfItem;
executed (the execution status of this line is deduced): reasons |= BreakOpportunity | StartOfItem | EndOfItem;
-
500 if (pos == 0)
evaluated: pos == 0
TRUEFALSE
yes
Evaluation Count:45
yes
Evaluation Count:94
45-94
501 reasons &= (~EndOfItem);
executed: reasons &= (~EndOfItem);
Execution Count:45
45
502 else if (pos == length)
evaluated: pos == length
TRUEFALSE
yes
Evaluation Count:45
yes
Evaluation Count:49
45-49
503 reasons &= (~StartOfItem);
executed: reasons &= (~StartOfItem);
Execution Count:45
45
504 } -
505 break;
executed: break;
Execution Count:324
324
506 case Line: -
507 // ### TR#14 LB2 prohibits break at sot -
508 if (attr.lineBreak || pos == 0) {
evaluated: attr.lineBreak
TRUEFALSE
yes
Evaluation Count:318
yes
Evaluation Count:300
evaluated: pos == 0
TRUEFALSE
yes
Evaluation Count:78
yes
Evaluation Count:222
78-318
509 reasons |= BreakOpportunity;
executed (the execution status of this line is deduced): reasons |= BreakOpportunity;
-
510 if (attr.mandatoryBreak || pos == 0) {
evaluated: attr.mandatoryBreak
TRUEFALSE
yes
Evaluation Count:150
yes
Evaluation Count:246
evaluated: pos == 0
TRUEFALSE
yes
Evaluation Count:78
yes
Evaluation Count:168
78-246
511 reasons |= MandatoryBreak | StartOfItem | EndOfItem;
executed (the execution status of this line is deduced): reasons |= MandatoryBreak | StartOfItem | EndOfItem;
-
512 if (pos == 0)
evaluated: pos == 0
TRUEFALSE
yes
Evaluation Count:78
yes
Evaluation Count:150
78-150
513 reasons &= (~EndOfItem);
executed: reasons &= (~EndOfItem);
Execution Count:78
78
514 else if (pos == length)
evaluated: pos == length
TRUEFALSE
yes
Evaluation Count:78
yes
Evaluation Count:72
72-78
515 reasons &= (~StartOfItem);
executed: reasons &= (~StartOfItem);
Execution Count:78
78
516 } else if (pos > 0 && chars[pos - 1].unicode() == QChar::SoftHyphen) {
partially evaluated: pos > 0
TRUEFALSE
yes
Evaluation Count:168
no
Evaluation Count:0
evaluated: chars[pos - 1].unicode() == QChar::SoftHyphen
TRUEFALSE
yes
Evaluation Count:24
yes
Evaluation Count:144
0-168
517 reasons |= SoftHyphen;
executed (the execution status of this line is deduced): reasons |= SoftHyphen;
-
518 }
executed: }
Execution Count:24
24
519 } -
520 break;
executed: break;
Execution Count:618
618
521 default: -
522 break;
never executed: break;
0
523 } -
524 -
525 return reasons;
executed: return reasons;
Execution Count:2489
2489
526} -
527 -
528QT_END_NAMESPACE -
529 -
Source codeSwitch to Preprocessed file

Generated by Squish Coco Non-Commercial