Skip to content

Commit 90402d1

Browse files
committed
Release 1.3.1
1 parent b5ccc39 commit 90402d1

File tree

4 files changed

+49
-1
lines changed

4 files changed

+49
-1
lines changed

Release/include/cpprest/json.h

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -268,6 +268,26 @@ namespace web { namespace json
268268
/// <returns><c>true</c> if the value is a number value, <c>false</c> otherwise</returns>
269269
bool is_number() const { return type() == Number; }
270270

271+
/// <summary>
272+
/// Is the current value represented as an integer number value?
273+
/// </summary>
274+
/// <remarks>
275+
/// Note that if a json value is a number but represented as a double it can still
276+
/// be retrieved as a integer using as_integer(), however the value will be truncated.
277+
/// </remarks>
278+
/// <returns><c>true</c> if the value is an integer value, <c>false</c> otherwise.</returns>
279+
_ASYNCRTIMP bool is_integer() const ;
280+
281+
/// <summary>
282+
/// Is the current value represented as an double number value?
283+
/// </summary>
284+
/// <remarks>
285+
/// Note that if a json value is a number but represented as a int it can still
286+
/// be retrieved as a double using as_double().
287+
/// </remarks>
288+
/// <returns><c>true</c> if the value is an double value, <c>false</c> otherwise.</returns>
289+
_ASYNCRTIMP bool is_double() const ;
290+
271291
/// <summary>
272292
/// Is the current value a Boolean value?
273293
/// </summary>
@@ -568,6 +588,9 @@ namespace web { namespace json
568588

569589
virtual json::value::value_type type() const { return json::value::Null; }
570590

591+
virtual bool is_integer() const { throw json_exception(_XPLATSTR("not a number")); }
592+
virtual bool is_double() const { throw json_exception(_XPLATSTR("not a number")); }
593+
571594
virtual double as_double() const { throw json_exception(_XPLATSTR("not a number")); }
572595
virtual int32_t as_integer() const { throw json_exception(_XPLATSTR("not a number")); }
573596
virtual bool as_bool() const { throw json_exception(_XPLATSTR("not a boolean")); }
@@ -647,6 +670,9 @@ namespace web { namespace json
647670

648671
virtual json::value::value_type type() const { return json::value::Number; }
649672

673+
virtual bool is_integer() const { return m_was_int; }
674+
virtual bool is_double() const { return !m_was_int; }
675+
650676
virtual double as_double() const { return m_was_int ? static_cast<double>(m_intval) : m_value; }
651677
virtual int32_t as_integer() const { return m_was_int ? m_intval : static_cast<int32_t>(m_value); }
652678

Release/include/cpprest/version.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
*
1616
* ==--==
1717
*/
18-
#define CPPREST_VERSION_REVISION 0
18+
#define CPPREST_VERSION_REVISION 1
1919
#define CPPREST_VERSION_MINOR 3
2020
#define CPPREST_VERSION_MAJOR 1
2121

Release/src/json/json.cpp

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -435,6 +435,24 @@ web::json::details::_Object::_Object(const _Object& other):web::json::details::_
435435

436436
web::json::value::value_type json::value::type() const { return m_value->type(); }
437437

438+
bool json::value::is_integer() const
439+
{
440+
if(!is_number())
441+
{
442+
return false;
443+
}
444+
return m_value->is_integer();
445+
}
446+
447+
bool json::value::is_double() const
448+
{
449+
if(!is_number())
450+
{
451+
return false;
452+
}
453+
return m_value->is_double();
454+
}
455+
438456
json::value& web::json::details::_Object::index(const utility::string_t &key)
439457
{
440458
map_fields();

Release/tests/Functional/json/construction_tests.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,8 +157,12 @@ TEST(constructor_overloads)
157157
VERIFY_IS_TRUE(v0.is_null());
158158
VERIFY_ARE_EQUAL(v1.type(), json::value::Number);
159159
VERIFY_IS_TRUE(v1.is_number());
160+
VERIFY_IS_TRUE(v1.is_integer());
161+
VERIFY_IS_FALSE(v1.is_double());
160162
VERIFY_ARE_EQUAL(v2.type(), json::value::Number);
161163
VERIFY_IS_TRUE(v2.is_number());
164+
VERIFY_IS_TRUE(v2.is_double());
165+
VERIFY_IS_FALSE(v2.is_integer());
162166
VERIFY_ARE_EQUAL(v3.type(), json::value::Boolean);
163167
VERIFY_IS_TRUE(v3.is_boolean());
164168
VERIFY_ARE_EQUAL(v4.type(), json::value::String);

0 commit comments

Comments
 (0)