uic: Avoid creating multiline QStringLiterals for MSVC.
The compiler complains about L"foo" "bar". Change-Id: I94be0528b26fe65413db56d210a5c02fcdba13a3 Reviewed-by: Friedemann Kleint <Friedemann.Kleint@nokia.com>
This commit is contained in:
parent
2c515ea42c
commit
26c3bec09b
@ -55,21 +55,27 @@ inline bool toBool(const QString &str)
|
||||
inline QString toString(const DomString *str)
|
||||
{ return str ? str->text() : QString(); }
|
||||
|
||||
inline QString fixString(const QString &str, const QString &indent, bool *isUtf8Ret=0)
|
||||
enum StringFlags {
|
||||
Utf8String = 0x1,
|
||||
MultiLineString = 0x2
|
||||
};
|
||||
|
||||
inline QString fixString(const QString &str, const QString &indent,
|
||||
unsigned *stringFlags = 0)
|
||||
{
|
||||
QString cursegment;
|
||||
QStringList result;
|
||||
const QByteArray utf8 = str.toUtf8();
|
||||
const int utf8Length = utf8.length();
|
||||
|
||||
bool isUtf8 = false;
|
||||
unsigned flags = 0;
|
||||
|
||||
for (int i = 0; i < utf8Length; ++i) {
|
||||
const uchar cbyte = utf8.at(i);
|
||||
if (cbyte >= 0x80) {
|
||||
cursegment += QLatin1Char('\\');
|
||||
cursegment += QString::number(cbyte, 8);
|
||||
isUtf8 = true;
|
||||
flags |= Utf8String;
|
||||
} else {
|
||||
switch(cbyte) {
|
||||
case '\\':
|
||||
@ -79,6 +85,7 @@ inline QString fixString(const QString &str, const QString &indent, bool *isUtf8
|
||||
case '\r':
|
||||
break;
|
||||
case '\n':
|
||||
flags |= MultiLineString;
|
||||
cursegment += QLatin1String("\\n\"\n\""); break;
|
||||
default:
|
||||
cursegment += QLatin1Char(cbyte);
|
||||
@ -103,18 +110,26 @@ inline QString fixString(const QString &str, const QString &indent, bool *isUtf8
|
||||
QString rc(QLatin1Char('"'));
|
||||
rc += result.join(joinstr);
|
||||
rc += QLatin1Char('"');
|
||||
if (isUtf8Ret)
|
||||
*isUtf8Ret = isUtf8;
|
||||
|
||||
if (result.size() > 1)
|
||||
flags |= MultiLineString;
|
||||
|
||||
if (stringFlags)
|
||||
*stringFlags = flags;
|
||||
|
||||
return rc;
|
||||
}
|
||||
|
||||
inline QString writeString(const QString &s, const QString &indent)
|
||||
{
|
||||
bool isUtf8 = false;
|
||||
const QString ret = fixString(s, indent, &isUtf8);
|
||||
if (isUtf8)
|
||||
unsigned flags = 0;
|
||||
const QString ret = fixString(s, indent, &flags);
|
||||
if (flags & Utf8String)
|
||||
return QLatin1String("QString::fromUtf8(") + ret + QLatin1Char(')');
|
||||
else
|
||||
// MSVC cannot concat L"foo" "bar" (C2308: concatenating mismatched strings),
|
||||
// use QLatin1String instead (all platforms to avoid cross-compiling issues).
|
||||
if (flags & MultiLineString)
|
||||
return QLatin1String("QLatin1String(") + ret + QLatin1Char(')');
|
||||
return QLatin1String("QStringLiteral(") + ret + QLatin1Char(')');
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user