summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorUlf Hermann <ulf.hermann@theqtcompany.com>2016-04-07 13:04:30 +0200
committerUlf Hermann <ulf.hermann@theqtcompany.com>2016-04-07 13:11:31 +0000
commit4400b45523f558150fbd6b92fedc6b970f18d819 (patch)
tree09851d5450a10088089730c0329f6a02cc4fb27b
parent26453251cf21d44089a905c68d70752dbd0b2e5d (diff)
Make sure the output files are proper UTF-8
Making the text codec explicit saves us from surprises on systems where the system text codec is something else. MSVC only considers source files as UTF-8 if they contain a byte order mark (BOM). As we write UTF-8, we should also generate BOMs then. Change-Id: Id2cc35ed4fb9e37bc567db09e18fb71ac4ce54b0 Reviewed-by: Simon Hausmann <simon.hausmann@theqtcompany.com>
-rw-r--r--tools/qscxmlc/qscxmlc.cpp15
1 files changed, 14 insertions, 1 deletions
diff --git a/tools/qscxmlc/qscxmlc.cpp b/tools/qscxmlc/qscxmlc.cpp
index 896d088..fe8e40e 100644
--- a/tools/qscxmlc/qscxmlc.cpp
+++ b/tools/qscxmlc/qscxmlc.cpp
@@ -34,6 +34,7 @@
#include <QCommandLineParser>
#include <QFile>
#include <QFileInfo>
+#include <QTextCodec>
enum {
NoError = 0,
@@ -43,7 +44,8 @@ enum {
ParseError = -4,
CannotOpenOutputHeaderFileError = -5,
CannotOpenOutputCppFileError = -6,
- ScxmlVerificationError = -7
+ ScxmlVerificationError = -7,
+ NoTextCodecError = -8
};
int write(TranslationUnit *tu)
@@ -62,8 +64,19 @@ int write(TranslationUnit *tu)
return CannotOpenOutputCppFileError;
}
+ // Make sure it outputs UTF-8, as that is what C++ expects.
+ QTextCodec *utf8 = QTextCodec::codecForName("UTF-8");
+ if (!utf8) {
+ errs << QStringLiteral("Error: cannot find a QTextCodec for generating UTF-8.");
+ return NoTextCodecError;
+ }
+
QTextStream h(&outH);
+ h.setCodec(utf8);
+ h.setGenerateByteOrderMark(true);
QTextStream c(&outCpp);
+ c.setCodec(utf8);
+ c.setGenerateByteOrderMark(true);
CppDumper dumper(h, c);
dumper.dump(tu);
h.flush();