mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-04-03 07:35:48 +08:00
Replace QRegExp with QRegularExpression
Reviewers: kbasan, msutcliffe Reviewed By: kbasan, msutcliffe Subscribers: jenkins Differential Revision: https://dev.swift-project.org/D11
This commit is contained in:
@@ -21,7 +21,7 @@
|
||||
#include "blackmisc/pq/units.h"
|
||||
|
||||
#include <QLocale>
|
||||
#include <QRegExp>
|
||||
#include <QRegularExpression>
|
||||
#include <QThreadStorage>
|
||||
#include <QtDebug>
|
||||
|
||||
@@ -45,12 +45,10 @@ namespace BlackMisc
|
||||
// check
|
||||
if (vs.isEmpty()) { return v; }
|
||||
|
||||
static QThreadStorage<QRegExp> tsRegex;
|
||||
if (! tsRegex.hasLocalData()) { tsRegex.setLocalData(QRegExp("([-+]?[0-9]*[\\.,]?[0-9]+)\\s*(\\D*)$")); }
|
||||
const auto ®ex = tsRegex.localData();
|
||||
|
||||
if (regex.indexIn(value) < 0) { return v; } // not a valid number
|
||||
QString unit = regex.cap(2).trimmed();
|
||||
thread_local const QRegularExpression regex("([-+]?[0-9]*[\\.,]?[0-9]+)\\s*(\\D*)$");
|
||||
auto match = regex.match(value);
|
||||
if (!match.hasMatch()) { return v; } // not a valid number
|
||||
QString unit = match.captured(2).trimmed();
|
||||
QString number = QString(value).replace(unit, "");
|
||||
unit = unit.trimmed(); // trim after replace, not before
|
||||
|
||||
|
||||
Reference in New Issue
Block a user