changeset 31998:4d01a2860f3e

Replace deprecated QRegExp by QRegularExpression in libgui/qterminal/libqterminal/unix. * libgui/qterminal/libqterminal/unix/Filter.cpp (RegExpFilter::setRegExp, RegExpFilter::regExp, RegExpFilter::process, UrlFilter::process, UrlFilter::HotSpot::UrlType, UrlFilter::HotSpot::activate, UrlFilter::FullUrlRegExp, UrlFilter::EmailAddressRegExp, UrlFilter::CompleteUrlRegExp, UrlFilter::ErrorLinkRegExp, UrlFilter::ParseErrorLinkRegExp, UrlFilter::CompleteErrorLinkRegExp, UrlFilter::HotSpot::actions), libgui/qterminal/libqterminal/unix/Filter.h, libgui/qterminal/libqterminal/unix/KeyboardTranslator.cpp (KeyboardTranslatorReader::tokenize): Replace deprecated QRegExp by QRegularExpression. Cleanup Qt header includes. * libgui/qterminal/libqterminal/unix/Emulation.cpp, libgui/qterminal/libqterminal/unix/TerminalMode.cpp: Cleanup Qt header includes.
author Markus Mützel <markus.muetzel@gmx.de>
date Wed, 12 Apr 2023 15:23:05 +0200
parents 7e92d6468a35
children 835e9eab3ead
files libgui/qterminal/libqterminal/unix/Emulation.cpp libgui/qterminal/libqterminal/unix/Filter.cpp libgui/qterminal/libqterminal/unix/Filter.h libgui/qterminal/libqterminal/unix/KeyboardTranslator.cpp libgui/qterminal/libqterminal/unix/TerminalModel.cpp
diffstat 5 files changed, 135 insertions(+), 129 deletions(-) [+]
line wrap: on
line diff
--- a/libgui/qterminal/libqterminal/unix/Emulation.cpp	Wed Apr 12 13:22:50 2023 +0200
+++ b/libgui/qterminal/libqterminal/unix/Emulation.cpp	Wed Apr 12 15:23:05 2023 +0200
@@ -35,13 +35,11 @@
 // Qt
 #include <QApplication>
 #include <QClipboard>
-#include <QtCore/QHash>
+#include <QHash>
 #include <QKeyEvent>
-#include <QtCore/QRegExp>
-#include <QtCore/QTextStream>
-#include <QtCore/QThread>
-
-#include <QtCore/QTime>
+#include <QTextStream>
+#include <QThread>
+#include <QTime>
 
 // Konsole
 #include "unix/KeyboardTranslator.h"
--- a/libgui/qterminal/libqterminal/unix/Filter.cpp	Wed Apr 12 13:22:50 2023 +0200
+++ b/libgui/qterminal/libqterminal/unix/Filter.cpp	Wed Apr 12 15:23:05 2023 +0200
@@ -28,9 +28,9 @@
 #include <QAction>
 #include <QApplication>
 #include <QClipboard>
-#include <QtCore/QString>
+#include <QString>
 
-#include <QtCore/QSharedData>
+#include <QSharedData>
 #include <QtCore>
 
 // Konsole
@@ -349,11 +349,11 @@
     return _capturedTexts;
 }
 
-void RegExpFilter::setRegExp(const QRegExp& regExp)
+void RegExpFilter::setRegExp (const QRegularExpression& regExp)
 {
     _searchText = regExp;
 }
-QRegExp RegExpFilter::regExp() const
+QRegularExpression RegExpFilter::regExp () const
 {
     return _searchText;
 }
@@ -361,7 +361,7 @@
 {
     _buffer = QString();
 }*/
