Skip to content
Permalink
Browse files

Rollback some changes for now

  • Loading branch information
nyalldawson committed Apr 1, 2021
1 parent 22f6a46 commit f8a35e31d8daea990ecf66e5f9ad75797e7722ee
@@ -717,10 +717,8 @@ QgsDelimitedTextFile::Status QgsDelimitedTextFile::parseRegexp( QString &buffer,
// and extract capture groups
if ( mAnchoredRegexp )
{
const QRegularExpressionMatch match = mDelimRegexp.match( buffer );
if ( !match.hasMatch() )
return RecordInvalid;
const QStringList groups = match.capturedTexts();
if ( mDelimRegexp.indexIn( buffer ) < 0 ) return RecordInvalid;
QStringList groups = mDelimRegexp.capturedTexts();
for ( int i = 1; i < groups.size(); i++ )
{
appendField( fields, groups[i] );
@@ -732,19 +730,15 @@ QgsDelimitedTextFile::Status QgsDelimitedTextFile::parseRegexp( QString &buffer,
int size = buffer.size();
while ( true )
{
if ( pos >= size )
break;
QRegularExpressionMatch match = mDelimRegexp.match( buffer, pos );

int matchPos = match.capturedStart();
if ( pos >= size ) break;
int matchPos = mDelimRegexp.indexIn( buffer, pos );
// If match won't advance cursor, then need to force it along one place
// to avoid infinite loop.
int matchLen = match.capturedLength();
int matchLen = mDelimRegexp.matchedLength();
if ( matchPos == pos && matchLen == 0 )
{
match = mDelimRegexp.match( buffer, pos + 1 );
matchPos = match.capturedStart();
matchLen = match.capturedLength();
matchPos = mDelimRegexp.indexIn( buffer, pos + 1 );
matchLen = mDelimRegexp.matchedLength();
}
// If no match, then field is to end of record
if ( matchPos < 0 )
@@ -757,7 +751,7 @@ QgsDelimitedTextFile::Status QgsDelimitedTextFile::parseRegexp( QString &buffer,
appendField( fields, buffer.mid( pos, matchPos - pos ) );
if ( mDelimRegexp.captureCount() > 0 )
{
QStringList groups = match.capturedTexts();
QStringList groups = mDelimRegexp.capturedTexts();
for ( int i = 1; i < groups.size(); i++ )
{
appendField( fields, groups[i] );
@@ -419,7 +419,7 @@ class QgsDelimitedTextFile : public QObject
int mMaxNameLength = 200;

// Parameters used by parsers
QRegularExpression mDelimRegexp;
QRegExp mDelimRegexp;
bool mAnchoredRegexp = false;
QString mDelimChars;
QString mQuoteChar;
@@ -223,9 +223,8 @@ QStringList QgsDelimitedTextProvider::readCsvtFieldTypes( const QString &filenam
// not allowed in OGR CSVT files. Also doesn't care if int and string fields have

strTypeList = strTypeList.toLower();
const QRegularExpression reTypeList( QRegularExpression::anchoredPattern( QStringLiteral( "^(?:\\s*(\\\"?)(?:integer|real|double|long|longlong|int8|string|date|datetime|time)(?:\\(\\d+(?:\\.\\d+)?\\))?\\1\\s*(?:,|$))+" ) ) );
const QRegularExpressionMatch match = reTypeList.match( strTypeList );
if ( !match.hasMatch() )
QRegExp reTypeList( "^(?:\\s*(\\\"?)(?:integer|real|double|long|longlong|int8|string|date|datetime|time)(?:\\(\\d+(?:\\.\\d+)?\\))?\\1\\s*(?:,|$))+" );
if ( ! reTypeList.exactMatch( strTypeList ) )
{
// Looks like this was supposed to be a CSVT file, so report bad formatted string
if ( message ) { *message = tr( "File type string in %1 is not correctly formatted" ).arg( csvtInfo.fileName() ); }
@@ -237,16 +236,13 @@ QStringList QgsDelimitedTextProvider::readCsvtFieldTypes( const QString &filenam
QgsDebugMsgLevel( QStringLiteral( "Field type string: %1" ).arg( strTypeList ), 2 );

int pos = 0;
const QRegularExpression reType( QStringLiteral( "(integer|real|double|string|date|datetime|time)" ) );
QRegExp reType( "(integer|real|double|string|date|datetime|time)" );

QRegularExpressionMatch typeMatch = reType.match( strTypeList, pos );
while ( typeMatch.hasMatch() )
while ( ( pos = reType.indexIn( strTypeList, pos ) ) != -1 )
{
QgsDebugMsgLevel( QStringLiteral( "Found type: %1" ).arg( typeMatch.captured( 1 ) ), 2 );
types << typeMatch.captured( 1 );
pos += typeMatch.capturedLength();

typeMatch = reType.match( strTypeList, pos );
QgsDebugMsgLevel( QStringLiteral( "Found type: %1" ).arg( reType.cap( 1 ) ), 2 );
types << reType.cap( 1 );
pos += reType.matchedLength();
}

if ( message )

0 comments on commit f8a35e3

Please sign in to comment.