18 #include <QRegularExpression>
24 static const QList<QString > sSeps{
"=>",
"," };
27 while ( i <
string.length() )
29 while ( i <
string.length() &&
string.at( i ).isSpace() )
31 QString current =
string.mid( i );
32 QString sep = sSeps.at( bits.length() );
33 if ( current.startsWith(
'"' ) )
35 QRegularExpression re( QStringLiteral(
"^\"((?:\\\\.|[^\"\\\\])*)\".*" ) );
36 QRegularExpressionMatch match = re.match( current );
38 if ( match.hasMatch() )
40 bits[bits.length() - 1] = match.captured( 1 ).replace( QLatin1String(
"\\\"" ), QLatin1String(
"\"" ) ).replace( QLatin1String(
"\\\\" ), QLatin1String(
"\\" ) );
41 i += match.captured( 1 ).length() + 2;
42 while ( i <
string.length() &&
string.at( i ).isSpace() )
45 if (
string.midRef( i ).startsWith( sep ) )
49 else if ( i <
string.length() )
52 i += current.length();
58 i += current.length();
59 bits[bits.length() - 1] = current.trimmed();
64 int sepPos = current.indexOf( sep );
67 i += current.length();
68 bits << current.trimmed();
72 i += sepPos + sep.length();
73 bits << current.left( sepPos ).trimmed();
77 if ( bits.length() == 2 )
79 if ( !bits.at( 0 ).isEmpty() && !bits.at( 1 ).isEmpty() )
80 map[ bits.at( 0 ) ] = bits.at( 1 );
91 for ( QVariantMap::const_iterator it = map.constBegin(); it != map.constEnd(); ++it )
93 QString key = it.key();
94 QString value = it.value().toString();
95 list << QString(
"\"%1\"=>\"%2\"" ).arg( key.replace(
"\\",
"\\\\" ).replace(
"\"",
"\\\"" ),
96 value.replace(
"\\",
"\\\\" ).replace(
"\"",
"\\\"" ) );
98 return list.join(
',' );