Replace QRegExp with QRegularExpression

This commit is contained in:
Jonas Kvinge 2020-07-18 04:21:19 +02:00
parent 9830f21e4a
commit cbcc223150
3 changed files with 22 additions and 18 deletions

View File

@ -35,7 +35,8 @@
#include <QMap>
#include <QString>
#include <QStringList>
#include <QRegExp>
#include <QRegularExpression>
#include <QRegularExpressionMatch>
#include <QDateTime>
#include <QIODevice>
#include <QBuffer>
@ -306,11 +307,12 @@ QString LinuxDemangle(const QString &symbol);
QString LinuxDemangle(const QString &symbol) {
QRegExp regex("\\(([^+]+)");
if (!symbol.contains(regex)) {
QRegularExpression regex("\\(([^+]+)");
QRegularExpressionMatch match = regex.match(symbol);
if (!match.hasMatch()) {
return symbol;
}
QString mangled_function = regex.cap(1);
QString mangled_function = match.captured(1);
return CXXDemangle(mangled_function);
}

View File

@ -23,6 +23,8 @@
#include <QVariant>
#include <QString>
#include <QChar>
#include <QRegularExpression>
#include <QRegularExpressionMatch>
#include "fmpsparser.h"
@ -89,20 +91,20 @@ bool FMPSParser::Parse(const QString &data) {
int FMPSParser::ParseValueRef(const QStringRef& data, QVariant* ret) const {
// Try to match a float
int pos = float_re_.indexIn(*data.string(), data.position());
if (pos == data.position()) {
*ret = float_re_.cap(1).toDouble();
return float_re_.matchedLength();
QRegularExpressionMatch re_match = float_re_.match(*data.string(), data.position());
if (re_match.captured() == data.position()) {
*ret = re_match.captured(1).toDouble();
return re_match.capturedLength();
}
// Otherwise try to match a string
pos = string_re_.indexIn(*data.string(), data.position());
if (pos == data.position()) {
re_match = string_re_.match(*data.string(), data.position());
if (re_match.captured() == data.position()) {
// Replace escape sequences with their actual characters
QString value = string_re_.cap(1);
QString value = re_match.captured(1);
value.replace(escape_re_, "\\1");
*ret = value;
return string_re_.matchedLength();
return re_match.capturedLength();
}
return -1;

View File

@ -23,12 +23,12 @@
#include <QList>
#include <QMetaType>
#include <QString>
#include <QRegExp>
#include <QRegularExpression>
class QVariant;
class FMPSParser {
public:
public:
FMPSParser();
// A FMPS result is a list of lists of values (where a value is a string or
@ -54,10 +54,10 @@ public:
int ParseListList(const QString &data, Result *ret) const;
int ParseListListRef(const QStringRef &data, Result *ret) const;
private:
QRegExp float_re_;
QRegExp string_re_;
QRegExp escape_re_;
private:
QRegularExpression float_re_;
QRegularExpression string_re_;
QRegularExpression escape_re_;
Result result_;
};