-void RegExpFilter::process()
+void RegExpFilter::process ()
 {
     int pos = 0;
     const QString* text = buffer();
@@ -371,37 +371,35 @@
     // ignore any regular expressions which match an empty string.
     // otherwise the while loop below will run indefinitely
     static const QString emptyString("");
-    if ( _searchText.exactMatch(emptyString) )
+    QRegularExpressionMatch match = _searchText.match (emptyString);
+    if ( match.hasMatch () )
         return;
 
-    while(pos >= 0)
+    match = _searchText.match (*text, pos);
+    while (match.hasMatch ())
     {
-        pos = _searchText.indexIn(*text,pos);
+        pos = match.capturedStart ();
+        int startLine = 0;
+        int endLine = 0;
+        int startColumn = 0;
+        int endColumn = 0;
 
-        if ( pos >= 0 )
-        {
-
-            int startLine = 0;
-            int endLine = 0;
-            int startColumn = 0;
-            int endColumn = 0;
-
+        //kDebug() << "pos from " << pos << " to " << pos + _searchText.matchedLength();
 
-            //kDebug() << "pos from " << pos << " to " << pos + _searchText.matchedLength();
+        getLineColumn (match.capturedStart (), startLine, startColumn);
+        getLineColumn (match.capturedEnd (), endLine, endColumn);
 
-            getLineColumn(pos,startLine,startColumn);
-            getLineColumn(pos + _searchText.matchedLength(),endLine,endColumn);
+        RegExpFilter::HotSpot* spot = newHotSpot(startLine,startColumn,
+                                       endLine,endColumn,_type);
+        spot->setCapturedTexts (match.capturedTexts ());
 
-            RegExpFilter::HotSpot* spot = newHotSpot(startLine,startColumn,
-                                           endLine,endColumn,_type);
-            spot->setCapturedTexts(_searchText.capturedTexts());
+        addHotSpot( spot );
+        pos += match.capturedLength ();
 
-            addHotSpot( spot );
-            pos += _searchText.matchedLength();
+        // if matchedLength == 0, the program will get stuck in an infinite loop
+        Q_ASSERT( match.capturedLength () > 0 );
 
-            // if matchedLength == 0, the program will get stuck in an infinite loop
-            Q_ASSERT( _searchText.matchedLength() > 0 );
-        }
+        match = _searchText.match (*text, pos);
     }
 }
 
@@ -419,7 +417,7 @@
                                                endLine,endColumn,t);
 }
 
-void UrlFilter::process()
+void UrlFilter::process ()
 {
     int pos = 0;
     const QString* text = buffer();
@@ -429,43 +427,40 @@
     // ignore any regular expressions which match an empty string.
     // otherwise the while loop below will run indefinitely
     static const QString emptyString("");
-    if ( _searchText.exactMatch(emptyString) )
+    QRegularExpressionMatch match = _searchText.match (emptyString);
+    if ( match.hasMatch () )
         return;
 
-    while(pos >= 0)
+    match = _searchText.match (*text, pos);
+    while (match.hasMatch ())
     {
-        pos = _searchText.indexIn(*text,pos);
-
-        if ( pos >= 0 )
-        {
+        int startLine = 0;
+        int endLine = 0;
+        int startColumn = 0;
+        int endColumn = 0;
 
-            int startLine = 0;
-            int endLine = 0;
-            int startColumn = 0;
-            int endColumn = 0;
+        //kDebug() << "pos from " << pos << " to " << pos + _searchText.matchedLength();
 
-
-            //kDebug() << "pos from " << pos << " to " << pos + _searchText.matchedLength();
+        getLineColumn (match.capturedStart (), startLine, startColumn);
+        getLineColumn (match.capturedEnd (), endLine, endColumn);
 
-            getLineColumn(pos,startLine,startColumn);
-            getLineColumn(pos + _searchText.matchedLength(),endLine,endColumn);
-
-            UrlFilter::HotSpot* spot = newHotSpot(startLine,startColumn,
-                                           endLine,endColumn,_type);
-            spot->setCapturedTexts(_searchText.capturedTexts());
+        UrlFilter::HotSpot* spot = newHotSpot(startLine,startColumn,
+                                              endLine,endColumn,_type);
+        spot->setCapturedTexts(match.capturedTexts ());
 
-            // Connect the signal of the urlobject to the slot of the filter;
-            // the filter is then signaling to the main window
-            connect (spot->get_urlObject (),
-                     SIGNAL (request_open_file_signal (const QString&, int)),
-                     this, SLOT (request_open_file (const QString&, int)));
+        // Connect the signal of the urlobject to the slot of the filter;
+        // the filter is then signaling to the main window
+        connect (spot->get_urlObject (),
+                 SIGNAL (request_open_file_signal (const QString&, int)),
+                 this, SLOT (request_open_file (const QString&, int)));
 
-            addHotSpot( spot );
-            pos += _searchText.matchedLength();
+        addHotSpot( spot );
+        pos += match.capturedLength();
 
-            // if matchedLength == 0, the program will get stuck in an infinite loop
-            Q_ASSERT( _searchText.matchedLength() > 0 );
-        }
+        // if matchedLength == 0, the program will get stuck in an infinite loop
+        Q_ASSERT( match.capturedLength () > 0 );
+
+        match = _searchText.match (*text, pos);
     }
 }
 
