MCPcopy Create free account
hub / github.com/antirez/botlib / cJSON_Compare

Function cJSON_Compare

cJSON.c:2977–3100  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

2975}
2976
2977CJSON_PUBLIC(cJSON_bool) cJSON_Compare(const cJSON * const a, const cJSON * const b, const cJSON_bool case_sensitive)
2978{
2979 if ((a == NULL) || (b == NULL) || ((a->type & 0xFF) != (b->type & 0xFF)) || cJSON_IsInvalid(a))
2980 {
2981 return false;
2982 }
2983
2984 /* check if type is valid */
2985 switch (a->type & 0xFF)
2986 {
2987 case cJSON_False:
2988 case cJSON_True:
2989 case cJSON_NULL:
2990 case cJSON_Number:
2991 case cJSON_String:
2992 case cJSON_Raw:
2993 case cJSON_Array:
2994 case cJSON_Object:
2995 break;
2996
2997 default:
2998 return false;
2999 }
3000
3001 /* identical objects are equal */
3002 if (a == b)
3003 {
3004 return true;
3005 }
3006
3007 switch (a->type & 0xFF)
3008 {
3009 /* in these cases and equal type is enough */
3010 case cJSON_False:
3011 case cJSON_True:
3012 case cJSON_NULL:
3013 return true;
3014
3015 case cJSON_Number:
3016 if (compare_double(a->valuedouble, b->valuedouble))
3017 {
3018 return true;
3019 }
3020 return false;
3021
3022 case cJSON_String:
3023 case cJSON_Raw:
3024 if ((a->valuestring == NULL) || (b->valuestring == NULL))
3025 {
3026 return false;
3027 }
3028 if (strcmp(a->valuestring, b->valuestring) == 0)
3029 {
3030 return true;
3031 }
3032
3033 return false;
3034

Callers

nothing calls this directly

Calls 3

cJSON_IsInvalidFunction · 0.85
compare_doubleFunction · 0.85
get_object_itemFunction · 0.85

Tested by

no test coverage detected