Commit e65fb592 authored by Ahmad Samir's avatar Ahmad Samir Committed by Nikita Sirgienko
Browse files

[Sage Backend] Port QRegExp to QRegularExpression

To match a backspace char with PCRE/QRegularExpression we have to use
\b inside [].

Use QStringLiteral with QRegularExpression ctor, as it doesn't have a
QLatin1String overload and will convert the to QString anyway.

All unittests pass except for:
- testlua (unrelated, fails on master too)
- testworksheet (hangs, here and on master too)
- testsage, fails to pass here and on master
parent 307ed227
...@@ -29,7 +29,7 @@ ...@@ -29,7 +29,7 @@
#include <QDebug> #include <QDebug>
#include <KLocalizedString> #include <KLocalizedString>
#include <QMimeDatabase> #include <QMimeDatabase>
#include <QRegExp> #include <QRegularExpression>
SageExpression::SageExpression( Cantor::Session* session, bool internal ) : Cantor::Expression(session, internal), SageExpression::SageExpression( Cantor::Session* session, bool internal ) : Cantor::Expression(session, internal),
m_isHelpRequest(false), m_isHelpRequest(false),
...@@ -79,14 +79,18 @@ void SageExpression::parseOutput(const QString& text) ...@@ -79,14 +79,18 @@ void SageExpression::parseOutput(const QString& text)
//remove carriage returns, we only use \n internally //remove carriage returns, we only use \n internally
output.remove(QLatin1Char('\r')); output.remove(QLatin1Char('\r'));
//replace appearing backspaces, as they mess the whole output up //replace appearing backspaces, as they mess the whole output up
output.remove(QRegExp(QLatin1String(".\b"))); //with QRegularExpression/PCRE to make \b match a backspace put it inside []
//see https://perldoc.perl.org/perlrecharclass.html#Bracketed-Character-Classes
output.remove(QRegularExpression(QStringLiteral(".[\b]")));
//replace Escape sequences (only tested with `ls` command) //replace Escape sequences (only tested with `ls` command)
const QChar ESC(0x1b); const QChar ESC(0x1b);
output.remove(QRegExp(QString(ESC)+QLatin1String("\\][^\a]*\a"))); output.remove(QRegularExpression(QString(ESC)+QLatin1String("\\][^\a]*\a")));
const QString promptRegexpBase(QLatin1String("(^|\\n)%1")); const QString promptRegexpBase(QLatin1String("(^|\\n)%1"));
const QRegExp promptRegexp(promptRegexpBase.arg(QRegExp::escape(QLatin1String(SageSession::SagePrompt)))); const QRegularExpression promptRegexp(promptRegexpBase.arg(
const QRegExp altPromptRegexp(promptRegexpBase.arg(QRegExp::escape(QLatin1String(SageSession::SageAlternativePrompt)))); QRegularExpression::escape(QLatin1String(SageSession::SagePrompt))));
const QRegularExpression altPromptRegexp(promptRegexpBase.arg(
QRegularExpression::escape(QLatin1String(SageSession::SageAlternativePrompt))));
bool endsWithAlternativePrompt=output.endsWith(QLatin1String(SageSession::SageAlternativePrompt)); bool endsWithAlternativePrompt=output.endsWith(QLatin1String(SageSession::SageAlternativePrompt));
...@@ -192,7 +196,7 @@ void SageExpression::evalFinished() ...@@ -192,7 +196,7 @@ void SageExpression::evalFinished()
//strip html tags //strip html tags
if(isHtml) if(isHtml)
{ {
stripped.remove( QRegExp( QLatin1String("<[a-zA-Z\\/][^>]*>") ) ); stripped.remove( QRegularExpression( QStringLiteral("<[a-zA-Z\\/][^>]*>") ) );
} }
if (stripped.endsWith(QLatin1Char('\n'))) if (stripped.endsWith(QLatin1Char('\n')))
...@@ -205,7 +209,7 @@ void SageExpression::evalFinished() ...@@ -205,7 +209,7 @@ void SageExpression::evalFinished()
stripped.replace(QLatin1Char('\n'), QLatin1String("<br/>\n")); stripped.replace(QLatin1Char('\n'), QLatin1String("<br/>\n"));
//make things quoted in `` `` bold //make things quoted in `` `` bold
stripped.replace(QRegExp(QLatin1String("``([^`]*)``")), QLatin1String("<b>\\1</b>")); stripped.replace(QRegularExpression(QStringLiteral("``([^`]*)``")), QStringLiteral("<b>\\1</b>"));
addResult(new Cantor::HelpResult(stripped, true)); addResult(new Cantor::HelpResult(stripped, true));
} }
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment