From cbcc223150289a9c1e0aa137990ebf1bca6ed96e Mon Sep 17 00:00:00 2001 From: Jonas Kvinge Date: Sat, 18 Jul 2020 04:21:19 +0200 Subject: [PATCH] Replace QRegExp with QRegularExpression --- ext/libstrawberry-common/core/logging.cpp | 10 ++++++---- ext/libstrawberry-tagreader/fmpsparser.cpp | 18 ++++++++++-------- ext/libstrawberry-tagreader/fmpsparser.h | 12 ++++++------ 3 files changed, 22 insertions(+), 18 deletions(-) diff --git a/ext/libstrawberry-common/core/logging.cpp b/ext/libstrawberry-common/core/logging.cpp index 5353535a..325f8ea9 100644 --- a/ext/libstrawberry-common/core/logging.cpp +++ b/ext/libstrawberry-common/core/logging.cpp @@ -35,7 +35,8 @@ #include #include #include -#include +#include +#include #include #include #include @@ -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); } diff --git a/ext/libstrawberry-tagreader/fmpsparser.cpp b/ext/libstrawberry-tagreader/fmpsparser.cpp index 556e74f4..0c1de1d3 100644 --- a/ext/libstrawberry-tagreader/fmpsparser.cpp +++ b/ext/libstrawberry-tagreader/fmpsparser.cpp @@ -23,6 +23,8 @@ #include #include #include +#include +#include #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; diff --git a/ext/libstrawberry-tagreader/fmpsparser.h b/ext/libstrawberry-tagreader/fmpsparser.h index 1090305e..a8ec5748 100644 --- a/ext/libstrawberry-tagreader/fmpsparser.h +++ b/ext/libstrawberry-tagreader/fmpsparser.h @@ -23,12 +23,12 @@ #include #include #include -#include +#include 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_; };