diff --git a/src/linguist/lupdate/cpp.cpp b/src/linguist/lupdate/cpp.cpp index 8288cbff5cd44e43604e679d1fb2e59d4d7ef227..ec02be157246f741553c5dbb9f1d913f42f28cee 100644 --- a/src/linguist/lupdate/cpp.cpp +++ b/src/linguist/lupdate/cpp.cpp @@ -2217,9 +2217,7 @@ const ParseResults *CppParser::recordResults(bool isHeader) void loadCPP(Translator &translator, const QStringList &filenames, ConversionData &cd) { - QByteArray codecName = cd.m_codecForSource.isEmpty() - ? "UTF-8" : cd.m_codecForSource; - QTextCodec *codec = QTextCodec::codecForName(codecName); + QTextCodec *codec = QTextCodec::codecForName(cd.m_sourceIsUtf16 ? "UTF-16" : "UTF-8"); foreach (const QString &filename, filenames) { if (!CppFiles::getResults(filename).isEmpty() || CppFiles::isBlacklisted(filename)) diff --git a/src/linguist/lupdate/java.cpp b/src/linguist/lupdate/java.cpp index 079847f43d5e4e46ba9fe99e19964a3a26e34d4b..210b8545857b5dfbb81ced8bd5c9380e37fd4bd1 100644 --- a/src/linguist/lupdate/java.cpp +++ b/src/linguist/lupdate/java.cpp @@ -622,12 +622,7 @@ bool loadJava(Translator &translator, const QString &filename, ConversionData &c yyParenLineNo = 1; QTextStream ts(&file); - QByteArray codecName; - if (!cd.m_codecForSource.isEmpty()) - codecName = cd.m_codecForSource; - else - codecName = "UTF-8"; - ts.setCodec(QTextCodec::codecForName(codecName)); + ts.setCodec(QTextCodec::codecForName(cd.m_sourceIsUtf16 ? "UTF-16" : "UTF-8")); ts.setAutoDetectUnicode(true); yyInStr = ts.readAll(); yyInPos = 0; diff --git a/src/linguist/lupdate/lupdate.h b/src/linguist/lupdate/lupdate.h index 3f3095a89f8f9e868daef47d6935acc07337f536..05a3ce5833d5e154de24754ec4042d26099106e7 100644 --- a/src/linguist/lupdate/lupdate.h +++ b/src/linguist/lupdate/lupdate.h @@ -65,7 +65,8 @@ enum UpdateOption { AbsoluteLocations = 256, RelativeLocations = 512, NoLocations = 1024, - NoUiLines = 2048 + NoUiLines = 2048, + SourceIsUtf16 = 4096 }; Q_DECLARE_FLAGS(UpdateOptions, UpdateOption) diff --git a/src/linguist/lupdate/main.cpp b/src/linguist/lupdate/main.cpp index ff7538de7508c58b8379d26258063abf38e75e5f..56078a5ae1bcfd75a9ec893364597b1bea20fba4 100644 --- a/src/linguist/lupdate/main.cpp +++ b/src/linguist/lupdate/main.cpp @@ -52,7 +52,6 @@ #include <QtCore/QFileInfo> #include <QtCore/QString> #include <QtCore/QStringList> -#include <QtCore/QTextCodec> #include <QtCore/QTranslator> #include <QtCore/QLibraryInfo> @@ -354,26 +353,29 @@ static void processSources(Translator &fetchedTor, static void processProjects(bool topLevel, bool nestComplain, const QStringList &proFiles, const QHash<QString, QString> &outDirMap, ProFileGlobals *option, QMakeParser *parser, - UpdateOptions options, const QByteArray &codecForSource, + UpdateOptions options, const QString &targetLanguage, const QString &sourceLanguage, Translator *parentTor, bool *fail); static void processProject( bool nestComplain, const QString &proFile, ProFileGlobals *option, QMakeParser *parser, ProFileEvaluator &visitor, - UpdateOptions options, const QByteArray &_codecForSource, + UpdateOptions options, const QString &targetLanguage, const QString &sourceLanguage, Translator *fetchedTor, bool *fail) { - QByteArray codecForSource = _codecForSource; QStringList tmp = visitor.values(QLatin1String("CODECFORSRC")); if (!tmp.isEmpty()) { - codecForSource = tmp.last().toLatin1(); - if (!QTextCodec::codecForName(codecForSource)) { + QByteArray codecForSource = tmp.last().toLatin1().toUpper(); + if (codecForSource == "UTF16" || codecForSource == "UTF-16") { + options |= SourceIsUtf16; + } else if (codecForSource == "UTF8" || codecForSource == "UTF-8") { + options &= ~SourceIsUtf16; + } else { printErr(LU::tr("lupdate warning: Codec for source '%1' is invalid." - " Falling back to codec for tr().\n") + " Falling back to UTF-8.\n") .arg(QString::fromLatin1(codecForSource))); - codecForSource.clear(); + options &= ~SourceIsUtf16; } } QString proPath = QFileInfo(proFile).path(); @@ -395,12 +397,12 @@ static void processProject( subProFiles << subPro; } processProjects(false, nestComplain, subProFiles, QHash<QString, QString>(), - option, parser, options, codecForSource, + option, parser, options, targetLanguage, sourceLanguage, fetchedTor, fail); } else { ConversionData cd; cd.m_noUiLines = options & NoUiLines; - cd.m_codecForSource = codecForSource; + cd.m_sourceIsUtf16 = options & SourceIsUtf16; cd.m_includePath = visitor.values(QLatin1String("INCLUDEPATH")); QStringList sourceFiles = getSources(visitor, proPath); QSet<QString> sourceDirs; @@ -421,7 +423,7 @@ static void processProject( static void processProjects(bool topLevel, bool nestComplain, const QStringList &proFiles, const QHash<QString, QString> &outDirMap, ProFileGlobals *option, QMakeParser *parser, - UpdateOptions options, const QByteArray &codecForSource, + UpdateOptions options, const QString &targetLanguage, const QString &sourceLanguage, Translator *parentTor, bool *fail) { @@ -471,7 +473,7 @@ static void processProjects(bool topLevel, bool nestComplain, const QStringList continue; } Translator tor; - processProject(false, proFile, option, parser, visitor, options, codecForSource, + processProject(false, proFile, option, parser, visitor, options, targetLanguage, sourceLanguage, &tor, fail); updateTsFiles(tor, tsFiles, QStringList(), sourceLanguage, targetLanguage, options, fail); @@ -484,10 +486,10 @@ static void processProjects(bool topLevel, bool nestComplain, const QStringList printErr(LU::tr("lupdate warning: no TS files specified. Only diagnostics " "will be produced for '%1'.\n").arg(proFile)); Translator tor; - processProject(nestComplain, proFile, option, parser, visitor, options, codecForSource, + processProject(nestComplain, proFile, option, parser, visitor, options, targetLanguage, sourceLanguage, &tor, fail); } else { - processProject(nestComplain, proFile, option, parser, visitor, options, codecForSource, + processProject(nestComplain, proFile, option, parser, visitor, options, targetLanguage, sourceLanguage, parentTor, fail); } pro->deref(); @@ -802,6 +804,7 @@ int main(int argc, char **argv) Translator fetchedTor; ConversionData cd; cd.m_noUiLines = options & NoUiLines; + cd.m_sourceIsUtf16 = options & SourceIsUtf16; cd.m_projectRoots = projectRoots; cd.m_includePath = includePath; cd.m_allCSources = allCSources; @@ -827,12 +830,12 @@ int main(int argc, char **argv) if (!tsFileNames.isEmpty()) { Translator fetchedTor; - processProjects(true, true, proFiles, outDirMap, &option, &parser, options, QByteArray(), + processProjects(true, true, proFiles, outDirMap, &option, &parser, options, targetLanguage, sourceLanguage, &fetchedTor, &fail); updateTsFiles(fetchedTor, tsFileNames, alienFiles, sourceLanguage, targetLanguage, options, &fail); } else { - processProjects(true, false, proFiles, outDirMap, &option, &parser, options, QByteArray(), + processProjects(true, false, proFiles, outDirMap, &option, &parser, options, targetLanguage, sourceLanguage, 0, &fail); } } diff --git a/src/linguist/shared/translator.h b/src/linguist/shared/translator.h index 7120982199c2864067df1e21439dda56e5a9e405..17dc3d53d7a0f3ffafde706ebeed68d96ff8986c 100644 --- a/src/linguist/shared/translator.h +++ b/src/linguist/shared/translator.h @@ -97,7 +97,7 @@ public: public: QString m_defaultContext; - QByteArray m_codecForSource; // CPP, PO & QM specific + bool m_sourceIsUtf16; // CPP & JAVA specific QString m_unTrPrefix; // QM specific QString m_sourceFileName; QString m_targetFileName;