diff options
author | Ulf Hermann <ulf.hermann@theqtcompany.com> | 2016-04-12 12:05:33 +0200 |
---|---|---|
committer | Ulf Hermann <ulf.hermann@theqtcompany.com> | 2016-04-13 12:29:50 +0000 |
commit | 9968c72f7cac511235ab6aab2e948d29da4ff059 (patch) | |
tree | 08b4caf7c3a90219971841afb2155302a1a5c636 /tools/qscxmlc/scxmlcppdumper.cpp | |
parent | e1513d7f904f03617c38f14d65cdaa8afd4ff2b2 (diff) |
Write generated string literals as array of numbers
Having UTF-8 literals in source code is notoriously brittle, as
compilers interpret them differently. Let's just write every byte or
qunicodechar as a number. That should remove any ambguity.
Change-Id: I3d79c7f15dc58a3b74b3a79e9186a612d38cb5a5
Reviewed-by: Simon Hausmann <simon.hausmann@theqtcompany.com>
Diffstat (limited to 'tools/qscxmlc/scxmlcppdumper.cpp')
-rw-r--r-- | tools/qscxmlc/scxmlcppdumper.cpp | 21 |
1 files changed, 12 insertions, 9 deletions
diff --git a/tools/qscxmlc/scxmlcppdumper.cpp b/tools/qscxmlc/scxmlcppdumper.cpp index f981486..434f0a8 100644 --- a/tools/qscxmlc/scxmlcppdumper.cpp +++ b/tools/qscxmlc/scxmlcppdumper.cpp @@ -1020,17 +1020,20 @@ private: ucharCount += length + 1; return str; }); - t << QStringLiteral("},"); - if (strings.isEmpty()) { - t << QStringLiteral("QT_UNICODE_LITERAL_II(\"\")"); - } else { - for (int i = 0, ei = strings.size(); i < ei; ++i) { - QString s = cEscape(strings.at(i)); - t << QStringLiteral("QT_UNICODE_LITERAL_II(\"%1\") // %3: %2") - .arg(s + QStringLiteral("\\x00"), s, QString::number(i)); + t << QStringLiteral("},{"); + for (int i = 0, ei = strings.size(); i < ei; ++i) { + const QString &string = strings.at(i); + QString result; + for (int charPos = 0, eCharPos = string.size(); charPos < eCharPos; ++charPos) { + result.append(QStringLiteral("0x%1,") + .arg(QString::number(string.at(charPos).unicode(), 16))); } + result.append(QStringLiteral("0%1 // %2: %3") + .arg(QLatin1String(i < ei - 1 ? "," : ""), QString::number(i), + cEscape(string))); + t << result; } - t << QStringLiteral("};") << QStringLiteral(""); + t << QStringLiteral("}};") << QStringLiteral(""); clazz.classFields << QStringLiteral("static struct Strings {") << QStringLiteral(" QArrayData data[%1];").arg(strings.size()) |