From 90402d1ebcb32651f5f9cc77c7d082b5838ec098 Mon Sep 17 00:00:00 2001 From: Artur Laksberg Date: Thu, 14 Nov 2013 15:08:09 -0800 Subject: [PATCH] Release 1.3.1 --- Release/include/cpprest/json.h | 26 +++++++++++++++++++ Release/include/cpprest/version.h | 2 +- Release/src/json/json.cpp | 18 +++++++++++++ .../Functional/json/construction_tests.cpp | 4 +++ 4 files changed, 49 insertions(+), 1 deletion(-) diff --git a/Release/include/cpprest/json.h b/Release/include/cpprest/json.h index 4cf4102034..0e0b2bde04 100644 --- a/Release/include/cpprest/json.h +++ b/Release/include/cpprest/json.h @@ -268,6 +268,26 @@ namespace web { namespace json /// true if the value is a number value, false otherwise bool is_number() const { return type() == Number; } + /// + /// Is the current value represented as an integer number value? + /// + /// + /// Note that if a json value is a number but represented as a double it can still + /// be retrieved as a integer using as_integer(), however the value will be truncated. + /// + /// true if the value is an integer value, false otherwise. + _ASYNCRTIMP bool is_integer() const ; + + /// + /// Is the current value represented as an double number value? + /// + /// + /// Note that if a json value is a number but represented as a int it can still + /// be retrieved as a double using as_double(). + /// + /// true if the value is an double value, false otherwise. + _ASYNCRTIMP bool is_double() const ; + /// /// Is the current value a Boolean value? /// @@ -568,6 +588,9 @@ namespace web { namespace json virtual json::value::value_type type() const { return json::value::Null; } + virtual bool is_integer() const { throw json_exception(_XPLATSTR("not a number")); } + virtual bool is_double() const { throw json_exception(_XPLATSTR("not a number")); } + virtual double as_double() const { throw json_exception(_XPLATSTR("not a number")); } virtual int32_t as_integer() const { throw json_exception(_XPLATSTR("not a number")); } virtual bool as_bool() const { throw json_exception(_XPLATSTR("not a boolean")); } @@ -647,6 +670,9 @@ namespace web { namespace json virtual json::value::value_type type() const { return json::value::Number; } + virtual bool is_integer() const { return m_was_int; } + virtual bool is_double() const { return !m_was_int; } + virtual double as_double() const { return m_was_int ? static_cast(m_intval) : m_value; } virtual int32_t as_integer() const { return m_was_int ? m_intval : static_cast(m_value); } diff --git a/Release/include/cpprest/version.h b/Release/include/cpprest/version.h index 262eb03666..3e7e948ecf 100644 --- a/Release/include/cpprest/version.h +++ b/Release/include/cpprest/version.h @@ -15,7 +15,7 @@ * * ==--== */ -#define CPPREST_VERSION_REVISION 0 +#define CPPREST_VERSION_REVISION 1 #define CPPREST_VERSION_MINOR 3 #define CPPREST_VERSION_MAJOR 1 diff --git a/Release/src/json/json.cpp b/Release/src/json/json.cpp index d225fff12f..a24d5082a9 100644 --- a/Release/src/json/json.cpp +++ b/Release/src/json/json.cpp @@ -435,6 +435,24 @@ web::json::details::_Object::_Object(const _Object& other):web::json::details::_ web::json::value::value_type json::value::type() const { return m_value->type(); } +bool json::value::is_integer() const +{ + if(!is_number()) + { + return false; + } + return m_value->is_integer(); +} + +bool json::value::is_double() const +{ + if(!is_number()) + { + return false; + } + return m_value->is_double(); +} + json::value& web::json::details::_Object::index(const utility::string_t &key) { map_fields(); diff --git a/Release/tests/Functional/json/construction_tests.cpp b/Release/tests/Functional/json/construction_tests.cpp index c29abcc20f..f2ac288478 100644 --- a/Release/tests/Functional/json/construction_tests.cpp +++ b/Release/tests/Functional/json/construction_tests.cpp @@ -157,8 +157,12 @@ TEST(constructor_overloads) VERIFY_IS_TRUE(v0.is_null()); VERIFY_ARE_EQUAL(v1.type(), json::value::Number); VERIFY_IS_TRUE(v1.is_number()); + VERIFY_IS_TRUE(v1.is_integer()); + VERIFY_IS_FALSE(v1.is_double()); VERIFY_ARE_EQUAL(v2.type(), json::value::Number); VERIFY_IS_TRUE(v2.is_number()); + VERIFY_IS_TRUE(v2.is_double()); + VERIFY_IS_FALSE(v2.is_integer()); VERIFY_ARE_EQUAL(v3.type(), json::value::Boolean); VERIFY_IS_TRUE(v3.is_boolean()); VERIFY_ARE_EQUAL(v4.type(), json::value::String);