提交 413ea14f authored 作者: Seven Du's avatar Seven Du 提交者: Muteesa Fred

[FS-11092] #resolve add cJSON_isTrue

上级 a8354158
...@@ -93,6 +93,31 @@ static inline cJSON *json_add_child_string(cJSON *json, const char *name, const ...@@ -93,6 +93,31 @@ static inline cJSON *json_add_child_string(cJSON *json, const char *name, const
return new_json; return new_json;
} }
static inline int cJSON_isTrue(cJSON *json)
{
if (!json) return 0;
if (json->type == cJSON_True) return 1;
if (json->type == cJSON_String && (
!strcasecmp(json->valuestring, "yes") ||
!strcasecmp(json->valuestring, "on") ||
!strcasecmp(json->valuestring, "true") ||
!strcasecmp(json->valuestring, "t") ||
!strcasecmp(json->valuestring, "enabled") ||
!strcasecmp(json->valuestring, "active") ||
!strcasecmp(json->valuestring, "allow") ||
atoi(json->valuestring))) {
return 1;
}
if (json->type == cJSON_Number && (json->valueint || json->valuedouble)) {
return 1;
}
return 0;
}
#ifdef __cplusplus #ifdef __cplusplus
} }
#endif #endif
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论