mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-04-01 21:56:43 +08:00
Fixes of MS'review as proposed
https://dev.vatsim-germany.org/issues/368#change-2380 (1,2) https://dev.vatsim-germany.org/issues/364#change-2379 (1-11,13)
This commit is contained in:
@@ -10,6 +10,7 @@
|
||||
#include "pqstring.h"
|
||||
#include "tuple.h"
|
||||
#include "pqallquantities.h"
|
||||
#include <QThreadStorage>
|
||||
|
||||
namespace BlackMisc
|
||||
{
|
||||
@@ -28,24 +29,27 @@ namespace BlackMisc
|
||||
*/
|
||||
CVariant CPqString::parseToVariant(const QString &value, SeparatorMode mode)
|
||||
{
|
||||
static QRegExp rx("([-+]?[0-9]*[\\.,]?[0-9]+)\\s*(\\D*)$");
|
||||
CVariant v;
|
||||
|
||||
// fine tuning of the string
|
||||
QString vs = value.trimmed().simplified();
|
||||
|
||||
// check
|
||||
if (vs.isEmpty()) return v;
|
||||
if (vs.isEmpty()) { return v; }
|
||||
|
||||
if (rx.indexIn(value) < 0) return v; // not a valid number
|
||||
QString unit = rx.cap(2).trimmed();
|
||||
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();
|
||||
QString number = QString(value).replace(unit, "");
|
||||
unit = unit.trimmed(); // trim after replace, not before
|
||||
|
||||
if (unit.isEmpty() || number.isEmpty()) return v;
|
||||
if (unit.isEmpty() || number.isEmpty()) { return v; }
|
||||
bool success;
|
||||
double numberD = parseNumber(number, success, mode);
|
||||
if (!success) return v;
|
||||
if (!success) {return v; }
|
||||
|
||||
if (CMeasurementUnit::isValidUnitSymbol<CAccelerationUnit>(unit))
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user