tools/qtextboundaryfinder.cpp

Switch to Source codePreprocessed file
LineSource CodeCoverage
1 -
2 -
3 -
4 -
5class QTextBoundaryFinderPrivate -
6{ -
7public: -
8 QCharAttributes attributes[1]; -
9}; -
10 -
11static void init(QTextBoundaryFinder::BoundaryType type, const QChar *chars, int length, QCharAttributes *attributes) -
12{ -
13 QVarLengthArray<QUnicodeTools::ScriptItem> scriptItems; -
14 -
15 const ushort *string = reinterpret_cast<const ushort *>(chars); -
16 const ushort *unicode = string; -
17 -
18 const ushort *uc = unicode; -
19 const ushort *e = uc + length; -
20 int script = QUnicodeTables::Common; -
21 int lastScript = QUnicodeTables::Common; -
22 const ushort *start = uc; -
23 while (uc < e) {
evaluated: uc < e
TRUEFALSE
yes
Evaluation Count:3286
yes
Evaluation Count:113
113-3286
24 int s = QUnicodeTables::script(*uc); -
25 if (s != QUnicodeTables::Inherited)
evaluated: s != QUnicodeTables::Inherited
TRUEFALSE
yes
Evaluation Count:3268
yes
Evaluation Count:18
18-3268
26 script = s;
executed: script = s;
Execution Count:3268
3268
27 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
28 script = QUnicodeTables::Common;
executed: script = QUnicodeTables::Common;
Execution Count:4
4
29 if (script != lastScript) {
partially evaluated: script != lastScript
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:3286
0-3286
30 if (uc != start) {
never evaluated: uc != start
0
31 QUnicodeTools::ScriptItem item; -
32 item.position = start - string; -
33 item.script = lastScript; -
34 scriptItems.append(item); -
35 start = uc; -
36 }
never executed: }
0
37 lastScript = script; -
38 }
never executed: }
0
39 ++uc; -
40 }
executed: }
Execution Count:3286
3286
41 if (uc != start) {
partially evaluated: uc != start
TRUEFALSE
yes
Evaluation Count:113
no
Evaluation Count:0
0-113
42 QUnicodeTools::ScriptItem item; -
43 item.position = start - string; -
44 item.script = lastScript; -
45 scriptItems.append(item); -
46 }
executed: }
Execution Count:113
113
47 -
48 QUnicodeTools::CharAttributeOptions options = 0; -
49 switch (type) { -
50 case QTextBoundaryFinder::Grapheme: options |= QUnicodeTools::GraphemeBreaks; break;
executed: break;
Execution Count:6
6
51 case QTextBoundaryFinder::Word: options |= QUnicodeTools::WordBreaks; break;
executed: break;
Execution Count:62
62
52 case QTextBoundaryFinder::Sentence: options |= QUnicodeTools::SentenceBreaks; break;
executed: break;
Execution Count:18
18
53 case QTextBoundaryFinder::Line: options |= QUnicodeTools::LineBreaks; break;
executed: break;
Execution Count:27
27
54 default: break;
never executed: break;
0
55 } -
56 QUnicodeTools::initCharAttributes(string, length, scriptItems.data(), scriptItems.count(), attributes, options); -
57}
executed: }
Execution Count:113
113
58QTextBoundaryFinder::QTextBoundaryFinder() -
59 : t(Grapheme) -
60 , chars(0) -
61 , length(0) -
62 , freePrivate(true) -
63 , d(0) -
64{ -
65}
executed: }
Execution Count:1
1
66 -
67 -
68 -
69 -
70QTextBoundaryFinder::QTextBoundaryFinder(const QTextBoundaryFinder &other) -
71 : t(other.t) -
72 , s(other.s) -
73 , chars(other.chars) -
74 , length(other.length) -
75 , pos(other.pos) -
76 , freePrivate(true) -
77 , d(0) -
78{ -
79 if (other.d) {
partially evaluated: other.d
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:15
0-15
80 qt_noop(); -
81 d = (QTextBoundaryFinderPrivate *) malloc((length + 1) * sizeof(QCharAttributes)); -
82 do { if (!(d)) qBadAlloc(); } while (0);
never evaluated: 0
never executed: qBadAlloc();
never executed: }
never evaluated: !(d)
0
83 memcpy(d, other.d, (length + 1) * sizeof(QCharAttributes)); -
84 }
never executed: }
0
85}
executed: }
Execution Count:15
15
86 -
87 -
88 -
89 -
90QTextBoundaryFinder &QTextBoundaryFinder::operator=(const QTextBoundaryFinder &other) -
91{ -
92 if (&other == this)
partially evaluated: &other == this
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:4
0-4
93 return *this;
never executed: return *this;
0
94 -
95 if (other.d) {
evaluated: other.d
TRUEFALSE
yes
Evaluation Count:2
yes
Evaluation Count:2
2
96 qt_noop(); -
97 uint newCapacity = (other.length + 1) * sizeof(QCharAttributes); -
98 QTextBoundaryFinderPrivate *newD = (QTextBoundaryFinderPrivate *) realloc(freePrivate ? d : 0, newCapacity); -
99 do { if (!(newD)) qBadAlloc(); } while (0);
partially evaluated: 0
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:2
never executed: qBadAlloc();
executed: }
Execution Count:2
partially evaluated: !(newD)
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:2
0-2
100 freePrivate = true; -
101 d = newD; -
102 }
executed: }
Execution Count:2
2
103 -
104 t = other.t; -
105 s = other.s; -
106 chars = other.chars; -
107 length = other.length; -
108 pos = other.pos; -
109 -
110 if (other.d) {
evaluated: other.d
TRUEFALSE
yes
Evaluation Count:2
yes
Evaluation Count:2
2
111 memcpy(d, other.d, (length + 1) * sizeof(QCharAttributes)); -
112 } else {
executed: }
Execution Count:2
2
113 if (freePrivate)
partially evaluated: freePrivate
TRUEFALSE
yes
Evaluation Count:2
no
Evaluation Count:0
0-2
114 free(d);
executed: free(d);
Execution Count:2
2
115 d = 0; -
116 }
executed: }
Execution Count:2
2
117 -
118 return *this;
executed: return *this;
Execution Count:4
4
119} -
120 -
121 -
122 -
123 -
124QTextBoundaryFinder::~QTextBoundaryFinder() -
125{ -
126 if (freePrivate)
partially evaluated: freePrivate
TRUEFALSE
yes
Evaluation Count:134
no
Evaluation Count:0
0-134
127 free(d);
executed: free(d);
Execution Count:134
134
128}
executed: }
Execution Count:134
134
129 -
130 -
131 -
132 -
133QTextBoundaryFinder::QTextBoundaryFinder(BoundaryType type, const QString &string) -
134 : t(type) -
135 , s(string) -
136 , chars(string.unicode()) -
137 , length(string.length()) -
138 , pos(0) -
139 , freePrivate(true) -
140 , d(0) -
141{ -
142 if (length > 0) {
evaluated: length > 0
TRUEFALSE
yes
Evaluation Count:112
yes
Evaluation Count:1
1-112
143 d = (QTextBoundaryFinderPrivate *) malloc((length + 1) * sizeof(QCharAttributes)); -
144 do { if (!(d)) qBadAlloc(); } while (0);
partially evaluated: !(d)
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:112
partially evaluated: 0
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:112
never executed: qBadAlloc();
executed: }
Execution Count:112
0-112
145 init(t, chars, length, d->attributes); -
146 }
executed: }
Execution Count:112
112
147}
executed: }
Execution Count:113
113
148QTextBoundaryFinder::QTextBoundaryFinder(BoundaryType type, const QChar *chars, int length, unsigned char *buffer, int bufferSize) -
149 : t(type) -
150 , chars(chars) -
151 , length(length) -
152 , pos(0) -
153 , freePrivate(true) -
154 , d(0) -
155{ -
156 if (!chars) {
evaluated: !chars
TRUEFALSE
yes
Evaluation Count:2
yes
Evaluation Count:3
2-3
157 length = 0; -
158 } else if (length > 0) {
evaluated: length > 0
TRUEFALSE
yes
Evaluation Count:1
yes
Evaluation Count:2
executed: }
Execution Count:2
1-2
159 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
160 d = (QTextBoundaryFinderPrivate *)buffer; -
161 freePrivate = false; -
162 } else {
never executed: }
0
163 d = (QTextBoundaryFinderPrivate *) malloc((length + 1) * sizeof(QCharAttributes)); -
164 do { if (!(d)) qBadAlloc(); } while (0);
partially evaluated: !(d)
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:1
partially evaluated: 0
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:1
never executed: qBadAlloc();
executed: }
Execution Count:1
0-1
165 }
executed: }
Execution Count:1
1
166 init(t, chars, length, d->attributes); -
167 }
executed: }
Execution Count:1
1
168} -
169 -
170 -
171 -
172 -
173 -
174 -
175void QTextBoundaryFinder::toStart() -
176{ -
177 pos = 0; -
178}
never executed: }
0
179 -
180 -
181 -
182 -
183 -
184 -
185void QTextBoundaryFinder::toEnd() -
186{ -
187 pos = length; -
188}
executed: }
Execution Count:92
92
189int QTextBoundaryFinder::position() const -
190{ -
191 return pos;
executed: return pos;
Execution Count:855
855
192} -
193void QTextBoundaryFinder::setPosition(int position) -
194{ -
195 pos = qBound(0, position, length); -
196}
executed: }
Execution Count:1421
1421
197QString QTextBoundaryFinder::string() const -
198{ -
199 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
200 return s;
executed: return s;
Execution Count:2
2
201 return QString(chars, length);
executed: return QString(chars, length);
Execution Count:2
2
202} -
203 -
204 -
205 -
206 -
207 -
208 -
209 -
210int QTextBoundaryFinder::toNextBoundary() -
211{ -
212 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
213 pos = -1; -
214 return pos;
executed: return pos;
Execution Count:100
100
215 } -
216 -
217 ++pos; -
218 switch(t) { -
219 case Grapheme: -
220 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
221 ++pos;
never executed: ++pos;
0
222 break;
executed: break;
Execution Count:6
6
223 case Word: -
224 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
225 ++pos;
executed: ++pos;
Execution Count:516
516
226 break;
executed: break;
Execution Count:306
306
227 case Sentence: -
228 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
229 ++pos;
executed: ++pos;
Execution Count:271
271
230 break;
executed: break;
Execution Count:33
33
231 case Line: -
232 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
233 ++pos;
executed: ++pos;
Execution Count:222
222
234 break;
executed: break;
Execution Count:106
106
235 } -
236 -
237 return pos;
executed: return pos;
Execution Count:451
451
238} -
239 -
240 -
241 -
242 -
243 -
244 -
245int QTextBoundaryFinder::toPreviousBoundary() -
246{ -
247 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
248 pos = -1; -
249 return pos;
executed: return pos;
Execution Count:92
92
250 } -
251 -
252 --pos; -
253 switch(t) { -
254 case Grapheme: -
255 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
256 --pos;
never executed: --pos;
0
257 break;
executed: break;
Execution Count:1
1
258 case Word: -
259 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
260 --pos;
executed: --pos;
Execution Count:490
490
261 break;
executed: break;
Execution Count:298
298
262 case Sentence: -
263 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
264 --pos;
executed: --pos;
Execution Count:225
225
265 break;
executed: break;
Execution Count:33
33
266 case Line: -
267 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
268 --pos;
executed: --pos;
Execution Count:222
222
269 break;
executed: break;
Execution Count:106
106
270 } -
271 -
272 return pos;
executed: return pos;
Execution Count:438
438
273} -
274 -
275 -
276 -
277 -
278bool QTextBoundaryFinder::isAtBoundary() const -
279{ -
280 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
281 return false;
executed: return false;
Execution Count:184
184
282 -
283 switch(t) { -
284 case Grapheme: -
285 return d->attributes[pos].graphemeBoundary;
never executed: return d->attributes[pos].graphemeBoundary;
0
286 case Word: -
287 return d->attributes[pos].wordBreak;
executed: return d->attributes[pos].wordBreak;
Execution Count:684
684
288 case Sentence: -
289 return d->attributes[pos].sentenceBoundary;
executed: return d->attributes[pos].sentenceBoundary;
Execution Count:90
90
290 case Line: -
291 -
292 return d->attributes[pos].lineBreak || pos == 0;
executed: return d->attributes[pos].lineBreak || pos == 0;
Execution Count:264
264
293 } -
294 return false;
never executed: return false;
0
295} -
296 -
297 -
298 -
299 -
300QTextBoundaryFinder::BoundaryReasons QTextBoundaryFinder::boundaryReasons() const -
301{ -
302 BoundaryReasons reasons = NotAtBoundary; -
303 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
304 return reasons;
executed: return reasons;
Execution Count:199
199
305 -
306 const QCharAttributes attr = d->attributes[pos]; -
307 switch (t) { -
308 case Grapheme: -
309 if (attr.graphemeBoundary) {
partially evaluated: attr.graphemeBoundary
TRUEFALSE
yes
Evaluation Count:10
no
Evaluation Count:0
0-10
310 reasons |= BreakOpportunity | StartOfItem | EndOfItem; -
311 if (pos == 0)
evaluated: pos == 0
TRUEFALSE
yes
Evaluation Count:1
yes
Evaluation Count:9
1-9
312 reasons &= (~EndOfItem);
executed: reasons &= (~EndOfItem);
Execution Count:1
1
313 else if (pos == length)
partially evaluated: pos == length
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:9
0-9
314 reasons &= (~StartOfItem);
never executed: reasons &= (~StartOfItem);
0
315 } -
316 break;
executed: break;
Execution Count:10
10
317 case Word: -
318 if (attr.wordBreak) {
evaluated: attr.wordBreak
TRUEFALSE
yes
Evaluation Count:1053
yes
Evaluation Count:484
484-1053
319 reasons |= BreakOpportunity; -
320 if (attr.wordStart)
evaluated: attr.wordStart
TRUEFALSE
yes
Evaluation Count:371
yes
Evaluation Count:682
371-682
321 reasons |= StartOfItem;
executed: reasons |= StartOfItem;
Execution Count:371
371
322 if (attr.wordEnd)
evaluated: attr.wordEnd
TRUEFALSE
yes
Evaluation Count:371
yes
Evaluation Count:682
371-682
323 reasons |= EndOfItem;
executed: reasons |= EndOfItem;
Execution Count:371
371
324 }
executed: }
Execution Count:1053
1053
325 break;
executed: break;
Execution Count:1537
1537
326 case Sentence: -
327 if (attr.sentenceBoundary) {
evaluated: attr.sentenceBoundary
TRUEFALSE
yes
Evaluation Count:139
yes
Evaluation Count:185
139-185
328 reasons |= BreakOpportunity | StartOfItem | EndOfItem; -
329 if (pos == 0)
evaluated: pos == 0
TRUEFALSE
yes
Evaluation Count:45
yes
Evaluation Count:94
45-94
330 reasons &= (~EndOfItem);
executed: reasons &= (~EndOfItem);
Execution Count:45
45
331 else if (pos == length)
evaluated: pos == length
TRUEFALSE
yes
Evaluation Count:45
yes
Evaluation Count:49
45-49
332 reasons &= (~StartOfItem);
executed: reasons &= (~StartOfItem);
Execution Count:45
45
333 } -
334 break;
executed: break;
Execution Count:324
324
335 case Line: -
336 -
337 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
338 reasons |= BreakOpportunity; -
339 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
340 reasons |= MandatoryBreak | StartOfItem | EndOfItem; -
341 if (pos == 0)
evaluated: pos == 0
TRUEFALSE
yes
Evaluation Count:78
yes
Evaluation Count:150
78-150
342 reasons &= (~EndOfItem);
executed: reasons &= (~EndOfItem);
Execution Count:78
78
343 else if (pos == length)
evaluated: pos == length
TRUEFALSE
yes
Evaluation Count:78
yes
Evaluation Count:72
72-78
344 reasons &= (~StartOfItem);
executed: reasons &= (~StartOfItem);
Execution Count:78
78
345 } 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
346 reasons |= SoftHyphen; -
347 }
executed: }
Execution Count:24
24
348 } -
349 break;
executed: break;
Execution Count:618
618
350 default: -
351 break;
never executed: break;
0
352 } -
353 -
354 return reasons;
executed: return reasons;
Execution Count:2489
2489
355} -
356 -
357 -
358 -
Switch to Source codePreprocessed file

Generated by Squish Coco Non-Commercial