Skip to content

Commit

Permalink
Work around MSVC bug with QStringLiterals.
Browse files Browse the repository at this point in the history
  • Loading branch information
steveire committed Sep 24, 2014
1 parent d2c3f54 commit edf560d
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
11 changes: 10 additions & 1 deletion templates/lib/node.cpp
Expand Up @@ -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 "
Expand All @@ -203,6 +210,8 @@ QStringList AbstractNodeFactory::smartSplit( const QString &str ) const
")" // End match
) );

#undef STRING_LITERAL

QStringList l;
int count = 0;
int pos = 0;
Expand Down
11 changes: 10 additions & 1 deletion templates/tests/testgenerictypes.cpp
Expand Up @@ -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 %}"
Expand All @@ -659,6 +666,8 @@ void TestGenericTypes::testNestedContainers()
"{% endfor %}" )
, QStringLiteral( "template1" ) );

#undef STRING_LITERAL

QString result = t1->render( &c );

QString expectedResult = QStringLiteral(
Expand Down

0 comments on commit edf560d

Please sign in to comment.