diff options
Diffstat (limited to 'cpp/src/qpid')
| -rw-r--r-- | cpp/src/qpid/messaging/AddressParser.cpp | 7 | ||||
| -rw-r--r-- | cpp/src/qpid/types/Variant.cpp | 37 |
2 files changed, 41 insertions, 3 deletions
diff --git a/cpp/src/qpid/messaging/AddressParser.cpp b/cpp/src/qpid/messaging/AddressParser.cpp index c34c9c0f56..d088b94f32 100644 --- a/cpp/src/qpid/messaging/AddressParser.cpp +++ b/cpp/src/qpid/messaging/AddressParser.cpp @@ -196,13 +196,14 @@ bool AddressParser::readQuotedValue(Variant& value) return false; } } - -bool AddressParser::readSimpleValue(Variant& value) + +bool AddressParser::readSimpleValue(Variant& value) { std::string s; if (readWord(s)) { - value = s; + value.fromString(s); return true; + } else { return false; } diff --git a/cpp/src/qpid/types/Variant.cpp b/cpp/src/qpid/types/Variant.cpp index bf255b4423..ea4f5ffbbf 100644 --- a/cpp/src/qpid/types/Variant.cpp +++ b/cpp/src/qpid/types/Variant.cpp @@ -23,6 +23,7 @@ #include "qpid/log/Statement.h" #include <boost/format.hpp> #include <boost/lexical_cast.hpp> +#include <boost/algorithm/string.hpp> #include <algorithm> #include <limits> #include <sstream> @@ -766,6 +767,42 @@ Variant& Variant::operator=(const Variant& v) return *this; } + +template <class T> +bool from_string(T& t, const std::string& s) +{ + char c; // Make sure there are no extra characters + + std::istringstream iss(s); + return !(iss >> t).fail() && (iss>>c).fail(); +} + +Variant& Variant::fromString(const std::string& s) +{ + double d; + int i; + + if (from_string<int>(i, s)) { + return operator=(i); + } + else if (from_string<double>(d, s)) { + return operator=(d); + } + else { + std::string upper(boost::to_upper_copy(s)); + if (upper == "TRUE") { + return operator=(true); + } + else if (upper == "FALSE") { + return operator=(false); + } + else { + return operator=(s); + } + } +} + + VariantType Variant::getType() const { return impl ? impl->getType() : VAR_VOID; } bool Variant::isVoid() const { return getType() == VAR_VOID; } bool Variant::asBool() const { return impl && impl->asBool(); } |