@@ -489,23 +484,27 @@
     else
         return QString();
 }
-UrlFilter::HotSpot::UrlType UrlFilter::HotSpot::urlType() const
+UrlFilter::HotSpot::UrlType UrlFilter::HotSpot::urlType () const
 {
     QString url = capturedTexts().first();
 
-    if ( FullUrlRegExp.exactMatch(url) )
+    QRegularExpressionMatch match = FullUrlRegExp.match (url);
+    if ( match.hasMatch () )
         return StandardUrl;
-    else if ( EmailAddressRegExp.exactMatch(url) )
+    match = EmailAddressRegExp.match (url);
+    if ( match.hasMatch () )
         return Email;
-    else if ( ErrorLinkRegExp.exactMatch(url) )
+    match = ErrorLinkRegExp.match (url);
+    if ( match.hasMatch () )
         return ErrorLink;
-    else if ( ParseErrorLinkRegExp.exactMatch(url) )
+    match = ParseErrorLinkRegExp.match (url);
+    if ( match.hasMatch () )
         return ParseErrorLink;
-    else
-        return Unknown;
+
+    return Unknown;
 }
 
-void UrlFilter::HotSpot::activate(QObject* object)
+void UrlFilter::HotSpot::activate (QObject* object)
 {
     QString url = capturedTexts().first();
 
@@ -538,11 +537,11 @@
           }
         else if (kind == ErrorLink)
           {
-            int pos = ErrorLinkRegExp.indexIn (url);
-            if (pos > -1)
+            QRegularExpressionMatch match = ErrorLinkRegExp.match (url);
+            if (match.hasMatch ())
               {
-                QString file_name = ErrorLinkRegExp.cap (1);
-                QString line = ErrorLinkRegExp.cap (2);
+                QString file_name = match.captured (1);
+                QString line = match.captured (2);
                 // call the urlobject's method for opening a file; this
                 // method then signals to the filter
                 _urlObject->request_open_file (file_name, line.toInt ());
@@ -550,11 +549,11 @@
           }
         else if (kind == ParseErrorLink)
           {
-            int pos = ParseErrorLinkRegExp.indexIn (url);
-            if (pos > -1)
+            QRegularExpressionMatch match = ParseErrorLinkRegExp.match (url);
+            if (match.hasMatch ())
               {
-                QString line = ParseErrorLinkRegExp.cap (1);
-                QString file_name = ParseErrorLinkRegExp.cap (2);
+                QString line = match.captured (1);
+                QString file_name = match.captured (2);
                 // call the urlobject's method for opening a file; this
                 // method then signals to the filter
                 _urlObject->request_open_file (file_name, line.toInt ());
@@ -574,21 +573,27 @@
 //regexp matches:
 // full url:
 // protocolname:// or www. followed by anything other than whitespaces, <, >, ' or ", and ends before whitespaces, <, >, ', ", ], !, comma and dot
-const QRegExp UrlFilter::FullUrlRegExp("(www\\.(?!\\.)|[a-z][a-z0-9+.-]*://)[^\\s<>'\"]+[^!,\\.\\s<>'\"\\]]");
+const QRegularExpression
+UrlFilter::FullUrlRegExp {"(www\\.(?!\\.)|[a-z][a-z0-9+.-]*://)[^\\s<>'\"]+[^!,\\.\\s<>'\"\\]]"};
 // email address:
 // [word chars, dots or dashes]@[word chars, dots or dashes].[word chars]
-const QRegExp UrlFilter::EmailAddressRegExp("\\b(\\w|\\.|-)+@(\\w|\\.|-)+\\.\\w+\\b");
+const QRegularExpression
+UrlFilter::EmailAddressRegExp {"\\b(\\w|\\.|-)+@(\\w|\\.|-)+\\.\\w+\\b"};
 // matches full url or email address
-const QRegExp UrlFilter::CompleteUrlRegExp('('+FullUrlRegExp.pattern()+'|'+
-                                            EmailAddressRegExp.pattern()+')');
+const QRegularExpression
+UrlFilter::CompleteUrlRegExp {'(' + FullUrlRegExp.pattern() + '|' +
+                              EmailAddressRegExp.pattern() + ')'};
 // error link:
 //   normal error
-const QRegExp UrlFilter::ErrorLinkRegExp ("(\\S+) at line (\\d+) column (?:\\d+)");
+const QRegularExpression
+UrlFilter::ErrorLinkRegExp {"(\\S+) at line (\\d+) column (?:\\d+)"};
 //   parse error
-const QRegExp UrlFilter::ParseErrorLinkRegExp ("parse error near line (\\d+) of file (\\S+)");
+const QRegularExpression
+UrlFilter::ParseErrorLinkRegExp {"parse error near line (\\d+) of file (\\S+)"};
 //   complete regexp
-const QRegExp UrlFilter::CompleteErrorLinkRegExp ('('+ErrorLinkRegExp.pattern ()+'|'+
-                                                     ParseErrorLinkRegExp.pattern ()+')');
+const QRegularExpression
+UrlFilter::CompleteErrorLinkRegExp {'('+ErrorLinkRegExp.pattern ()+'|'+
+                                    ParseErrorLinkRegExp.pattern ()+')'};
 
 
 UrlFilter::UrlFilter (Type t)
@@ -607,7 +612,7 @@
 {
     _filter->activate(sender());
 }
-QList<QAction*> UrlFilter::HotSpot::actions()
+QList<QAction*> UrlFilter::HotSpot::actions ()
 {
     QList<QAction*> list;
 
@@ -633,11 +638,11 @@
     else if ( kind == ErrorLink )
     {
       QString url = capturedTexts().first();
-      int pos = ErrorLinkRegExp.indexIn (url);
-      if (pos >= 0)
+      QRegularExpressionMatch match = ErrorLinkRegExp.match (url);
+      if (match.hasMatch ())
         {
-          QString file_name = ErrorLinkRegExp.cap (1);
-          QString line = ErrorLinkRegExp.cap (2);
+          QString file_name = match.captured (1);
+          QString line = match.captured (2);
           openAction->setText(tr ("Edit %1 at line %2")
                               .arg (file_name).arg (line));
         }
@@ -645,11 +650,11 @@
     else if ( kind == ParseErrorLink )
     {
       QString url = capturedTexts().first();
-      int pos = ParseErrorLinkRegExp.indexIn (url);
-      if (pos >= 0)
+      QRegularExpressionMatch match = ParseErrorLinkRegExp.match (url);
+      if (match.hasMatch ())
         {
-          QString line = ParseErrorLinkRegExp.cap (1);
-          QString file_name = ParseErrorLinkRegExp.cap (2);
+          QString line = match.captured (1);
+          QString file_name = match.captured (2);
           openAction->setText(tr ("Edit %1 at line %2")
                               .arg (file_name).arg (line));
         }
--- a/libgui/qterminal/libqterminal/unix/Filter.h	Wed Apr 12 13:22:50 2023 +0200
+++ b/libgui/qterminal/libqterminal/unix/Filter.h	Wed Apr 12 15:23:05 2023 +0200
@@ -25,11 +25,11 @@
 
 // Qt
 #include <QAction>
-#include <QtCore/QList>
-#include <QtCore/QObject>
-#include <QtCore/QStringList>
-#include <QtCore/QHash>
-#include <QtCore/QRegExp>
+#include <QHash>
+#include <QList>
+#include <QObject>
+#include <QRegularExpression>
+#include <QStringList>
 
 // Local
 #include "unix/Character.h"
@@ -230,9 +230,9 @@
      * Regular expressions which match the empty string are treated as not matching
      * anything.
      */
-    void setRegExp(const QRegExp& text);
+    void setRegExp(const QRegularExpression& text);
     /** Returns the regular expression which the filter searches for in blocks of text */
-    QRegExp regExp() const;
+    QRegularExpression regExp() const;
 
     /**
      * Reimplemented to search the filter's text buffer for text matching regExp()
@@ -256,7 +256,7 @@
                                     int endLine,int endColumn, Type);
     Type _type;
 
-    QRegExp _searchText;
+    QRegularExpression _searchText;
 };
 
 class FilterObject;
@@ -316,14 +316,14 @@
 
 private:
 
-    static const QRegExp FullUrlRegExp;
-    static const QRegExp EmailAddressRegExp;
-    static const QRegExp ErrorLinkRegExp;
-    static const QRegExp ParseErrorLinkRegExp;
-    static const QRegExp CompleteErrorLinkRegExp;
+    static const QRegularExpression FullUrlRegExp;
+    static const QRegularExpression EmailAddressRegExp;
+    static const QRegularExpression ErrorLinkRegExp;
+    static const QRegularExpression ParseErrorLinkRegExp;
+    static const QRegularExpression CompleteErrorLinkRegExp;
 
     // combined OR of FullUrlRegExp and EmailAddressRegExp
-    static const QRegExp CompleteUrlRegExp;
+    static const QRegularExpression CompleteUrlRegExp;
 };
 
 class FilterObject : public QObject
--- a/libgui/qterminal/libqterminal/unix/KeyboardTranslator.cpp	Wed Apr 12 13:22:50 2023 +0200
+++ b/libgui/qterminal/libqterminal/unix/KeyboardTranslator.cpp	Wed Apr 12 15:23:05 2023 +0200
@@ -29,9 +29,10 @@
 #include <stdio.h>
 
 // Qt
-#include <QtCore/QBuffer>
-#include <QtCore/QFile>
-#include <QtCore/QFileInfo>
+#include <QBuffer>
+#include <QFile>
+#include <QFileInfo>
+#include <QRegularExpression>
 #include <QtCore>
 #include <QtGui>
 
@@ -509,49 +510,52 @@
 {
     return false;
 }
-QList<KeyboardTranslatorReader::Token> KeyboardTranslatorReader::tokenize(const QString& line)
+QList<KeyboardTranslatorReader::Token>
+KeyboardTranslatorReader::tokenize (const QString& line)
 {
     QString text = line.simplified();
 
     // comment line: # comment
-    static QRegExp comment("\\#.*");
+    static QRegularExpression comment {"\\#.*"};
     // title line: keyboard "title"
-    static QRegExp title("keyboard\\s+\"(.*)\"");
+    static QRegularExpression title {"keyboard\\s+\"(.*)\""};
     // key line: key KeySequence : "output"
     // key line: key KeySequence : command
-    static QRegExp key("key\\s+([\\w\\+\\s\\-]+)\\s*:\\s*(\"(.*)\"|\\w+)");
+    static QRegularExpression key {"key\\s+([\\w\\+\\s\\-]+)\\s*:\\s*(\"(.*)\"|\\w+)"};
 
     QList<Token> list;
 
-    if ( text.isEmpty() || comment.exactMatch(text) )
+    if ( text.isEmpty() || comment.match (text).hasMatch () )
     {
         return list;
     }
 
-    if ( title.exactMatch(text) )
+    QRegularExpressionMatch match;
+    if ((match = title.match (text)).hasMatch ())
     {
         Token titleToken = { Token::TitleKeyword , QString() };
-        Token textToken = { Token::TitleText , title.capturedTexts()[1] };
+        Token textToken = { Token::TitleText , match.captured (1) };
 
         list << titleToken << textToken;
     }
-    else if  ( key.exactMatch(text) )
+    else if  ((match = key.match (text)).hasMatch ())
     {
         Token keyToken = { Token::KeyKeyword , QString() };
-        Token sequenceToken = { Token::KeySequence , key.capturedTexts()[1].remove(' ') };
+        Token sequenceToken = { Token::KeySequence,
+                                match.captured (1).remove (' ') };
 
         list << keyToken << sequenceToken;
 
-        if ( key.capturedTexts()[3].isEmpty() )
+        if ( match.captured (3).isEmpty () )
         {
             // capturedTexts()[2] is a command
-            Token commandToken = { Token::Command , key.capturedTexts()[2] };
+            Token commandToken = { Token::Command , match.captured (2) };
             list << commandToken;
         }
         else
         {
             // capturedTexts()[3] is the output string
-            Token outputToken = { Token::OutputText , key.capturedTexts()[3] };
+            Token outputToken = { Token::OutputText , match.captured (3) };
             list << outputToken;
         }
     }
--- a/libgui/qterminal/libqterminal/unix/TerminalModel.cpp	Wed Apr 12 13:22:50 2023 +0200
+++ b/libgui/qterminal/libqterminal/unix/TerminalModel.cpp	Wed Apr 12 15:23:05 2023 +0200
@@ -32,11 +32,10 @@
 
 // Qt
 #include <QApplication>
-#include <QtCore/QByteRef>
-#include <QtCore/QDir>
-#include <QtCore/QFile>
-#include <QtCore/QRegExp>
-#include <QtCore/QStringList>
+#include <QByteRef>
+#include <QDir>
+#include <QFile>
+#include <QStringList>
 #include <QtCore>
 
 #include "unix/TerminalView.h"