Line | Source Code | Coverage |
---|
1 | | - |
2 | | - |
3 | | - |
4 | | - |
5 | | - |
6 | | - |
7 | | - |
8 | | - |
9 | | - |
10 | | - |
11 | | - |
12 | | - |
13 | | - |
14 | | - |
15 | | - |
16 | | - |
17 | | - |
18 | | - |
19 | static QMutex *textCodecsMutex() { static QGlobalStatic<QMutex > thisGlobalStatic = { { (0) }, false }; if (!thisGlobalStatic.pointer.load() && !thisGlobalStatic.destroyed) { QMutex *x = new QMutex (QMutex::Recursive); if (!thisGlobalStatic.pointer.testAndSetOrdered(0, x)) delete x; else static QGlobalStaticDeleter<QMutex > cleanup(thisGlobalStatic); } return thisGlobalStatic.pointer.load(); }; never executed: delete x; executed: return thisGlobalStatic.pointer.load(); Execution Count:24817 partially evaluated: !thisGlobalStatic.pointer.testAndSetOrdered(0, x) no Evaluation Count:0 | yes Evaluation Count:116 |
evaluated: !thisGlobalStatic.pointer.load() yes Evaluation Count:117 | yes Evaluation Count:24700 |
evaluated: !thisGlobalStatic.destroyed yes Evaluation Count:116 | yes Evaluation Count:1 |
| 0-24817 |
20 | QMutex *qTextCodecsMutex() { return textCodecsMutex(); } never executed: return textCodecsMutex(); | 0 |
21 | static void setup() {} | - |
22 | QTextCodec::ConverterState::~ConverterState() | - |
23 | { | - |
24 | if (flags & FreeFunction) evaluated: flags & FreeFunction yes Evaluation Count:85171 | yes Evaluation Count:1290211 |
| 85171-1290211 |
25 | (QTextCodecUnalignedPointer::decode(state_data))(this); executed: (QTextCodecUnalignedPointer::decode(state_data))(this); Execution Count:85171 | 85171 |
26 | else if (d) partially evaluated: d no Evaluation Count:0 | yes Evaluation Count:1290211 |
| 0-1290211 |
27 | free(d); | 0 |
28 | } | - |
29 | QTextCodec::QTextCodec() | - |
30 | { | - |
31 | QMutexLocker locker(textCodecsMutex()); | - |
32 | | - |
33 | QCoreGlobalData::instance()->allCodecs.prepend(this); | - |
34 | } executed: } Execution Count:256 | 256 |
35 | QTextCodec::~QTextCodec() | - |
36 | { | - |
37 | } | - |
38 | QTextCodec *QTextCodec::codecForName(const QByteArray &name) | - |
39 | { | - |
40 | if (name.isEmpty()) evaluated: name.isEmpty() yes Evaluation Count:2 | yes Evaluation Count:11154 |
| 2-11154 |
41 | return 0; executed: return 0; Execution Count:2 | 2 |
42 | | - |
43 | QMutexLocker locker(textCodecsMutex()); | - |
44 | | - |
45 | QCoreGlobalData *globalData = QCoreGlobalData::instance(); | - |
46 | if (!globalData) evaluated: !globalData yes Evaluation Count:1 | yes Evaluation Count:11153 |
| 1-11153 |
47 | return 0; executed: return 0; Execution Count:1 | 1 |
48 | setup(); | - |
49 | return QIcuCodec::codecForNameUnlocked(name); executed: return QIcuCodec::codecForNameUnlocked(name); Execution Count:11153 | 11153 |
50 | | - |
51 | } | - |
52 | | - |
53 | | - |
54 | | - |
55 | | - |
56 | | - |
57 | | - |
58 | | - |
59 | QTextCodec* QTextCodec::codecForMib(int mib) | - |
60 | { | - |
61 | QMutexLocker locker(textCodecsMutex()); | - |
62 | | - |
63 | QCoreGlobalData *globalData = QCoreGlobalData::instance(); | - |
64 | if (!globalData) partially evaluated: !globalData no Evaluation Count:0 | yes Evaluation Count:13153 |
| 0-13153 |
65 | return 0; never executed: return 0; | 0 |
66 | if (globalData->allCodecs.isEmpty()) evaluated: globalData->allCodecs.isEmpty() yes Evaluation Count:2 | yes Evaluation Count:13151 |
| 2-13151 |
67 | setup(); executed: setup(); Execution Count:2 | 2 |
68 | | - |
69 | QByteArray key = "MIB: " + QByteArray::number(mib); | - |
70 | | - |
71 | QTextCodecCache *cache = &globalData->codecCache; | - |
72 | QTextCodec *codec; | - |
73 | if (cache) { partially evaluated: cache yes Evaluation Count:13153 | no Evaluation Count:0 |
| 0-13153 |
74 | codec = cache->value(key); | - |
75 | if (codec) evaluated: codec yes Evaluation Count:12998 | yes Evaluation Count:155 |
| 155-12998 |
76 | return codec; executed: return codec; Execution Count:12998 | 12998 |
77 | } executed: } Execution Count:155 | 155 |
78 | | - |
79 | QList<QTextCodec*>::ConstIterator i; | - |
80 | for (int i = 0; i < globalData->allCodecs.size(); ++i) { evaluated: i < globalData->allCodecs.size() yes Evaluation Count:6543 | yes Evaluation Count:27 |
| 27-6543 |
81 | QTextCodec *cursor = globalData->allCodecs.at(i); | - |
82 | if (cursor->mibEnum() == mib) { evaluated: cursor->mibEnum() == mib yes Evaluation Count:128 | yes Evaluation Count:6415 |
| 128-6415 |
83 | if (cache) partially evaluated: cache yes Evaluation Count:128 | no Evaluation Count:0 |
| 0-128 |
84 | cache->insert(key, cursor); executed: cache->insert(key, cursor); Execution Count:128 | 128 |
85 | return cursor; executed: return cursor; Execution Count:128 | 128 |
86 | } | - |
87 | } executed: } Execution Count:6415 | 6415 |
88 | | - |
89 | | - |
90 | return QIcuCodec::codecForMibUnlocked(mib); executed: return QIcuCodec::codecForMibUnlocked(mib); Execution Count:27 | 27 |
91 | | - |
92 | | - |
93 | | - |
94 | } | - |
95 | QList<QByteArray> QTextCodec::availableCodecs() | - |
96 | { | - |
97 | | - |
98 | return QIcuCodec::availableCodecs(); executed: return QIcuCodec::availableCodecs(); Execution Count:2 | 2 |
99 | } | - |
100 | QList<int> QTextCodec::availableMibs() | - |
101 | { | - |
102 | | - |
103 | return QIcuCodec::availableMibs(); executed: return QIcuCodec::availableMibs(); Execution Count:2 | 2 |
104 | } | - |
105 | void QTextCodec::setCodecForLocale(QTextCodec *c) | - |
106 | { | - |
107 | QCoreGlobalData::instance()->codecForLocale.storeRelease(c); | - |
108 | } executed: } Execution Count:2 | 2 |
109 | QTextCodec* QTextCodec::codecForLocale() | - |
110 | { | - |
111 | QCoreGlobalData *globalData = QCoreGlobalData::instance(); | - |
112 | if (!globalData) partially evaluated: !globalData no Evaluation Count:0 | yes Evaluation Count:462578 |
| 0-462578 |
113 | return 0; never executed: return 0; | 0 |
114 | | - |
115 | QTextCodec *codec = globalData->codecForLocale.loadAcquire(); | - |
116 | if (!codec) { evaluated: !codec yes Evaluation Count:127 | yes Evaluation Count:462456 |
| 127-462456 |
117 | | - |
118 | textCodecsMutex()->lock(); | - |
119 | codec = QIcuCodec::defaultCodecUnlocked(); | - |
120 | textCodecsMutex()->unlock(); | - |
121 | | - |
122 | | - |
123 | | - |
124 | | - |
125 | } executed: } Execution Count:127 | 127 |
126 | | - |
127 | return codec; executed: return codec; Execution Count:462581 | 462581 |
128 | } | - |
129 | QList<QByteArray> QTextCodec::aliases() const | - |
130 | { | - |
131 | return QList<QByteArray>(); executed: return QList<QByteArray>(); Execution Count:296 | 296 |
132 | } | - |
133 | QTextDecoder* QTextCodec::makeDecoder(QTextCodec::ConversionFlags flags) const | - |
134 | { | - |
135 | return new QTextDecoder(this, flags); executed: return new QTextDecoder(this, flags); Execution Count:5380 | 5380 |
136 | } | - |
137 | QTextEncoder* QTextCodec::makeEncoder(QTextCodec::ConversionFlags flags) const | - |
138 | { | - |
139 | return new QTextEncoder(this, flags); executed: return new QTextEncoder(this, flags); Execution Count:992 | 992 |
140 | } | - |
141 | QByteArray QTextCodec::fromUnicode(const QString& str) const | - |
142 | { | - |
143 | return convertFromUnicode(str.constData(), str.length(), 0); executed: return convertFromUnicode(str.constData(), str.length(), 0); Execution Count:274079 | 274079 |
144 | } | - |
145 | QString QTextCodec::toUnicode(const QByteArray& a) const | - |
146 | { | - |
147 | return convertToUnicode(a.constData(), a.length(), 0); executed: return convertToUnicode(a.constData(), a.length(), 0); Execution Count:1030 | 1030 |
148 | } | - |
149 | | - |
150 | | - |
151 | | - |
152 | | - |
153 | | - |
154 | bool QTextCodec::canEncode(QChar ch) const | - |
155 | { | - |
156 | ConverterState state; | - |
157 | state.flags = ConvertInvalidToNull; | - |
158 | convertFromUnicode(&ch, 1, &state); | - |
159 | return (state.invalidChars == 0); executed: return (state.invalidChars == 0); Execution Count:915126 | 915126 |
160 | } | - |
161 | | - |
162 | | - |
163 | | - |
164 | | - |
165 | | - |
166 | | - |
167 | bool QTextCodec::canEncode(const QString& s) const | - |
168 | { | - |
169 | ConverterState state; | - |
170 | state.flags = ConvertInvalidToNull; | - |
171 | convertFromUnicode(s.constData(), s.length(), &state); | - |
172 | return (state.invalidChars == 0); executed: return (state.invalidChars == 0); Execution Count:9 | 9 |
173 | } | - |
174 | | - |
175 | | - |
176 | | - |
177 | | - |
178 | | - |
179 | | - |
180 | QString QTextCodec::toUnicode(const char *chars) const | - |
181 | { | - |
182 | int len = qstrlen(chars); | - |
183 | return convertToUnicode(chars, len, 0); executed: return convertToUnicode(chars, len, 0); Execution Count:1 | 1 |
184 | } | - |
185 | QTextEncoder::QTextEncoder(const QTextCodec *codec, QTextCodec::ConversionFlags flags) | - |
186 | : c(codec), state() | - |
187 | { | - |
188 | state.flags = flags; | - |
189 | } executed: } Execution Count:992 | 992 |
190 | | - |
191 | | - |
192 | | - |
193 | | - |
194 | QTextEncoder::~QTextEncoder() | - |
195 | { | - |
196 | } | - |
197 | bool QTextEncoder::hasFailure() const | - |
198 | { | - |
199 | return state.invalidChars != 0; executed: return state.invalidChars != 0; Execution Count:494 | 494 |
200 | } | - |
201 | | - |
202 | | - |
203 | | - |
204 | | - |
205 | QByteArray QTextEncoder::fromUnicode(const QString& str) | - |
206 | { | - |
207 | QByteArray result = c->fromUnicode(str.constData(), str.length(), &state); | - |
208 | return result; executed: return result; Execution Count:5867 | 5867 |
209 | } | - |
210 | | - |
211 | | - |
212 | | - |
213 | | - |
214 | | - |
215 | | - |
216 | | - |
217 | QByteArray QTextEncoder::fromUnicode(const QChar *uc, int len) | - |
218 | { | - |
219 | QByteArray result = c->fromUnicode(uc, len, &state); | - |
220 | return result; executed: return result; Execution Count:2889 | 2889 |
221 | } | - |
222 | QTextDecoder::QTextDecoder(const QTextCodec *codec, QTextCodec::ConversionFlags flags) | - |
223 | : c(codec), state() | - |
224 | { | - |
225 | state.flags = flags; | - |
226 | } executed: } Execution Count:5380 | 5380 |
227 | | - |
228 | | - |
229 | | - |
230 | | - |
231 | QTextDecoder::~QTextDecoder() | - |
232 | { | - |
233 | } | - |
234 | QString QTextDecoder::toUnicode(const char *chars, int len) | - |
235 | { | - |
236 | return c->toUnicode(chars, len, &state); executed: return c->toUnicode(chars, len, &state); Execution Count:51617 | 51617 |
237 | } | - |
238 | | - |
239 | | - |
240 | | - |
241 | | - |
242 | | - |
243 | | - |
244 | void QTextDecoder::toUnicode(QString *target, const char *chars, int len) | - |
245 | { | - |
246 | qt_noop(); | - |
247 | switch (c->mibEnum()) { | - |
248 | case 106: | - |
249 | static_cast<const QUtf8Codec*>(c)->convertToUnicode(target, chars, len, &state); | - |
250 | break; executed: break; Execution Count:59082 | 59082 |
251 | case 4: { | - |
252 | target->resize(len); | - |
253 | ushort *data = (ushort*)target->data(); | - |
254 | for (int i = len; i >=0; --i) evaluated: i >=0 yes Evaluation Count:454 | yes Evaluation Count:3 |
| 3-454 |
255 | data[i] = (uchar) chars[i]; executed: data[i] = (uchar) chars[i]; Execution Count:454 | 454 |
256 | } break; executed: break; Execution Count:3 | 3 |
257 | default: | - |
258 | *target = c->toUnicode(chars, len, &state); | - |
259 | } executed: } Execution Count:427 | 427 |
260 | } executed: } Execution Count:59512 | 59512 |
261 | QString QTextDecoder::toUnicode(const QByteArray &ba) | - |
262 | { | - |
263 | return c->toUnicode(ba.constData(), ba.length(), &state); executed: return c->toUnicode(ba.constData(), ba.length(), &state); Execution Count:300 | 300 |
264 | } | - |
265 | QTextCodec *QTextCodec::codecForHtml(const QByteArray &ba, QTextCodec *defaultCodec) | - |
266 | { | - |
267 | | - |
268 | int pos; | - |
269 | QTextCodec *c = 0; | - |
270 | | - |
271 | c = QTextCodec::codecForUtfText(ba, c); | - |
272 | if (!c) { evaluated: !c yes Evaluation Count:53 | yes Evaluation Count:1 |
| 1-53 |
273 | QByteArray header = ba.left(512).toLower(); | - |
274 | if ((pos = header.indexOf("http-equiv=")) != -1) { evaluated: (pos = header.indexOf("http-equiv=")) != -1 yes Evaluation Count:5 | yes Evaluation Count:48 |
| 5-48 |
275 | if ((pos = header.lastIndexOf("meta ", pos)) != -1) { partially evaluated: (pos = header.lastIndexOf("meta ", pos)) != -1 yes Evaluation Count:5 | no Evaluation Count:0 |
| 0-5 |
276 | pos = header.indexOf("charset=", pos) + int(strlen("charset=")); | - |
277 | if (pos != -1) { partially evaluated: pos != -1 yes Evaluation Count:5 | no Evaluation Count:0 |
| 0-5 |
278 | int pos2 = header.indexOf('\"', pos+1); | - |
279 | QByteArray cs = header.mid(pos, pos2-pos); | - |
280 | | - |
281 | c = QTextCodec::codecForName(cs); | - |
282 | } executed: } Execution Count:5 | 5 |
283 | } executed: } Execution Count:5 | 5 |
284 | } executed: } Execution Count:5 | 5 |
285 | } executed: } Execution Count:53 | 53 |
286 | if (!c) evaluated: !c yes Evaluation Count:50 | yes Evaluation Count:4 |
| 4-50 |
287 | c = defaultCodec; executed: c = defaultCodec; Execution Count:50 | 50 |
288 | | - |
289 | return c; executed: return c; Execution Count:54 | 54 |
290 | } | - |
291 | QTextCodec *QTextCodec::codecForHtml(const QByteArray &ba) | - |
292 | { | - |
293 | return codecForHtml(ba, QTextCodec::codecForName("ISO-8859-1")); executed: return codecForHtml(ba, QTextCodec::codecForName("ISO-8859-1")); Execution Count:49 | 49 |
294 | } | - |
295 | QTextCodec *QTextCodec::codecForUtfText(const QByteArray &ba, QTextCodec *defaultCodec) | - |
296 | { | - |
297 | const int arraySize = ba.size(); | - |
298 | | - |
299 | if (arraySize > 3) { evaluated: arraySize > 3 yes Evaluation Count:2559 | yes Evaluation Count:1996 |
| 1996-2559 |
300 | if ((uchar)ba[0] == 0x00 evaluated: (uchar)ba[0] == 0x00 yes Evaluation Count:12 | yes Evaluation Count:2547 |
| 12-2547 |
301 | && (uchar)ba[1] == 0x00 evaluated: (uchar)ba[1] == 0x00 yes Evaluation Count:11 | yes Evaluation Count:1 |
| 1-11 |
302 | && (uchar)ba[2] == 0xFE evaluated: (uchar)ba[2] == 0xFE yes Evaluation Count:10 | yes Evaluation Count:1 |
| 1-10 |
303 | && (uchar)ba[3] == 0xFF) partially evaluated: (uchar)ba[3] == 0xFF yes Evaluation Count:10 | no Evaluation Count:0 |
| 0-10 |
304 | return QTextCodec::codecForMib(1018); executed: return QTextCodec::codecForMib(1018); Execution Count:10 | 10 |
305 | else if ((uchar)ba[0] == 0xFF evaluated: (uchar)ba[0] == 0xFF yes Evaluation Count:69 | yes Evaluation Count:2480 |
| 69-2480 |
306 | && (uchar)ba[1] == 0xFE partially evaluated: (uchar)ba[1] == 0xFE yes Evaluation Count:69 | no Evaluation Count:0 |
| 0-69 |
307 | && (uchar)ba[2] == 0x00 evaluated: (uchar)ba[2] == 0x00 yes Evaluation Count:10 | yes Evaluation Count:59 |
| 10-59 |
308 | && (uchar)ba[3] == 0x00) partially evaluated: (uchar)ba[3] == 0x00 yes Evaluation Count:10 | no Evaluation Count:0 |
| 0-10 |
309 | return QTextCodec::codecForMib(1019); executed: return QTextCodec::codecForMib(1019); Execution Count:10 | 10 |
310 | } | - |
311 | | - |
312 | if (arraySize < 2) evaluated: arraySize < 2 yes Evaluation Count:1841 | yes Evaluation Count:2694 |
| 1841-2694 |
313 | return defaultCodec; executed: return defaultCodec; Execution Count:1841 | 1841 |
314 | if ((uchar)ba[0] == 0xfe && (uchar)ba[1] == 0xff) evaluated: (uchar)ba[0] == 0xfe yes Evaluation Count:82 | yes Evaluation Count:2612 |
partially evaluated: (uchar)ba[1] == 0xff yes Evaluation Count:82 | no Evaluation Count:0 |
| 0-2612 |
315 | return QTextCodec::codecForMib(1013); executed: return QTextCodec::codecForMib(1013); Execution Count:82 | 82 |
316 | else if ((uchar)ba[0] == 0xff && (uchar)ba[1] == 0xfe) evaluated: (uchar)ba[0] == 0xff yes Evaluation Count:74 | yes Evaluation Count:2538 |
partially evaluated: (uchar)ba[1] == 0xfe yes Evaluation Count:74 | no Evaluation Count:0 |
| 0-2538 |
317 | return QTextCodec::codecForMib(1014); executed: return QTextCodec::codecForMib(1014); Execution Count:74 | 74 |
318 | | - |
319 | if (arraySize < 3) evaluated: arraySize < 3 yes Evaluation Count:54 | yes Evaluation Count:2484 |
| 54-2484 |
320 | return defaultCodec; executed: return defaultCodec; Execution Count:54 | 54 |
321 | if ((uchar)ba[0] == 0xef evaluated: (uchar)ba[0] == 0xef yes Evaluation Count:11 | yes Evaluation Count:2473 |
| 11-2473 |
322 | && (uchar)ba[1] == 0xbb partially evaluated: (uchar)ba[1] == 0xbb yes Evaluation Count:11 | no Evaluation Count:0 |
| 0-11 |
323 | && (uchar)ba[2] == 0xbf) partially evaluated: (uchar)ba[2] == 0xbf yes Evaluation Count:11 | no Evaluation Count:0 |
| 0-11 |
324 | return QTextCodec::codecForMib(106); executed: return QTextCodec::codecForMib(106); Execution Count:11 | 11 |
325 | | - |
326 | return defaultCodec; executed: return defaultCodec; Execution Count:2473 | 2473 |
327 | } | - |
328 | QTextCodec *QTextCodec::codecForUtfText(const QByteArray &ba) | - |
329 | { | - |
330 | return codecForUtfText(ba, QTextCodec::codecForMib( 4)); never executed: return codecForUtfText(ba, QTextCodec::codecForMib( 4)); | 0 |
331 | } | - |
332 | bool QTextDecoder::hasFailure() const | - |
333 | { | - |
334 | return state.invalidChars != 0; executed: return state.invalidChars != 0; Execution Count:57634 | 57634 |
335 | } | - |
336 | | - |
337 | | - |
338 | | - |
| | |