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:
Klaus Basan
2015-01-18 22:02:07 +01:00
parent 054db94997
commit 4e1db5c837
19 changed files with 100 additions and 47 deletions

View File

@@ -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 &regex = 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))
{