Line | Source Code | Coverage |
---|
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 | | - |
42 | #include "qplatformdefs.h" | - |
43 | | - |
44 | #include "qtranslator.h" | - |
45 | | - |
46 | #ifndef QT_NO_TRANSLATION | - |
47 | | - |
48 | #include "qfileinfo.h" | - |
49 | #include "qstring.h" | - |
50 | #include "qstringlist.h" | - |
51 | #include "qcoreapplication.h" | - |
52 | #include "qcoreapplication_p.h" | - |
53 | #include "qdatastream.h" | - |
54 | #include "qfile.h" | - |
55 | #include "qmap.h" | - |
56 | #include "qalgorithms.h" | - |
57 | #include "qhash.h" | - |
58 | #include "qtranslator_p.h" | - |
59 | #include "qlocale.h" | - |
60 | #include "qendian.h" | - |
61 | #include "qresource.h" | - |
62 | | - |
63 | #if defined(Q_OS_UNIX) && !defined(Q_OS_INTEGRITY) | - |
64 | #define QT_USE_MMAP | - |
65 | #include "private/qcore_unix_p.h" | - |
66 | #endif | - |
67 | | - |
68 | // most of the headers below are already included in qplatformdefs.h | - |
69 | // also this lacks Large File support but that's probably irrelevant | - |
70 | #if defined(QT_USE_MMAP) | - |
71 | // for mmap | - |
72 | #include <sys/mman.h> | - |
73 | #include <errno.h> | - |
74 | #endif | - |
75 | | - |
76 | #include <stdlib.h> | - |
77 | | - |
78 | #include "qobject_p.h" | - |
79 | | - |
80 | QT_BEGIN_NAMESPACE | - |
81 | | - |
82 | enum Tag { Tag_End = 1, Tag_SourceText16, Tag_Translation, Tag_Context16, Tag_Obsolete1, | - |
83 | Tag_SourceText, Tag_Context, Tag_Comment, Tag_Obsolete2 }; | - |
84 | /* | - |
85 | $ mcookie | - |
86 | 3cb86418caef9c95cd211cbf60a1bddd | - |
87 | $ | - |
88 | */ | - |
89 | | - |
90 | // magic number for the file | - |
91 | static const int MagicLength = 16; | - |
92 | static const uchar magic[MagicLength] = { | - |
93 | 0x3c, 0xb8, 0x64, 0x18, 0xca, 0xef, 0x9c, 0x95, | - |
94 | 0xcd, 0x21, 0x1c, 0xbf, 0x60, 0xa1, 0xbd, 0xdd | - |
95 | }; | - |
96 | | - |
97 | static bool match(const uchar* found, const char* target, uint len) | - |
98 | { | - |
99 | // catch the case if \a found has a zero-terminating symbol and \a len includes it. | - |
100 | // (normalize it to be without the zero-terminating symbol) | - |
101 | if (len > 0 && found[len-1] == '\0') evaluated: len > 0 yes Evaluation Count:346 | yes Evaluation Count:167 |
evaluated: found[len-1] == '\0' yes Evaluation Count:12 | yes Evaluation Count:334 |
| 12-346 |
102 | --len; executed: --len; Execution Count:12 | 12 |
103 | return (memcmp(found, target, len) == 0 && target[len] == '\0'); executed: return (memcmp(found, target, len) == 0 && target[len] == '\0'); Execution Count:513 | 513 |
104 | } | - |
105 | | - |
106 | static void elfHash_continue(const char *name, uint &h) | - |
107 | { | - |
108 | const uchar *k; executed (the execution status of this line is deduced): const uchar *k; | - |
109 | uint g; executed (the execution status of this line is deduced): uint g; | - |
110 | | - |
111 | k = (const uchar *) name; executed (the execution status of this line is deduced): k = (const uchar *) name; | - |
112 | while (*k) { evaluated: *k yes Evaluation Count:11514 | yes Evaluation Count:544 |
| 544-11514 |
113 | h = (h << 4) + *k++; executed (the execution status of this line is deduced): h = (h << 4) + *k++; | - |
114 | if ((g = (h & 0xf0000000)) != 0) evaluated: (g = (h & 0xf0000000)) != 0 yes Evaluation Count:9554 | yes Evaluation Count:1960 |
| 1960-9554 |
115 | h ^= g >> 24; executed: h ^= g >> 24; Execution Count:9554 | 9554 |
116 | h &= ~g; executed (the execution status of this line is deduced): h &= ~g; | - |
117 | } executed: } Execution Count:11514 | 11514 |
118 | } executed: } Execution Count:544 | 544 |
119 | | - |
120 | static void elfHash_finish(uint &h) | - |
121 | { | - |
122 | if (!h) partially evaluated: !h no Evaluation Count:0 | yes Evaluation Count:272 |
| 0-272 |
123 | h = 1; | 0 |
124 | } executed: } Execution Count:272 | 272 |
125 | | - |
126 | static uint elfHash(const char *name) | - |
127 | { | - |
128 | uint hash = 0; never executed (the execution status of this line is deduced): uint hash = 0; | - |
129 | elfHash_continue(name, hash); never executed (the execution status of this line is deduced): elfHash_continue(name, hash); | - |
130 | elfHash_finish(hash); never executed (the execution status of this line is deduced): elfHash_finish(hash); | - |
131 | return hash; never executed: return hash; | 0 |
132 | } | - |
133 | | - |
134 | /* | - |
135 | \internal | - |
136 | | - |
137 | Determines whether \a rules are valid "numerus rules". Test input with this | - |
138 | function before calling numerusHelper, below. | - |
139 | */ | - |
140 | static bool isValidNumerusRules(const uchar *rules, uint rulesSize) | - |
141 | { | - |
142 | // Disabled computation of maximum numerus return value | - |
143 | // quint32 numerus = 0; | - |
144 | | - |
145 | if (rulesSize == 0) evaluated: rulesSize == 0 yes Evaluation Count:1 | yes Evaluation Count:15 |
| 1-15 |
146 | return true; executed: return true; Execution Count:1 | 1 |
147 | | - |
148 | quint32 offset = 0; executed (the execution status of this line is deduced): quint32 offset = 0; | - |
149 | do { | - |
150 | uchar opcode = rules[offset]; executed (the execution status of this line is deduced): uchar opcode = rules[offset]; | - |
151 | uchar op = opcode & Q_OP_MASK; executed (the execution status of this line is deduced): uchar op = opcode & Q_OP_MASK; | - |
152 | | - |
153 | if (opcode & 0x80) partially evaluated: opcode & 0x80 no Evaluation Count:0 | yes Evaluation Count:15 |
| 0-15 |
154 | return false; // Bad op never executed: return false; | 0 |
155 | | - |
156 | if (++offset == rulesSize) partially evaluated: ++offset == rulesSize no Evaluation Count:0 | yes Evaluation Count:15 |
| 0-15 |
157 | return false; // Missing operand never executed: return false; | 0 |
158 | | - |
159 | // right operand | - |
160 | ++offset; executed (the execution status of this line is deduced): ++offset; | - |
161 | | - |
162 | switch (op) | - |
163 | { | - |
164 | case Q_EQ: | - |
165 | case Q_LT: | - |
166 | case Q_LEQ: | - |
167 | break; executed: break; Execution Count:15 | 15 |
168 | | - |
169 | case Q_BETWEEN: | - |
170 | if (offset != rulesSize) { never evaluated: offset != rulesSize | 0 |
171 | // third operand | - |
172 | ++offset; never executed (the execution status of this line is deduced): ++offset; | - |
173 | break; | 0 |
174 | } | - |
175 | return false; // Missing operand never executed: return false; | 0 |
176 | | - |
177 | default: | - |
178 | return false; // Bad op (0) never executed: return false; | 0 |
179 | } | - |
180 | | - |
181 | // ++numerus; | - |
182 | if (offset == rulesSize) partially evaluated: offset == rulesSize yes Evaluation Count:15 | no Evaluation Count:0 |
| 0-15 |
183 | return true; executed: return true; Execution Count:15 | 15 |
184 | | - |
185 | } while (((rules[offset] == Q_AND) never executed: } never evaluated: (rules[offset] == Q_AND) | 0 |
186 | || (rules[offset] == Q_OR) never evaluated: (rules[offset] == Q_OR) | 0 |
187 | || (rules[offset] == Q_NEWRULE)) never evaluated: (rules[offset] == Q_NEWRULE) | 0 |
188 | && ++offset != rulesSize); never evaluated: ++offset != rulesSize | 0 |
189 | | - |
190 | // Bad op | - |
191 | return false; never executed: return false; | 0 |
192 | } | - |
193 | | - |
194 | /* | - |
195 | \internal | - |
196 | | - |
197 | This function does no validation of input and assumes it is well-behaved, | - |
198 | these assumptions can be checked with isValidNumerusRules, above. | - |
199 | | - |
200 | Determines which translation to use based on the value of \a n. The return | - |
201 | value is an index identifying the translation to be used. | - |
202 | | - |
203 | \a rules is a character array of size \a rulesSize containing bytecode that | - |
204 | operates on the value of \a n and ultimately determines the result. | - |
205 | | - |
206 | This function has O(1) space and O(rulesSize) time complexity. | - |
207 | */ | - |
208 | static uint numerusHelper(int n, const uchar *rules, uint rulesSize) | - |
209 | { | - |
210 | uint result = 0; executed (the execution status of this line is deduced): uint result = 0; | - |
211 | uint i = 0; executed (the execution status of this line is deduced): uint i = 0; | - |
212 | | - |
213 | if (rulesSize == 0) partially evaluated: rulesSize == 0 no Evaluation Count:0 | yes Evaluation Count:9 |
| 0-9 |
214 | return 0; never executed: return 0; | 0 |
215 | | - |
216 | for (;;) { executed (the execution status of this line is deduced): for (;;) { | - |
217 | bool orExprTruthValue = false; executed (the execution status of this line is deduced): bool orExprTruthValue = false; | - |
218 | | - |
219 | for (;;) { executed (the execution status of this line is deduced): for (;;) { | - |
220 | bool andExprTruthValue = true; executed (the execution status of this line is deduced): bool andExprTruthValue = true; | - |
221 | | - |
222 | for (;;) { executed (the execution status of this line is deduced): for (;;) { | - |
223 | bool truthValue = true; executed (the execution status of this line is deduced): bool truthValue = true; | - |
224 | int opcode = rules[i++]; executed (the execution status of this line is deduced): int opcode = rules[i++]; | - |
225 | | - |
226 | int leftOperand = n; executed (the execution status of this line is deduced): int leftOperand = n; | - |
227 | if (opcode & Q_MOD_10) { partially evaluated: opcode & Q_MOD_10 no Evaluation Count:0 | yes Evaluation Count:9 |
| 0-9 |
228 | leftOperand %= 10; never executed (the execution status of this line is deduced): leftOperand %= 10; | - |
229 | } else if (opcode & Q_MOD_100) { never executed: } partially evaluated: opcode & Q_MOD_100 no Evaluation Count:0 | yes Evaluation Count:9 |
| 0-9 |
230 | leftOperand %= 100; never executed (the execution status of this line is deduced): leftOperand %= 100; | - |
231 | } else if (opcode & Q_LEAD_1000) { never executed: } partially evaluated: opcode & Q_LEAD_1000 no Evaluation Count:0 | yes Evaluation Count:9 |
| 0-9 |
232 | while (leftOperand >= 1000) never evaluated: leftOperand >= 1000 | 0 |
233 | leftOperand /= 1000; never executed: leftOperand /= 1000; | 0 |
234 | } | 0 |
235 | | - |
236 | int op = opcode & Q_OP_MASK; executed (the execution status of this line is deduced): int op = opcode & Q_OP_MASK; | - |
237 | int rightOperand = rules[i++]; executed (the execution status of this line is deduced): int rightOperand = rules[i++]; | - |
238 | | - |
239 | switch (op) { | - |
240 | case Q_EQ: | - |
241 | truthValue = (leftOperand == rightOperand); executed (the execution status of this line is deduced): truthValue = (leftOperand == rightOperand); | - |
242 | break; executed: break; Execution Count:9 | 9 |
243 | case Q_LT: | - |
244 | truthValue = (leftOperand < rightOperand); never executed (the execution status of this line is deduced): truthValue = (leftOperand < rightOperand); | - |
245 | break; | 0 |
246 | case Q_LEQ: | - |
247 | truthValue = (leftOperand <= rightOperand); never executed (the execution status of this line is deduced): truthValue = (leftOperand <= rightOperand); | - |
248 | break; | 0 |
249 | case Q_BETWEEN: | - |
250 | int bottom = rightOperand; never executed (the execution status of this line is deduced): int bottom = rightOperand; | - |
251 | int top = rules[i++]; never executed (the execution status of this line is deduced): int top = rules[i++]; | - |
252 | truthValue = (leftOperand >= bottom && leftOperand <= top); never evaluated: leftOperand >= bottom never evaluated: leftOperand <= top | 0 |
253 | } | 0 |
254 | | - |
255 | if (opcode & Q_NOT) partially evaluated: opcode & Q_NOT no Evaluation Count:0 | yes Evaluation Count:9 |
| 0-9 |
256 | truthValue = !truthValue; never executed: truthValue = !truthValue; | 0 |
257 | | - |
258 | andExprTruthValue = andExprTruthValue && truthValue; partially evaluated: andExprTruthValue yes Evaluation Count:9 | no Evaluation Count:0 |
evaluated: truthValue yes Evaluation Count:3 | yes Evaluation Count:6 |
| 0-9 |
259 | | - |
260 | if (i == rulesSize || rules[i] != Q_AND) partially evaluated: i == rulesSize yes Evaluation Count:9 | no Evaluation Count:0 |
never evaluated: rules[i] != Q_AND | 0-9 |
261 | break; executed: break; Execution Count:9 | 9 |
262 | ++i; never executed (the execution status of this line is deduced): ++i; | - |
263 | } | 0 |
264 | | - |
265 | orExprTruthValue = orExprTruthValue || andExprTruthValue; partially evaluated: orExprTruthValue no Evaluation Count:0 | yes Evaluation Count:9 |
evaluated: andExprTruthValue yes Evaluation Count:3 | yes Evaluation Count:6 |
| 0-9 |
266 | | - |
267 | if (i == rulesSize || rules[i] != Q_OR) partially evaluated: i == rulesSize yes Evaluation Count:9 | no Evaluation Count:0 |
never evaluated: rules[i] != Q_OR | 0-9 |
268 | break; executed: break; Execution Count:9 | 9 |
269 | ++i; never executed (the execution status of this line is deduced): ++i; | - |
270 | } | 0 |
271 | | - |
272 | if (orExprTruthValue) evaluated: orExprTruthValue yes Evaluation Count:3 | yes Evaluation Count:6 |
| 3-6 |
273 | return result; executed: return result; Execution Count:3 | 3 |
274 | | - |
275 | ++result; executed (the execution status of this line is deduced): ++result; | - |
276 | | - |
277 | if (i == rulesSize) partially evaluated: i == rulesSize yes Evaluation Count:6 | no Evaluation Count:0 |
| 0-6 |
278 | return result; executed: return result; Execution Count:6 | 6 |
279 | | - |
280 | i++; // Q_NEWRULE never executed (the execution status of this line is deduced): i++; | - |
281 | } | 0 |
282 | | - |
283 | Q_ASSERT(false); never executed (the execution status of this line is deduced): qt_noop(); | - |
284 | } | 0 |
285 | | - |
286 | class QTranslatorPrivate : public QObjectPrivate | - |
287 | { | - |
288 | Q_DECLARE_PUBLIC(QTranslator) | - |
289 | public: | - |
290 | enum { Contexts = 0x2f, Hashes = 0x42, Messages = 0x69, NumerusRules = 0x88, Dependencies = 0x96 }; | - |
291 | | - |
292 | QTranslatorPrivate() : | - |
293 | #if defined(QT_USE_MMAP) | - |
294 | used_mmap(0), | - |
295 | #endif | - |
296 | unmapPointer(0), unmapLength(0), resource(0), | - |
297 | messageArray(0), offsetArray(0), contextArray(0), numerusRulesArray(0), | - |
298 | messageLength(0), offsetLength(0), contextLength(0), numerusRulesLength(0) {} executed: } Execution Count:14 | 14 |
299 | | - |
300 | #if defined(QT_USE_MMAP) | - |
301 | bool used_mmap : 1; | - |
302 | #endif | - |
303 | char *unmapPointer; // used memory (mmap, new or resource file) | - |
304 | quint32 unmapLength; | - |
305 | | - |
306 | // The resource object in case we loaded the translations from a resource | - |
307 | QResource *resource; | - |
308 | | - |
309 | // used if the translator has dependencies | - |
310 | QList<QTranslator*> subTranslators; | - |
311 | | - |
312 | // Pointers and offsets into unmapPointer[unmapLength] array, or user | - |
313 | // provided data array | - |
314 | const uchar *messageArray; | - |
315 | const uchar *offsetArray; | - |
316 | const uchar *contextArray; | - |
317 | const uchar *numerusRulesArray; | - |
318 | uint messageLength; | - |
319 | uint offsetLength; | - |
320 | uint contextLength; | - |
321 | uint numerusRulesLength; | - |
322 | | - |
323 | bool do_load(const QString &filename, const QString &directory); | - |
324 | bool do_load(const uchar *data, int len, const QString &directory); | - |
325 | QString do_translate(const char *context, const char *sourceText, const char *comment, | - |
326 | int n) const; | - |
327 | void clear(); | - |
328 | }; | - |
329 | | - |
330 | /*! | - |
331 | \class QTranslator | - |
332 | \inmodule QtCore | - |
333 | | - |
334 | \brief The QTranslator class provides internationalization support for text | - |
335 | output. | - |
336 | | - |
337 | \ingroup i18n | - |
338 | | - |
339 | An object of this class contains a set of translations from a | - |
340 | source language to a target language. QTranslator provides | - |
341 | functions to look up translations in a translation file. | - |
342 | Translation files are created using \l{Qt Linguist}. | - |
343 | | - |
344 | The most common use of QTranslator is to: load a translation | - |
345 | file, install it using QCoreApplication::installTranslator(), and use | - |
346 | it via QObject::tr(). Here's an example \c main() function using the | - |
347 | QTranslator: | - |
348 | | - |
349 | \snippet hellotrmain.cpp 0 | - |
350 | | - |
351 | Note that the translator must be created \e before the | - |
352 | application's widgets. | - |
353 | | - |
354 | Most applications will never need to do anything else with this | - |
355 | class. The other functions provided by this class are useful for | - |
356 | applications that work on translator files. | - |
357 | | - |
358 | \section1 Looking up Translations | - |
359 | | - |
360 | It is possible to look up a translation using translate() (as tr() | - |
361 | and QCoreApplication::translate() do). The translate() function takes | - |
362 | up to three parameters: | - |
363 | | - |
364 | \list | - |
365 | \li The \e context - usually the class name for the tr() caller. | - |
366 | \li The \e {source text} - usually the argument to tr(). | - |
367 | \li The \e disambiguation - an optional string that helps disambiguate | - |
368 | different uses of the same text in the same context. | - |
369 | \endlist | - |
370 | | - |
371 | For example, the "Cancel" in a dialog might have "Anuluj" when the | - |
372 | program runs in Polish (in this case the source text would be | - |
373 | "Cancel"). The context would (normally) be the dialog's class | - |
374 | name; there would normally be no comment, and the translated text | - |
375 | would be "Anuluj". | - |
376 | | - |
377 | But it's not always so simple. The Spanish version of a printer | - |
378 | dialog with settings for two-sided printing and binding would | - |
379 | probably require both "Activado" and "Activada" as translations | - |
380 | for "Enabled". In this case the source text would be "Enabled" in | - |
381 | both cases, and the context would be the dialog's class name, but | - |
382 | the two items would have disambiguations such as "two-sided printing" | - |
383 | for one and "binding" for the other. The disambiguation enables the | - |
384 | translator to choose the appropriate gender for the Spanish version, | - |
385 | and enables Qt to distinguish between translations. | - |
386 | | - |
387 | \section1 Using Multiple Translations | - |
388 | | - |
389 | Multiple translation files can be installed in an application. | - |
390 | Translations are searched for in the reverse order in which they were | - |
391 | installed, so the most recently installed translation file is searched | - |
392 | for translations first and the earliest translation file is searched | - |
393 | last. The search stops as soon as a translation containing a matching | - |
394 | string is found. | - |
395 | | - |
396 | This mechanism makes it possible for a specific translation to be | - |
397 | "selected" or given priority over the others; simply uninstall the | - |
398 | translator from the application by passing it to the | - |
399 | QCoreApplication::removeTranslator() function and reinstall it with | - |
400 | QCoreApplication::installTranslator(). It will then be the first | - |
401 | translation to be searched for matching strings. | - |
402 | | - |
403 | \sa QCoreApplication::installTranslator(), QCoreApplication::removeTranslator(), | - |
404 | QObject::tr(), QCoreApplication::translate(), {I18N Example}, | - |
405 | {Hello tr() Example}, {Arrow Pad Example}, {Troll Print Example} | - |
406 | */ | - |
407 | | - |
408 | /*! | - |
409 | Constructs an empty message file object with parent \a parent that | - |
410 | is not connected to any file. | - |
411 | */ | - |
412 | | - |
413 | QTranslator::QTranslator(QObject * parent) | - |
414 | : QObject(*new QTranslatorPrivate, parent) | - |
415 | { | - |
416 | } executed: } Execution Count:14 | 14 |
417 | | - |
418 | /*! | - |
419 | Destroys the object and frees any allocated resources. | - |
420 | */ | - |
421 | | - |
422 | QTranslator::~QTranslator() | - |
423 | { | - |
424 | if (QCoreApplication::instance()) partially evaluated: QCoreApplication::instance() yes Evaluation Count:14 | no Evaluation Count:0 |
| 0-14 |
425 | QCoreApplication::removeTranslator(this); executed: QCoreApplication::removeTranslator(this); Execution Count:14 | 14 |
426 | Q_D(QTranslator); executed (the execution status of this line is deduced): QTranslatorPrivate * const d = d_func(); | - |
427 | d->clear(); executed (the execution status of this line is deduced): d->clear(); | - |
428 | } executed: } Execution Count:14 | 14 |
429 | | - |
430 | /*! | - |
431 | | - |
432 | Loads \a filename + \a suffix (".qm" if the \a suffix is not | - |
433 | specified), which may be an absolute file name or relative to \a | - |
434 | directory. Returns true if the translation is successfully loaded; | - |
435 | otherwise returns false. | - |
436 | | - |
437 | If \a directory is not specified, the directory of the | - |
438 | application's executable is used (i.e., as | - |
439 | \l{QCoreApplication::}{applicationDirPath()}). | - |
440 | | - |
441 | The previous contents of this translator object are discarded. | - |
442 | | - |
443 | If the file name does not exist, other file names are tried | - |
444 | in the following order: | - |
445 | | - |
446 | \list 1 | - |
447 | \li File name without \a suffix appended. | - |
448 | \li File name with text after a character in \a search_delimiters | - |
449 | stripped ("_." is the default for \a search_delimiters if it is | - |
450 | an empty string) and \a suffix. | - |
451 | \li File name stripped without \a suffix appended. | - |
452 | \li File name stripped further, etc. | - |
453 | \endlist | - |
454 | | - |
455 | For example, an application running in the fr_CA locale | - |
456 | (French-speaking Canada) might call load("foo.fr_ca", | - |
457 | "/opt/foolib"). load() would then try to open the first existing | - |
458 | readable file from this list: | - |
459 | | - |
460 | \list 1 | - |
461 | \li \c /opt/foolib/foo.fr_ca.qm | - |
462 | \li \c /opt/foolib/foo.fr_ca | - |
463 | \li \c /opt/foolib/foo.fr.qm | - |
464 | \li \c /opt/foolib/foo.fr | - |
465 | \li \c /opt/foolib/foo.qm | - |
466 | \li \c /opt/foolib/foo | - |
467 | \endlist | - |
468 | */ | - |
469 | | - |
470 | bool QTranslator::load(const QString & filename, const QString & directory, | - |
471 | const QString & search_delimiters, | - |
472 | const QString & suffix) | - |
473 | { | - |
474 | Q_D(QTranslator); executed (the execution status of this line is deduced): QTranslatorPrivate * const d = d_func(); | - |
475 | d->clear(); executed (the execution status of this line is deduced): d->clear(); | - |
476 | | - |
477 | QString prefix; executed (the execution status of this line is deduced): QString prefix; | - |
478 | if (QFileInfo(filename).isRelative()) { evaluated: QFileInfo(filename).isRelative() yes Evaluation Count:15 | yes Evaluation Count:3 |
| 3-15 |
479 | prefix = directory; executed (the execution status of this line is deduced): prefix = directory; | - |
480 | if (prefix.length() && !prefix.endsWith(QLatin1Char('/'))) evaluated: prefix.length() yes Evaluation Count:1 | yes Evaluation Count:14 |
partially evaluated: !prefix.endsWith(QLatin1Char('/')) yes Evaluation Count:1 | no Evaluation Count:0 |
| 0-14 |
481 | prefix += QLatin1Char('/'); executed: prefix += QLatin1Char('/'); Execution Count:1 | 1 |
482 | } executed: } Execution Count:15 | 15 |
483 | | - |
484 | QString fname = filename; executed (the execution status of this line is deduced): QString fname = filename; | - |
485 | QString realname; executed (the execution status of this line is deduced): QString realname; | - |
486 | QString delims; executed (the execution status of this line is deduced): QString delims; | - |
487 | delims = search_delimiters.isNull() ? QString::fromLatin1("_.") : search_delimiters; partially evaluated: search_delimiters.isNull() yes Evaluation Count:18 | no Evaluation Count:0 |
| 0-18 |
488 | | - |
489 | for (;;) { executed (the execution status of this line is deduced): for (;;) { | - |
490 | QFileInfo fi; executed (the execution status of this line is deduced): QFileInfo fi; | - |
491 | | - |
492 | realname = prefix + fname + (suffix.isNull() ? QString::fromLatin1(".qm") : suffix); partially evaluated: suffix.isNull() yes Evaluation Count:18 | no Evaluation Count:0 |
| 0-18 |
493 | fi.setFile(realname); executed (the execution status of this line is deduced): fi.setFile(realname); | - |
494 | if (fi.isReadable() && fi.isFile()) evaluated: fi.isReadable() yes Evaluation Count:9 | yes Evaluation Count:9 |
partially evaluated: fi.isFile() yes Evaluation Count:9 | no Evaluation Count:0 |
| 0-9 |
495 | break; executed: break; Execution Count:9 | 9 |
496 | | - |
497 | realname = prefix + fname; executed (the execution status of this line is deduced): realname = prefix + fname; | - |
498 | fi.setFile(realname); executed (the execution status of this line is deduced): fi.setFile(realname); | - |
499 | if (fi.isReadable() && fi.isFile()) evaluated: fi.isReadable() yes Evaluation Count:6 | yes Evaluation Count:3 |
evaluated: fi.isFile() yes Evaluation Count:5 | yes Evaluation Count:1 |
| 1-6 |
500 | break; executed: break; Execution Count:5 | 5 |
501 | | - |
502 | int rightmost = 0; executed (the execution status of this line is deduced): int rightmost = 0; | - |
503 | for (int i = 0; i < (int)delims.length(); i++) { evaluated: i < (int)delims.length() yes Evaluation Count:8 | yes Evaluation Count:4 |
| 4-8 |
504 | int k = fname.lastIndexOf(delims[i]); executed (the execution status of this line is deduced): int k = fname.lastIndexOf(delims[i]); | - |
505 | if (k > rightmost) partially evaluated: k > rightmost no Evaluation Count:0 | yes Evaluation Count:8 |
| 0-8 |
506 | rightmost = k; never executed: rightmost = k; | 0 |
507 | } executed: } Execution Count:8 | 8 |
508 | | - |
509 | // no truncations? fail | - |
510 | if (rightmost == 0) partially evaluated: rightmost == 0 yes Evaluation Count:4 | no Evaluation Count:0 |
| 0-4 |
511 | return false; executed: return false; Execution Count:4 | 4 |
512 | | - |
513 | fname.truncate(rightmost); never executed (the execution status of this line is deduced): fname.truncate(rightmost); | - |
514 | } | 0 |
515 | | - |
516 | // realname is now the fully qualified name of a readable file. | - |
517 | return d->do_load(realname, directory); executed: return d->do_load(realname, directory); Execution Count:14 | 14 |
518 | } | - |
519 | | - |
520 | bool QTranslatorPrivate::do_load(const QString &realname, const QString &directory) | - |
521 | { | - |
522 | QTranslatorPrivate *d = this; executed (the execution status of this line is deduced): QTranslatorPrivate *d = this; | - |
523 | bool ok = false; executed (the execution status of this line is deduced): bool ok = false; | - |
524 | | - |
525 | if (realname.startsWith(':')) { evaluated: realname.startsWith(':') yes Evaluation Count:3 | yes Evaluation Count:11 |
| 3-11 |
526 | // If the translation is in a non-compressed resource file, the data is already in | - |
527 | // memory, so no need to use QFile to copy it again. | - |
528 | Q_ASSERT(!d->resource); executed (the execution status of this line is deduced): qt_noop(); | - |
529 | d->resource = new QResource(realname); executed (the execution status of this line is deduced): d->resource = new QResource(realname); | - |
530 | if (resource->isValid() && !resource->isCompressed() && resource->size() > MagicLength partially evaluated: resource->isValid() yes Evaluation Count:3 | no Evaluation Count:0 |
evaluated: !resource->isCompressed() yes Evaluation Count:2 | yes Evaluation Count:1 |
partially evaluated: resource->size() > MagicLength yes Evaluation Count:2 | no Evaluation Count:0 |
| 0-3 |
531 | && !memcmp(resource->data(), magic, MagicLength)) { partially evaluated: !memcmp(resource->data(), magic, MagicLength) yes Evaluation Count:2 | no Evaluation Count:0 |
| 0-2 |
532 | d->unmapLength = resource->size(); executed (the execution status of this line is deduced): d->unmapLength = resource->size(); | - |
533 | d->unmapPointer = reinterpret_cast<char *>(const_cast<uchar *>(resource->data())); executed (the execution status of this line is deduced): d->unmapPointer = reinterpret_cast<char *>(const_cast<uchar *>(resource->data())); | - |
534 | #if defined(QT_USE_MMAP) | - |
535 | d->used_mmap = false; executed (the execution status of this line is deduced): d->used_mmap = false; | - |
536 | #endif | - |
537 | ok = true; executed (the execution status of this line is deduced): ok = true; | - |
538 | } else { executed: } Execution Count:2 | 2 |
539 | delete resource; executed (the execution status of this line is deduced): delete resource; | - |
540 | resource = 0; executed (the execution status of this line is deduced): resource = 0; | - |
541 | } executed: } Execution Count:1 | 1 |
542 | } | - |
543 | | - |
544 | if (!ok) { evaluated: !ok yes Evaluation Count:12 | yes Evaluation Count:2 |
| 2-12 |
545 | QFile file(realname); executed (the execution status of this line is deduced): QFile file(realname); | - |
546 | if (!file.open(QIODevice::ReadOnly | QIODevice::Unbuffered)) partially evaluated: !file.open(QIODevice::ReadOnly | QIODevice::Unbuffered) no Evaluation Count:0 | yes Evaluation Count:12 |
| 0-12 |
547 | return false; never executed: return false; | 0 |
548 | | - |
549 | qint64 fileSize = file.size(); executed (the execution status of this line is deduced): qint64 fileSize = file.size(); | - |
550 | if (fileSize <= MagicLength || quint32(-1) <= fileSize) partially evaluated: fileSize <= MagicLength no Evaluation Count:0 | yes Evaluation Count:12 |
partially evaluated: quint32(-1) <= fileSize no Evaluation Count:0 | yes Evaluation Count:12 |
| 0-12 |
551 | return false; never executed: return false; | 0 |
552 | | - |
553 | { | - |
554 | char magicBuffer[MagicLength]; executed (the execution status of this line is deduced): char magicBuffer[MagicLength]; | - |
555 | if (MagicLength != file.read(magicBuffer, MagicLength) partially evaluated: MagicLength != file.read(magicBuffer, MagicLength) no Evaluation Count:0 | yes Evaluation Count:12 |
| 0-12 |
556 | || memcmp(magicBuffer, magic, MagicLength)) partially evaluated: memcmp(magicBuffer, magic, MagicLength) no Evaluation Count:0 | yes Evaluation Count:12 |
| 0-12 |
557 | return false; never executed: return false; | 0 |
558 | } | - |
559 | | - |
560 | d->unmapLength = quint32(fileSize); executed (the execution status of this line is deduced): d->unmapLength = quint32(fileSize); | - |
561 | | - |
562 | #ifdef QT_USE_MMAP | - |
563 | | - |
564 | #ifndef MAP_FILE | - |
565 | #define MAP_FILE 0 | - |
566 | #endif | - |
567 | #ifndef MAP_FAILED | - |
568 | #define MAP_FAILED -1 | - |
569 | #endif | - |
570 | | - |
571 | int fd = file.handle(); executed (the execution status of this line is deduced): int fd = file.handle(); | - |
572 | if (fd >= 0) { evaluated: fd >= 0 yes Evaluation Count:11 | yes Evaluation Count:1 |
| 1-11 |
573 | char *ptr; executed (the execution status of this line is deduced): char *ptr; | - |
574 | ptr = reinterpret_cast<char *>( executed (the execution status of this line is deduced): ptr = reinterpret_cast<char *>( | - |
575 | mmap(0, d->unmapLength, // any address, whole file executed (the execution status of this line is deduced): mmap(0, d->unmapLength, | - |
576 | PROT_READ, // read-only memory executed (the execution status of this line is deduced): 0x1, | - |
577 | MAP_FILE | MAP_PRIVATE, // swap-backed map from file executed (the execution status of this line is deduced): 0 | 0x02, | - |
578 | fd, 0)); // from offset 0 of fd executed (the execution status of this line is deduced): fd, 0)); | - |
579 | if (ptr && ptr != reinterpret_cast<char *>(MAP_FAILED)) { partially evaluated: ptr yes Evaluation Count:11 | no Evaluation Count:0 |
partially evaluated: ptr != reinterpret_cast<char *>(((void *) -1)) yes Evaluation Count:11 | no Evaluation Count:0 |
| 0-11 |
580 | file.close(); executed (the execution status of this line is deduced): file.close(); | - |
581 | d->used_mmap = true; executed (the execution status of this line is deduced): d->used_mmap = true; | - |
582 | d->unmapPointer = ptr; executed (the execution status of this line is deduced): d->unmapPointer = ptr; | - |
583 | ok = true; executed (the execution status of this line is deduced): ok = true; | - |
584 | } executed: } Execution Count:11 | 11 |
585 | } executed: } Execution Count:11 | 11 |
586 | #endif // QT_USE_MMAP | - |
587 | | - |
588 | if (!ok) { evaluated: !ok yes Evaluation Count:1 | yes Evaluation Count:11 |
| 1-11 |
589 | d->unmapPointer = new char[d->unmapLength]; executed (the execution status of this line is deduced): d->unmapPointer = new char[d->unmapLength]; | - |
590 | if (d->unmapPointer) { partially evaluated: d->unmapPointer yes Evaluation Count:1 | no Evaluation Count:0 |
| 0-1 |
591 | file.seek(0); executed (the execution status of this line is deduced): file.seek(0); | - |
592 | qint64 readResult = file.read(d->unmapPointer, d->unmapLength); executed (the execution status of this line is deduced): qint64 readResult = file.read(d->unmapPointer, d->unmapLength); | - |
593 | if (readResult == qint64(unmapLength)) partially evaluated: readResult == qint64(unmapLength) yes Evaluation Count:1 | no Evaluation Count:0 |
| 0-1 |
594 | ok = true; executed: ok = true; Execution Count:1 | 1 |
595 | } executed: } Execution Count:1 | 1 |
596 | } executed: } Execution Count:1 | 1 |
597 | } executed: } Execution Count:12 | 12 |
598 | | - |
599 | if (ok && d->do_load(reinterpret_cast<const uchar *>(d->unmapPointer), d->unmapLength, directory)) partially evaluated: ok yes Evaluation Count:14 | no Evaluation Count:0 |
partially evaluated: d->do_load(reinterpret_cast<const uchar *>(d->unmapPointer), d->unmapLength, directory) yes Evaluation Count:14 | no Evaluation Count:0 |
| 0-14 |
600 | return true; executed: return true; Execution Count:14 | 14 |
601 | | - |
602 | #if defined(QT_USE_MMAP) | - |
603 | if (used_mmap) { never evaluated: used_mmap | 0 |
604 | used_mmap = false; never executed (the execution status of this line is deduced): used_mmap = false; | - |
605 | munmap(unmapPointer, unmapLength); never executed (the execution status of this line is deduced): munmap(unmapPointer, unmapLength); | - |
606 | } else | 0 |
607 | #endif | - |
608 | if (!d->resource) never evaluated: !d->resource | 0 |
609 | delete [] unmapPointer; never executed: delete [] unmapPointer; | 0 |
610 | | - |
611 | delete d->resource; never executed (the execution status of this line is deduced): delete d->resource; | - |
612 | d->resource = 0; never executed (the execution status of this line is deduced): d->resource = 0; | - |
613 | d->unmapPointer = 0; never executed (the execution status of this line is deduced): d->unmapPointer = 0; | - |
614 | d->unmapLength = 0; never executed (the execution status of this line is deduced): d->unmapLength = 0; | - |
615 | | - |
616 | return false; never executed: return false; | 0 |
617 | } | - |
618 | | - |
619 | static QString find_translation(const QLocale & locale, | - |
620 | const QString & filename, | - |
621 | const QString & prefix, | - |
622 | const QString & directory, | - |
623 | const QString & suffix) | - |
624 | { | - |
625 | QString path; never executed (the execution status of this line is deduced): QString path; | - |
626 | if (QFileInfo(filename).isRelative()) { never evaluated: QFileInfo(filename).isRelative() | 0 |
627 | path = directory; never executed (the execution status of this line is deduced): path = directory; | - |
628 | if (!path.isEmpty() && !path.endsWith(QLatin1Char('/'))) never evaluated: !path.isEmpty() never evaluated: !path.endsWith(QLatin1Char('/')) | 0 |
629 | path += QLatin1Char('/'); never executed: path += QLatin1Char('/'); | 0 |
630 | } | 0 |
631 | | - |
632 | QFileInfo fi; never executed (the execution status of this line is deduced): QFileInfo fi; | - |
633 | QString realname; never executed (the execution status of this line is deduced): QString realname; | - |
634 | QStringList fuzzyLocales; never executed (the execution status of this line is deduced): QStringList fuzzyLocales; | - |
635 | | - |
636 | // see http://www.unicode.org/reports/tr35/#LanguageMatching for inspiration | - |
637 | | - |
638 | QStringList languages = locale.uiLanguages(); never executed (the execution status of this line is deduced): QStringList languages = locale.uiLanguages(); | - |
639 | #if defined(Q_OS_UNIX) | - |
640 | for (int i = languages.size()-1; i >= 0; --i) { | 0 |
641 | QString lang = languages.at(i); never executed (the execution status of this line is deduced): QString lang = languages.at(i); | - |
642 | QString lowerLang = lang.toLower(); never executed (the execution status of this line is deduced): QString lowerLang = lang.toLower(); | - |
643 | if (lang != lowerLang) never evaluated: lang != lowerLang | 0 |
644 | languages.insert(i+1, lowerLang); never executed: languages.insert(i+1, lowerLang); | 0 |
645 | } | 0 |
646 | #endif | - |
647 | | - |
648 | // try explicit locales names first | - |
649 | foreach (QString localeName, languages) { never executed (the execution status of this line is deduced): for (QForeachContainer<__typeof__(languages)> _container_(languages); !_container_.brk && _container_.i != _container_.e; __extension__ ({ ++_container_.brk; ++_container_.i; })) for (QString localeName = *_container_.i;; __extension__ ({--_container_.brk; break;})) { | - |
650 | localeName.replace(QLatin1Char('-'), QLatin1Char('_')); never executed (the execution status of this line is deduced): localeName.replace(QLatin1Char('-'), QLatin1Char('_')); | - |
651 | | - |
652 | realname = path + filename + prefix + localeName + (suffix.isNull() ? QLatin1String(".qm") : suffix); never evaluated: suffix.isNull() | 0 |
653 | fi.setFile(realname); never executed (the execution status of this line is deduced): fi.setFile(realname); | - |
654 | if (fi.isReadable() && fi.isFile()) never evaluated: fi.isReadable() never evaluated: fi.isFile() | 0 |
655 | return realname; never executed: return realname; | 0 |
656 | | - |
657 | realname = path + filename + prefix + localeName; never executed (the execution status of this line is deduced): realname = path + filename + prefix + localeName; | - |
658 | fi.setFile(realname); never executed (the execution status of this line is deduced): fi.setFile(realname); | - |
659 | if (fi.isReadable() && fi.isFile()) never evaluated: fi.isReadable() never evaluated: fi.isFile() | 0 |
660 | return realname; never executed: return realname; | 0 |
661 | | - |
662 | fuzzyLocales.append(localeName); never executed (the execution status of this line is deduced): fuzzyLocales.append(localeName); | - |
663 | } | 0 |
664 | | - |
665 | // start guessing | - |
666 | foreach (QString localeName, fuzzyLocales) { never executed (the execution status of this line is deduced): for (QForeachContainer<__typeof__(fuzzyLocales)> _container_(fuzzyLocales); !_container_.brk && _container_.i != _container_.e; __extension__ ({ ++_container_.brk; ++_container_.i; })) for (QString localeName = *_container_.i;; __extension__ ({--_container_.brk; break;})) { | - |
667 | for (;;) { never executed (the execution status of this line is deduced): for (;;) { | - |
668 | int rightmost = localeName.lastIndexOf(QLatin1Char('_')); never executed (the execution status of this line is deduced): int rightmost = localeName.lastIndexOf(QLatin1Char('_')); | - |
669 | // no truncations? fail | - |
670 | if (rightmost <= 0) never evaluated: rightmost <= 0 | 0 |
671 | break; | 0 |
672 | localeName.truncate(rightmost); never executed (the execution status of this line is deduced): localeName.truncate(rightmost); | - |
673 | | - |
674 | realname = path + filename + prefix + localeName + (suffix.isNull() ? QLatin1String(".qm") : suffix); never evaluated: suffix.isNull() | 0 |
675 | fi.setFile(realname); never executed (the execution status of this line is deduced): fi.setFile(realname); | - |
676 | if (fi.isReadable() && fi.isFile()) never evaluated: fi.isReadable() never evaluated: fi.isFile() | 0 |
677 | return realname; never executed: return realname; | 0 |
678 | | - |
679 | realname = path + filename + prefix + localeName; never executed (the execution status of this line is deduced): realname = path + filename + prefix + localeName; | - |
680 | fi.setFile(realname); never executed (the execution status of this line is deduced): fi.setFile(realname); | - |
681 | if (fi.isReadable() && fi.isFile()) never evaluated: fi.isReadable() never evaluated: fi.isFile() | 0 |
682 | return realname; never executed: return realname; | 0 |
683 | } | 0 |
684 | } | 0 |
685 | | - |
686 | if (!suffix.isNull()) { never evaluated: !suffix.isNull() | 0 |
687 | realname = path + filename + suffix; never executed (the execution status of this line is deduced): realname = path + filename + suffix; | - |
688 | fi.setFile(realname); never executed (the execution status of this line is deduced): fi.setFile(realname); | - |
689 | if (fi.isReadable() && fi.isFile()) never evaluated: fi.isReadable() never evaluated: fi.isFile() | 0 |
690 | return realname; never executed: return realname; | 0 |
691 | } | 0 |
692 | | - |
693 | realname = path + filename + prefix; never executed (the execution status of this line is deduced): realname = path + filename + prefix; | - |
694 | fi.setFile(realname); never executed (the execution status of this line is deduced): fi.setFile(realname); | - |
695 | if (fi.isReadable() && fi.isFile()) never evaluated: fi.isReadable() never evaluated: fi.isFile() | 0 |
696 | return realname; never executed: return realname; | 0 |
697 | | - |
698 | realname = path + filename; never executed (the execution status of this line is deduced): realname = path + filename; | - |
699 | fi.setFile(realname); never executed (the execution status of this line is deduced): fi.setFile(realname); | - |
700 | if (fi.isReadable() && fi.isFile()) never evaluated: fi.isReadable() never evaluated: fi.isFile() | 0 |
701 | return realname; never executed: return realname; | 0 |
702 | | - |
703 | return QString(); never executed: return QString(); | 0 |
704 | } | - |
705 | | - |
706 | /*! | - |
707 | \since 4.8 | - |
708 | | - |
709 | Loads \a filename + \a prefix + \l{QLocale::uiLanguages()}{ui language | - |
710 | name} + \a suffix (".qm" if the \a suffix is not specified), which may be | - |
711 | an absolute file name or relative to \a directory. Returns true if the | - |
712 | translation is successfully loaded; otherwise returns false. | - |
713 | | - |
714 | The previous contents of this translator object are discarded. | - |
715 | | - |
716 | If the file name does not exist, other file names are tried | - |
717 | in the following order: | - |
718 | | - |
719 | \list 1 | - |
720 | \li File name without \a suffix appended. | - |
721 | \li File name with ui language part after a "_" character stripped and \a suffix. | - |
722 | \li File name with ui language part stripped without \a suffix appended. | - |
723 | \li File name with ui language part stripped further, etc. | - |
724 | \endlist | - |
725 | | - |
726 | For example, an application running in the \a locale with the following | - |
727 | \l{QLocale::uiLanguages()}{ui languages} - "es", "fr-CA", "de" might call | - |
728 | load(QLocale::system(), "foo", ".", "/opt/foolib", ".qm"). load() would | - |
729 | replace '-' (dash) with '_' (underscore) in the ui language and then try to | - |
730 | open the first existing readable file from this list: | - |
731 | | - |
732 | \list 1 | - |
733 | \li \c /opt/foolib/foo.es.qm | - |
734 | \li \c /opt/foolib/foo.es | - |
735 | \li \c /opt/foolib/foo.fr_CA.qm | - |
736 | \li \c /opt/foolib/foo.fr_CA | - |
737 | \li \c /opt/foolib/foo.de.qm | - |
738 | \li \c /opt/foolib/foo.de | - |
739 | \li \c /opt/foolib/foo.fr.qm | - |
740 | \li \c /opt/foolib/foo.fr | - |
741 | \li \c /opt/foolib/foo.qm | - |
742 | \li \c /opt/foolib/foo. | - |
743 | \li \c /opt/foolib/foo | - |
744 | \endlist | - |
745 | | - |
746 | On operating systems where file system is case sensitive, QTranslator also | - |
747 | tries to load a lower-cased version of the locale name. | - |
748 | */ | - |
749 | bool QTranslator::load(const QLocale & locale, | - |
750 | const QString & filename, | - |
751 | const QString & prefix, | - |
752 | const QString & directory, | - |
753 | const QString & suffix) | - |
754 | { | - |
755 | Q_D(QTranslator); never executed (the execution status of this line is deduced): QTranslatorPrivate * const d = d_func(); | - |
756 | d->clear(); never executed (the execution status of this line is deduced): d->clear(); | - |
757 | QString fname = find_translation(locale, filename, prefix, directory, suffix); never executed (the execution status of this line is deduced): QString fname = find_translation(locale, filename, prefix, directory, suffix); | - |
758 | return !fname.isEmpty() && d->do_load(fname, directory); never executed: return !fname.isEmpty() && d->do_load(fname, directory); | 0 |
759 | } | - |
760 | | - |
761 | /*! | - |
762 | \overload load() | - |
763 | | - |
764 | Loads the QM file data \a data of length \a len into the | - |
765 | translator. | - |
766 | | - |
767 | The data is not copied. The caller must be able to guarantee that \a data | - |
768 | will not be deleted or modified. | - |
769 | | - |
770 | \a directory is only used to specify the base directory when loading the dependencies | - |
771 | of a QM file. If the file does not have dependencies, this argument is ignored. | - |
772 | */ | - |
773 | bool QTranslator::load(const uchar *data, int len, const QString &directory) | - |
774 | { | - |
775 | Q_D(QTranslator); executed (the execution status of this line is deduced): QTranslatorPrivate * const d = d_func(); | - |
776 | d->clear(); executed (the execution status of this line is deduced): d->clear(); | - |
777 | | - |
778 | if (!data || len < MagicLength || memcmp(data, magic, MagicLength)) partially evaluated: !data no Evaluation Count:0 | yes Evaluation Count:2 |
partially evaluated: len < MagicLength no Evaluation Count:0 | yes Evaluation Count:2 |
partially evaluated: memcmp(data, magic, MagicLength) no Evaluation Count:0 | yes Evaluation Count:2 |
| 0-2 |
779 | return false; never executed: return false; | 0 |
780 | | - |
781 | return d->do_load(data, len, directory); executed: return d->do_load(data, len, directory); Execution Count:2 | 2 |
782 | } | - |
783 | | - |
784 | static quint8 read8(const uchar *data) | - |
785 | { | - |
786 | return qFromBigEndian<quint8>(data); executed: return qFromBigEndian<quint8>(data); Execution Count:902 | 902 |
787 | } | - |
788 | | - |
789 | static quint16 read16(const uchar *data) | - |
790 | { | - |
791 | return qFromBigEndian<quint16>(data); never executed: return qFromBigEndian<quint16>(data); | 0 |
792 | } | - |
793 | | - |
794 | static quint32 read32(const uchar *data) | - |
795 | { | - |
796 | return qFromBigEndian<quint32>(data); executed: return qFromBigEndian<quint32>(data); Execution Count:3331 | 3331 |
797 | } | - |
798 | | - |
799 | bool QTranslatorPrivate::do_load(const uchar *data, int len, const QString &directory) | - |
800 | { | - |
801 | bool ok = true; executed (the execution status of this line is deduced): bool ok = true; | - |
802 | const uchar *end = data + len; executed (the execution status of this line is deduced): const uchar *end = data + len; | - |
803 | | - |
804 | data += MagicLength; executed (the execution status of this line is deduced): data += MagicLength; | - |
805 | | - |
806 | QStringList dependencies; executed (the execution status of this line is deduced): QStringList dependencies; | - |
807 | while (data < end - 4) { evaluated: data < end - 4 yes Evaluation Count:49 | yes Evaluation Count:16 |
| 16-49 |
808 | quint8 tag = read8(data++); executed (the execution status of this line is deduced): quint8 tag = read8(data++); | - |
809 | quint32 blockLen = read32(data); executed (the execution status of this line is deduced): quint32 blockLen = read32(data); | - |
810 | data += 4; executed (the execution status of this line is deduced): data += 4; | - |
811 | if (!tag || !blockLen) partially evaluated: !tag no Evaluation Count:0 | yes Evaluation Count:49 |
partially evaluated: !blockLen no Evaluation Count:0 | yes Evaluation Count:49 |
| 0-49 |
812 | break; | 0 |
813 | if (quint32(end - data) < blockLen) { partially evaluated: quint32(end - data) < blockLen no Evaluation Count:0 | yes Evaluation Count:49 |
| 0-49 |
814 | ok = false; never executed (the execution status of this line is deduced): ok = false; | - |
815 | break; | 0 |
816 | } | - |
817 | | - |
818 | if (tag == QTranslatorPrivate::Contexts) { partially evaluated: tag == QTranslatorPrivate::Contexts no Evaluation Count:0 | yes Evaluation Count:49 |
| 0-49 |
819 | contextArray = data; never executed (the execution status of this line is deduced): contextArray = data; | - |
820 | contextLength = blockLen; never executed (the execution status of this line is deduced): contextLength = blockLen; | - |
821 | } else if (tag == QTranslatorPrivate::Hashes) { never executed: } evaluated: tag == QTranslatorPrivate::Hashes yes Evaluation Count:16 | yes Evaluation Count:33 |
| 0-33 |
822 | offsetArray = data; executed (the execution status of this line is deduced): offsetArray = data; | - |
823 | offsetLength = blockLen; executed (the execution status of this line is deduced): offsetLength = blockLen; | - |
824 | } else if (tag == QTranslatorPrivate::Messages) { executed: } Execution Count:16 evaluated: tag == QTranslatorPrivate::Messages yes Evaluation Count:16 | yes Evaluation Count:17 |
| 16-17 |
825 | messageArray = data; executed (the execution status of this line is deduced): messageArray = data; | - |
826 | messageLength = blockLen; executed (the execution status of this line is deduced): messageLength = blockLen; | - |
827 | } else if (tag == QTranslatorPrivate::NumerusRules) { executed: } Execution Count:16 evaluated: tag == QTranslatorPrivate::NumerusRules yes Evaluation Count:15 | yes Evaluation Count:2 |
| 2-16 |
828 | numerusRulesArray = data; executed (the execution status of this line is deduced): numerusRulesArray = data; | - |
829 | numerusRulesLength = blockLen; executed (the execution status of this line is deduced): numerusRulesLength = blockLen; | - |
830 | } else if (tag == QTranslatorPrivate::Dependencies) { executed: } Execution Count:15 partially evaluated: tag == QTranslatorPrivate::Dependencies yes Evaluation Count:2 | no Evaluation Count:0 |
| 0-15 |
831 | QDataStream stream(QByteArray::fromRawData((const char*)data, blockLen)); executed (the execution status of this line is deduced): QDataStream stream(QByteArray::fromRawData((const char*)data, blockLen)); | - |
832 | QString dep; executed (the execution status of this line is deduced): QString dep; | - |
833 | while (!stream.atEnd()) { evaluated: !stream.atEnd() yes Evaluation Count:2 | yes Evaluation Count:2 |
| 2 |
834 | stream >> dep; executed (the execution status of this line is deduced): stream >> dep; | - |
835 | dependencies.append(dep); executed (the execution status of this line is deduced): dependencies.append(dep); | - |
836 | } executed: } Execution Count:2 | 2 |
837 | } executed: } Execution Count:2 | 2 |
838 | | - |
839 | data += blockLen; executed (the execution status of this line is deduced): data += blockLen; | - |
840 | } executed: } Execution Count:49 | 49 |
841 | | - |
842 | if (dependencies.isEmpty() && (!offsetArray || !messageArray)) evaluated: dependencies.isEmpty() yes Evaluation Count:14 | yes Evaluation Count:2 |
partially evaluated: !offsetArray no Evaluation Count:0 | yes Evaluation Count:14 |
partially evaluated: !messageArray no Evaluation Count:0 | yes Evaluation Count:14 |
| 0-14 |
843 | ok = false; never executed: ok = false; | 0 |
844 | if (ok && !isValidNumerusRules(numerusRulesArray, numerusRulesLength)) partially evaluated: ok yes Evaluation Count:16 | no Evaluation Count:0 |
partially evaluated: !isValidNumerusRules(numerusRulesArray, numerusRulesLength) no Evaluation Count:0 | yes Evaluation Count:16 |
| 0-16 |
845 | ok = false; never executed: ok = false; | 0 |
846 | if (ok) { partially evaluated: ok yes Evaluation Count:16 | no Evaluation Count:0 |
| 0-16 |
847 | const int dependenciesCount = dependencies.count(); executed (the execution status of this line is deduced): const int dependenciesCount = dependencies.count(); | - |
848 | subTranslators.reserve(dependenciesCount); executed (the execution status of this line is deduced): subTranslators.reserve(dependenciesCount); | - |
849 | for (int i = 0 ; i < dependenciesCount; ++i) { evaluated: i < dependenciesCount yes Evaluation Count:2 | yes Evaluation Count:16 |
| 2-16 |
850 | QTranslator *translator = new QTranslator; executed (the execution status of this line is deduced): QTranslator *translator = new QTranslator; | - |
851 | subTranslators.append(translator); executed (the execution status of this line is deduced): subTranslators.append(translator); | - |
852 | ok = translator->load(dependencies.at(i), directory); executed (the execution status of this line is deduced): ok = translator->load(dependencies.at(i), directory); | - |
853 | if (!ok) partially evaluated: !ok no Evaluation Count:0 | yes Evaluation Count:2 |
| 0-2 |
854 | break; | 0 |
855 | } executed: } Execution Count:2 | 2 |
856 | | - |
857 | // In case some dependencies fail to load, unload all the other ones too. | - |
858 | if (!ok) { partially evaluated: !ok no Evaluation Count:0 | yes Evaluation Count:16 |
| 0-16 |
859 | qDeleteAll(subTranslators); never executed (the execution status of this line is deduced): qDeleteAll(subTranslators); | - |
860 | subTranslators.clear(); never executed (the execution status of this line is deduced): subTranslators.clear(); | - |
861 | } | 0 |
862 | } executed: } Execution Count:16 | 16 |
863 | | - |
864 | if (!ok) { partially evaluated: !ok no Evaluation Count:0 | yes Evaluation Count:16 |
| 0-16 |
865 | messageArray = 0; never executed (the execution status of this line is deduced): messageArray = 0; | - |
866 | contextArray = 0; never executed (the execution status of this line is deduced): contextArray = 0; | - |
867 | offsetArray = 0; never executed (the execution status of this line is deduced): offsetArray = 0; | - |
868 | numerusRulesArray = 0; never executed (the execution status of this line is deduced): numerusRulesArray = 0; | - |
869 | messageLength = 0; never executed (the execution status of this line is deduced): messageLength = 0; | - |
870 | contextLength = 0; never executed (the execution status of this line is deduced): contextLength = 0; | - |
871 | offsetLength = 0; never executed (the execution status of this line is deduced): offsetLength = 0; | - |
872 | numerusRulesLength = 0; never executed (the execution status of this line is deduced): numerusRulesLength = 0; | - |
873 | } | 0 |
874 | | - |
875 | return ok; executed: return ok; Execution Count:16 | 16 |
876 | } | - |
877 | | - |
878 | static QString getMessage(const uchar *m, const uchar *end, const char *context, | - |
879 | const char *sourceText, const char *comment, uint numerus) | - |
880 | { | - |
881 | const uchar *tn = 0; executed (the execution status of this line is deduced): const uchar *tn = 0; | - |
882 | uint tn_length = 0; executed (the execution status of this line is deduced): uint tn_length = 0; | - |
883 | | - |
884 | for (;;) { executed (the execution status of this line is deduced): for (;;) { | - |
885 | uchar tag = 0; executed (the execution status of this line is deduced): uchar tag = 0; | - |
886 | if (m < end) partially evaluated: m < end yes Evaluation Count:853 | no Evaluation Count:0 |
| 0-853 |
887 | tag = read8(m++); executed: tag = read8(m++); Execution Count:853 | 853 |
888 | switch((Tag)tag) { | - |
889 | case Tag_End: | - |
890 | goto end; executed: goto end; Execution Count:144 | 144 |
891 | case Tag_Translation: { | - |
892 | int len = read32(m); executed (the execution status of this line is deduced): int len = read32(m); | - |
893 | if (len % 1) partially evaluated: len % 1 no Evaluation Count:0 | yes Evaluation Count:187 |
| 0-187 |
894 | return QString(); never executed: return QString(); | 0 |
895 | m += 4; executed (the execution status of this line is deduced): m += 4; | - |
896 | if (!numerus--) { evaluated: !numerus-- yes Evaluation Count:173 | yes Evaluation Count:14 |
| 14-173 |
897 | tn_length = len; executed (the execution status of this line is deduced): tn_length = len; | - |
898 | tn = m; executed (the execution status of this line is deduced): tn = m; | - |
899 | } executed: } Execution Count:173 | 173 |
900 | m += len; executed (the execution status of this line is deduced): m += len; | - |
901 | break; executed: break; Execution Count:187 | 187 |
902 | } | - |
903 | case Tag_Obsolete1: | - |
904 | m += 4; executed (the execution status of this line is deduced): m += 4; | - |
905 | break; executed: break; Execution Count:3 | 3 |
906 | case Tag_SourceText: { | - |
907 | quint32 len = read32(m); executed (the execution status of this line is deduced): quint32 len = read32(m); | - |
908 | m += 4; executed (the execution status of this line is deduced): m += 4; | - |
909 | if (!match(m, sourceText, len)) partially evaluated: !match(m, sourceText, len) no Evaluation Count:0 | yes Evaluation Count:173 |
| 0-173 |
910 | return QString(); never executed: return QString(); | 0 |
911 | m += len; executed (the execution status of this line is deduced): m += len; | - |
912 | } | - |
913 | break; executed: break; Execution Count:173 | 173 |
914 | case Tag_Context: { | - |
915 | quint32 len = read32(m); executed (the execution status of this line is deduced): quint32 len = read32(m); | - |
916 | m += 4; executed (the execution status of this line is deduced): m += 4; | - |
917 | if (!match(m, context, len)) evaluated: !match(m, context, len) yes Evaluation Count:29 | yes Evaluation Count:144 |
| 29-144 |
918 | return QString(); executed: return QString(); Execution Count:29 | 29 |
919 | m += len; executed (the execution status of this line is deduced): m += len; | - |
920 | } | - |
921 | break; executed: break; Execution Count:144 | 144 |
922 | case Tag_Comment: { | - |
923 | quint32 len = read32(m); executed (the execution status of this line is deduced): quint32 len = read32(m); | - |
924 | m += 4; executed (the execution status of this line is deduced): m += 4; | - |
925 | if (*m && !match(m, comment, len)) evaluated: *m yes Evaluation Count:167 | yes Evaluation Count:6 |
partially evaluated: !match(m, comment, len) no Evaluation Count:0 | yes Evaluation Count:167 |
| 0-167 |
926 | return QString(); never executed: return QString(); | 0 |
927 | m += len; executed (the execution status of this line is deduced): m += len; | - |
928 | } | - |
929 | break; executed: break; Execution Count:173 | 173 |
930 | default: | - |
931 | return QString(); never executed: return QString(); | 0 |
932 | } | - |
933 | } executed: } Execution Count:680 | 680 |
934 | end: code before this statement never executed: end: | 0 |
935 | if (!tn) partially evaluated: !tn no Evaluation Count:0 | yes Evaluation Count:144 |
| 0-144 |
936 | return QString(); never executed: return QString(); | 0 |
937 | QString str = QString((const QChar *)tn, tn_length/2); executed (the execution status of this line is deduced): QString str = QString((const QChar *)tn, tn_length/2); | - |
938 | if (QSysInfo::ByteOrder == QSysInfo::LittleEndian) { partially evaluated: QSysInfo::ByteOrder == QSysInfo::LittleEndian yes Evaluation Count:144 | no Evaluation Count:0 |
| 0-144 |
939 | for (int i = 0; i < str.length(); ++i) evaluated: i < str.length() yes Evaluation Count:818 | yes Evaluation Count:144 |
| 144-818 |
940 | str[i] = QChar((str.at(i).unicode() >> 8) + ((str.at(i).unicode() << 8) & 0xff00)); executed: str[i] = QChar((str.at(i).unicode() >> 8) + ((str.at(i).unicode() << 8) & 0xff00)); Execution Count:818 | 818 |
941 | } executed: } Execution Count:144 | 144 |
942 | return str; executed: return str; Execution Count:144 | 144 |
943 | } | - |
944 | | - |
945 | QString QTranslatorPrivate::do_translate(const char *context, const char *sourceText, | - |
946 | const char *comment, int n) const | - |
947 | { | - |
948 | if (context == 0) partially evaluated: context == 0 no Evaluation Count:0 | yes Evaluation Count:220 |
| 0-220 |
949 | context = ""; never executed: context = ""; | 0 |
950 | if (sourceText == 0) partially evaluated: sourceText == 0 no Evaluation Count:0 | yes Evaluation Count:220 |
| 0-220 |
951 | sourceText = ""; never executed: sourceText = ""; | 0 |
952 | if (comment == 0) evaluated: comment == 0 yes Evaluation Count:163 | yes Evaluation Count:57 |
| 57-163 |
953 | comment = ""; executed: comment = ""; Execution Count:163 | 163 |
954 | | - |
955 | uint numerus = 0; executed (the execution status of this line is deduced): uint numerus = 0; | - |
956 | size_t numItems = 0; executed (the execution status of this line is deduced): size_t numItems = 0; | - |
957 | | - |
958 | if (!offsetLength) partially evaluated: !offsetLength no Evaluation Count:0 | yes Evaluation Count:220 |
| 0-220 |
959 | goto searchDependencies; never executed: goto searchDependencies; | 0 |
960 | | - |
961 | /* | - |
962 | Check if the context belongs to this QTranslator. If many | - |
963 | translators are installed, this step is necessary. | - |
964 | */ | - |
965 | if (contextLength) { partially evaluated: contextLength no Evaluation Count:0 | yes Evaluation Count:220 |
| 0-220 |
966 | quint16 hTableSize = read16(contextArray); never executed (the execution status of this line is deduced): quint16 hTableSize = read16(contextArray); | - |
967 | uint g = elfHash(context) % hTableSize; never executed (the execution status of this line is deduced): uint g = elfHash(context) % hTableSize; | - |
968 | const uchar *c = contextArray + 2 + (g << 1); never executed (the execution status of this line is deduced): const uchar *c = contextArray + 2 + (g << 1); | - |
969 | quint16 off = read16(c); never executed (the execution status of this line is deduced): quint16 off = read16(c); | - |
970 | c += 2; never executed (the execution status of this line is deduced): c += 2; | - |
971 | if (off == 0) never evaluated: off == 0 | 0 |
972 | return QString(); never executed: return QString(); | 0 |
973 | c = contextArray + (2 + (hTableSize << 1) + (off << 1)); never executed (the execution status of this line is deduced): c = contextArray + (2 + (hTableSize << 1) + (off << 1)); | - |
974 | | - |
975 | for (;;) { never executed (the execution status of this line is deduced): for (;;) { | - |
976 | quint8 len = read8(c++); never executed (the execution status of this line is deduced): quint8 len = read8(c++); | - |
977 | if (len == 0) never evaluated: len == 0 | 0 |
978 | return QString(); never executed: return QString(); | 0 |
979 | if (match(c, context, len)) never evaluated: match(c, context, len) | 0 |
980 | break; | 0 |
981 | c += len; never executed (the execution status of this line is deduced): c += len; | - |
982 | } | 0 |
983 | } | 0 |
984 | | - |
985 | numItems = offsetLength / (2 * sizeof(quint32)); executed (the execution status of this line is deduced): numItems = offsetLength / (2 * sizeof(quint32)); | - |
986 | if (!numItems) partially evaluated: !numItems no Evaluation Count:0 | yes Evaluation Count:220 |
| 0-220 |
987 | goto searchDependencies; never executed: goto searchDependencies; | 0 |
988 | | - |
989 | if (n >= 0) evaluated: n >= 0 yes Evaluation Count:9 | yes Evaluation Count:211 |
| 9-211 |
990 | numerus = numerusHelper(n, numerusRulesArray, numerusRulesLength); executed: numerus = numerusHelper(n, numerusRulesArray, numerusRulesLength); Execution Count:9 | 9 |
991 | | - |
992 | for (;;) { executed (the execution status of this line is deduced): for (;;) { | - |
993 | quint32 h = 0; executed (the execution status of this line is deduced): quint32 h = 0; | - |
994 | elfHash_continue(sourceText, h); executed (the execution status of this line is deduced): elfHash_continue(sourceText, h); | - |
995 | elfHash_continue(comment, h); executed (the execution status of this line is deduced): elfHash_continue(comment, h); | - |
996 | elfHash_finish(h); executed (the execution status of this line is deduced): elfHash_finish(h); | - |
997 | | - |
998 | const uchar *start = offsetArray; executed (the execution status of this line is deduced): const uchar *start = offsetArray; | - |
999 | const uchar *end = start + ((numItems-1) << 3); executed (the execution status of this line is deduced): const uchar *end = start + ((numItems-1) << 3); | - |
1000 | while (start <= end) { evaluated: start <= end yes Evaluation Count:1871 | yes Evaluation Count:99 |
| 99-1871 |
1001 | const uchar *middle = start + (((end - start) >> 4) << 3); executed (the execution status of this line is deduced): const uchar *middle = start + (((end - start) >> 4) << 3); | - |
1002 | uint hash = read32(middle); executed (the execution status of this line is deduced): uint hash = read32(middle); | - |
1003 | if (h == hash) { evaluated: h == hash yes Evaluation Count:173 | yes Evaluation Count:1698 |
| 173-1698 |
1004 | start = middle; executed (the execution status of this line is deduced): start = middle; | - |
1005 | break; executed: break; Execution Count:173 | 173 |
1006 | } else if (hash < h) { evaluated: hash < h yes Evaluation Count:685 | yes Evaluation Count:1013 |
| 685-1013 |
1007 | start = middle + 8; executed (the execution status of this line is deduced): start = middle + 8; | - |
1008 | } else { executed: } Execution Count:685 | 685 |
1009 | end = middle - 8; executed (the execution status of this line is deduced): end = middle - 8; | - |
1010 | } executed: } Execution Count:1013 | 1013 |
1011 | } | - |
1012 | | - |
1013 | if (start <= end) { evaluated: start <= end yes Evaluation Count:173 | yes Evaluation Count:99 |
| 99-173 |
1014 | // go back on equal key | - |
1015 | while (start != offsetArray && read32(start) == read32(start-8)) evaluated: start != offsetArray yes Evaluation Count:165 | yes Evaluation Count:8 |
partially evaluated: read32(start) == read32(start-8) no Evaluation Count:0 | yes Evaluation Count:165 |
| 0-165 |
1016 | start -= 8; never executed: start -= 8; | 0 |
1017 | | - |
1018 | while (start < offsetArray + offsetLength) { partially evaluated: start < offsetArray + offsetLength yes Evaluation Count:202 | no Evaluation Count:0 |
| 0-202 |
1019 | quint32 rh = read32(start); executed (the execution status of this line is deduced): quint32 rh = read32(start); | - |
1020 | start += 4; executed (the execution status of this line is deduced): start += 4; | - |
1021 | if (rh != h) evaluated: rh != h yes Evaluation Count:29 | yes Evaluation Count:173 |
| 29-173 |
1022 | break; executed: break; Execution Count:29 | 29 |
1023 | quint32 ro = read32(start); executed (the execution status of this line is deduced): quint32 ro = read32(start); | - |
1024 | start += 4; executed (the execution status of this line is deduced): start += 4; | - |
1025 | QString tn = getMessage(messageArray + ro, messageArray + messageLength, context, executed (the execution status of this line is deduced): QString tn = getMessage(messageArray + ro, messageArray + messageLength, context, | - |
1026 | sourceText, comment, numerus); executed (the execution status of this line is deduced): sourceText, comment, numerus); | - |
1027 | if (!tn.isNull()) evaluated: !tn.isNull() yes Evaluation Count:144 | yes Evaluation Count:29 |
| 29-144 |
1028 | return tn; executed: return tn; Execution Count:144 | 144 |
1029 | } executed: } Execution Count:29 | 29 |
1030 | } executed: } Execution Count:29 | 29 |
1031 | if (!comment[0]) evaluated: !comment[0] yes Evaluation Count:76 | yes Evaluation Count:52 |
| 52-76 |
1032 | break; executed: break; Execution Count:76 | 76 |
1033 | comment = ""; executed (the execution status of this line is deduced): comment = ""; | - |
1034 | } executed: } Execution Count:52 | 52 |
1035 | | - |
1036 | searchDependencies: code before this statement executed: searchDependencies: Execution Count:76 | 76 |
1037 | foreach (QTranslator *translator, subTranslators) { executed (the execution status of this line is deduced): for (QForeachContainer<__typeof__(subTranslators)> _container_(subTranslators); !_container_.brk && _container_.i != _container_.e; __extension__ ({ ++_container_.brk; ++_container_.i; })) for (QTranslator *translator = *_container_.i;; __extension__ ({--_container_.brk; break;})) { | - |
1038 | QString tn = translator->translate(context, sourceText, comment, n); executed (the execution status of this line is deduced): QString tn = translator->translate(context, sourceText, comment, n); | - |
1039 | if (!tn.isNull()) partially evaluated: !tn.isNull() yes Evaluation Count:5 | no Evaluation Count:0 |
| 0-5 |
1040 | return tn; executed: return tn; Execution Count:5 | 5 |
1041 | } | 0 |
1042 | return QString(); executed: return QString(); Execution Count:71 | 71 |
1043 | } | - |
1044 | | - |
1045 | /*! | - |
1046 | Empties this translator of all contents. | - |
1047 | | - |
1048 | This function works with stripped translator files. | - |
1049 | */ | - |
1050 | | - |
1051 | void QTranslatorPrivate::clear() | - |
1052 | { | - |
1053 | Q_Q(QTranslator); executed (the execution status of this line is deduced): QTranslator * const q = q_func(); | - |
1054 | if (unmapPointer && unmapLength) { evaluated: unmapPointer yes Evaluation Count:14 | yes Evaluation Count:20 |
partially evaluated: unmapLength yes Evaluation Count:14 | no Evaluation Count:0 |
| 0-20 |
1055 | #if defined(QT_USE_MMAP) | - |
1056 | if (used_mmap) { evaluated: used_mmap yes Evaluation Count:11 | yes Evaluation Count:3 |
| 3-11 |
1057 | used_mmap = false; executed (the execution status of this line is deduced): used_mmap = false; | - |
1058 | munmap(unmapPointer, unmapLength); executed (the execution status of this line is deduced): munmap(unmapPointer, unmapLength); | - |
1059 | } else executed: } Execution Count:11 | 11 |
1060 | #endif | - |
1061 | if (!resource) evaluated: !resource yes Evaluation Count:1 | yes Evaluation Count:2 |
| 1-2 |
1062 | delete [] unmapPointer; executed: delete [] unmapPointer; Execution Count:1 | 1 |
1063 | } | - |
1064 | | - |
1065 | delete resource; executed (the execution status of this line is deduced): delete resource; | - |
1066 | resource = 0; executed (the execution status of this line is deduced): resource = 0; | - |
1067 | unmapPointer = 0; executed (the execution status of this line is deduced): unmapPointer = 0; | - |
1068 | unmapLength = 0; executed (the execution status of this line is deduced): unmapLength = 0; | - |
1069 | messageArray = 0; executed (the execution status of this line is deduced): messageArray = 0; | - |
1070 | contextArray = 0; executed (the execution status of this line is deduced): contextArray = 0; | - |
1071 | offsetArray = 0; executed (the execution status of this line is deduced): offsetArray = 0; | - |
1072 | numerusRulesArray = 0; executed (the execution status of this line is deduced): numerusRulesArray = 0; | - |
1073 | messageLength = 0; executed (the execution status of this line is deduced): messageLength = 0; | - |
1074 | contextLength = 0; executed (the execution status of this line is deduced): contextLength = 0; | - |
1075 | offsetLength = 0; executed (the execution status of this line is deduced): offsetLength = 0; | - |
1076 | numerusRulesLength = 0; executed (the execution status of this line is deduced): numerusRulesLength = 0; | - |
1077 | | - |
1078 | qDeleteAll(subTranslators); executed (the execution status of this line is deduced): qDeleteAll(subTranslators); | - |
1079 | subTranslators.clear(); executed (the execution status of this line is deduced): subTranslators.clear(); | - |
1080 | | - |
1081 | if (QCoreApplicationPrivate::isTranslatorInstalled(q)) evaluated: QCoreApplicationPrivate::isTranslatorInstalled(q) yes Evaluation Count:3 | yes Evaluation Count:31 |
| 3-31 |
1082 | QCoreApplication::postEvent(QCoreApplication::instance(), executed: QCoreApplication::postEvent(QCoreApplication::instance(), new QEvent(QEvent::LanguageChange)); Execution Count:3 | 3 |
1083 | new QEvent(QEvent::LanguageChange)); executed: QCoreApplication::postEvent(QCoreApplication::instance(), new QEvent(QEvent::LanguageChange)); Execution Count:3 | 3 |
1084 | } executed: } Execution Count:34 | 34 |
1085 | | - |
1086 | /*! | - |
1087 | \overload translate() | - |
1088 | | - |
1089 | Returns the translation for the key (\a context, \a sourceText, | - |
1090 | \a disambiguation). If none is found, also tries (\a context, \a | - |
1091 | sourceText, ""). If that still fails, returns a null string. | - |
1092 | | - |
1093 | If \a n is not -1, it is used to choose an appropriate form for | - |
1094 | the translation (e.g. "%n file found" vs. "%n files found"). | - |
1095 | | - |
1096 | If you need to programatically insert translations into a | - |
1097 | QTranslator, this function can be reimplemented. | - |
1098 | | - |
1099 | \sa load() | - |
1100 | */ | - |
1101 | QString QTranslator::translate(const char *context, const char *sourceText, const char *disambiguation, | - |
1102 | int n) const | - |
1103 | { | - |
1104 | Q_D(const QTranslator); executed (the execution status of this line is deduced): const QTranslatorPrivate * const d = d_func(); | - |
1105 | return d->do_translate(context, sourceText, disambiguation, n); executed: return d->do_translate(context, sourceText, disambiguation, n); Execution Count:220 | 220 |
1106 | } | - |
1107 | | - |
1108 | /*! | - |
1109 | Returns true if this translator is empty, otherwise returns false. | - |
1110 | This function works with stripped and unstripped translation files. | - |
1111 | */ | - |
1112 | bool QTranslator::isEmpty() const | - |
1113 | { | - |
1114 | Q_D(const QTranslator); executed (the execution status of this line is deduced): const QTranslatorPrivate * const d = d_func(); | - |
1115 | return !d->unmapPointer && !d->unmapLength && !d->messageArray && executed: return !d->unmapPointer && !d->unmapLength && !d->messageArray && !d->offsetArray && !d->contextArray && d->subTranslators.isEmpty(); Execution Count:39 | 39 |
1116 | !d->offsetArray && !d->contextArray && d->subTranslators.isEmpty(); executed: return !d->unmapPointer && !d->unmapLength && !d->messageArray && !d->offsetArray && !d->contextArray && d->subTranslators.isEmpty(); Execution Count:39 | 39 |
1117 | } | - |
1118 | | - |
1119 | QT_END_NAMESPACE | - |
1120 | | - |
1121 | #endif // QT_NO_TRANSLATION | - |
1122 | | - |
| | |