Replace QRegExp with QRegularExpression
This commit is contained in:
@@ -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;
|
||||
|
||||
@@ -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_;
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user