Add getNumberValue function

* Add GetNumberValue function and testcase

Co-authored-by: Alan Wang <[email protected]>
This commit is contained in:
Sang-Heon Jeon
2020-04-02 17:06:56 +08:00
committed by GitHub
co-authored by Alan Wang
parent 2371b7bc66
commit 5437b79086
3 changed files with 30 additions and 3 deletions
+14 -2
View File
@@ -71,14 +71,26 @@ CJSON_PUBLIC(const char *) cJSON_GetErrorPtr(void)
return (const char*) (global_error.json + global_error.position);
}
CJSON_PUBLIC(char *) cJSON_GetStringValue(cJSON *item) {
if (!cJSON_IsString(item)) {
CJSON_PUBLIC(char *) cJSON_GetStringValue(cJSON *item)
{
if (!cJSON_IsString(item))
{
return NULL;
}
return item->valuestring;
}
CJSON_PUBLIC(double) cJSON_GetNumberValue(cJSON *item)
{
if (!cJSON_IsNumber(item))
{
return 0.0/0.0;
}
return item->valuedouble;
}
/* This is a safeguard to prevent copy-pasters from using incompatible C and header files */
#if (CJSON_VERSION_MAJOR != 1) || (CJSON_VERSION_MINOR != 7) || (CJSON_VERSION_PATCH != 7)
#error cJSON.h and cJSON.c have different versions. Make sure that both have the same.