| 2797 | } |
| 2798 | |
| 2799 | CJSON_PUBLIC(cJSON_bool) cJSON_Compare(const cJSON * const a, const cJSON * const b, const cJSON_bool case_sensitive) |
| 2800 | { |
| 2801 | if ((a == NULL) || (b == NULL) || ((a->type & 0xFF) != (b->type & 0xFF)) || cJSON_IsInvalid(a)) |
| 2802 | { |
| 2803 | return false; |
| 2804 | } |
| 2805 | |
| 2806 | /* check if type is valid */ |
| 2807 | switch (a->type & 0xFF) |
| 2808 | { |
| 2809 | case cJSON_False: |
| 2810 | case cJSON_True: |
| 2811 | case cJSON_NULL: |
| 2812 | case cJSON_Number: |
| 2813 | case cJSON_String: |
| 2814 | case cJSON_Raw: |
| 2815 | case cJSON_Array: |
| 2816 | case cJSON_Object: |
| 2817 | break; |
| 2818 | |
| 2819 | default: |
| 2820 | return false; |
| 2821 | } |
| 2822 | |
| 2823 | /* identical objects are equal */ |
| 2824 | if (a == b) |
| 2825 | { |
| 2826 | return true; |
| 2827 | } |
| 2828 | |
| 2829 | switch (a->type & 0xFF) |
| 2830 | { |
| 2831 | /* in these cases and equal type is enough */ |
| 2832 | case cJSON_False: |
| 2833 | case cJSON_True: |
| 2834 | case cJSON_NULL: |
| 2835 | return true; |
| 2836 | |
| 2837 | case cJSON_Number: |
| 2838 | if (a->valuedouble == b->valuedouble) |
| 2839 | { |
| 2840 | return true; |
| 2841 | } |
| 2842 | return false; |
| 2843 | |
| 2844 | case cJSON_String: |
| 2845 | case cJSON_Raw: |
| 2846 | if ((a->valuestring == NULL) || (b->valuestring == NULL)) |
| 2847 | { |
| 2848 | return false; |
| 2849 | } |
| 2850 | if (strcmp(a->valuestring, b->valuestring) == 0) |
| 2851 | { |
| 2852 | return true; |
| 2853 | } |
| 2854 | |
| 2855 | return false; |
| 2856 |
nothing calls this directly
no test coverage detected