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)
|
inline QString toString(const DomString *str)
|
||||||
{ return str ? str->text() : QString(); }
|
{ 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;
|
QString cursegment;
|
||||||
QStringList result;
|
QStringList result;
|
||||||
const QByteArray utf8 = str.toUtf8();
|
const QByteArray utf8 = str.toUtf8();
|
||||||
const int utf8Length = utf8.length();
|
const int utf8Length = utf8.length();
|
||||||
|
|
||||||
bool isUtf8 = false;
|
unsigned flags = 0;
|
||||||
|
|
||||||
for (int i = 0; i < utf8Length; ++i) {
|
for (int i = 0; i < utf8Length; ++i) {
|
||||||
const uchar cbyte = utf8.at(i);
|
const uchar cbyte = utf8.at(i);
|
||||||
if (cbyte >= 0x80) {
|
if (cbyte >= 0x80) {
|
||||||
cursegment += QLatin1Char('\\');
|
cursegment += QLatin1Char('\\');
|
||||||
cursegment += QString::number(cbyte, 8);
|
cursegment += QString::number(cbyte, 8);
|
||||||
isUtf8 = true;
|
flags |= Utf8String;
|
||||||
} else {
|
} else {
|
||||||
switch(cbyte) {
|
switch(cbyte) {
|
||||||
case '\\':
|
case '\\':
|
||||||
@ -79,6 +85,7 @@ inline QString fixString(const QString &str, const QString &indent, bool *isUtf8
|
|||||||
case '\r':
|
case '\r':
|
||||||
break;
|
break;
|
||||||
case '\n':
|
case '\n':
|
||||||
|
flags |= MultiLineString;
|
||||||
cursegment += QLatin1String("\\n\"\n\""); break;
|
cursegment += QLatin1String("\\n\"\n\""); break;
|
||||||
default:
|
default:
|
||||||
cursegment += QLatin1Char(cbyte);
|
cursegment += QLatin1Char(cbyte);
|
||||||
@ -103,19 +110,27 @@ inline QString fixString(const QString &str, const QString &indent, bool *isUtf8
|
|||||||
QString rc(QLatin1Char('"'));
|
QString rc(QLatin1Char('"'));
|
||||||
rc += result.join(joinstr);
|
rc += result.join(joinstr);
|
||||||
rc += QLatin1Char('"');
|
rc += QLatin1Char('"');
|
||||||
if (isUtf8Ret)
|
|
||||||
*isUtf8Ret = isUtf8;
|
if (result.size() > 1)
|
||||||
|
flags |= MultiLineString;
|
||||||
|
|
||||||
|
if (stringFlags)
|
||||||
|
*stringFlags = flags;
|
||||||
|
|
||||||
return rc;
|
return rc;
|
||||||
}
|
}
|
||||||
|
|
||||||
inline QString writeString(const QString &s, const QString &indent)
|
inline QString writeString(const QString &s, const QString &indent)
|
||||||
{
|
{
|
||||||
bool isUtf8 = false;
|
unsigned flags = 0;
|
||||||
const QString ret = fixString(s, indent, &isUtf8);
|
const QString ret = fixString(s, indent, &flags);
|
||||||
if (isUtf8)
|
if (flags & Utf8String)
|
||||||
return QLatin1String("QString::fromUtf8(") + ret + QLatin1Char(')');
|
return QLatin1String("QString::fromUtf8(") + ret + QLatin1Char(')');
|
||||||
else
|
// MSVC cannot concat L"foo" "bar" (C2308: concatenating mismatched strings),
|
||||||
return QLatin1String("QStringLiteral(") + ret + QLatin1Char(')');
|
// use QLatin1String instead (all platforms to avoid cross-compiling issues).
|
||||||
|
if (flags & MultiLineString)
|
||||||
|
return QLatin1String("QLatin1String(") + ret + QLatin1Char(')');
|
||||||
|
return QLatin1String("QStringLiteral(") + ret + QLatin1Char(')');
|
||||||
}
|
}
|
||||||
|
|
||||||
inline QHash<QString, DomProperty *> propertyMap(const QList<DomProperty *> &properties)
|
inline QHash<QString, DomProperty *> propertyMap(const QList<DomProperty *> &properties)
|
||||||
|
Loading…
Reference in New Issue
Block a user