From c9db7d0c0bfdc934e2cf71989d69e9945f666438 Mon Sep 17 00:00:00 2001 From: Xiao Yi Fang Date: Fri, 21 Jun 2024 17:54:45 +0800 Subject: [PATCH] opt: hunspell replace QRegExp with QRegularExpression --- src/dict/hunspell.cc | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/src/dict/hunspell.cc b/src/dict/hunspell.cc index 165ba86ec..d234757c5 100644 --- a/src/dict/hunspell.cc +++ b/src/dict/hunspell.cc @@ -13,11 +13,9 @@ #include #include #include -#if ( QT_VERSION >= QT_VERSION_CHECK( 6, 0, 0 ) ) - #include -#else - #include -#endif + +#include + #include #include #include @@ -394,7 +392,7 @@ QVector< wstring > suggest( wstring & word, QMutex & hunspellMutex, Hunspell & h wstring lowercasedWord = Folding::applySimpleCaseOnly( word ); - static QRegExp cutStem( R"(^\s*st:(((\s+(?!\w{2}:)(?!-)(?!\+))|\S+)+))" ); + static QRegularExpression cutStem( R"(^\s*st:(((\s+(?!\w{2}:)(?!-)(?!\+))|\S+)+))" ); for ( const auto & x : suggestions ) { QString suggestion = QString::fromStdU32String( decodeFromHunspell( hunspell, x.c_str() ) ); @@ -406,8 +404,9 @@ QVector< wstring > suggest( wstring & word, QMutex & hunspellMutex, Hunspell & h GD_DPRINTF( ">>>Sugg: %s\n", suggestion.toLocal8Bit().data() ); - if ( cutStem.indexIn( suggestion.trimmed() ) != -1 ) { - wstring alt = gd::toWString( cutStem.cap( 1 ) ); + auto match = cutStem.match( suggestion.trimmed() ); + if ( match.hasMatch() ) { + wstring alt = gd::toWString( match.captured( 1 ) ); if ( Folding::applySimpleCaseOnly( alt ) != lowercasedWord ) // No point in providing same word {