summaryrefslogtreecommitdiffstats
path: root/tools/linguist/lupdate/cpp.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'tools/linguist/lupdate/cpp.cpp')
-rw-r--r--tools/linguist/lupdate/cpp.cpp22
1 files changed, 10 insertions, 12 deletions
diff --git a/tools/linguist/lupdate/cpp.cpp b/tools/linguist/lupdate/cpp.cpp
index 7c9b27a..857233e 100644
--- a/tools/linguist/lupdate/cpp.cpp
+++ b/tools/linguist/lupdate/cpp.cpp
@@ -306,7 +306,6 @@ private:
// the string to read from and current position in the string
QTextCodec *yySourceCodec;
- bool yySourceIsUnicode;
QString yyInStr;
const ushort *yyInPtr;
@@ -353,7 +352,6 @@ void CppParser::setInput(const QString &in)
yyInStr = in;
yyFileName = QString();
yySourceCodec = 0;
- yySourceIsUnicode = true;
yyForceUtf8 = true;
}
@@ -362,7 +360,6 @@ void CppParser::setInput(QTextStream &ts, const QString &fileName)
yyInStr = ts.readAll();
yyFileName = fileName;
yySourceCodec = ts.codec();
- yySourceIsUnicode = yySourceCodec->name().startsWith("UTF-");
yyForceUtf8 = false;
}
@@ -1430,24 +1427,24 @@ QString CppParser::transcode(const QString &str, bool utf8)
{
static const char tab[] = "abfnrtv";
static const char backTab[] = "\a\b\f\n\r\t\v";
- const QString in = (!utf8 || yySourceIsUnicode)
- ? str : QString::fromUtf8(yySourceCodec->fromUnicode(str).data());
- QString out;
+ // This function has to convert back to bytes, as C's \0* sequences work at that level.
+ const QByteArray in = yyForceUtf8 ? str.toUtf8() : tor->codec()->fromUnicode(str);
+ QByteArray out;
out.reserve(in.length());
for (int i = 0; i < in.length();) {
- ushort c = in[i++].unicode();
+ uchar c = in[i++];
if (c == '\\') {
if (i >= in.length())
break;
- c = in[i++].unicode();
+ c = in[i++];
if (c == '\n')
continue;
if (c == 'x') {
QByteArray hex;
- while (i < in.length() && isxdigit((c = in[i].unicode()))) {
+ while (i < in.length() && isxdigit((c = in[i]))) {
hex += c;
i++;
}
@@ -1456,7 +1453,7 @@ QString CppParser::transcode(const QString &str, bool utf8)
QByteArray oct;
int n = 0;
oct += c;
- while (n < 2 && i < in.length() && (c = in[i].unicode()) >= '0' && c < '8') {
+ while (n < 2 && i < in.length() && (c = in[i]) >= '0' && c < '8') {
i++;
n++;
oct += c;
@@ -1464,13 +1461,14 @@ QString CppParser::transcode(const QString &str, bool utf8)
out += oct.toUInt(0, 8);
} else {
const char *p = strchr(tab, c);
- out += QChar(QLatin1Char(!p ? c : backTab[p - tab]));
+ out += !p ? c : backTab[p - tab];
}
} else {
out += c;
}
}
- return out;
+ return (utf8 || yyForceUtf8) ? QString::fromUtf8(out.constData(), out.length())
+ : tor->codec()->toUnicode(out);
}
void CppParser::recordMessage(