Skip to content

Commit

Permalink
Rollback some changes for now
Browse files Browse the repository at this point in the history
  • Loading branch information
nyalldawson committed Apr 1, 2021
1 parent 22f6a46 commit f8a35e3
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 26 deletions.
22 changes: 8 additions & 14 deletions src/providers/delimitedtext/qgsdelimitedtextfile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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] );
Expand All @@ -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 )
Expand All @@ -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] );
Expand Down
2 changes: 1 addition & 1 deletion src/providers/delimitedtext/qgsdelimitedtextfile.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
18 changes: 7 additions & 11 deletions src/providers/delimitedtext/qgsdelimitedtextprovider.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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() ); }
Expand All @@ -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 )
Expand Down

0 comments on commit f8a35e3

Please sign in to comment.