| Absolute File Name: | /home/qt/qt5_coco/qt5/qtbase/src/corelib/kernel/qtranslator.cpp |
| Switch to Source code | Preprocessed file |
| Line | Source | Count | ||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 1 | - | |||||||||||||||||||
| 2 | - | |||||||||||||||||||
| 3 | - | |||||||||||||||||||
| 4 | - | |||||||||||||||||||
| 5 | - | |||||||||||||||||||
| 6 | - | |||||||||||||||||||
| 7 | - | |||||||||||||||||||
| 8 | - | |||||||||||||||||||
| 9 | - | |||||||||||||||||||
| 10 | - | |||||||||||||||||||
| 11 | - | |||||||||||||||||||
| 12 | - | |||||||||||||||||||
| 13 | - | |||||||||||||||||||
| 14 | - | |||||||||||||||||||
| 15 | - | |||||||||||||||||||
| 16 | - | |||||||||||||||||||
| 17 | - | |||||||||||||||||||
| 18 | - | |||||||||||||||||||
| 19 | - | |||||||||||||||||||
| 20 | - | |||||||||||||||||||
| 21 | enum Tag { Tag_End = 1, Tag_SourceText16, Tag_Translation, Tag_Context16, Tag_Obsolete1, | - | ||||||||||||||||||
| 22 | Tag_SourceText, Tag_Context, Tag_Comment, Tag_Obsolete2 }; | - | ||||||||||||||||||
| 23 | - | |||||||||||||||||||
| 24 | - | |||||||||||||||||||
| 25 | - | |||||||||||||||||||
| 26 | - | |||||||||||||||||||
| 27 | - | |||||||||||||||||||
| 28 | - | |||||||||||||||||||
| 29 | - | |||||||||||||||||||
| 30 | static const int MagicLength = 16; | - | ||||||||||||||||||
| 31 | static const uchar magic[MagicLength] = { | - | ||||||||||||||||||
| 32 | 0x3c, 0xb8, 0x64, 0x18, 0xca, 0xef, 0x9c, 0x95, | - | ||||||||||||||||||
| 33 | 0xcd, 0x21, 0x1c, 0xbf, 0x60, 0xa1, 0xbd, 0xdd | - | ||||||||||||||||||
| 34 | }; | - | ||||||||||||||||||
| 35 | - | |||||||||||||||||||
| 36 | static bool match(const uchar *found, uint foundLen, const char *target, uint targetLen) | - | ||||||||||||||||||
| 37 | { | - | ||||||||||||||||||
| 38 | - | |||||||||||||||||||
| 39 | - | |||||||||||||||||||
| 40 | if (foundLen > 0
| 12-346 | ||||||||||||||||||
| 41 | -- executed 12 times by 1 test: foundLen;--foundLen;Executed by:
executed 12 times by 1 test: --foundLen;Executed by:
| 12 | ||||||||||||||||||
| 42 | return executed 513 times by 2 tests: ((return ((targetLen == foundLen) && memcmp(found, target, foundLen) == 0);Executed by:
executed 513 times by 2 tests: return ((targetLen == foundLen) && memcmp(found, target, foundLen) == 0);Executed by:
| 0-513 | ||||||||||||||||||
| 43 | } | - | ||||||||||||||||||
| 44 | - | |||||||||||||||||||
| 45 | static void elfHash_continue(const char *name, uint &h) | - | ||||||||||||||||||
| 46 | { | - | ||||||||||||||||||
| 47 | const uchar *k; | - | ||||||||||||||||||
| 48 | uint g; | - | ||||||||||||||||||
| 49 | - | |||||||||||||||||||
| 50 | k = (const uchar *) name; | - | ||||||||||||||||||
| 51 | while (*
| 624-11634 | ||||||||||||||||||
| 52 | h = (h << 4) + *k++; | - | ||||||||||||||||||
| 53 | if ((
| 2080-9554 | ||||||||||||||||||
| 54 | h ^= g >> 24; executed 9554 times by 2 tests: h ^= g >> 24;Executed by:
| 9554 | ||||||||||||||||||
| 55 | h &= ~g; | - | ||||||||||||||||||
| 56 | } executed 11634 times by 2 tests: end of blockExecuted by:
| 11634 | ||||||||||||||||||
| 57 | } executed 624 times by 2 tests: end of blockExecuted by:
| 624 | ||||||||||||||||||
| 58 | - | |||||||||||||||||||
| 59 | static void elfHash_finish(uint &h) | - | ||||||||||||||||||
| 60 | { | - | ||||||||||||||||||
| 61 | if (!h
| 0-312 | ||||||||||||||||||
| 62 | h = 1; never executed: h = 1; | 0 | ||||||||||||||||||
| 63 | } executed 312 times by 2 tests: end of blockExecuted by:
| 312 | ||||||||||||||||||
| 64 | - | |||||||||||||||||||
| 65 | static uint elfHash(const char *name) | - | ||||||||||||||||||
| 66 | { | - | ||||||||||||||||||
| 67 | uint hash = 0; | - | ||||||||||||||||||
| 68 | elfHash_continue(name, hash); | - | ||||||||||||||||||
| 69 | elfHash_finish(hash); | - | ||||||||||||||||||
| 70 | return never executed: hash;return hash;never executed: return hash; | 0 | ||||||||||||||||||
| 71 | } | - | ||||||||||||||||||
| 72 | - | |||||||||||||||||||
| 73 | - | |||||||||||||||||||
| 74 | - | |||||||||||||||||||
| 75 | - | |||||||||||||||||||
| 76 | - | |||||||||||||||||||
| 77 | - | |||||||||||||||||||
| 78 | - | |||||||||||||||||||
| 79 | static bool isValidNumerusRules(const uchar *rules, uint rulesSize) | - | ||||||||||||||||||
| 80 | { | - | ||||||||||||||||||
| 81 | - | |||||||||||||||||||
| 82 | - | |||||||||||||||||||
| 83 | - | |||||||||||||||||||
| 84 | if (rulesSize == 0
| 1-15 | ||||||||||||||||||
| 85 | return executed 1 time by 1 test: true;return true;Executed by:
executed 1 time by 1 test: return true;Executed by:
| 1 | ||||||||||||||||||
| 86 | - | |||||||||||||||||||
| 87 | quint32 offset = 0; | - | ||||||||||||||||||
| 88 | do { | - | ||||||||||||||||||
| 89 | uchar opcode = rules[offset]; | - | ||||||||||||||||||
| 90 | uchar op = opcode & Q_OP_MASK; | - | ||||||||||||||||||
| 91 | - | |||||||||||||||||||
| 92 | if (opcode & 0x80
| 0-15 | ||||||||||||||||||
| 93 | return never executed: false;return false;never executed: return false; | 0 | ||||||||||||||||||
| 94 | - | |||||||||||||||||||
| 95 | if (++
| 0-15 | ||||||||||||||||||
| 96 | return never executed: false;return false;never executed: return false; | 0 | ||||||||||||||||||
| 97 | - | |||||||||||||||||||
| 98 | - | |||||||||||||||||||
| 99 | ++offset; | - | ||||||||||||||||||
| 100 | - | |||||||||||||||||||
| 101 | switch (op) | - | ||||||||||||||||||
| 102 | { | - | ||||||||||||||||||
| 103 | case executed 15 times by 2 tests: Q_EQ:case Q_EQ:Executed by:
executed 15 times by 2 tests: case Q_EQ:Executed by:
| 15 | ||||||||||||||||||
| 104 | case never executed: Q_LT:case Q_LT:never executed: case Q_LT: | 0 | ||||||||||||||||||
| 105 | case never executed: Q_LEQ:case Q_LEQ:never executed: case Q_LEQ: | 0 | ||||||||||||||||||
| 106 | break; executed 15 times by 2 tests: break;Executed by:
| 15 | ||||||||||||||||||
| 107 | - | |||||||||||||||||||
| 108 | case never executed: Q_BETWEEN:case Q_BETWEEN:never executed: case Q_BETWEEN: | 0 | ||||||||||||||||||
| 109 | if (offset != rulesSize
| 0 | ||||||||||||||||||
| 110 | - | |||||||||||||||||||
| 111 | ++offset; | - | ||||||||||||||||||
| 112 | break; never executed: break; | 0 | ||||||||||||||||||
| 113 | } | - | ||||||||||||||||||
| 114 | return never executed: false;return false;never executed: return false; | 0 | ||||||||||||||||||
| 115 | - | |||||||||||||||||||
| 116 | default never executed: :default:never executed: default: | 0 | ||||||||||||||||||
| 117 | return never executed: false;return false;never executed: return false; | 0 | ||||||||||||||||||
| 118 | } | - | ||||||||||||||||||
| 119 | - | |||||||||||||||||||
| 120 | - | |||||||||||||||||||
| 121 | if (offset == rulesSize
| 0-15 | ||||||||||||||||||
| 122 | return executed 15 times by 2 tests: true;return true;Executed by:
executed 15 times by 2 tests: return true;Executed by:
| 15 | ||||||||||||||||||
| 123 | - | |||||||||||||||||||
| 124 | } never executed: while (((end of block
| 0 | ||||||||||||||||||
| 125 | || (
| 0 | ||||||||||||||||||
| 126 | || (
| 0 | ||||||||||||||||||
| 127 | && ++
| 0 | ||||||||||||||||||
| 128 | - | |||||||||||||||||||
| 129 | - | |||||||||||||||||||
| 130 | return never executed: false;return false;never executed: return false; | 0 | ||||||||||||||||||
| 131 | } | - | ||||||||||||||||||
| 132 | static uint numerusHelper(int n, const uchar *rules, uint rulesSize) | - | ||||||||||||||||||
| 133 | { | - | ||||||||||||||||||
| 134 | uint result = 0; | - | ||||||||||||||||||
| 135 | uint i = 0; | - | ||||||||||||||||||
| 136 | - | |||||||||||||||||||
| 137 | if (rulesSize == 0
| 0-9 | ||||||||||||||||||
| 138 | return never executed: 0;return 0;never executed: return 0; | 0 | ||||||||||||||||||
| 139 | - | |||||||||||||||||||
| 140 | for (;;) { | - | ||||||||||||||||||
| 141 | bool orExprTruthValue = false; | - | ||||||||||||||||||
| 142 | - | |||||||||||||||||||
| 143 | for (;;) { | - | ||||||||||||||||||
| 144 | bool andExprTruthValue = true; | - | ||||||||||||||||||
| 145 | - | |||||||||||||||||||
| 146 | for (;;) { | - | ||||||||||||||||||
| 147 | bool truthValue = true; | - | ||||||||||||||||||
| 148 | int opcode = rules[i++]; | - | ||||||||||||||||||
| 149 | - | |||||||||||||||||||
| 150 | int leftOperand = n; | - | ||||||||||||||||||
| 151 | if (opcode & Q_MOD_10
| 0-9 | ||||||||||||||||||
| 152 | leftOperand %= 10; | - | ||||||||||||||||||
| 153 | } never executed: else if (opcode & Q_MOD_100end of block
| 0-9 | ||||||||||||||||||
| 154 | leftOperand %= 100; | - | ||||||||||||||||||
| 155 | } never executed: else if (opcode & Q_LEAD_1000end of block
| 0-9 | ||||||||||||||||||
| 156 | while (leftOperand >= 1000
| 0 | ||||||||||||||||||
| 157 | leftOperand /= 1000; never executed: leftOperand /= 1000; | 0 | ||||||||||||||||||
| 158 | } never executed: end of block | 0 | ||||||||||||||||||
| 159 | - | |||||||||||||||||||
| 160 | int op = opcode & Q_OP_MASK; | - | ||||||||||||||||||
| 161 | int rightOperand = rules[i++]; | - | ||||||||||||||||||
| 162 | - | |||||||||||||||||||
| 163 | switch (op) { | - | ||||||||||||||||||
| 164 | case executed 9 times by 1 test: Q_EQ:case Q_EQ:Executed by:
executed 9 times by 1 test: case Q_EQ:Executed by:
| 9 | ||||||||||||||||||
| 165 | truthValue = (leftOperand == rightOperand); | - | ||||||||||||||||||
| 166 | break; executed 9 times by 1 test: break;Executed by:
| 9 | ||||||||||||||||||
| 167 | case never executed: Q_LT:case Q_LT:never executed: case Q_LT: | 0 | ||||||||||||||||||
| 168 | truthValue = (leftOperand < rightOperand); | - | ||||||||||||||||||
| 169 | break; never executed: break; | 0 | ||||||||||||||||||
| 170 | case never executed: Q_LEQ:case Q_LEQ:never executed: case Q_LEQ: | 0 | ||||||||||||||||||
| 171 | truthValue = (leftOperand <= rightOperand); | - | ||||||||||||||||||
| 172 | break; never executed: break; | 0 | ||||||||||||||||||
| 173 | case never executed: Q_BETWEEN:case Q_BETWEEN:never executed: case Q_BETWEEN: | 0 | ||||||||||||||||||
| 174 | int bottom = rightOperand; | - | ||||||||||||||||||
| 175 | int top = rules[i++]; | - | ||||||||||||||||||
| 176 | truthValue = (leftOperand >= bottom
| 0 | ||||||||||||||||||
| 177 | } never executed: end of block | 0 | ||||||||||||||||||
| 178 | - | |||||||||||||||||||
| 179 | if (opcode & Q_NOT
| 0-9 | ||||||||||||||||||
| 180 | truthValue = !truthValue; never executed: truthValue = !truthValue; | 0 | ||||||||||||||||||
| 181 | - | |||||||||||||||||||
| 182 | andExprTruthValue = andExprTruthValue
| 0-9 | ||||||||||||||||||
| 183 | - | |||||||||||||||||||
| 184 | if (i == rulesSize
| 0-9 | ||||||||||||||||||
| 185 | break; executed 9 times by 1 test: break;Executed by:
| 9 | ||||||||||||||||||
| 186 | ++i; | - | ||||||||||||||||||
| 187 | } never executed: end of block | 0 | ||||||||||||||||||
| 188 | - | |||||||||||||||||||
| 189 | orExprTruthValue = orExprTruthValue
| 0-9 | ||||||||||||||||||
| 190 | - | |||||||||||||||||||
| 191 | if (i == rulesSize
| 0-9 | ||||||||||||||||||
| 192 | break; executed 9 times by 1 test: break;Executed by:
| 9 | ||||||||||||||||||
| 193 | ++i; | - | ||||||||||||||||||
| 194 | } never executed: end of block | 0 | ||||||||||||||||||
| 195 | - | |||||||||||||||||||
| 196 | if (orExprTruthValue
| 3-6 | ||||||||||||||||||
| 197 | return executed 3 times by 1 test: result;return result;Executed by:
executed 3 times by 1 test: return result;Executed by:
| 3 | ||||||||||||||||||
| 198 | - | |||||||||||||||||||
| 199 | ++result; | - | ||||||||||||||||||
| 200 | - | |||||||||||||||||||
| 201 | if (i == rulesSize
| 0-6 | ||||||||||||||||||
| 202 | return executed 6 times by 1 test: result;return result;Executed by:
executed 6 times by 1 test: return result;Executed by:
| 6 | ||||||||||||||||||
| 203 | - | |||||||||||||||||||
| 204 | i++; | - | ||||||||||||||||||
| 205 | } never executed: end of block | 0 | ||||||||||||||||||
| 206 | - | |||||||||||||||||||
| 207 | ((!(false)) ? qt_assert("false",__FILE__,274) : qt_noop()); | - | ||||||||||||||||||
| 208 | return never executed: 0;return 0;never executed: return 0; | 0 | ||||||||||||||||||
| 209 | } | - | ||||||||||||||||||
| 210 | - | |||||||||||||||||||
| 211 | class QTranslatorPrivate : public QObjectPrivate | - | ||||||||||||||||||
| 212 | { | - | ||||||||||||||||||
| 213 | inline QTranslator* q_func() { return static_cast<QTranslator *>(q_ptr); } inline const QTranslator* q_func() const { return static_cast<const QTranslator *>(q_ptr); } friend class QTranslator; | - | ||||||||||||||||||
| 214 | public: | - | ||||||||||||||||||
| 215 | enum { Contexts = 0x2f, Hashes = 0x42, Messages = 0x69, NumerusRules = 0x88, Dependencies = 0x96 }; | - | ||||||||||||||||||
| 216 | - | |||||||||||||||||||
| 217 | QTranslatorPrivate() : | - | ||||||||||||||||||
| 218 | - | |||||||||||||||||||
| 219 | used_mmap(0), | - | ||||||||||||||||||
| 220 | - | |||||||||||||||||||
| 221 | unmapPointer(0), unmapLength(0), resource(0), | - | ||||||||||||||||||
| 222 | messageArray(0), offsetArray(0), contextArray(0), numerusRulesArray(0), | - | ||||||||||||||||||
| 223 | messageLength(0), offsetLength(0), contextLength(0), numerusRulesLength(0) {} executed 18 times by 4 tests: end of blockExecuted by:
| 18 | ||||||||||||||||||
| 224 | - | |||||||||||||||||||
| 225 | - | |||||||||||||||||||
| 226 | bool used_mmap : 1; | - | ||||||||||||||||||
| 227 | - | |||||||||||||||||||
| 228 | char *unmapPointer; | - | ||||||||||||||||||
| 229 | quint32 unmapLength; | - | ||||||||||||||||||
| 230 | - | |||||||||||||||||||
| 231 | - | |||||||||||||||||||
| 232 | QResource *resource; | - | ||||||||||||||||||
| 233 | - | |||||||||||||||||||
| 234 | - | |||||||||||||||||||
| 235 | QList<QTranslator*> subTranslators; | - | ||||||||||||||||||
| 236 | - | |||||||||||||||||||
| 237 | - | |||||||||||||||||||
| 238 | - | |||||||||||||||||||
| 239 | const uchar *messageArray; | - | ||||||||||||||||||
| 240 | const uchar *offsetArray; | - | ||||||||||||||||||
| 241 | const uchar *contextArray; | - | ||||||||||||||||||
| 242 | const uchar *numerusRulesArray; | - | ||||||||||||||||||
| 243 | uint messageLength; | - | ||||||||||||||||||
| 244 | uint offsetLength; | - | ||||||||||||||||||
| 245 | uint contextLength; | - | ||||||||||||||||||
| 246 | uint numerusRulesLength; | - | ||||||||||||||||||
| 247 | - | |||||||||||||||||||
| 248 | bool do_load(const QString &filename, const QString &directory); | - | ||||||||||||||||||
| 249 | bool do_load(const uchar *data, int len, const QString &directory); | - | ||||||||||||||||||
| 250 | QString do_translate(const char *context, const char *sourceText, const char *comment, | - | ||||||||||||||||||
| 251 | int n) const; | - | ||||||||||||||||||
| 252 | void clear(); | - | ||||||||||||||||||
| 253 | }; | - | ||||||||||||||||||
| 254 | QTranslator::QTranslator(QObject * parent) | - | ||||||||||||||||||
| 255 | : QObject(*new QTranslatorPrivate, parent) | - | ||||||||||||||||||
| 256 | { | - | ||||||||||||||||||
| 257 | } executed 18 times by 4 tests: end of blockExecuted by:
| 18 | ||||||||||||||||||
| 258 | - | |||||||||||||||||||
| 259 | - | |||||||||||||||||||
| 260 | - | |||||||||||||||||||
| 261 | - | |||||||||||||||||||
| 262 | - | |||||||||||||||||||
| 263 | QTranslator::~QTranslator() | - | ||||||||||||||||||
| 264 | { | - | ||||||||||||||||||
| 265 | if (QCoreApplication::instance()
| 0-18 | ||||||||||||||||||
| 266 | QCoreApplication::removeTranslator(this); executed 18 times by 4 tests: QCoreApplication::removeTranslator(this);Executed by:
| 18 | ||||||||||||||||||
| 267 | QTranslatorPrivate * const d = d_func(); | - | ||||||||||||||||||
| 268 | d->clear(); | - | ||||||||||||||||||
| 269 | } executed 18 times by 4 tests: end of blockExecuted by:
| 18 | ||||||||||||||||||
| 270 | bool QTranslator::load(const QString & filename, const QString & directory, | - | ||||||||||||||||||
| 271 | const QString & search_delimiters, | - | ||||||||||||||||||
| 272 | const QString & suffix) | - | ||||||||||||||||||
| 273 | { | - | ||||||||||||||||||
| 274 | QTranslatorPrivate * const d = d_func(); | - | ||||||||||||||||||
| 275 | d->clear(); | - | ||||||||||||||||||
| 276 | - | |||||||||||||||||||
| 277 | QString prefix; | - | ||||||||||||||||||
| 278 | if (QFileInfo(filename).isRelative()
| 3-15 | ||||||||||||||||||
| 279 | prefix = directory; | - | ||||||||||||||||||
| 280 | if (prefix.length()
| 0-14 | ||||||||||||||||||
| 281 | prefix += QLatin1Char('/'); executed 1 time by 1 test: prefix += QLatin1Char('/');Executed by:
| 1 | ||||||||||||||||||
| 282 | } executed 15 times by 1 test: end of blockExecuted by:
| 15 | ||||||||||||||||||
| 283 | - | |||||||||||||||||||
| 284 | QString fname = filename; | - | ||||||||||||||||||
| 285 | QString realname; | - | ||||||||||||||||||
| 286 | QString delims; | - | ||||||||||||||||||
| 287 | delims = search_delimiters.isNull()
| 0-18 | ||||||||||||||||||
| 288 | - | |||||||||||||||||||
| 289 | for (;;) { | - | ||||||||||||||||||
| 290 | QFileInfo fi; | - | ||||||||||||||||||
| 291 | - | |||||||||||||||||||
| 292 | realname = prefix + fname + (suffix.isNull()
| 0-18 | ||||||||||||||||||
| 293 | fi.setFile(realname); | - | ||||||||||||||||||
| 294 | if (fi.isReadable()
| 0-9 | ||||||||||||||||||
| 295 | break; executed 9 times by 2 tests: break;Executed by:
| 9 | ||||||||||||||||||
| 296 | - | |||||||||||||||||||
| 297 | realname = prefix + fname; | - | ||||||||||||||||||
| 298 | fi.setFile(realname); | - | ||||||||||||||||||
| 299 | if (fi.isReadable()
| 1-6 | ||||||||||||||||||
| 300 | break; executed 5 times by 1 test: break;Executed by:
| 5 | ||||||||||||||||||
| 301 | - | |||||||||||||||||||
| 302 | int rightmost = 0; | - | ||||||||||||||||||
| 303 | for (int i = 0; i < (int)delims.length()
| 4-8 | ||||||||||||||||||
| 304 | int k = fname.lastIndexOf(delims[i]); | - | ||||||||||||||||||
| 305 | if (k > rightmost
| 0-8 | ||||||||||||||||||
| 306 | rightmost = k; never executed: rightmost = k; | 0 | ||||||||||||||||||
| 307 | } executed 8 times by 1 test: end of blockExecuted by:
| 8 | ||||||||||||||||||
| 308 | - | |||||||||||||||||||
| 309 | - | |||||||||||||||||||
| 310 | if (rightmost == 0
| 0-4 | ||||||||||||||||||
| 311 | return executed 4 times by 1 test: false;return false;Executed by:
executed 4 times by 1 test: return false;Executed by:
| 4 | ||||||||||||||||||
| 312 | - | |||||||||||||||||||
| 313 | fname.truncate(rightmost); | - | ||||||||||||||||||
| 314 | } never executed: end of block | 0 | ||||||||||||||||||
| 315 | - | |||||||||||||||||||
| 316 | - | |||||||||||||||||||
| 317 | return executed 14 times by 2 tests: d->do_load(realname, directory);return d->do_load(realname, directory);Executed by:
executed 14 times by 2 tests: return d->do_load(realname, directory);Executed by:
| 14 | ||||||||||||||||||
| 318 | } | - | ||||||||||||||||||
| 319 | - | |||||||||||||||||||
| 320 | bool QTranslatorPrivate::do_load(const QString &realname, const QString &directory) | - | ||||||||||||||||||
| 321 | { | - | ||||||||||||||||||
| 322 | QTranslatorPrivate *d = this; | - | ||||||||||||||||||
| 323 | bool ok = false; | - | ||||||||||||||||||
| 324 | - | |||||||||||||||||||
| 325 | if (realname.startsWith(':')
| 3-11 | ||||||||||||||||||
| 326 | - | |||||||||||||||||||
| 327 | - | |||||||||||||||||||
| 328 | ((!(!d->resource)) ? qt_assert("!d->resource",__FILE__,525) : qt_noop()); | - | ||||||||||||||||||
| 329 | d->resource = new QResource(realname); | - | ||||||||||||||||||
| 330 | if (resource->isValid()
| 0-3 | ||||||||||||||||||
| 331 | && !memcmp(resource->data(), magic, MagicLength)
| 0-2 | ||||||||||||||||||
| 332 | d->unmapLength = resource->size(); | - | ||||||||||||||||||
| 333 | d->unmapPointer = reinterpret_cast<char *>(const_cast<uchar *>(resource->data())); | - | ||||||||||||||||||
| 334 | - | |||||||||||||||||||
| 335 | d->used_mmap = false; | - | ||||||||||||||||||
| 336 | - | |||||||||||||||||||
| 337 | ok = true; | - | ||||||||||||||||||
| 338 | } executed 2 times by 2 tests: else {end of blockExecuted by:
| 2 | ||||||||||||||||||
| 339 | delete resource; | - | ||||||||||||||||||
| 340 | resource = 0; | - | ||||||||||||||||||
| 341 | } executed 1 time by 1 test: end of blockExecuted by:
| 1 | ||||||||||||||||||
| 342 | } | - | ||||||||||||||||||
| 343 | - | |||||||||||||||||||
| 344 | if (!ok
| 2-12 | ||||||||||||||||||
| 345 | QFile file(realname); | - | ||||||||||||||||||
| 346 | if (!file.open(QIODevice::ReadOnly | QIODevice::Unbuffered)
| 0-12 | ||||||||||||||||||
| 347 | return never executed: false;return false;never executed: return false; | 0 | ||||||||||||||||||
| 348 | - | |||||||||||||||||||
| 349 | qint64 fileSize = file.size(); | - | ||||||||||||||||||
| 350 | if (fileSize <= MagicLength
| 0-12 | ||||||||||||||||||
| 351 | return never executed: false;return false;never executed: return false; | 0 | ||||||||||||||||||
| 352 | - | |||||||||||||||||||
| 353 | { | - | ||||||||||||||||||
| 354 | char magicBuffer[MagicLength]; | - | ||||||||||||||||||
| 355 | if (MagicLength != file.read(magicBuffer, MagicLength)
| 0-12 | ||||||||||||||||||
| 356 | || memcmp(magicBuffer, magic, MagicLength)
| 0-12 | ||||||||||||||||||
| 357 | return never executed: false;return false;never executed: return false; | 0 | ||||||||||||||||||
| 358 | } | - | ||||||||||||||||||
| 359 | - | |||||||||||||||||||
| 360 | d->unmapLength = quint32(fileSize); | - | ||||||||||||||||||
| 361 | int fd = file.handle(); | - | ||||||||||||||||||
| 362 | if (fd >= 0
| 1-11 | ||||||||||||||||||
| 363 | char *ptr; | - | ||||||||||||||||||
| 364 | ptr = reinterpret_cast<char *>( | - | ||||||||||||||||||
| 365 | mmap(0, d->unmapLength, | - | ||||||||||||||||||
| 366 | 0x1, | - | ||||||||||||||||||
| 367 | 0 | 0x02, | - | ||||||||||||||||||
| 368 | fd, 0)); | - | ||||||||||||||||||
| 369 | if (ptr
| 0-11 | ||||||||||||||||||
| 370 | file.close(); | - | ||||||||||||||||||
| 371 | d->used_mmap = true; | - | ||||||||||||||||||
| 372 | d->unmapPointer = ptr; | - | ||||||||||||||||||
| 373 | ok = true; | - | ||||||||||||||||||
| 374 | } executed 11 times by 1 test: end of blockExecuted by:
| 11 | ||||||||||||||||||
| 375 | } executed 11 times by 1 test: end of blockExecuted by:
| 11 | ||||||||||||||||||
| 376 | - | |||||||||||||||||||
| 377 | - | |||||||||||||||||||
| 378 | if (!ok
| 1-11 | ||||||||||||||||||
| 379 | d->unmapPointer = new char[d->unmapLength]; | - | ||||||||||||||||||
| 380 | if (d->unmapPointer
| 0-1 | ||||||||||||||||||
| 381 | file.seek(0); | - | ||||||||||||||||||
| 382 | qint64 readResult = file.read(d->unmapPointer, d->unmapLength); | - | ||||||||||||||||||
| 383 | if (readResult == qint64(unmapLength)
| 0-1 | ||||||||||||||||||
| 384 | ok = true; executed 1 time by 1 test: ok = true;Executed by:
| 1 | ||||||||||||||||||
| 385 | } executed 1 time by 1 test: end of blockExecuted by:
| 1 | ||||||||||||||||||
| 386 | } executed 1 time by 1 test: end of blockExecuted by:
| 1 | ||||||||||||||||||
| 387 | } executed 12 times by 2 tests: end of blockExecuted by:
| 12 | ||||||||||||||||||
| 388 | - | |||||||||||||||||||
| 389 | if (ok
| 0-14 | ||||||||||||||||||
| 390 | return executed 14 times by 2 tests: true;return true;Executed by:
executed 14 times by 2 tests: return true;Executed by:
| 14 | ||||||||||||||||||
| 391 | - | |||||||||||||||||||
| 392 | - | |||||||||||||||||||
| 393 | if (used_mmap
| 0 | ||||||||||||||||||
| 394 | used_mmap = false; | - | ||||||||||||||||||
| 395 | munmap(unmapPointer, unmapLength); | - | ||||||||||||||||||
| 396 | } never executed: elseend of block | 0 | ||||||||||||||||||
| 397 | - | |||||||||||||||||||
| 398 | if (!d->resource
| 0 | ||||||||||||||||||
| 399 | delete [] unmapPointer; never executed: delete [] unmapPointer; | 0 | ||||||||||||||||||
| 400 | - | |||||||||||||||||||
| 401 | delete d->resource; | - | ||||||||||||||||||
| 402 | d->resource = 0; | - | ||||||||||||||||||
| 403 | d->unmapPointer = 0; | - | ||||||||||||||||||
| 404 | d->unmapLength = 0; | - | ||||||||||||||||||
| 405 | - | |||||||||||||||||||
| 406 | return never executed: false;return false;never executed: return false; | 0 | ||||||||||||||||||
| 407 | } | - | ||||||||||||||||||
| 408 | - | |||||||||||||||||||
| 409 | static QString find_translation(const QLocale & locale, | - | ||||||||||||||||||
| 410 | const QString & filename, | - | ||||||||||||||||||
| 411 | const QString & prefix, | - | ||||||||||||||||||
| 412 | const QString & directory, | - | ||||||||||||||||||
| 413 | const QString & suffix) | - | ||||||||||||||||||
| 414 | { | - | ||||||||||||||||||
| 415 | QString path; | - | ||||||||||||||||||
| 416 | if (QFileInfo(filename).isRelative()
| 0 | ||||||||||||||||||
| 417 | path = directory; | - | ||||||||||||||||||
| 418 | if (!path.isEmpty()
| 0 | ||||||||||||||||||
| 419 | path += QLatin1Char('/'); never executed: path += QLatin1Char('/'); | 0 | ||||||||||||||||||
| 420 | } never executed: end of block | 0 | ||||||||||||||||||
| 421 | - | |||||||||||||||||||
| 422 | QFileInfo fi; | - | ||||||||||||||||||
| 423 | QString realname; | - | ||||||||||||||||||
| 424 | QStringList fuzzyLocales; | - | ||||||||||||||||||
| 425 | - | |||||||||||||||||||
| 426 | - | |||||||||||||||||||
| 427 | - | |||||||||||||||||||
| 428 | QStringList languages = locale.uiLanguages(); | - | ||||||||||||||||||
| 429 | - | |||||||||||||||||||
| 430 | for (int i = languages.size()-1; i >= 0
| 0 | ||||||||||||||||||
| 431 | QString lang = languages.at(i); | - | ||||||||||||||||||
| 432 | QString lowerLang = lang.toLower(); | - | ||||||||||||||||||
| 433 | if (lang != lowerLang
| 0 | ||||||||||||||||||
| 434 | languages.insert(i+1, lowerLang); never executed: languages.insert(i+1, lowerLang); | 0 | ||||||||||||||||||
| 435 | } never executed: end of block | 0 | ||||||||||||||||||
| 436 | - | |||||||||||||||||||
| 437 | - | |||||||||||||||||||
| 438 | - | |||||||||||||||||||
| 439 | for (QForeachContainer<typename QtPrivate::remove_reference<decltype(languages)>::type> _container_((languages)); _container_.control && _container_.i != _container_.e; ++_container_.i, _container_.control ^= 1) for (QString localeName = *_container_.i; _container_.control; _container_.control = 0) { | - | ||||||||||||||||||
| 440 | localeName.replace(QLatin1Char('-'), QLatin1Char('_')); | - | ||||||||||||||||||
| 441 | - | |||||||||||||||||||
| 442 | realname = path + filename + prefix + localeName + (suffix.isNull()
| 0 | ||||||||||||||||||
| 443 | fi.setFile(realname); | - | ||||||||||||||||||
| 444 | if (fi.isReadable()
| 0 | ||||||||||||||||||
| 445 | return never executed: realname;return realname;never executed: return realname; | 0 | ||||||||||||||||||
| 446 | - | |||||||||||||||||||
| 447 | realname = path + filename + prefix + localeName; | - | ||||||||||||||||||
| 448 | fi.setFile(realname); | - | ||||||||||||||||||
| 449 | if (fi.isReadable()
| 0 | ||||||||||||||||||
| 450 | return never executed: realname;return realname;never executed: return realname; | 0 | ||||||||||||||||||
| 451 | - | |||||||||||||||||||
| 452 | fuzzyLocales.append(localeName); | - | ||||||||||||||||||
| 453 | } never executed: end of block | 0 | ||||||||||||||||||
| 454 | - | |||||||||||||||||||
| 455 | - | |||||||||||||||||||
| 456 | for (QForeachContainer<typename QtPrivate::remove_reference<decltype(fuzzyLocales)>::type> _container_((fuzzyLocales)); _container_.control && _container_.i != _container_.e; ++_container_.i, _container_.control ^= 1) for (QString localeName = *_container_.i; _container_.control; _container_.control = 0) { | - | ||||||||||||||||||
| 457 | for (;;) { | - | ||||||||||||||||||
| 458 | int rightmost = localeName.lastIndexOf(QLatin1Char('_')); | - | ||||||||||||||||||
| 459 | - | |||||||||||||||||||
| 460 | if (rightmost <= 0
| 0 | ||||||||||||||||||
| 461 | break; never executed: break; | 0 | ||||||||||||||||||
| 462 | localeName.truncate(rightmost); | - | ||||||||||||||||||
| 463 | - | |||||||||||||||||||
| 464 | realname = path + filename + prefix + localeName + (suffix.isNull()
| 0 | ||||||||||||||||||
| 465 | fi.setFile(realname); | - | ||||||||||||||||||
| 466 | if (fi.isReadable()
| 0 | ||||||||||||||||||
| 467 | return never executed: realname;return realname;never executed: return realname; | 0 | ||||||||||||||||||
| 468 | - | |||||||||||||||||||
| 469 | realname = path + filename + prefix + localeName; | - | ||||||||||||||||||
| 470 | fi.setFile(realname); | - | ||||||||||||||||||
| 471 | if (fi.isReadable()
| 0 | ||||||||||||||||||
| 472 | return never executed: realname;return realname;never executed: return realname; | 0 | ||||||||||||||||||
| 473 | } never executed: end of block | 0 | ||||||||||||||||||
| 474 | } never executed: end of block | 0 | ||||||||||||||||||
| 475 | - | |||||||||||||||||||
| 476 | if (!suffix.isNull()
| 0 | ||||||||||||||||||
| 477 | realname = path + filename + suffix; | - | ||||||||||||||||||
| 478 | fi.setFile(realname); | - | ||||||||||||||||||
| 479 | if (fi.isReadable()
| 0 | ||||||||||||||||||
| 480 | return never executed: realname;return realname;never executed: return realname; | 0 | ||||||||||||||||||
| 481 | } never executed: end of block | 0 | ||||||||||||||||||
| 482 | - | |||||||||||||||||||
| 483 | realname = path + filename + prefix; | - | ||||||||||||||||||
| 484 | fi.setFile(realname); | - | ||||||||||||||||||
| 485 | if (fi.isReadable()
| 0 | ||||||||||||||||||
| 486 | return never executed: realname;return realname;never executed: return realname; | 0 | ||||||||||||||||||
| 487 | - | |||||||||||||||||||
| 488 | realname = path + filename; | - | ||||||||||||||||||
| 489 | fi.setFile(realname); | - | ||||||||||||||||||
| 490 | if (fi.isReadable()
| 0 | ||||||||||||||||||
| 491 | return never executed: realname;return realname;never executed: return realname; | 0 | ||||||||||||||||||
| 492 | - | |||||||||||||||||||
| 493 | return never executed: QString();return QString();never executed: return QString(); | 0 | ||||||||||||||||||
| 494 | } | - | ||||||||||||||||||
| 495 | bool QTranslator::load(const QLocale & locale, | - | ||||||||||||||||||
| 496 | const QString & filename, | - | ||||||||||||||||||
| 497 | const QString & prefix, | - | ||||||||||||||||||
| 498 | const QString & directory, | - | ||||||||||||||||||
| 499 | const QString & suffix) | - | ||||||||||||||||||
| 500 | { | - | ||||||||||||||||||
| 501 | QTranslatorPrivate * const d = d_func(); | - | ||||||||||||||||||
| 502 | d->clear(); | - | ||||||||||||||||||
| 503 | QString fname = find_translation(locale, filename, prefix, directory, suffix); | - | ||||||||||||||||||
| 504 | return never executed: !fname.isEmpty()return !fname.isEmpty() && d->do_load(fname, directory);
never executed: return !fname.isEmpty() && d->do_load(fname, directory); | 0 | ||||||||||||||||||
| 505 | } | - | ||||||||||||||||||
| 506 | bool QTranslator::load(const uchar *data, int len, const QString &directory) | - | ||||||||||||||||||
| 507 | { | - | ||||||||||||||||||
| 508 | QTranslatorPrivate * const d = d_func(); | - | ||||||||||||||||||
| 509 | d->clear(); | - | ||||||||||||||||||
| 510 | - | |||||||||||||||||||
| 511 | if (!data
| 0-2 | ||||||||||||||||||
| 512 | return never executed: false;return false;never executed: return false; | 0 | ||||||||||||||||||
| 513 | - | |||||||||||||||||||
| 514 | return executed 2 times by 1 test: d->do_load(data, len, directory);return d->do_load(data, len, directory);Executed by:
executed 2 times by 1 test: return d->do_load(data, len, directory);Executed by:
| 2 | ||||||||||||||||||
| 515 | } | - | ||||||||||||||||||
| 516 | - | |||||||||||||||||||
| 517 | static quint8 read8(const uchar *data) | - | ||||||||||||||||||
| 518 | { | - | ||||||||||||||||||
| 519 | return executed 902 times by 2 tests: qFromBigEndian<quint8>(data);return qFromBigEndian<quint8>(data);Executed by:
executed 902 times by 2 tests: return qFromBigEndian<quint8>(data);Executed by:
| 902 | ||||||||||||||||||
| 520 | } | - | ||||||||||||||||||
| 521 | - | |||||||||||||||||||
| 522 | static quint16 read16(const uchar *data) | - | ||||||||||||||||||
| 523 | { | - | ||||||||||||||||||
| 524 | return never executed: qFromBigEndian<quint16>(data);return qFromBigEndian<quint16>(data);never executed: return qFromBigEndian<quint16>(data); | 0 | ||||||||||||||||||
| 525 | } | - | ||||||||||||||||||
| 526 | - | |||||||||||||||||||
| 527 | static quint32 read32(const uchar *data) | - | ||||||||||||||||||
| 528 | { | - | ||||||||||||||||||
| 529 | return executed 3591 times by 2 tests: qFromBigEndian<quint32>(data);return qFromBigEndian<quint32>(data);Executed by:
executed 3591 times by 2 tests: return qFromBigEndian<quint32>(data);Executed by:
| 3591 | ||||||||||||||||||
| 530 | } | - | ||||||||||||||||||
| 531 | - | |||||||||||||||||||
| 532 | bool QTranslatorPrivate::do_load(const uchar *data, int len, const QString &directory) | - | ||||||||||||||||||
| 533 | { | - | ||||||||||||||||||
| 534 | bool ok = true; | - | ||||||||||||||||||
| 535 | const uchar *end = data + len; | - | ||||||||||||||||||
| 536 | - | |||||||||||||||||||
| 537 | data += MagicLength; | - | ||||||||||||||||||
| 538 | - | |||||||||||||||||||
| 539 | QStringList dependencies; | - | ||||||||||||||||||
| 540 | while (data < end - 4
| 16-49 | ||||||||||||||||||
| 541 | quint8 tag = read8(data++); | - | ||||||||||||||||||
| 542 | quint32 blockLen = read32(data); | - | ||||||||||||||||||
| 543 | data += 4; | - | ||||||||||||||||||
| 544 | if (!tag
| 0-49 | ||||||||||||||||||
| 545 | break; never executed: break; | 0 | ||||||||||||||||||
| 546 | if (quint32(end - data) < blockLen
| 0-49 | ||||||||||||||||||
| 547 | ok = false; | - | ||||||||||||||||||
| 548 | break; never executed: break; | 0 | ||||||||||||||||||
| 549 | } | - | ||||||||||||||||||
| 550 | - | |||||||||||||||||||
| 551 | if (tag == QTranslatorPrivate::Contexts
| 0-49 | ||||||||||||||||||
| 552 | contextArray = data; | - | ||||||||||||||||||
| 553 | contextLength = blockLen; | - | ||||||||||||||||||
| 554 | } never executed: else if (tag == QTranslatorPrivate::Hashesend of block
| 0-33 | ||||||||||||||||||
| 555 | offsetArray = data; | - | ||||||||||||||||||
| 556 | offsetLength = blockLen; | - | ||||||||||||||||||
| 557 | } executed 16 times by 2 tests: else if (tag == QTranslatorPrivate::Messagesend of blockExecuted by:
| 16-17 | ||||||||||||||||||
| 558 | messageArray = data; | - | ||||||||||||||||||
| 559 | messageLength = blockLen; | - | ||||||||||||||||||
| 560 | } executed 16 times by 2 tests: else if (tag == QTranslatorPrivate::NumerusRulesend of blockExecuted by:
| 2-16 | ||||||||||||||||||
| 561 | numerusRulesArray = data; | - | ||||||||||||||||||
| 562 | numerusRulesLength = blockLen; | - | ||||||||||||||||||
| 563 | } executed 15 times by 2 tests: else if (tag == QTranslatorPrivate::Dependenciesend of blockExecuted by:
| 0-15 | ||||||||||||||||||
| 564 | QDataStream stream(QByteArray::fromRawData((const char*)data, blockLen)); | - | ||||||||||||||||||
| 565 | QString dep; | - | ||||||||||||||||||
| 566 | while (!stream.atEnd()
| 2 | ||||||||||||||||||
| 567 | stream >> dep; | - | ||||||||||||||||||
| 568 | dependencies.append(dep); | - | ||||||||||||||||||
| 569 | } executed 2 times by 1 test: end of blockExecuted by:
| 2 | ||||||||||||||||||
| 570 | } executed 2 times by 1 test: end of blockExecuted by:
| 2 | ||||||||||||||||||
| 571 | - | |||||||||||||||||||
| 572 | data += blockLen; | - | ||||||||||||||||||
| 573 | } executed 49 times by 2 tests: end of blockExecuted by:
| 49 | ||||||||||||||||||
| 574 | - | |||||||||||||||||||
| 575 | if (dependencies.isEmpty()
| 0-14 | ||||||||||||||||||
| 576 | ok = false; never executed: ok = false; | 0 | ||||||||||||||||||
| 577 | if (ok
| 0-16 | ||||||||||||||||||
| 578 | ok = false; never executed: ok = false; | 0 | ||||||||||||||||||
| 579 | if (ok
| 0-16 | ||||||||||||||||||
| 580 | const int dependenciesCount = dependencies.count(); | - | ||||||||||||||||||
| 581 | subTranslators.reserve(dependenciesCount); | - | ||||||||||||||||||
| 582 | for (int i = 0 ; i < dependenciesCount
| 2-16 | ||||||||||||||||||
| 583 | QTranslator *translator = new QTranslator; | - | ||||||||||||||||||
| 584 | subTranslators.append(translator); | - | ||||||||||||||||||
| 585 | ok = translator->load(dependencies.at(i), directory); | - | ||||||||||||||||||
| 586 | if (!ok
| 0-2 | ||||||||||||||||||
| 587 | break; never executed: break; | 0 | ||||||||||||||||||
| 588 | } executed 2 times by 1 test: end of blockExecuted by:
| 2 | ||||||||||||||||||
| 589 | - | |||||||||||||||||||
| 590 | - | |||||||||||||||||||
| 591 | if (!ok
| 0-16 | ||||||||||||||||||
| 592 | qDeleteAll(subTranslators); | - | ||||||||||||||||||
| 593 | subTranslators.clear(); | - | ||||||||||||||||||
| 594 | } never executed: end of block | 0 | ||||||||||||||||||
| 595 | } executed 16 times by 2 tests: end of blockExecuted by:
| 16 | ||||||||||||||||||
| 596 | - | |||||||||||||||||||
| 597 | if (!ok
| 0-16 | ||||||||||||||||||
| 598 | messageArray = 0; | - | ||||||||||||||||||
| 599 | contextArray = 0; | - | ||||||||||||||||||
| 600 | offsetArray = 0; | - | ||||||||||||||||||
| 601 | numerusRulesArray = 0; | - | ||||||||||||||||||
| 602 | messageLength = 0; | - | ||||||||||||||||||
| 603 | contextLength = 0; | - | ||||||||||||||||||
| 604 | offsetLength = 0; | - | ||||||||||||||||||
| 605 | numerusRulesLength = 0; | - | ||||||||||||||||||
| 606 | } never executed: end of block | 0 | ||||||||||||||||||
| 607 | - | |||||||||||||||||||
| 608 | return executed 16 times by 2 tests: ok;return ok;Executed by:
executed 16 times by 2 tests: return ok;Executed by:
| 16 | ||||||||||||||||||
| 609 | } | - | ||||||||||||||||||
| 610 | - | |||||||||||||||||||
| 611 | static QString getMessage(const uchar *m, const uchar *end, const char *context, | - | ||||||||||||||||||
| 612 | const char *sourceText, const char *comment, uint numerus) | - | ||||||||||||||||||
| 613 | { | - | ||||||||||||||||||
| 614 | const uchar *tn = 0; | - | ||||||||||||||||||
| 615 | uint tn_length = 0; | - | ||||||||||||||||||
| 616 | const uint sourceTextLen = uint(strlen(sourceText)); | - | ||||||||||||||||||
| 617 | const uint contextLen = uint(strlen(context)); | - | ||||||||||||||||||
| 618 | const uint commentLen = uint(strlen(comment)); | - | ||||||||||||||||||
| 619 | - | |||||||||||||||||||
| 620 | for (;;) { | - | ||||||||||||||||||
| 621 | uchar tag = 0; | - | ||||||||||||||||||
| 622 | if (m < end
| 0-853 | ||||||||||||||||||
| 623 | tag = read8(m++); executed 853 times by 2 tests: tag = read8(m++);Executed by:
| 853 | ||||||||||||||||||
| 624 | switch((Tag)tag) { | - | ||||||||||||||||||
| 625 | case executed 144 times by 2 tests: Tag_End:case Tag_End:Executed by:
executed 144 times by 2 tests: case Tag_End:Executed by:
| 144 | ||||||||||||||||||
| 626 | goto executed 144 times by 2 tests: end;goto end;Executed by:
executed 144 times by 2 tests: goto end;Executed by:
| 144 | ||||||||||||||||||
| 627 | case executed 187 times by 2 tests: Tag_Translation:case Tag_Translation:Executed by:
executed 187 times by 2 tests: {case Tag_Translation:Executed by:
| 187 | ||||||||||||||||||
| 628 | int len = read32(m); | - | ||||||||||||||||||
| 629 | if (len % 1
| 0-187 | ||||||||||||||||||
| 630 | return never executed: QString();return QString();never executed: return QString(); | 0 | ||||||||||||||||||
| 631 | m += 4; | - | ||||||||||||||||||
| 632 | if (!numerus--
| 14-173 | ||||||||||||||||||
| 633 | tn_length = len; | - | ||||||||||||||||||
| 634 | tn = m; | - | ||||||||||||||||||
| 635 | } executed 173 times by 2 tests: end of blockExecuted by:
| 173 | ||||||||||||||||||
| 636 | m += len; | - | ||||||||||||||||||
| 637 | break; executed 187 times by 2 tests: break;Executed by:
| 187 | ||||||||||||||||||
| 638 | } | - | ||||||||||||||||||
| 639 | case executed 3 times by 1 test: Tag_Obsolete1:case Tag_Obsolete1:Executed by:
executed 3 times by 1 test: case Tag_Obsolete1:Executed by:
| 3 | ||||||||||||||||||
| 640 | m += 4; | - | ||||||||||||||||||
| 641 | break; executed 3 times by 1 test: break;Executed by:
| 3 | ||||||||||||||||||
| 642 | case executed 173 times by 2 tests: Tag_SourceText:case Tag_SourceText:Executed by:
executed 173 times by 2 tests: {case Tag_SourceText:Executed by:
| 173 | ||||||||||||||||||
| 643 | quint32 len = read32(m); | - | ||||||||||||||||||
| 644 | m += 4; | - | ||||||||||||||||||
| 645 | if (!match(m, len, sourceText, sourceTextLen)
| 0-173 | ||||||||||||||||||
| 646 | return never executed: QString();return QString();never executed: return QString(); | 0 | ||||||||||||||||||
| 647 | m += len; | - | ||||||||||||||||||
| 648 | } | - | ||||||||||||||||||
| 649 | break; executed 173 times by 2 tests: break;Executed by:
| 173 | ||||||||||||||||||
| 650 | case executed 173 times by 2 tests: Tag_Context:case Tag_Context:Executed by:
executed 173 times by 2 tests: {case Tag_Context:Executed by:
| 173 | ||||||||||||||||||
| 651 | quint32 len = read32(m); | - | ||||||||||||||||||
| 652 | m += 4; | - | ||||||||||||||||||
| 653 | if (!match(m, len, context, contextLen)
| 29-144 | ||||||||||||||||||
| 654 | return executed 29 times by 2 tests: QString();return QString();Executed by:
executed 29 times by 2 tests: return QString();Executed by:
| 29 | ||||||||||||||||||
| 655 | m += len; | - | ||||||||||||||||||
| 656 | } | - | ||||||||||||||||||
| 657 | break; executed 144 times by 2 tests: break;Executed by:
| 144 | ||||||||||||||||||
| 658 | case executed 173 times by 2 tests: Tag_Comment:case Tag_Comment:Executed by:
executed 173 times by 2 tests: {case Tag_Comment:Executed by:
| 173 | ||||||||||||||||||
| 659 | quint32 len = read32(m); | - | ||||||||||||||||||
| 660 | m += 4; | - | ||||||||||||||||||
| 661 | if (*
| 0-167 | ||||||||||||||||||
| 662 | return never executed: QString();return QString();never executed: return QString(); | 0 | ||||||||||||||||||
| 663 | m += len; | - | ||||||||||||||||||
| 664 | } | - | ||||||||||||||||||
| 665 | break; executed 173 times by 2 tests: break;Executed by:
| 173 | ||||||||||||||||||
| 666 | default never executed: :default:never executed: default: | 0 | ||||||||||||||||||
| 667 | return never executed: QString();return QString();never executed: return QString(); | 0 | ||||||||||||||||||
| 668 | } | - | ||||||||||||||||||
| 669 | } | - | ||||||||||||||||||
| 670 | end: code before this statement never executed: end: | 0 | ||||||||||||||||||
| 671 | if (!tn
| 0-144 | ||||||||||||||||||
| 672 | return never executed: QString();return QString();never executed: return QString(); | 0 | ||||||||||||||||||
| 673 | QString str = QString((const QChar *)tn, tn_length/2); | - | ||||||||||||||||||
| 674 | if (QSysInfo::ByteOrder == QSysInfo::LittleEndian
| 0-144 | ||||||||||||||||||
| 675 | for (int i = 0; i < str.length()
| 144-818 | ||||||||||||||||||
| 676 | 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:
| 818 | ||||||||||||||||||
| 677 | } executed 144 times by 2 tests: end of blockExecuted by:
| 144 | ||||||||||||||||||
| 678 | return executed 144 times by 2 tests: str;return str;Executed by:
executed 144 times by 2 tests: return str;Executed by:
| 144 | ||||||||||||||||||
| 679 | } | - | ||||||||||||||||||
| 680 | - | |||||||||||||||||||
| 681 | QString QTranslatorPrivate::do_translate(const char *context, const char *sourceText, | - | ||||||||||||||||||
| 682 | const char *comment, int n) const | - | ||||||||||||||||||
| 683 | { | - | ||||||||||||||||||
| 684 | if (context == 0
| 0-260 | ||||||||||||||||||
| 685 | context = ""; never executed: context = ""; | 0 | ||||||||||||||||||
| 686 | if (sourceText == 0
| 0-260 | ||||||||||||||||||
| 687 | sourceText = ""; never executed: sourceText = ""; | 0 | ||||||||||||||||||
| 688 | if (comment == 0
| 57-203 | ||||||||||||||||||
| 689 | comment = ""; executed 203 times by 2 tests: comment = "";Executed by:
| 203 | ||||||||||||||||||
| 690 | - | |||||||||||||||||||
| 691 | uint numerus = 0; | - | ||||||||||||||||||
| 692 | size_t numItems = 0; | - | ||||||||||||||||||
| 693 | - | |||||||||||||||||||
| 694 | if (!offsetLength
| 0-260 | ||||||||||||||||||
| 695 | goto never executed: searchDependencies;goto searchDependencies;never executed: goto searchDependencies; | 0 | ||||||||||||||||||
| 696 | - | |||||||||||||||||||
| 697 | - | |||||||||||||||||||
| 698 | - | |||||||||||||||||||
| 699 | - | |||||||||||||||||||
| 700 | - | |||||||||||||||||||
| 701 | if (contextLength
| 0-260 | ||||||||||||||||||
| 702 | quint16 hTableSize = read16(contextArray); | - | ||||||||||||||||||
| 703 | uint g = elfHash(context) % hTableSize; | - | ||||||||||||||||||
| 704 | const uchar *c = contextArray + 2 + (g << 1); | - | ||||||||||||||||||
| 705 | quint16 off = read16(c); | - | ||||||||||||||||||
| 706 | c += 2; | - | ||||||||||||||||||
| 707 | if (off == 0
| 0 | ||||||||||||||||||
| 708 | return never executed: QString();return QString();never executed: return QString(); | 0 | ||||||||||||||||||
| 709 | c = contextArray + (2 + (hTableSize << 1) + (off << 1)); | - | ||||||||||||||||||
| 710 | - | |||||||||||||||||||
| 711 | const uint contextLen = uint(strlen(context)); | - | ||||||||||||||||||
| 712 | for (;;) { | - | ||||||||||||||||||
| 713 | quint8 len = read8(c++); | - | ||||||||||||||||||
| 714 | if (len == 0
| 0 | ||||||||||||||||||
| 715 | return never executed: QString();return QString();never executed: return QString(); | 0 | ||||||||||||||||||
| 716 | if (match(c, len, context, contextLen)
| 0 | ||||||||||||||||||
| 717 | break; never executed: break; | 0 | ||||||||||||||||||
| 718 | c += len; | - | ||||||||||||||||||
| 719 | } never executed: end of block | 0 | ||||||||||||||||||
| 720 | } never executed: end of block | 0 | ||||||||||||||||||
| 721 | - | |||||||||||||||||||
| 722 | numItems = offsetLength / (2 * sizeof(quint32)); | - | ||||||||||||||||||
| 723 | if (!numItems
| 0-260 | ||||||||||||||||||
| 724 | goto never executed: searchDependencies;goto searchDependencies;never executed: goto searchDependencies; | 0 | ||||||||||||||||||
| 725 | - | |||||||||||||||||||
| 726 | if (n >= 0
| 9-251 | ||||||||||||||||||
| 727 | numerus = numerusHelper(n, numerusRulesArray, numerusRulesLength); executed 9 times by 1 test: numerus = numerusHelper(n, numerusRulesArray, numerusRulesLength);Executed by:
| 9 | ||||||||||||||||||
| 728 | - | |||||||||||||||||||
| 729 | for (;;) { | - | ||||||||||||||||||
| 730 | quint32 h = 0; | - | ||||||||||||||||||
| 731 | elfHash_continue(sourceText, h); | - | ||||||||||||||||||
| 732 | elfHash_continue(comment, h); | - | ||||||||||||||||||
| 733 | elfHash_finish(h); | - | ||||||||||||||||||
| 734 | - | |||||||||||||||||||
| 735 | const uchar *start = offsetArray; | - | ||||||||||||||||||
| 736 | const uchar *end = start + ((numItems-1) << 3); | - | ||||||||||||||||||
| 737 | while (start <= end
| 139-2131 | ||||||||||||||||||
| 738 | const uchar *middle = start + (((end - start) >> 4) << 3); | - | ||||||||||||||||||
| 739 | uint hash = read32(middle); | - | ||||||||||||||||||
| 740 | if (h == hash
| 173-1958 | ||||||||||||||||||
| 741 | start = middle; | - | ||||||||||||||||||
| 742 | break; executed 173 times by 2 tests: break;Executed by:
| 173 | ||||||||||||||||||
| 743 | } else if (hash < h
| 745-1213 | ||||||||||||||||||
| 744 | start = middle + 8; | - | ||||||||||||||||||
| 745 | } executed 745 times by 2 tests: else {end of blockExecuted by:
| 745 | ||||||||||||||||||
| 746 | end = middle - 8; | - | ||||||||||||||||||
| 747 | } executed 1213 times by 2 tests: end of blockExecuted by:
| 1213 | ||||||||||||||||||
| 748 | } | - | ||||||||||||||||||
| 749 | - | |||||||||||||||||||
| 750 | if (start <= end
| 139-173 | ||||||||||||||||||
| 751 | - | |||||||||||||||||||
| 752 | while (start != offsetArray
| 0-165 | ||||||||||||||||||
| 753 | start -= 8; never executed: start -= 8; | 0 | ||||||||||||||||||
| 754 | - | |||||||||||||||||||
| 755 | while (start < offsetArray + offsetLength
| 0-202 | ||||||||||||||||||
| 756 | quint32 rh = read32(start); | - | ||||||||||||||||||
| 757 | start += 4; | - | ||||||||||||||||||
| 758 | if (rh != h
| 29-173 | ||||||||||||||||||
| 759 | break; executed 29 times by 2 tests: break;Executed by:
| 29 | ||||||||||||||||||
| 760 | quint32 ro = read32(start); | - | ||||||||||||||||||
| 761 | start += 4; | - | ||||||||||||||||||
| 762 | QString tn = getMessage(messageArray + ro, messageArray + messageLength, context, | - | ||||||||||||||||||
| 763 | sourceText, comment, numerus); | - | ||||||||||||||||||
| 764 | if (!tn.isNull()
| 29-144 | ||||||||||||||||||
| 765 | return executed 144 times by 2 tests: tn;return tn;Executed by:
executed 144 times by 2 tests: return tn;Executed by:
| 144 | ||||||||||||||||||
| 766 | } executed 29 times by 2 tests: end of blockExecuted by:
| 29 | ||||||||||||||||||
| 767 | } executed 29 times by 2 tests: end of blockExecuted by:
| 29 | ||||||||||||||||||
| 768 | if (!comment[0]
| 52-116 | ||||||||||||||||||
| 769 | break; executed 116 times by 2 tests: break;Executed by:
| 116 | ||||||||||||||||||
| 770 | comment = ""; | - | ||||||||||||||||||
| 771 | } executed 52 times by 1 test: end of blockExecuted by:
| 52 | ||||||||||||||||||
| 772 | - | |||||||||||||||||||
| 773 | searchDependencies: code before this statement executed 116 times by 2 tests: searchDependencies:Executed by:
| 116 | ||||||||||||||||||
| 774 | for (QForeachContainer<typename QtPrivate::remove_reference<decltype(subTranslators)>::type> _container_((subTranslators)); _container_.control && _container_.i != _container_.e; ++_container_.i, _container_.control ^= 1) for (QTranslator *translator = *_container_.i; _container_.control; _container_.control = 0) { | - | ||||||||||||||||||
| 775 | QString tn = translator->translate(context, sourceText, comment, n); | - | ||||||||||||||||||
| 776 | if (!tn.isNull()
| 0-5 | ||||||||||||||||||
| 777 | return executed 5 times by 1 test: tn;return tn;Executed by:
executed 5 times by 1 test: return tn;Executed by:
| 5 | ||||||||||||||||||
| 778 | } never executed: end of block | 0 | ||||||||||||||||||
| 779 | return executed 111 times by 2 tests: QString();return QString();Executed by:
executed 111 times by 2 tests: return QString();Executed by:
| 111 | ||||||||||||||||||
| 780 | } | - | ||||||||||||||||||
| 781 | - | |||||||||||||||||||
| 782 | - | |||||||||||||||||||
| 783 | - | |||||||||||||||||||
| 784 | - | |||||||||||||||||||
| 785 | - | |||||||||||||||||||
| 786 | - | |||||||||||||||||||
| 787 | - | |||||||||||||||||||
| 788 | void QTranslatorPrivate::clear() | - | ||||||||||||||||||
| 789 | { | - | ||||||||||||||||||
| 790 | QTranslator * const q = q_func(); | - | ||||||||||||||||||
| 791 | if (unmapPointer
| 0-24 | ||||||||||||||||||
| 792 | - | |||||||||||||||||||
| 793 | if (used_mmap
| 3-11 | ||||||||||||||||||
| 794 | used_mmap = false; | - | ||||||||||||||||||
| 795 | munmap(unmapPointer, unmapLength); | - | ||||||||||||||||||
| 796 | } executed 11 times by 1 test: elseend of blockExecuted by:
| 11 | ||||||||||||||||||
| 797 | - | |||||||||||||||||||
| 798 | if (!resource
| 1-2 | ||||||||||||||||||
| 799 | delete [] unmapPointer; executed 1 time by 1 test: delete [] unmapPointer;Executed by:
| 1 | ||||||||||||||||||
| 800 | } executed 14 times by 2 tests: end of blockExecuted by:
| 14 | ||||||||||||||||||
| 801 | - | |||||||||||||||||||
| 802 | delete resource; | - | ||||||||||||||||||
| 803 | resource = 0; | - | ||||||||||||||||||
| 804 | unmapPointer = 0; | - | ||||||||||||||||||
| 805 | unmapLength = 0; | - | ||||||||||||||||||
| 806 | messageArray = 0; | - | ||||||||||||||||||
| 807 | contextArray = 0; | - | ||||||||||||||||||
| 808 | offsetArray = 0; | - | ||||||||||||||||||
| 809 | numerusRulesArray = 0; | - | ||||||||||||||||||
| 810 | messageLength = 0; | - | ||||||||||||||||||
| 811 | contextLength = 0; | - | ||||||||||||||||||
| 812 | offsetLength = 0; | - | ||||||||||||||||||
| 813 | numerusRulesLength = 0; | - | ||||||||||||||||||
| 814 | - | |||||||||||||||||||
| 815 | qDeleteAll(subTranslators); | - | ||||||||||||||||||
| 816 | subTranslators.clear(); | - | ||||||||||||||||||
| 817 | - | |||||||||||||||||||
| 818 | if (QCoreApplicationPrivate::isTranslatorInstalled(q)
| 3-35 | ||||||||||||||||||
| 819 | QCoreApplication::postEvent(QCoreApplication::instance(), executed 3 times by 1 test: QCoreApplication::postEvent(QCoreApplication::instance(), new QEvent(QEvent::LanguageChange));Executed by:
| 3 | ||||||||||||||||||
| 820 | new QEvent(QEvent::LanguageChange)); executed 3 times by 1 test: QCoreApplication::postEvent(QCoreApplication::instance(), new QEvent(QEvent::LanguageChange));Executed by:
| 3 | ||||||||||||||||||
| 821 | } executed 38 times by 5 tests: end of blockExecuted by:
| 38 | ||||||||||||||||||
| 822 | QString QTranslator::translate(const char *context, const char *sourceText, const char *disambiguation, | - | ||||||||||||||||||
| 823 | int n) const | - | ||||||||||||||||||
| 824 | { | - | ||||||||||||||||||
| 825 | const QTranslatorPrivate * const d = d_func(); | - | ||||||||||||||||||
| 826 | return executed 260 times by 2 tests: d->do_translate(context, sourceText, disambiguation, n);return d->do_translate(context, sourceText, disambiguation, n);Executed by:
executed 260 times by 2 tests: return d->do_translate(context, sourceText, disambiguation, n);Executed by:
| 260 | ||||||||||||||||||
| 827 | } | - | ||||||||||||||||||
| 828 | - | |||||||||||||||||||
| 829 | - | |||||||||||||||||||
| 830 | - | |||||||||||||||||||
| 831 | - | |||||||||||||||||||
| 832 | - | |||||||||||||||||||
| 833 | bool QTranslator::isEmpty() const | - | ||||||||||||||||||
| 834 | { | - | ||||||||||||||||||
| 835 | const QTranslatorPrivate * const d = d_func(); | - | ||||||||||||||||||
| 836 | return executed 39 times by 2 tests: !d->unmapPointerreturn !d->unmapPointer && !d->unmapLength && !d->messageArray && !d->offsetArray && !d->contextArray && d->subTranslators.isEmpty();Executed by:
executed 39 times by 2 tests: return !d->unmapPointer && !d->unmapLength && !d->messageArray && !d->offsetArray && !d->contextArray && d->subTranslators.isEmpty();Executed by:
| 0-39 | ||||||||||||||||||
| 837 | !d->offsetArray
executed 39 times by 2 tests: return !d->unmapPointer && !d->unmapLength && !d->messageArray && !d->offsetArray && !d->contextArray && d->subTranslators.isEmpty();Executed by:
| 0-39 | ||||||||||||||||||
| 838 | } | - | ||||||||||||||||||
| 839 | - | |||||||||||||||||||
| 840 | - | |||||||||||||||||||
| Switch to Source code | Preprocessed file |