forked from qt-creator/qt-creator
Fixed string escaping when writing QML properties.
This commit is contained in:
@@ -97,7 +97,7 @@ QString QmlTextGenerator::toQml(const AbstractProperty &property, int indentDept
|
|||||||
return stringValue;
|
return stringValue;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
return QString(QLatin1String("\"%1\"")).arg(stringValue);
|
return QString(QLatin1String("\"%1\"")).arg(escape(stringValue));
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
Q_ASSERT("Unknown property type");
|
Q_ASSERT("Unknown property type");
|
||||||
@@ -176,3 +176,16 @@ QString QmlTextGenerator::propertyToQml(const AbstractProperty &property, int in
|
|||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QString QmlTextGenerator::escape(const QString &value)
|
||||||
|
{
|
||||||
|
QString result = value;
|
||||||
|
|
||||||
|
result.replace(QLatin1String("\\"), QLatin1String("\\\\"));
|
||||||
|
result.replace(QLatin1String("\""), QLatin1String("\\\""));
|
||||||
|
result.replace(QLatin1String("\t"), QLatin1String("\\\t"));
|
||||||
|
result.replace(QLatin1String("\r"), QLatin1String("\\\r"));
|
||||||
|
result.replace(QLatin1String("\n"), QLatin1String("\\\n"));
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|||||||
@@ -56,6 +56,8 @@ private:
|
|||||||
QString propertiesToQml(const ModelNode &node, int indentDepth) const;
|
QString propertiesToQml(const ModelNode &node, int indentDepth) const;
|
||||||
QString propertyToQml(const AbstractProperty &property, int indentDepth) const;
|
QString propertyToQml(const AbstractProperty &property, int indentDepth) const;
|
||||||
|
|
||||||
|
static QString escape(const QString &value);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QStringList m_propertyOrder;
|
QStringList m_propertyOrder;
|
||||||
int m_indentDepth;
|
int m_indentDepth;
|
||||||
|
|||||||
Reference in New Issue
Block a user