summaryrefslogtreecommitdiff
path: root/cpp/src
diff options
context:
space:
mode:
Diffstat (limited to 'cpp/src')
-rw-r--r--cpp/src/qpid/messaging/AddressParser.cpp3
-rw-r--r--cpp/src/qpid/types/Variant.cpp46
2 files changed, 14 insertions, 35 deletions
diff --git a/cpp/src/qpid/messaging/AddressParser.cpp b/cpp/src/qpid/messaging/AddressParser.cpp
index d088b94f32..4c8f35fbc5 100644
--- a/cpp/src/qpid/messaging/AddressParser.cpp
+++ b/cpp/src/qpid/messaging/AddressParser.cpp
@@ -201,9 +201,8 @@ bool AddressParser::readSimpleValue(Variant& value)
{
std::string s;
if (readWord(s)) {
- value.fromString(s);
+ value.parse(s);
return true;
-
} else {
return false;
}
diff --git a/cpp/src/qpid/types/Variant.cpp b/cpp/src/qpid/types/Variant.cpp
index ea4f5ffbbf..5d8878bdac 100644
--- a/cpp/src/qpid/types/Variant.cpp
+++ b/cpp/src/qpid/types/Variant.cpp
@@ -767,39 +767,19 @@ 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);
- }
- }
+Variant& Variant::parse(const std::string& s)
+{
+ operator=(s);
+ try {
+ return operator=(asInt64());
+ } catch (const InvalidConversion&) {}
+ try {
+ return operator=(asDouble());
+ } catch (const InvalidConversion&) {}
+ try {
+ return operator=(asBool());
+ } catch (const InvalidConversion&) {}
+ return *this;
}