-
-
Notifications
You must be signed in to change notification settings - Fork 3.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Addition of a QgsHstoreUtils parse function
- Loading branch information
Showing
6 changed files
with
171 additions
and
64 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
/************************************************************************ | ||
* This file has been generated automatically from * | ||
* * | ||
* src/core/qgshstoreutils.h * | ||
* * | ||
* Do not edit manually ! Edit header and run scripts/sipify.pl again * | ||
************************************************************************/ | ||
|
||
|
||
|
||
%ModuleHeaderCode | ||
#include "qgshstoreutils.h" | ||
%End | ||
|
||
namespace QgsHstoreUtils | ||
{ | ||
|
||
QVariantMap parse( const QString &string ); | ||
%Docstring | ||
Returns a QVariantMap object containing the key and values from a hstore-formatted string. | ||
|
||
:param string: The hstored-formatted string | ||
|
||
.. versionadded:: 3.4 | ||
%End | ||
|
||
}; | ||
|
||
/************************************************************************ | ||
* This file has been generated automatically from * | ||
* * | ||
* src/core/qgshstoreutils.h * | ||
* * | ||
* Do not edit manually ! Edit header and run scripts/sipify.pl again * | ||
************************************************************************/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
/*************************************************************************** | ||
qgshstoreutils.h | ||
--------------------- | ||
begin : Sept 2018 | ||
copyright : (C) 2018 by Mathieu Pellerin | ||
email : nirvn dot asia at gmail dot com | ||
*************************************************************************** | ||
* * | ||
* This program is free software; you can redistribute it and/or modify * | ||
* it under the terms of the GNU General Public License as published by * | ||
* the Free Software Foundation; either version 2 of the License, or * | ||
* (at your option) any later version. * | ||
* * | ||
***************************************************************************/ | ||
|
||
#include "qgshstoreutils.h" | ||
|
||
#include <QRegularExpression> | ||
|
||
QVariantMap QgsHstoreUtils::parse( const QString &string ) | ||
{ | ||
QVariantMap map; | ||
QList<QString> bits; | ||
static const QList<QString > sSeps{ "=>", "," }; | ||
|
||
int i = 0; | ||
while ( i < string.length() ) | ||
{ | ||
while ( i < string.length() && string.at( i ).isSpace() ) | ||
++i; | ||
QString current = string.mid( i ); | ||
QString sep = sSeps.at( bits.length() ); | ||
if ( current.startsWith( '"' ) ) | ||
{ | ||
QRegularExpression re( "^\"((?:\\\\.|[^\"\\\\])*)\".*" ); | ||
QRegularExpressionMatch match = re.match( current ); | ||
bits << QString(); | ||
if ( match.hasMatch() ) | ||
{ | ||
bits[bits.length() - 1] = match.captured( 1 ).replace( QLatin1String( "\\\"" ), QLatin1String( "\"" ) ).replace( QLatin1String( "\\\\" ), QLatin1String( "\\" ) ); | ||
i += match.captured( 1 ).length() + 2; | ||
while ( i < string.length() && string.at( i ).isSpace() ) | ||
++i; | ||
|
||
if ( string.midRef( i ).startsWith( sep ) ) | ||
{ | ||
i += sep.length(); | ||
} | ||
else if ( i < string.length() ) | ||
{ | ||
// hstore string format broken, end construction | ||
i += current.length(); | ||
} | ||
} | ||
else | ||
{ | ||
// hstore string format broken, end construction | ||
i += current.length(); | ||
bits[bits.length() - 1] = current.trimmed(); | ||
} | ||
} | ||
else | ||
{ | ||
int sepPos = current.indexOf( sep ); | ||
if ( sepPos < 0 ) | ||
{ | ||
i += current.length(); | ||
bits << current.trimmed(); | ||
} | ||
else | ||
{ | ||
i += sepPos + sep.length(); | ||
bits << current.left( sepPos ).trimmed(); | ||
} | ||
} | ||
|
||
if ( bits.length() == 2 ) | ||
{ | ||
if ( !bits.at( 0 ).isEmpty() && !bits.at( 1 ).isEmpty() ) | ||
map[ bits.at( 0 ) ] = bits.at( 1 ); | ||
bits.clear(); | ||
} | ||
} | ||
|
||
return map; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
/*************************************************************************** | ||
qgshstoreutils.h | ||
--------------------- | ||
begin : Sept 2018 | ||
copyright : (C) 2018 by Mathieu Pellerin | ||
email : nirvn dot asia at gmail dot com | ||
*************************************************************************** | ||
* * | ||
* This program is free software; you can redistribute it and/or modify * | ||
* it under the terms of the GNU General Public License as published by * | ||
* the Free Software Foundation; either version 2 of the License, or * | ||
* (at your option) any later version. * | ||
* * | ||
***************************************************************************/ | ||
|
||
#ifndef QGSHSTOREUTILS_H | ||
#define QGSHSTOREUTILS_H | ||
|
||
#include "qgis_core.h" | ||
#include "qgis.h" | ||
|
||
#ifdef SIP_RUN | ||
% ModuleHeaderCode | ||
#include "qgshstoreutils.h" | ||
% End | ||
#endif | ||
|
||
/** | ||
* \ingroup core | ||
* The QgsHstoreUtils namespace provides functions to handle hstore-formatted strings. | ||
* \since QGIS 3.4 | ||
*/ | ||
namespace QgsHstoreUtils | ||
{ | ||
|
||
/** | ||
* Returns a QVariantMap object containing the key and values from a hstore-formatted string. | ||
* \param string The hstored-formatted string | ||
* \since QGIS 3.4 | ||
*/ | ||
CORE_EXPORT QVariantMap parse( const QString &string ); | ||
|
||
}; | ||
|
||
#endif //QGSHSTOREUTILS_H |