qtranslator.cpp

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

Generated by Squish Coco Non-Commercial 4.3.0-BETA-master-30-08-2018-4cb69e9