From f2512856ee19fd0cf4ec5c83f77d57378f680e78 Mon Sep 17 00:00:00 2001 From: Guenter Obiltschnig Date: Thu, 18 Sep 2014 20:57:34 +0200 Subject: [PATCH] added Var::isBoolean() and fixed JSON stringifier --- Foundation/include/Poco/Dynamic/Var.h | 11 +++ Foundation/include/Poco/Dynamic/VarHolder.h | 91 +++++++++++++++++++++ JSON/src/Stringifier.cpp | 4 + 3 files changed, 106 insertions(+) diff --git a/Foundation/include/Poco/Dynamic/Var.h b/Foundation/include/Poco/Dynamic/Var.h index d00001776..dbd524522 100644 --- a/Foundation/include/Poco/Dynamic/Var.h +++ b/Foundation/include/Poco/Dynamic/Var.h @@ -495,6 +495,10 @@ public: /// Returns true if stored value is numeric. /// Returns false for numeric strings (e.g. "123" is string, not number) + bool isBoolean() const; + /// Returns true if stored value is boolean. + /// Returns false for boolean strings (e.g. "true" is string, not number) + bool isString() const; /// Returns true if stored value is std::string. @@ -825,6 +829,13 @@ inline bool Var::isNumeric() const } +inline bool Var::isBoolean() const +{ + VarHolder* pHolder = content(); + return pHolder ? pHolder->isBoolean() : false; +} + + inline bool Var::isString() const { VarHolder* pHolder = content(); diff --git a/Foundation/include/Poco/Dynamic/VarHolder.h b/Foundation/include/Poco/Dynamic/VarHolder.h index 313e736b3..a42fbf61a 100644 --- a/Foundation/include/Poco/Dynamic/VarHolder.h +++ b/Foundation/include/Poco/Dynamic/VarHolder.h @@ -246,6 +246,10 @@ public: /// Returns false. Must be properly overriden in a type /// specialization in order to suport the diagnostic. + virtual bool isBoolean() const; + /// Returns false. Must be properly overriden in a type + /// specialization in order to suport the diagnostic. + virtual bool isString() const; /// Returns false. Must be properly overriden in a type /// specialization in order to suport the diagnostic. @@ -594,6 +598,12 @@ inline bool VarHolder::isNumeric() const } +inline bool VarHolder::isBoolean() const +{ + return false; +} + + inline bool VarHolder::isString() const { return false; @@ -782,6 +792,11 @@ public: return std::numeric_limits::is_specialized; } + bool isBoolean() const + { + return false; + } + bool isString() const { return false; @@ -921,6 +936,7 @@ public: return std::numeric_limits::is_specialized; } + bool isString() const { return false; @@ -1054,6 +1070,11 @@ public: return std::numeric_limits::is_specialized; } + bool isBoolean() const + { + return false; + } + bool isString() const { return false; @@ -1202,6 +1223,11 @@ public: return std::numeric_limits::is_specialized; } + bool isBoolean() const + { + return false; + } + bool isString() const { return false; @@ -1335,6 +1361,11 @@ public: return std::numeric_limits::is_specialized; } + bool isBoolean() const + { + return false; + } + bool isString() const { return false; @@ -1468,6 +1499,11 @@ public: return std::numeric_limits::is_specialized; } + bool isBoolean() const + { + return false; + } + bool isString() const { return false; @@ -1601,6 +1637,11 @@ public: return std::numeric_limits::is_specialized; } + bool isBoolean() const + { + return false; + } + bool isString() const { return false; @@ -1755,6 +1796,11 @@ public: return std::numeric_limits::is_specialized; } + bool isBoolean() const + { + return false; + } + bool isString() const { return false; @@ -1886,6 +1932,11 @@ public: return std::numeric_limits::is_specialized; } + bool isBoolean() const + { + return true; + } + bool isString() const { return false; @@ -2020,6 +2071,11 @@ public: return std::numeric_limits::is_specialized; } + bool isBoolean() const + { + return false; + } + bool isString() const { return false; @@ -2160,6 +2216,11 @@ public: return std::numeric_limits::is_specialized; } + bool isBoolean() const + { + return false; + } + bool isString() const { return false; @@ -2291,6 +2352,11 @@ public: return std::numeric_limits::is_specialized; } + bool isBoolean() const + { + return false; + } + bool isString() const { return false; @@ -2793,6 +2859,11 @@ public: return std::numeric_limits::is_specialized; } + bool isBoolean() const + { + return false; + } + bool isString() const { return false; @@ -2926,6 +2997,11 @@ public: return std::numeric_limits::is_specialized; } + bool isBoolean() const + { + return false; + } + bool isString() const { return false; @@ -3245,6 +3321,11 @@ public: return false; } + bool isBoolean() const + { + return false; + } + bool isString() const { return false; @@ -3341,6 +3422,11 @@ public: return false; } + bool isBoolean() const + { + return false; + } + bool isString() const { return false; @@ -3437,6 +3523,11 @@ public: return false; } + bool isBoolean() const + { + return false; + } + bool isString() const { return false; diff --git a/JSON/src/Stringifier.cpp b/JSON/src/Stringifier.cpp index b3cc03a9d..21be0a3fc 100644 --- a/JSON/src/Stringifier.cpp +++ b/JSON/src/Stringifier.cpp @@ -55,6 +55,10 @@ void Stringifier::stringify(const Var& any, std::ostream& out, unsigned int inde { out << "null"; } + else if ( any.isNumeric() || any.isBoolean() ) + { + out << any.convert(); + } else { std::string value = any.convert();