tools/qstringmatcher.cpp

Switch to Source codePreprocessed file
LineSource CodeCoverage
1 -
2 -
3static void bm_init_skiptable(const ushort *uc, int len, uchar *skiptable, Qt::CaseSensitivity cs) -
4{ -
5 int l = qMin(len, 255); -
6 memset(skiptable, l, 256*sizeof(uchar)); -
7 uc += len - l; -
8 if (cs == Qt::CaseSensitive) {
evaluated: cs == Qt::CaseSensitive
TRUEFALSE
yes
Evaluation Count:362973
yes
Evaluation Count:189
189-362973
9 while (l--) {
evaluated: l--
TRUEFALSE
yes
Evaluation Count:4400897
yes
Evaluation Count:362040
362040-4400897
10 skiptable[*uc & 0xff] = l; -
11 uc++; -
12 }
executed: }
Execution Count:4400259
4400259
13 } else {
executed: }
Execution Count:361619
361619
14 const ushort *start = uc; -
15 while (l--) {
evaluated: l--
TRUEFALSE
yes
Evaluation Count:6096
yes
Evaluation Count:189
189-6096
16 skiptable[foldCase(uc, start) & 0xff] = l; -
17 uc++; -
18 }
executed: }
Execution Count:6096
6096
19 }
executed: }
Execution Count:189
189
20} -
21 -
22static inline int bm_find(const ushort *uc, uint l, int index, const ushort *puc, uint pl, -
23 const uchar *skiptable, Qt::CaseSensitivity cs) -
24{ -
25 if (pl == 0)
evaluated: pl == 0
TRUEFALSE
yes
Evaluation Count:34
yes
Evaluation Count:365490
34-365490
26 return index > (int)l ? -1 : index;
executed: return index > (int)l ? -1 : index;
Execution Count:34
34
27 const uint pl_minus_one = pl - 1; -
28 -
29 register const ushort *current = uc + index + pl_minus_one; -
30 const ushort *end = uc + l; -
31 if (cs == Qt::CaseSensitive) {
evaluated: cs == Qt::CaseSensitive
TRUEFALSE
yes
Evaluation Count:364511
yes
Evaluation Count:1212
1212-364511
32 while (current < end) {
evaluated: current < end
TRUEFALSE
yes
Evaluation Count:30302292
yes
Evaluation Count:56226
56226-30302292
33 uint skip = skiptable[*current & 0xff]; -
34 if (!skip) {
evaluated: !skip
TRUEFALSE
yes
Evaluation Count:214839
yes
Evaluation Count:30473768
214839-30473768
35 -
36 while (skip < pl) {
evaluated: skip < pl
TRUEFALSE
yes
Evaluation Count:728772
yes
Evaluation Count:196931
196931-728772
37 if (*(current - skip) != puc[pl_minus_one-skip])
evaluated: *(current - skip) != puc[pl_minus_one-skip]
TRUEFALSE
yes
Evaluation Count:17109
yes
Evaluation Count:709471
17109-709471
38 break;
executed: break;
Execution Count:17109
17109
39 skip++; -
40 }
executed: }
Execution Count:712546
712546
41 if (skip > pl_minus_one)
evaluated: skip > pl_minus_one
TRUEFALSE
yes
Evaluation Count:196975
yes
Evaluation Count:17109
17109-196975
42 return (current - uc) - pl_minus_one;
executed: return (current - uc) - pl_minus_one;
Execution Count:197102
197102
43 -
44 -
45 -
46 if (skiptable[*(current - skip) & 0xff] == pl)
evaluated: skiptable[*(current - skip) & 0xff] == pl
TRUEFALSE
yes
Evaluation Count:1972
yes
Evaluation Count:15137
1972-15137
47 skip = pl - skip;
executed: skip = pl - skip;
Execution Count:1972
1972
48 else -
49 skip = 1;
executed: skip = 1;
Execution Count:15137
15137
50 } -
51 if (current > end - skip)
evaluated: current > end - skip
TRUEFALSE
yes
Evaluation Count:106318
yes
Evaluation Count:30473377
106318-30473377
52 break;
executed: break;
Execution Count:106318
106318
53 current += skip; -
54 }
executed: }
Execution Count:30255380
30255380
55 } else {
executed: }
Execution Count:162544
162544
56 while (current < end) {
evaluated: current < end
TRUEFALSE
yes
Evaluation Count:1442
yes
Evaluation Count:315
315-1442
57 uint skip = skiptable[foldCase(current, uc) & 0xff]; -
58 if (!skip) {
evaluated: !skip
TRUEFALSE
yes
Evaluation Count:239
yes
Evaluation Count:1203
239-1203
59 -
60 while (skip < pl) {
evaluated: skip < pl
TRUEFALSE
yes
Evaluation Count:9568
yes
Evaluation Count:201
201-9568
61 if (foldCase(current - skip, uc) != foldCase(puc + pl_minus_one - skip, puc))
evaluated: foldCase(current - skip, uc) != foldCase(puc + pl_minus_one - skip, puc)
TRUEFALSE
yes
Evaluation Count:38
yes
Evaluation Count:9530
38-9530
62 break;
executed: break;
Execution Count:38
38
63 skip++; -
64 }
executed: }
Execution Count:9530
9530
65 if (skip > pl_minus_one)
evaluated: skip > pl_minus_one
TRUEFALSE
yes
Evaluation Count:201
yes
Evaluation Count:38
38-201
66 return (current - uc) - pl_minus_one;
executed: return (current - uc) - pl_minus_one;
Execution Count:201
201
67 -
68 -
69 if (skiptable[foldCase(current - skip, uc) & 0xff] == pl)
evaluated: skiptable[foldCase(current - skip, uc) & 0xff] == pl
TRUEFALSE
yes
Evaluation Count:22
yes
Evaluation Count:16
16-22
70 skip = pl - skip;
executed: skip = pl - skip;
Execution Count:22
22
71 else -
72 skip = 1;
executed: skip = 1;
Execution Count:16
16
73 } -
74 if (current > end - skip)
evaluated: current > end - skip
TRUEFALSE
yes
Evaluation Count:696
yes
Evaluation Count:545
545-696
75 break;
executed: break;
Execution Count:696
696
76 current += skip; -
77 }
executed: }
Execution Count:545
545
78 }
executed: }
Execution Count:1011
1011
79 return -1;
executed: return -1;
Execution Count:163555
163555
80} -
81QStringMatcher::QStringMatcher() -
82 : d_ptr(0), q_cs(Qt::CaseSensitive) -
83{ -
84 memset(q_data, 0, sizeof(q_data)); -
85}
executed: }
Execution Count:14
14
86 -
87 -
88 -
89 -
90 -
91 -
92 -
93QStringMatcher::QStringMatcher(const QString &pattern, Qt::CaseSensitivity cs) -
94 : d_ptr(0), q_pattern(pattern), q_cs(cs) -
95{ -
96 p.uc = pattern.unicode(); -
97 p.len = pattern.size(); -
98 bm_init_skiptable((const ushort *)p.uc, p.len, p.q_skiptable, cs); -
99}
executed: }
Execution Count:198
198
100QStringMatcher::QStringMatcher(const QChar *uc, int len, Qt::CaseSensitivity cs) -
101 : d_ptr(0), q_cs(cs) -
102{ -
103 p.uc = uc; -
104 p.len = len; -
105 bm_init_skiptable((const ushort *)p.uc, len, p.q_skiptable, cs); -
106}
executed: }
Execution Count:361644
361644
107 -
108 -
109 -
110 -
111QStringMatcher::QStringMatcher(const QStringMatcher &other) -
112 : d_ptr(0) -
113{ -
114 operator=(other); -
115}
executed: }
Execution Count:1
1
116 -
117 -
118 -
119 -
120QStringMatcher::~QStringMatcher() -
121{ -
122} -
123 -
124 -
125 -
126 -
127QStringMatcher &QStringMatcher::operator=(const QStringMatcher &other) -
128{ -
129 if (this != &other) {
partially evaluated: this != &other
TRUEFALSE
yes
Evaluation Count:1
no
Evaluation Count:0
0-1
130 q_pattern = other.q_pattern; -
131 q_cs = other.q_cs; -
132 memcpy(q_data, other.q_data, sizeof(q_data)); -
133 }
executed: }
Execution Count:1
1
134 return *this;
executed: return *this;
Execution Count:1
1
135} -
136 -
137 -
138 -
139 -
140 -
141 -
142 -
143void QStringMatcher::setPattern(const QString &pattern) -
144{ -
145 q_pattern = pattern; -
146 p.uc = pattern.unicode(); -
147 p.len = pattern.size(); -
148 bm_init_skiptable((const ushort *)pattern.unicode(), pattern.size(), p.q_skiptable, q_cs); -
149}
executed: }
Execution Count:12
12
150QString QStringMatcher::pattern() const -
151{ -
152 if (!q_pattern.isEmpty())
evaluated: !q_pattern.isEmpty()
TRUEFALSE
yes
Evaluation Count:1
yes
Evaluation Count:1
1
153 return q_pattern;
executed: return q_pattern;
Execution Count:1
1
154 return QString(p.uc, p.len);
executed: return QString(p.uc, p.len);
Execution Count:1
1
155} -
156 -
157 -
158 -
159 -
160 -
161 -
162 -
163void QStringMatcher::setCaseSensitivity(Qt::CaseSensitivity cs) -
164{ -
165 if (cs == q_cs)
evaluated: cs == q_cs
TRUEFALSE
yes
Evaluation Count:3
yes
Evaluation Count:2
2-3
166 return;
executed: return;
Execution Count:3
3
167 bm_init_skiptable((const ushort *)q_pattern.unicode(), q_pattern.size(), p.q_skiptable, cs); -
168 q_cs = cs; -
169}
executed: }
Execution Count:2
2
170int QStringMatcher::indexIn(const QString &str, int from) const -
171{ -
172 if (from < 0)
evaluated: from < 0
TRUEFALSE
yes
Evaluation Count:1
yes
Evaluation Count:165480
1-165480
173 from = 0;
executed: from = 0;
Execution Count:1
1
174 return bm_find((const ushort *)str.unicode(), str.size(), from, 165481
175 (const ushort *)p.uc, p.len, 165481
176 p.q_skiptable, q_cs);
executed: return bm_find((const ushort *)str.unicode(), str.size(), from, (const ushort *)p.uc, p.len, p.q_skiptable, q_cs);
Execution Count:165481
165481
177} -
178int QStringMatcher::indexIn(const QChar *str, int length, int from) const -
179{ -
180 if (from < 0)
partially evaluated: from < 0
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:199802
0-199802
181 from = 0;
never executed: from = 0;
0
182 return bm_find((const ushort *)str, length, from, 199915
183 (const ushort *)p.uc, p.len, 199915
184 p.q_skiptable, q_cs);
executed: return bm_find((const ushort *)str, length, from, (const ushort *)p.uc, p.len, p.q_skiptable, q_cs);
Execution Count:199915
199915
185} -
186int qFindStringBoyerMoore( -
187 const QChar *haystack, int haystackLen, int haystackOffset, -
188 const QChar *needle, int needleLen, Qt::CaseSensitivity cs) -
189{ -
190 uchar skiptable[256]; -
191 bm_init_skiptable((const ushort *)needle, needleLen, skiptable, cs); -
192 if (haystackOffset < 0)
partially evaluated: haystackOffset < 0
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:208
0-208
193 haystackOffset = 0;
never executed: haystackOffset = 0;
0
194 return bm_find((const ushort *)haystack, haystackLen, haystackOffset, 208
195 (const ushort *)needle, needleLen, skiptable, cs);
executed: return bm_find((const ushort *)haystack, haystackLen, haystackOffset, (const ushort *)needle, needleLen, skiptable, cs);
Execution Count:208
208
196} -
197 -
198 -
199 -
Switch to Source codePreprocessed file

Generated by Squish Coco Non-Commercial