codecs/qtextcodec.cpp

Switch to Source codePreprocessed file
LineSource CodeCoverage
1 -
2 -
3 -
4 -
5 -
6 -
7 -
8 -
9 -
10 -
11 -
12 -
13 -
14 -
15 -
16 -
17 -
18 -
19static 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)
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:116
evaluated: !thisGlobalStatic.pointer.load()
TRUEFALSE
yes
Evaluation Count:117
yes
Evaluation Count:24700
evaluated: !thisGlobalStatic.destroyed
TRUEFALSE
yes
Evaluation Count:116
yes
Evaluation Count:1
0-24817
20QMutex *qTextCodecsMutex() { return textCodecsMutex(); }
never executed: return textCodecsMutex();
0
21static void setup() {} -
22QTextCodec::ConverterState::~ConverterState() -
23{ -
24 if (flags & FreeFunction)
evaluated: flags & FreeFunction
TRUEFALSE
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
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:1290211
0-1290211
27 free(d);
never executed: free(d);
0
28} -
29QTextCodec::QTextCodec() -
30{ -
31 QMutexLocker locker(textCodecsMutex()); -
32 -
33 QCoreGlobalData::instance()->allCodecs.prepend(this); -
34}
executed: }
Execution Count:256
256
35QTextCodec::~QTextCodec() -
36{ -
37} -
38QTextCodec *QTextCodec::codecForName(const QByteArray &name) -
39{ -
40 if (name.isEmpty())
evaluated: name.isEmpty()
TRUEFALSE
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
TRUEFALSE
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 -
59QTextCodec* QTextCodec::codecForMib(int mib) -
60{ -
61 QMutexLocker locker(textCodecsMutex()); -
62 -
63 QCoreGlobalData *globalData = QCoreGlobalData::instance(); -
64 if (!globalData)
partially evaluated: !globalData
TRUEFALSE
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()
TRUEFALSE
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
TRUEFALSE
yes
Evaluation Count:13153
no
Evaluation Count:0
0-13153
74 codec = cache->value(key); -
75 if (codec)
evaluated: codec
TRUEFALSE
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()
TRUEFALSE
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
TRUEFALSE
yes
Evaluation Count:128
yes
Evaluation Count:6415
128-6415
83 if (cache)
partially evaluated: cache
TRUEFALSE
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} -
95QList<QByteArray> QTextCodec::availableCodecs() -
96{ -
97 -
98 return QIcuCodec::availableCodecs();
executed: return QIcuCodec::availableCodecs();
Execution Count:2
2
99} -
100QList<int> QTextCodec::availableMibs() -
101{ -
102 -
103 return QIcuCodec::availableMibs();
executed: return QIcuCodec::availableMibs();
Execution Count:2
2
104} -
105void QTextCodec::setCodecForLocale(QTextCodec *c) -
106{ -
107 QCoreGlobalData::instance()->codecForLocale.storeRelease(c); -
108}
executed: }
Execution Count:2
2
109QTextCodec* QTextCodec::codecForLocale() -
110{ -
111 QCoreGlobalData *globalData = QCoreGlobalData::instance(); -
112 if (!globalData)
partially evaluated: !globalData
TRUEFALSE
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
TRUEFALSE
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} -
129QList<QByteArray> QTextCodec::aliases() const -
130{ -
131 return QList<QByteArray>();
executed: return QList<QByteArray>();
Execution Count:296
296
132} -
133QTextDecoder* QTextCodec::makeDecoder(QTextCodec::ConversionFlags flags) const -
134{ -
135 return new QTextDecoder(this, flags);
executed: return new QTextDecoder(this, flags);
Execution Count:5380
5380
136} -
137QTextEncoder* QTextCodec::makeEncoder(QTextCodec::ConversionFlags flags) const -
138{ -
139 return new QTextEncoder(this, flags);
executed: return new QTextEncoder(this, flags);
Execution Count:992
992
140} -
141QByteArray 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} -
145QString 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 -
154bool 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 -
167bool 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 -
180QString 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} -
185QTextEncoder::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 -
194QTextEncoder::~QTextEncoder() -
195{ -
196} -
197bool QTextEncoder::hasFailure() const -
198{ -
199 return state.invalidChars != 0;
executed: return state.invalidChars != 0;
Execution Count:494
494
200} -
201 -
202 -
203 -
204 -
205QByteArray 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 -
217QByteArray 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} -
222QTextDecoder::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 -
231QTextDecoder::~QTextDecoder() -
232{ -
233} -
234QString 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 -
244void 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
TRUEFALSE
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
261QString 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} -
265QTextCodec *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
TRUEFALSE
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
TRUEFALSE
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
TRUEFALSE
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
TRUEFALSE
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
TRUEFALSE
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} -
291QTextCodec *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} -
295QTextCodec *QTextCodec::codecForUtfText(const QByteArray &ba, QTextCodec *defaultCodec) -
296{ -
297 const int arraySize = ba.size(); -
298 -
299 if (arraySize > 3) {
evaluated: arraySize > 3
TRUEFALSE
yes
Evaluation Count:2559
yes
Evaluation Count:1996
1996-2559
300 if ((uchar)ba[0] == 0x00
evaluated: (uchar)ba[0] == 0x00
TRUEFALSE
yes
Evaluation Count:12
yes
Evaluation Count:2547
12-2547
301 && (uchar)ba[1] == 0x00
evaluated: (uchar)ba[1] == 0x00
TRUEFALSE
yes
Evaluation Count:11
yes
Evaluation Count:1
1-11
302 && (uchar)ba[2] == 0xFE
evaluated: (uchar)ba[2] == 0xFE
TRUEFALSE
yes
Evaluation Count:10
yes
Evaluation Count:1
1-10
303 && (uchar)ba[3] == 0xFF)
partially evaluated: (uchar)ba[3] == 0xFF
TRUEFALSE
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
TRUEFALSE
yes
Evaluation Count:69
yes
Evaluation Count:2480
69-2480
306 && (uchar)ba[1] == 0xFE
partially evaluated: (uchar)ba[1] == 0xFE
TRUEFALSE
yes
Evaluation Count:69
no
Evaluation Count:0
0-69
307 && (uchar)ba[2] == 0x00
evaluated: (uchar)ba[2] == 0x00
TRUEFALSE
yes
Evaluation Count:10
yes
Evaluation Count:59
10-59
308 && (uchar)ba[3] == 0x00)
partially evaluated: (uchar)ba[3] == 0x00
TRUEFALSE
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
TRUEFALSE
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
TRUEFALSE
yes
Evaluation Count:82
yes
Evaluation Count:2612
partially evaluated: (uchar)ba[1] == 0xff
TRUEFALSE
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
TRUEFALSE
yes
Evaluation Count:74
yes
Evaluation Count:2538
partially evaluated: (uchar)ba[1] == 0xfe
TRUEFALSE
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
TRUEFALSE
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
TRUEFALSE
yes
Evaluation Count:11
yes
Evaluation Count:2473
11-2473
322 && (uchar)ba[1] == 0xbb
partially evaluated: (uchar)ba[1] == 0xbb
TRUEFALSE
yes
Evaluation Count:11
no
Evaluation Count:0
0-11
323 && (uchar)ba[2] == 0xbf)
partially evaluated: (uchar)ba[2] == 0xbf
TRUEFALSE
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} -
328QTextCodec *QTextCodec::codecForUtfText(const QByteArray &ba) -
329{ -
330 return codecForUtfText(ba, QTextCodec::codecForMib( 4));
never executed: return codecForUtfText(ba, QTextCodec::codecForMib( 4));
0
331} -
332bool QTextDecoder::hasFailure() const -
333{ -
334 return state.invalidChars != 0;
executed: return state.invalidChars != 0;
Execution Count:57634
57634
335} -
336 -
337 -
338 -
Switch to Source codePreprocessed file

Generated by Squish Coco Non-Commercial