mirror of
https://github.com/DaveGamble/cJSON.git
synced 2023-08-10 21:13:26 +03:00
Add cJSON_IsInt()
This commit is contained in:
parent
1208b35e03
commit
4bafe51b12
10
cJSON.c
10
cJSON.c
@ -3007,6 +3007,16 @@ CJSON_PUBLIC(cJSON_bool) cJSON_IsNumber(const cJSON * const item)
|
||||
return (item->type & 0xFF) == cJSON_Number;
|
||||
}
|
||||
|
||||
CJSON_PUBLIC(cJSON_bool) cJSON_IsInt(const cJSON * const item)
|
||||
{
|
||||
if (item == NULL)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
return ((item->type & 0xFF) == cJSON_Number) && (item->type & cJSON_PreferInt);
|
||||
}
|
||||
|
||||
CJSON_PUBLIC(cJSON_bool) cJSON_IsString(const cJSON * const item)
|
||||
{
|
||||
if (item == NULL)
|
||||
|
1
cJSON.h
1
cJSON.h
@ -214,6 +214,7 @@ CJSON_PUBLIC(cJSON_bool) cJSON_IsTrue(const cJSON * const item);
|
||||
CJSON_PUBLIC(cJSON_bool) cJSON_IsBool(const cJSON * const item);
|
||||
CJSON_PUBLIC(cJSON_bool) cJSON_IsNull(const cJSON * const item);
|
||||
CJSON_PUBLIC(cJSON_bool) cJSON_IsNumber(const cJSON * const item);
|
||||
CJSON_PUBLIC(cJSON_bool) cJSON_IsInt(const cJSON * const item);
|
||||
CJSON_PUBLIC(cJSON_bool) cJSON_IsString(const cJSON * const item);
|
||||
CJSON_PUBLIC(cJSON_bool) cJSON_IsArray(const cJSON * const item);
|
||||
CJSON_PUBLIC(cJSON_bool) cJSON_IsObject(const cJSON * const item);
|
||||
|
@ -188,6 +188,12 @@ static void typecheck_functions_should_check_type(void)
|
||||
TEST_ASSERT_FALSE(cJSON_IsNumber(NULL));
|
||||
TEST_ASSERT_FALSE(cJSON_IsNumber(invalid));
|
||||
TEST_ASSERT_TRUE(cJSON_IsNumber(item));
|
||||
TEST_ASSERT_FALSE(cJSON_IsInt(item));
|
||||
|
||||
item->type = cJSON_Number | cJSON_StringIsConst | cJSON_PreferInt;
|
||||
TEST_ASSERT_FALSE(cJSON_IsInt(NULL));
|
||||
TEST_ASSERT_FALSE(cJSON_IsInt(invalid));
|
||||
TEST_ASSERT_TRUE(cJSON_IsInt(item));
|
||||
|
||||
item->type = cJSON_String | cJSON_StringIsConst;
|
||||
TEST_ASSERT_FALSE(cJSON_IsString(NULL));
|
||||
@ -381,6 +387,7 @@ static void cjson_functions_should_not_crash_with_null_pointers(void)
|
||||
TEST_ASSERT_FALSE(cJSON_IsBool(NULL));
|
||||
TEST_ASSERT_FALSE(cJSON_IsNull(NULL));
|
||||
TEST_ASSERT_FALSE(cJSON_IsNumber(NULL));
|
||||
TEST_ASSERT_FALSE(cJSON_IsInt(NULL));
|
||||
TEST_ASSERT_FALSE(cJSON_IsString(NULL));
|
||||
TEST_ASSERT_FALSE(cJSON_IsArray(NULL));
|
||||
TEST_ASSERT_FALSE(cJSON_IsObject(NULL));
|
||||
|
Loading…
x
Reference in New Issue
Block a user