From 8e9a711996de3c79bcc2b82ccd7132866adb9997 Mon Sep 17 00:00:00 2001 From: Niels Date: Mon, 15 Jun 2015 16:37:49 +0200 Subject: [PATCH] closes #90 --- src/json.hpp | 12 ++++++++++++ src/json.hpp.re2c | 12 ++++++++++++ test/unit.cpp | 16 ++++++++++++++++ 3 files changed, 40 insertions(+) diff --git a/src/json.hpp b/src/json.hpp index b4cd9b33..f2a86d15 100644 --- a/src/json.hpp +++ b/src/json.hpp @@ -825,6 +825,18 @@ class basic_json return (m_type == value_t::number_integer) or (m_type == value_t::number_float); } + // return whether value an integer is number + bool is_number_integer() const noexcept + { + return m_type == value_t::number_integer; + } + + // return whether value is a floating-point number + bool is_number_float() const noexcept + { + return m_type == value_t::number_float; + } + // return whether value is object bool is_object() const noexcept { diff --git a/src/json.hpp.re2c b/src/json.hpp.re2c index dee59e4f..2131f47d 100644 --- a/src/json.hpp.re2c +++ b/src/json.hpp.re2c @@ -825,6 +825,18 @@ class basic_json return (m_type == value_t::number_integer) or (m_type == value_t::number_float); } + // return whether value an integer is number + bool is_number_integer() const noexcept + { + return m_type == value_t::number_integer; + } + + // return whether value is a floating-point number + bool is_number_float() const noexcept + { + return m_type == value_t::number_float; + } + // return whether value is object bool is_object() const noexcept { diff --git a/test/unit.cpp b/test/unit.cpp index 3a490460..1dab03d9 100644 --- a/test/unit.cpp +++ b/test/unit.cpp @@ -1328,6 +1328,8 @@ TEST_CASE("object inspection") CHECK(not j.is_null()); CHECK(not j.is_boolean()); CHECK(not j.is_number()); + CHECK(not j.is_number_integer()); + CHECK(not j.is_number_float()); CHECK(j.is_object()); CHECK(not j.is_array()); CHECK(not j.is_string()); @@ -1340,6 +1342,8 @@ TEST_CASE("object inspection") CHECK(not j.is_null()); CHECK(not j.is_boolean()); CHECK(not j.is_number()); + CHECK(not j.is_number_integer()); + CHECK(not j.is_number_float()); CHECK(not j.is_object()); CHECK(j.is_array()); CHECK(not j.is_string()); @@ -1352,6 +1356,8 @@ TEST_CASE("object inspection") CHECK(j.is_null()); CHECK(not j.is_boolean()); CHECK(not j.is_number()); + CHECK(not j.is_number_integer()); + CHECK(not j.is_number_float()); CHECK(not j.is_object()); CHECK(not j.is_array()); CHECK(not j.is_string()); @@ -1364,6 +1370,8 @@ TEST_CASE("object inspection") CHECK(not j.is_null()); CHECK(j.is_boolean()); CHECK(not j.is_number()); + CHECK(not j.is_number_integer()); + CHECK(not j.is_number_float()); CHECK(not j.is_object()); CHECK(not j.is_array()); CHECK(not j.is_string()); @@ -1376,6 +1384,8 @@ TEST_CASE("object inspection") CHECK(not j.is_null()); CHECK(not j.is_boolean()); CHECK(not j.is_number()); + CHECK(not j.is_number_integer()); + CHECK(not j.is_number_float()); CHECK(not j.is_object()); CHECK(not j.is_array()); CHECK(j.is_string()); @@ -1388,6 +1398,8 @@ TEST_CASE("object inspection") CHECK(not j.is_null()); CHECK(not j.is_boolean()); CHECK(j.is_number()); + CHECK(j.is_number_integer()); + CHECK(not j.is_number_float()); CHECK(not j.is_object()); CHECK(not j.is_array()); CHECK(not j.is_string()); @@ -1400,6 +1412,8 @@ TEST_CASE("object inspection") CHECK(not j.is_null()); CHECK(not j.is_boolean()); CHECK(j.is_number()); + CHECK(not j.is_number_integer()); + CHECK(j.is_number_float()); CHECK(not j.is_object()); CHECK(not j.is_array()); CHECK(not j.is_string()); @@ -1412,6 +1426,8 @@ TEST_CASE("object inspection") CHECK(not j.is_null()); CHECK(not j.is_boolean()); CHECK(not j.is_number()); + CHECK(not j.is_number_integer()); + CHECK(not j.is_number_float()); CHECK(not j.is_object()); CHECK(not j.is_array()); CHECK(not j.is_string());