Skip to content

Commit

Permalink
lxqtsysstatutils.cpp: port to QRegularExpression TODO
Browse files Browse the repository at this point in the history
TODO: check syntax and merge with previous commit
  • Loading branch information
gfgit committed Feb 22, 2024
1 parent 65108ff commit 53182fb
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 7 deletions.
13 changes: 7 additions & 6 deletions plugin-sysstat/lxqtsysstatutils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
*
* END_COMMON_COPYRIGHT_HEADER */

#include <QRegExp>
#include <QRegularExpression>
#include <qmath.h>

#include "lxqtsysstatutils.h"
Expand All @@ -44,13 +44,14 @@ QString netSpeedToString(int value)
return QStringLiteral("%1 %2B/s").arg(1 << (value % 10)).arg(prefix);
}

int netSpeedFromString(QString value)
int netSpeedFromString(const QStringView& value)
{
QRegExp re(QStringLiteral("^(\\d+) ([kMG])B/s$"));
if (re.exactMatch(value))
static QRegularExpression re(QStringLiteral("^(\\d+) ([kMG])B/s$"));
QRegularExpressionMatch match = re.matchView(value);
if (match.hasMatch())
{
int shift = 0;
switch (re.cap(2).at(0).toLatin1())
switch (match.capturedView(2).at(0).toLatin1())
{
case 'k':
shift = 10;
Expand All @@ -65,7 +66,7 @@ int netSpeedFromString(QString value)
break;
}

return qCeil(qLn(re.cap(1).toInt()) / qLn(2.)) + shift;
return qCeil(qLn(match.capturedView(1).toInt()) / qLn(2.)) + shift;
}

return 0;
Expand Down
2 changes: 1 addition & 1 deletion plugin-sysstat/lxqtsysstatutils.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ namespace PluginSysStat
{

QString netSpeedToString(int value);
int netSpeedFromString(QString value);
int netSpeedFromString(const QStringView &value);

}

Expand Down

0 comments on commit 53182fb

Please sign in to comment.