Skip to content

Commit 5183e34

Browse files
committedDec 7, 2021
Port away from QRegExp
1 parent 4be459f commit 5183e34

File tree

2 files changed

+10
-7
lines changed

2 files changed

+10
-7
lines changed
 

‎src/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ if (NOT IOS)
1919
add_subdirectory(crssync)
2020
endif()
2121

22-
if (NOT WITH_QT6 AND ((WIN32 AND NOT MINGW) OR (UNIX AND NOT APPLE AND NOT ANDROID AND NOT IOS)))
22+
if ((WIN32 AND NOT MINGW) OR (UNIX AND NOT APPLE AND NOT ANDROID AND NOT IOS))
2323
add_subdirectory(crashhandler)
2424
endif()
2525
add_subdirectory(test)

‎src/crashhandler/qgscrashreport.cpp

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -330,16 +330,19 @@ QString QgsCrashReport::htmlToMarkdown( const QString &html )
330330
converted.replace( QLatin1String( "<b>" ), QLatin1String( "**" ) );
331331
converted.replace( QLatin1String( "</b>" ), QLatin1String( "**" ) );
332332

333-
static QRegExp hrefRegEx( "<a\\s+href\\s*=\\s*([^<>]*)\\s*>([^<>]*)</a>" );
333+
static thread_local QRegularExpression hrefRegEx( QStringLiteral( "<a\\s+href\\s*=\\s*([^<>]*)\\s*>([^<>]*)</a>" ) );
334+
334335
int offset = 0;
335-
while ( hrefRegEx.indexIn( converted, offset ) != -1 )
336+
QRegularExpressionMatch match = hrefRegEx.match( converted );
337+
while ( match.hasMatch() )
336338
{
337-
QString url = hrefRegEx.cap( 1 ).replace( QLatin1String( "\"" ), QString() );
339+
QString url = match.captured( 1 ).replace( QLatin1String( "\"" ), QString() );
338340
url.replace( '\'', QString() );
339-
QString name = hrefRegEx.cap( 2 );
341+
QString name = match.captured( 2 );
340342
QString anchor = QStringLiteral( "[%1](%2)" ).arg( name, url );
341-
converted.replace( hrefRegEx, anchor );
342-
offset = hrefRegEx.pos( 1 ) + anchor.length();
343+
converted.replace( match.capturedStart(), match.capturedLength(), anchor );
344+
offset = match.capturedStart() + anchor.length();
345+
match = hrefRegEx.match( converted, offset );
343346
}
344347

345348
return converted;

0 commit comments

Comments
 (0)
Please sign in to comment.