From: Enar Väikene Date: Thu, 6 Oct 2011 11:02:01 +0000 (+0300) Subject: Better handling of boolean types. X-Git-Url: https://vaikene.ee/gitweb/gitweb.cgi?a=commitdiff_plain;h=32d6a193150b17fbbde109348ad5a8107bba5529;p=evaf Better handling of boolean types. Added support for ASCII codes for character types. --- diff --git a/src/libs/Common/util.cpp b/src/libs/Common/util.cpp index ccabdab..eeedb61 100644 --- a/src/libs/Common/util.cpp +++ b/src/libs/Common/util.cpp @@ -19,6 +19,7 @@ #include "util.h" +#include //------------------------------------------------------------------- @@ -58,21 +59,38 @@ QVariant eVaf::Common::toVariant(QString const & value, QVariant const & default break; } case QVariant::Bool: { - bool ok; - uint v = value.toUInt(&ok, 0); if (eVaf::Common::isTrue(value)) return QVariant(true); else if (eVaf::Common::isFalse(value)) return QVariant(false); - else - return QVariant(v); + else { + bool ok; + uint v = value.toUInt(&ok, 0); + if (ok) + return QVariant(v); + else + return defaultValue; + } break; } case QVariant::Char: { - if (value.size() > 0) - return QVariant(value.at(0)); - else - return defaultValue; + if (value.size() > 0) { + if (value.startsWith("\\0x")) { + bool ok; + char c = value.mid(1).toUInt(&ok, 16); + if (ok) + return QVariant(c); + } + else if (value.startsWith("\\0")) { + bool ok; + char c = value.mid(1).toUInt(&ok, 8); + if (ok) + return QVariant(c); + } + else + return QVariant(value.at(0)); + } + return defaultValue; break; } default: