mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-04-01 05:26:45 +08:00
refs #212, fixed parsing for PQs
* trimmed strings * renamed to parseToVariant methods avos ambiguity with template method
This commit is contained in:
@@ -90,14 +90,17 @@ namespace BlackMisc
|
||||
qDBusRegisterMetaType<CPqString>();
|
||||
}
|
||||
|
||||
QVariant CPqString::parse(const QString &value)
|
||||
/*
|
||||
* Parse
|
||||
*/
|
||||
QVariant CPqString::parseToVariant(const QString &value)
|
||||
{
|
||||
QVariant v;
|
||||
if (value.isEmpty()) return v;
|
||||
QRegExp rx("^([-+]?[0-9]*\\.?[0-9]+)\\s*(\\D*)$");
|
||||
if (rx.indexIn(value) < 0) return v;
|
||||
QString number = rx.cap(1);
|
||||
QString unit = rx.cap(2);
|
||||
QString number = rx.cap(1).trimmed();
|
||||
QString unit = rx.cap(2).trimmed();
|
||||
if (unit.isEmpty() || number.isEmpty()) return v;
|
||||
bool success;
|
||||
double numberD = number.toDouble(&success);
|
||||
|
||||
Reference in New Issue
Block a user