From edf560d9402a8f45c6e00f6381dad56c338b3a5a Mon Sep 17 00:00:00 2001 From: Stephen Kelly Date: Wed, 24 Sep 2014 14:45:55 +0200 Subject: [PATCH] Work around MSVC bug with QStringLiterals. --- templates/lib/node.cpp | 11 ++++++++++- templates/tests/testgenerictypes.cpp | 11 ++++++++++- 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/templates/lib/node.cpp b/templates/lib/node.cpp index 2f85cfce..a933eab6 100644 --- a/templates/lib/node.cpp +++ b/templates/lib/node.cpp @@ -188,7 +188,14 @@ QList< FilterExpression > AbstractNodeFactory::getFilterExpressionList( const QS QStringList AbstractNodeFactory::smartSplit( const QString &str ) const { - const QRegExp r( QStringLiteral( "(" // match +#if defined(Q_CC_MSVC) +// MSVC doesn't like static string concatenations like L"foo" "bar", as +// results from QStringLiteral, so use QLatinString here instead. +#define STRING_LITERAL QLatinString +#else +#define STRING_LITERAL QStringLiteral +#endif + const QRegExp r( STRING_LITERAL( "(" // match "(?:[^\\s\\\'\\\"]*" // things that are not whitespace or escaped quote chars "(?:" // followed by "(?:\"" // Either a quote starting with " @@ -203,6 +210,8 @@ QStringList AbstractNodeFactory::smartSplit( const QString &str ) const ")" // End match ) ); +#undef STRING_LITERAL + QStringList l; int count = 0; int pos = 0; diff --git a/templates/tests/testgenerictypes.cpp b/templates/tests/testgenerictypes.cpp index 347743d3..0bf558b6 100644 --- a/templates/tests/testgenerictypes.cpp +++ b/templates/tests/testgenerictypes.cpp @@ -647,8 +647,15 @@ void TestGenericTypes::testNestedContainers() Grantlee::Context c; c.insert( QStringLiteral( "stack" ), QVariant::fromValue( getMapStack() ) ); +#if defined(Q_CC_MSVC) +// MSVC doesn't like static string concatenations like L"foo" "bar", as +// results from QStringLiteral, so use QLatinString here instead. +#define STRING_LITERAL QLatinString +#else +#define STRING_LITERAL QStringLiteral +#endif Grantlee::Template t1 = engine.newTemplate( - QStringLiteral( "{% for map in stack %}" + STRING_LITERAL( "{% for map in stack %}" "(M {% for key, list in map.items %}" "({{ key }} : (L {% for vector in list %}" "(V {% for number in vector %}" @@ -659,6 +666,8 @@ void TestGenericTypes::testNestedContainers() "{% endfor %}" ) , QStringLiteral( "template1" ) ); +#undef STRING_LITERAL + QString result = t1->render( &c ); QString expectedResult = QStringLiteral(