MCPcopy Create free account
hub / github.com/TheForceEngine/TheForceEngine / cJSON_Compare

Function cJSON_Compare

TheForceEngine/TFE_System/cJSON.c:2996–3119  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

2994}
2995
2996CJSON_PUBLIC(cJSON_bool) cJSON_Compare(const cJSON * const a, const cJSON * const b, const cJSON_bool case_sensitive)
2997{
2998 if ((a == NULL) || (b == NULL) || ((a->type & 0xFF) != (b->type & 0xFF)))
2999 {
3000 return false;
3001 }
3002
3003 /* check if type is valid */
3004 switch (a->type & 0xFF)
3005 {
3006 case cJSON_False:
3007 case cJSON_True:
3008 case cJSON_NULL:
3009 case cJSON_Number:
3010 case cJSON_String:
3011 case cJSON_Raw:
3012 case cJSON_Array:
3013 case cJSON_Object:
3014 break;
3015
3016 default:
3017 return false;
3018 }
3019
3020 /* identical objects are equal */
3021 if (a == b)
3022 {
3023 return true;
3024 }
3025
3026 switch (a->type & 0xFF)
3027 {
3028 /* in these cases and equal type is enough */
3029 case cJSON_False:
3030 case cJSON_True:
3031 case cJSON_NULL:
3032 return true;
3033
3034 case cJSON_Number:
3035 if (compare_double(a->valuedouble, b->valuedouble))
3036 {
3037 return true;
3038 }
3039 return false;
3040
3041 case cJSON_String:
3042 case cJSON_Raw:
3043 if ((a->valuestring == NULL) || (b->valuestring == NULL))
3044 {
3045 return false;
3046 }
3047 if (strcmp(a->valuestring, b->valuestring) == 0)
3048 {
3049 return true;
3050 }
3051
3052 return false;
3053

Callers

nothing calls this directly

Calls 3

compare_doubleFunction · 0.85
cJSON_ArrayForEachFunction · 0.85
get_object_itemFunction · 0.85

Tested by

no test coverage detected