Commit bc3003f7 authored by Ahmad Samir's avatar Ahmad Samir
Browse files

[kio-extras] Port some QRegExp usage to QRegularExpression

Test Plan: Showing man pages in konqueror still works

Reviewers: dfaure, sitter, apol, meven

Reviewed By: meven

Subscribers: meven, kfm-devel, kde-frameworks-devel

Tags: #dolphin, #frameworks

Differential Revision: https://phabricator.kde.org/D28161
parent a5ded8f0
......@@ -21,7 +21,7 @@
#include <stdio.h>
#include <stdlib.h>
#include <qregexp.h>
#include <QRegularExpression>
#include <qtextdocument.h>
#include <qurlquery.h>
......@@ -181,7 +181,8 @@ int BookmarksProtocol::sizeOfGroup( const KBookmarkGroup &folder, bool real )
void BookmarksProtocol::get( const QUrl& url )
{
QString path = url.path();
QRegExp regexp("^/(background|icon)/([\\S]+)");
const QRegularExpression regexp(QStringLiteral("^/(background|icon)/([\\S]+)"));
QRegularExpressionMatch rmatch;
if (path.isEmpty() || path == "/") {
echoIndex();
......@@ -191,8 +192,8 @@ void BookmarksProtocol::get( const QUrl& url )
} else if (path == "/editbookmarks") {
KToolInvocation::kdeinitExec("keditbookmarks");
echoHead("bookmarks:/");
} else if (regexp.indexIn(path) >= 0) {
echoImage(regexp.cap(1), regexp.cap(2), QUrlQuery(url).queryItemValue("size"));
} else if (path.indexOf(regexp, 0, &rmatch) >= 0) {
echoImage(rmatch.captured(1), rmatch.captured(2), QUrlQuery(url).queryItemValue("size"));
} else {
echoHead();
echo("<p class=\"message\">" + i18n("Wrong request: %1", url.toDisplayString().toHtmlEscaped()) + "</p>");
......
......@@ -30,7 +30,7 @@
#include <config-fish.h>
#include <QFile>
#include <QDateTime>
#include <QRegExp>
#include <QRegularExpression>
#include <QCoreApplication>
#include <QDebug>
#include <QStandardPaths>
......@@ -787,16 +787,16 @@ bool fishProtocol::sendCommand(fish_command_type cmd, ...) {
va_start(list, cmd);
QString realCmd = info.command;
QString realAlt = info.alt;
static QRegExp rx("[][\\\\\n $`#!()*?{}~&<>;'\"%^@|\t]");
static const QRegularExpression rx("[][\\\\\n $`#!()*?{}~&<>;'\"%^@|\t]");
for (int i = 0; i < info.params; i++) {
QString arg(va_arg(list, const char *));
int pos = -2;
while ((pos = rx.indexIn(arg,pos+2)) >= 0) {
while ((pos = arg.indexOf(rx, pos + 2)) >= 0) {
arg.replace(pos,0,QString("\\"));
}
//myDebug( << "arg " << i << ": " << arg);
realCmd.append(" ").append(arg);
realAlt.replace(QRegExp('%'+QString::number(i+1)),arg);
realAlt.replace(QRegularExpression(QLatin1Char('%') + QString::number(i + 1)), arg);
}
QString s("#");
s.append(realCmd).append("\n ").append(realAlt).append(" 2>&1;echo '### 000'\n");
......
......@@ -32,7 +32,7 @@
#include <QTextStream>
#include <QTextDocument>
#include <QMap>
#include <QRegExp>
#include <QRegularExpression>
#include <QStandardPaths>
#include <QTextCodec>
#include <QProcess>
......@@ -146,16 +146,17 @@ MANProtocol::~MANProtocol()
void MANProtocol::parseWhatIs( QMap<QString, QString> &i, QTextStream &t, const QString &mark )
{
QRegExp re( mark );
const QRegularExpression re(mark);
QString l;
while ( !t.atEnd() )
{
l = t.readLine();
int pos = re.indexIn( l );
QRegularExpressionMatch match = re.match(l);
int pos = match.capturedStart(0);
if (pos != -1)
{
QString names = l.left(pos);
QString descr = l.mid(pos + re.matchedLength());
QString descr = l.mid(match.capturedEnd(0));
while ((pos = names.indexOf(",")) != -1)
{
i[names.left(pos++)] = descr;
......@@ -830,12 +831,17 @@ void MANProtocol::constructPath(QStringList& constr_path, QStringList constr_cat
// Mappings from $PATH to manpath are given by lines starting with
// "MANPATH_MAP"
QRegExp manpath_regex( "^MANPATH\\s" );
QRegExp mandatory_regex( "^MANDATORY_MANPATH\\s" );
QRegExp manpath_map_regex( "^MANPATH_MAP\\s" );
QRegExp mandb_map_regex( "^MANDB_MAP\\s" );
// The entry is e.g. "MANDATORY_MANPATH <manpath>"
const QRegularExpression manpath_regex("^(?:MANPATH|MANDATORY_MANPATH)\\s+(\\S+)");
// The entry is "MANPATH_MAP <path> <manpath>"
const QRegularExpression manpath_map_regex("^MANPATH_MAP\\s+(\\S+)\\s+(\\S+)");
// The entry is "MANDB_MAP <manpath> <catmanpath>"
const QRegularExpression mandb_map_regex("^MANDB_MAP\\s+(\\S+)\\s+(\\S+)");
//QRegExp section_regex( "^SECTION\\s" );
QRegExp space_regex( "\\s+" ); // for parsing manpath map
const QRegularExpression space_regex("\\s+"); // for parsing manpath map
QFile mc("/etc/man.conf"); // Caldera
if (!mc.exists())
......@@ -851,43 +857,18 @@ void MANProtocol::constructPath(QStringList& constr_path, QStringList constr_cat
while (!is.atEnd())
{
const QString line = is.readLine();
if ( manpath_regex.indexIn(line) == 0 )
{
const QString path = line.mid(8).trimmed();
constr_path += path;
}
else if ( mandatory_regex.indexIn(line) == 0 )
{
const QString path = line.mid(18).trimmed();
constr_path += path;
}
else if ( manpath_map_regex.indexIn(line) == 0 )
{
// The entry is "MANPATH_MAP <path> <manpath>"
const QStringList mapping =
line.split( space_regex);
if ( mapping.count() == 3 )
{
const QString dir = QDir::cleanPath( mapping[1] );
const QString mandir = QDir::cleanPath( mapping[2] );
manpath_map[ dir ] = mandir;
}
}
else if ( mandb_map_regex.indexIn(line) == 0 )
{
// The entry is "MANDB_MAP <manpath> <catmanpath>"
const QStringList mapping =
line.split( space_regex);
if ( mapping.count() == 3 )
{
const QString mandir = QDir::cleanPath( mapping[1] );
const QString catmandir = QDir::cleanPath( mapping[2] );
mandb_map[ mandir ] = catmandir;
}
QRegularExpressionMatch rmatch;
if (line.contains(manpath_regex, &rmatch)) {
constr_path += rmatch.captured(1);
} else if (line.contains(manpath_map_regex, &rmatch)) {
const QString dir = QDir::cleanPath(rmatch.captured(1));
const QString mandir = QDir::cleanPath(rmatch.captured(2));
manpath_map[dir] = mandir;
} else if (line.contains(mandb_map_regex, &rmatch)) {
const QString mandir = QDir::cleanPath(rmatch.captured(1));
const QString catmandir = QDir::cleanPath(rmatch.captured(2));
mandb_map[mandir] = catmandir;
}
/* sections are not used
else if ( section_regex.find(line, 0) == 0 )
......
......@@ -130,6 +130,7 @@
#include <QString>
#include <QTextCodec>
#include <QDebug>
#include <QRegularExpression>
#ifdef SIMPLE_MAN2HTML
# include <stdlib.h>
......@@ -6167,11 +6168,12 @@ char *manPageToUtf8(const QByteArray &input, const QByteArray &dirName)
// some pages contain "coding:" information. See "man manconv"
// (but I find pages which do not exactly obey the format described in manconv, e.g.
// the control char is either "." or "'")
// Therefore use a QRegExp
QRegExp regex("[\\.']\\\\\"[^$]*coding:\\s*(\\S*)\\s", Qt::CaseInsensitive);
if ( regex.indexIn(QLatin1String(input)) == 0 )
// Therefore use a QRegularExpression
const QRegularExpression regex("[\\.']\\\\\"[^$]*coding:\\s*(\\S*)\\s", QRegularExpression::CaseInsensitiveOption);
QRegularExpressionMatch rmatch;
if (QString::fromLatin1(input).indexOf(regex, 0, &rmatch) == 0)
{
encoding = regex.cap(1).toLatin1();
encoding = rmatch.captured(1).toLatin1();
qCDebug(KIO_MAN_LOG) << "found embedded encoding" << encoding;
}
......
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