Skip to content

Commit

Permalink
Port away from QRegExp
Browse files Browse the repository at this point in the history
  • Loading branch information
nyalldawson committed Dec 7, 2021
1 parent 4be459f commit 5183e34
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 7 deletions.
2 changes: 1 addition & 1 deletion src/CMakeLists.txt
Expand Up @@ -19,7 +19,7 @@ if (NOT IOS)
add_subdirectory(crssync)
endif()

if (NOT WITH_QT6 AND ((WIN32 AND NOT MINGW) OR (UNIX AND NOT APPLE AND NOT ANDROID AND NOT IOS)))
if ((WIN32 AND NOT MINGW) OR (UNIX AND NOT APPLE AND NOT ANDROID AND NOT IOS))
add_subdirectory(crashhandler)
endif()
add_subdirectory(test)
Expand Down
15 changes: 9 additions & 6 deletions src/crashhandler/qgscrashreport.cpp
Expand Up @@ -330,16 +330,19 @@ QString QgsCrashReport::htmlToMarkdown( const QString &html )
converted.replace( QLatin1String( "<b>" ), QLatin1String( "**" ) );
converted.replace( QLatin1String( "</b>" ), QLatin1String( "**" ) );

static QRegExp hrefRegEx( "<a\\s+href\\s*=\\s*([^<>]*)\\s*>([^<>]*)</a>" );
static thread_local QRegularExpression hrefRegEx( QStringLiteral( "<a\\s+href\\s*=\\s*([^<>]*)\\s*>([^<>]*)</a>" ) );

int offset = 0;
while ( hrefRegEx.indexIn( converted, offset ) != -1 )
QRegularExpressionMatch match = hrefRegEx.match( converted );
while ( match.hasMatch() )
{
QString url = hrefRegEx.cap( 1 ).replace( QLatin1String( "\"" ), QString() );
QString url = match.captured( 1 ).replace( QLatin1String( "\"" ), QString() );
url.replace( '\'', QString() );
QString name = hrefRegEx.cap( 2 );
QString name = match.captured( 2 );
QString anchor = QStringLiteral( "[%1](%2)" ).arg( name, url );
converted.replace( hrefRegEx, anchor );
offset = hrefRegEx.pos( 1 ) + anchor.length();
converted.replace( match.capturedStart(), match.capturedLength(), anchor );
offset = match.capturedStart() + anchor.length();
match = hrefRegEx.match( converted, offset );
}

return converted;
Expand Down

0 comments on commit 5183e34

Please sign in to comment.