]> vaikene.ee Git - evaf/commitdiff
Better handling of boolean types.
authorEnar Väikene <enar@vaikene.net>
Thu, 6 Oct 2011 11:02:01 +0000 (14:02 +0300)
committerEnar Väikene <enar@vaikene.net>
Thu, 6 Oct 2011 11:02:01 +0000 (14:02 +0300)
Added support for ASCII codes for character types.

src/libs/Common/util.cpp

index ccabdab922921a0ac2b927149cfd8e6dc22c86d8..eeedb61ff19fddeab479a322c9dc0eedec681c36 100644 (file)
@@ -19,6 +19,7 @@
 
 #include "util.h"
 
+#include <stdio.h>
 
 //-------------------------------------------------------------------
 
@@ -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: