From d0ff7ccf7cfc6f15af6f534997f74ca491a4d73c Mon Sep 17 00:00:00 2001 From: Aleksandar Fabijanic Date: Wed, 3 Apr 2013 22:03:39 -0500 Subject: [PATCH] add toString() --- Foundation/include/Poco/Dynamic/Var.h | 24 +++++++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-) diff --git a/Foundation/include/Poco/Dynamic/Var.h b/Foundation/include/Poco/Dynamic/Var.h index d4957cbb9..4088b175c 100644 --- a/Foundation/include/Poco/Dynamic/Var.h +++ b/Foundation/include/Poco/Dynamic/Var.h @@ -510,12 +510,30 @@ public: bool isString() const; /// Returns true if stored value is std::string. + std::string toString() const + /// Returns the stored value as string. + { + VarHolder* pHolder = content(); + + if (!pHolder) + throw InvalidAccessException("Can not convert empty value."); + + if (typeid(std::string) == pHolder->type()) + return extract(); + else + { + std::string result; + pHolder->convert(result); + return result; + } + } + static Var parse(const std::string& val); /// Parses the string which must be in JSON format - static std::string toString(const Var& any); - /// Converts the Var to a string in JSON format. Note that toString will return - /// a different result than any.convert()! + static std::string toString(const Var& var); + /// Converts the Var to a string in JSON format. Note that toString(const Var&) will return + /// a different result than Var::convert() and Var::toString()! private: static Var parse(const std::string& val, std::string::size_type& offset);