Classes | Macros | Typedefs | Functions | Variables
cJSON.c File Reference
#include <ctype.h>
#include <float.h>
#include <limits.h>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "cJSON.h"
Include dependency graph for cJSON.c:

Go to the source code of this file.

Classes

struct  error
 
struct  internal_hooks
 
struct  parse_buffer
 
struct  printbuffer
 

Macros

#define buffer_at_offset(buffer)   ((buffer)->content + (buffer)->offset)
 
#define can_access_at_index(buffer, index)   ((buffer != NULL) && (((buffer)->offset + index) < (buffer)->length))
 
#define can_read(buffer, size)   ((buffer != NULL) && (((buffer)->offset + size) <= (buffer)->length))
 
#define cannot_access_at_index(buffer, index)   (!can_access_at_index(buffer, index))
 
#define cjson_min(a, b)   (((a) < (b)) ? (a) : (b))
 
#define false   ((cJSON_bool)0)
 
#define internal_free   free
 
#define internal_malloc   malloc
 
#define internal_realloc   realloc
 
#define isinf(d)   (isnan((d - d)) && !isnan(d))
 
#define isnan(d)   (d != d)
 
#define NAN   0.0 / 0.0
 
#define static_strlen(string_literal)   (sizeof(string_literal) - sizeof(""))
 
#define true   ((cJSON_bool)1)
 

Typedefs

typedef struct internal_hooks internal_hooks
 

Functions

static cJSON_bool add_item_to_array (cJSON *array, cJSON *item)
 
static cJSON_bool add_item_to_object (cJSON *const object, const char *const string, cJSON *const item, const internal_hooks *const hooks, const cJSON_bool constant_key)
 
static parse_bufferbuffer_skip_whitespace (parse_buffer *const buffer)
 
static int case_insensitive_strcmp (const unsigned char *string1, const unsigned char *string2)
 
static voidcast_away_const (const void *string)
 
 cJSON_AddArrayToObject (cJSON *const object, const char *const name)
 
 cJSON_AddBoolToObject (cJSON *const object, const char *const name, const cJSON_bool boolean)
 
 cJSON_AddFalseToObject (cJSON *const object, const char *const name)
 
 cJSON_AddItemReferenceToArray (cJSON *array, cJSON *item)
 
 cJSON_AddItemReferenceToObject (cJSON *object, const char *string, cJSON *item)
 
 cJSON_AddItemToObject (cJSON *object, const char *string, cJSON *item)
 
 cJSON_AddItemToObjectCS (cJSON *object, const char *string, cJSON *item)
 
 cJSON_AddNullToObject (cJSON *const object, const char *const name)
 
 cJSON_AddNumberToObject (cJSON *const object, const char *const name, const double number)
 
 cJSON_AddObjectToObject (cJSON *const object, const char *const name)
 
 cJSON_AddRawToObject (cJSON *const object, const char *const name, const char *const raw)
 
 cJSON_AddStringToObject (cJSON *const object, const char *const name, const char *const string)
 
 cJSON_AddTrueToObject (cJSON *const object, const char *const name)
 
 cJSON_Compare (const cJSON *const a, const cJSON *const b, const cJSON_bool case_sensitive)
 
 cJSON_CreateDoubleArray (const double *numbers, int count)
 
 cJSON_CreateStringArray (const char *const *strings, int count)
 
 cJSON_DeleteItemFromObject (cJSON *object, const char *string)
 
 cJSON_DeleteItemFromObjectCaseSensitive (cJSON *object, const char *string)
 
 cJSON_DetachItemFromObject (cJSON *object, const char *string)
 
 cJSON_DetachItemFromObjectCaseSensitive (cJSON *object, const char *string)
 
 cJSON_DetachItemViaPointer (cJSON *parent, cJSON *const item)
 
 cJSON_GetObjectItem (const cJSON *const object, const char *const string)
 
 cJSON_GetObjectItemCaseSensitive (const cJSON *const object, const char *const string)
 
 cJSON_HasObjectItem (const cJSON *object, const char *string)
 
 cJSON_InsertItemInArray (cJSON *array, int which, cJSON *newitem)
 
static cJSONcJSON_New_Item (const internal_hooks *const hooks)
 
 cJSON_ParseWithLength (const char *value, size_t buffer_length)
 
 cJSON_ParseWithLengthOpts (const char *value, size_t buffer_length, const char **return_parse_end, cJSON_bool require_null_terminated)
 
 cJSON_ParseWithOpts (const char *value, const char **return_parse_end, cJSON_bool require_null_terminated)
 
 cJSON_PrintBuffered (const cJSON *item, int prebuffer, cJSON_bool fmt)
 
 cJSON_PrintPreallocated (cJSON *item, char *buffer, const int length, const cJSON_bool format)
 
 CJSON_PUBLIC (char *)
 
 CJSON_PUBLIC (cJSON *)
 
 CJSON_PUBLIC (const char *)
 
 CJSON_PUBLIC (double)
 
 CJSON_PUBLIC (int)
 
 CJSON_PUBLIC (void *)
 
 CJSON_PUBLIC (void)
 
 cJSON_ReplaceItemInArray (cJSON *array, int which, cJSON *newitem)
 
 cJSON_ReplaceItemInObject (cJSON *object, const char *string, cJSON *newitem)
 
 cJSON_ReplaceItemInObjectCaseSensitive (cJSON *object, const char *string, cJSON *newitem)
 
 cJSON_ReplaceItemViaPointer (cJSON *const parent, cJSON *const item, cJSON *replacement)
 
 cJSON_SetValuestring (cJSON *object, const char *valuestring)
 
static unsigned char * cJSON_strdup (const unsigned char *string, const internal_hooks *const hooks)
 
static cJSON_bool compare_double (double a, double b)
 
static cJSONcreate_reference (const cJSON *item, const internal_hooks *const hooks)
 
static unsigned char * ensure (printbuffer *const p, size_t needed)
 
static cJSONget_array_item (const cJSON *array, size_t index)
 
static unsigned char get_decimal_point (void)
 
static cJSONget_object_item (const cJSON *const object, const char *const name, const cJSON_bool case_sensitive)
 
static void minify_string (char **input, char **output)
 
static cJSON_bool parse_array (cJSON *const item, parse_buffer *const input_buffer)
 
static unsigned parse_hex4 (const unsigned char *const input)
 
static cJSON_bool parse_number (cJSON *const item, parse_buffer *const input_buffer)
 
static cJSON_bool parse_object (cJSON *const item, parse_buffer *const input_buffer)
 
static cJSON_bool parse_string (cJSON *const item, parse_buffer *const input_buffer)
 
static cJSON_bool parse_value (cJSON *const item, parse_buffer *const input_buffer)
 
static unsigned char * print (const cJSON *const item, cJSON_bool format, const internal_hooks *const hooks)
 
static cJSON_bool print_array (const cJSON *const item, printbuffer *const output_buffer)
 
static cJSON_bool print_number (const cJSON *const item, printbuffer *const output_buffer)
 
static cJSON_bool print_object (const cJSON *const item, printbuffer *const output_buffer)
 
static cJSON_bool print_string (const cJSON *const item, printbuffer *const p)
 
static cJSON_bool print_string_ptr (const unsigned char *const input, printbuffer *const output_buffer)
 
static cJSON_bool print_value (const cJSON *const item, printbuffer *const output_buffer)
 
static cJSON_bool replace_item_in_object (cJSON *object, const char *string, cJSON *replacement, cJSON_bool case_sensitive)
 
static void skip_multiline_comment (char **input)
 
static void skip_oneline_comment (char **input)
 
static parse_bufferskip_utf8_bom (parse_buffer *const buffer)
 
static void suffix_object (cJSON *prev, cJSON *item)
 
static void update_offset (printbuffer *const buffer)
 
static unsigned char utf16_literal_to_utf8 (const unsigned char *const input_pointer, const unsigned char *const input_end, unsigned char **output_pointer)
 

Variables

static error global_error = {NULL, 0}
 
static internal_hooks global_hooks
 

Macro Definition Documentation

◆ buffer_at_offset

#define buffer_at_offset (   buffer)    ((buffer)->content + (buffer)->offset)

Definition at line 276 of file cJSON.c.

◆ can_access_at_index

#define can_access_at_index (   buffer,
  index 
)    ((buffer != NULL) && (((buffer)->offset + index) < (buffer)->length))

Definition at line 271 of file cJSON.c.

◆ can_read

#define can_read (   buffer,
  size 
)    ((buffer != NULL) && (((buffer)->offset + size) <= (buffer)->length))

Definition at line 268 of file cJSON.c.

◆ cannot_access_at_index

#define cannot_access_at_index (   buffer,
  index 
)    (!can_access_at_index(buffer, index))

Definition at line 273 of file cJSON.c.

◆ cjson_min

#define cjson_min (   a,
  b 
)    (((a) < (b)) ? (a) : (b))

Definition at line 1072 of file cJSON.c.

◆ false

#define false   ((cJSON_bool)0)

Definition at line 70 of file cJSON.c.

◆ internal_free

#define internal_free   free

Definition at line 163 of file cJSON.c.

◆ internal_malloc

#define internal_malloc   malloc

Definition at line 162 of file cJSON.c.

◆ internal_realloc

#define internal_realloc   realloc

Definition at line 164 of file cJSON.c.

◆ isinf

#define isinf (   d)    (isnan((d - d)) && !isnan(d))

Definition at line 74 of file cJSON.c.

◆ isnan

#define isnan (   d)    (d != d)

Definition at line 77 of file cJSON.c.

◆ NAN

#define NAN   0.0 / 0.0

Definition at line 84 of file cJSON.c.

◆ static_strlen

#define static_strlen (   string_literal)    (sizeof(string_literal) - sizeof(""))

Definition at line 168 of file cJSON.c.

◆ true

#define true   ((cJSON_bool)1)

Definition at line 65 of file cJSON.c.

Typedef Documentation

◆ internal_hooks

Function Documentation

◆ add_item_to_array()

static cJSON_bool add_item_to_array ( cJSON array,
cJSON item 
)
static

Definition at line 1775 of file cJSON.c.

◆ add_item_to_object()

static cJSON_bool add_item_to_object ( cJSON *const  object,
const char *const  string,
cJSON *const  item,
const internal_hooks *const  hooks,
const cJSON_bool  constant_key 
)
static

Definition at line 1823 of file cJSON.c.

◆ buffer_skip_whitespace()

static parse_buffer* buffer_skip_whitespace ( parse_buffer *const  buffer)
static

Definition at line 936 of file cJSON.c.

◆ case_insensitive_strcmp()

static int case_insensitive_strcmp ( const unsigned char *  string1,
const unsigned char *  string2 
)
static

Definition at line 129 of file cJSON.c.

◆ cast_away_const()

static void* cast_away_const ( const void string)
static

Definition at line 1816 of file cJSON.c.

◆ cJSON_AddArrayToObject()

cJSON_AddArrayToObject ( cJSON *const  object,
const char *const  name 
)

Definition at line 1982 of file cJSON.c.

◆ cJSON_AddBoolToObject()

cJSON_AddBoolToObject ( cJSON *const  object,
const char *const  name,
const cJSON_bool  boolean 
)

Definition at line 1923 of file cJSON.c.

◆ cJSON_AddFalseToObject()

cJSON_AddFalseToObject ( cJSON *const  object,
const char *const  name 
)

Definition at line 1912 of file cJSON.c.

◆ cJSON_AddItemReferenceToArray()

cJSON_AddItemReferenceToArray ( cJSON array,
cJSON item 
)

Definition at line 1870 of file cJSON.c.

◆ cJSON_AddItemReferenceToObject()

cJSON_AddItemReferenceToObject ( cJSON object,
const char *  string,
cJSON item 
)

Definition at line 1879 of file cJSON.c.

◆ cJSON_AddItemToObject()

cJSON_AddItemToObject ( cJSON object,
const char *  string,
cJSON item 
)

Definition at line 1859 of file cJSON.c.

◆ cJSON_AddItemToObjectCS()

cJSON_AddItemToObjectCS ( cJSON object,
const char *  string,
cJSON item 
)

Definition at line 1865 of file cJSON.c.

◆ cJSON_AddNullToObject()

cJSON_AddNullToObject ( cJSON *const  object,
const char *const  name 
)

Definition at line 1890 of file cJSON.c.

◆ cJSON_AddNumberToObject()

cJSON_AddNumberToObject ( cJSON *const  object,
const char *const  name,
const double  number 
)

Definition at line 1935 of file cJSON.c.

◆ cJSON_AddObjectToObject()

cJSON_AddObjectToObject ( cJSON *const  object,
const char *const  name 
)

Definition at line 1971 of file cJSON.c.

◆ cJSON_AddRawToObject()

cJSON_AddRawToObject ( cJSON *const  object,
const char *const  name,
const char *const  raw 
)

Definition at line 1959 of file cJSON.c.

◆ cJSON_AddStringToObject()

cJSON_AddStringToObject ( cJSON *const  object,
const char *const  name,
const char *const  string 
)

Definition at line 1947 of file cJSON.c.

◆ cJSON_AddTrueToObject()

cJSON_AddTrueToObject ( cJSON *const  object,
const char *const  name 
)

Definition at line 1901 of file cJSON.c.

◆ cJSON_Compare()

cJSON_Compare ( const cJSON *const  a,
const cJSON *const  b,
const cJSON_bool  case_sensitive 
)

Definition at line 2685 of file cJSON.c.

◆ cJSON_CreateDoubleArray()

cJSON_CreateDoubleArray ( const double *  numbers,
int  count 
)

Definition at line 2378 of file cJSON.c.

◆ cJSON_CreateStringArray()

cJSON_CreateStringArray ( const char *const *  strings,
int  count 
)

Definition at line 2412 of file cJSON.c.

◆ cJSON_DeleteItemFromObject()

cJSON_DeleteItemFromObject ( cJSON object,
const char *  string 
)

Definition at line 2050 of file cJSON.c.

◆ cJSON_DeleteItemFromObjectCaseSensitive()

cJSON_DeleteItemFromObjectCaseSensitive ( cJSON object,
const char *  string 
)

Definition at line 2055 of file cJSON.c.

◆ cJSON_DetachItemFromObject()

cJSON_DetachItemFromObject ( cJSON object,
const char *  string 
)

Definition at line 2036 of file cJSON.c.

◆ cJSON_DetachItemFromObjectCaseSensitive()

cJSON_DetachItemFromObjectCaseSensitive ( cJSON object,
const char *  string 
)

Definition at line 2043 of file cJSON.c.

◆ cJSON_DetachItemViaPointer()

cJSON_DetachItemViaPointer ( cJSON parent,
cJSON *const  item 
)

Definition at line 1993 of file cJSON.c.

◆ cJSON_GetObjectItem()

cJSON_GetObjectItem ( const cJSON *const  object,
const char *const  string 
)

Definition at line 1734 of file cJSON.c.

◆ cJSON_GetObjectItemCaseSensitive()

cJSON_GetObjectItemCaseSensitive ( const cJSON *const  object,
const char *const  string 
)

Definition at line 1739 of file cJSON.c.

◆ cJSON_HasObjectItem()

cJSON_HasObjectItem ( const cJSON object,
const char *  string 
)

Definition at line 1745 of file cJSON.c.

◆ cJSON_InsertItemInArray()

cJSON_InsertItemInArray ( cJSON array,
int  which,
cJSON newitem 
)

Definition at line 2061 of file cJSON.c.

◆ cJSON_New_Item()

static cJSON* cJSON_New_Item ( const internal_hooks *const  hooks)
static

Definition at line 220 of file cJSON.c.

◆ cJSON_ParseWithLength()

cJSON_ParseWithLength ( const char *  value,
size_t  buffer_length 
)

Definition at line 1068 of file cJSON.c.

◆ cJSON_ParseWithLengthOpts()

cJSON_ParseWithLengthOpts ( const char *  value,
size_t  buffer_length,
const char **  return_parse_end,
cJSON_bool  require_null_terminated 
)

Definition at line 991 of file cJSON.c.

◆ cJSON_ParseWithOpts()

cJSON_ParseWithOpts ( const char *  value,
const char **  return_parse_end,
cJSON_bool  require_null_terminated 
)

Definition at line 974 of file cJSON.c.

◆ cJSON_PrintBuffered()

cJSON_PrintBuffered ( const cJSON item,
int  prebuffer,
cJSON_bool  fmt 
)

Definition at line 1143 of file cJSON.c.

◆ cJSON_PrintPreallocated()

cJSON_PrintPreallocated ( cJSON item,
char *  buffer,
const int  length,
const cJSON_bool  format 
)

Definition at line 1170 of file cJSON.c.

◆ CJSON_PUBLIC() [1/7]

CJSON_PUBLIC ( char *  )

Definition at line 98 of file cJSON.c.

◆ CJSON_PUBLIC() [2/7]

CJSON_PUBLIC ( cJSON )

Definition at line 1063 of file cJSON.c.

◆ CJSON_PUBLIC() [3/7]

CJSON_PUBLIC ( const char *  )

Definition at line 94 of file cJSON.c.

◆ CJSON_PUBLIC() [4/7]

CJSON_PUBLIC ( double  )

Definition at line 106 of file cJSON.c.

◆ CJSON_PUBLIC() [5/7]

CJSON_PUBLIC ( int  )

Definition at line 1659 of file cJSON.c.

◆ CJSON_PUBLIC() [6/7]

CJSON_PUBLIC ( void )

Definition at line 2793 of file cJSON.c.

◆ CJSON_PUBLIC() [7/7]

CJSON_PUBLIC ( void  )

Definition at line 192 of file cJSON.c.

◆ cJSON_ReplaceItemInArray()

cJSON_ReplaceItemInArray ( cJSON array,
int  which,
cJSON newitem 
)

Definition at line 2132 of file cJSON.c.

◆ cJSON_ReplaceItemInObject()

cJSON_ReplaceItemInObject ( cJSON object,
const char *  string,
cJSON newitem 
)

Definition at line 2166 of file cJSON.c.

◆ cJSON_ReplaceItemInObjectCaseSensitive()

cJSON_ReplaceItemInObjectCaseSensitive ( cJSON object,
const char *  string,
cJSON newitem 
)

Definition at line 2171 of file cJSON.c.

◆ cJSON_ReplaceItemViaPointer()

cJSON_ReplaceItemViaPointer ( cJSON *const  parent,
cJSON *const  item,
cJSON replacement 
)

Definition at line 2090 of file cJSON.c.

◆ cJSON_SetValuestring()

cJSON_SetValuestring ( cJSON object,
const char *  valuestring 
)

Definition at line 362 of file cJSON.c.

◆ cJSON_strdup()

static unsigned char* cJSON_strdup ( const unsigned char *  string,
const internal_hooks *const  hooks 
)
static

Definition at line 173 of file cJSON.c.

◆ compare_double()

static cJSON_bool compare_double ( double  a,
double  b 
)
static

Definition at line 482 of file cJSON.c.

◆ create_reference()

static cJSON* create_reference ( const cJSON item,
const internal_hooks *const  hooks 
)
static

Definition at line 1756 of file cJSON.c.

◆ ensure()

static unsigned char* ensure ( printbuffer *const  p,
size_t  needed 
)
static

Definition at line 401 of file cJSON.c.

◆ get_array_item()

static cJSON* get_array_item ( const cJSON array,
size_t  index 
)
static

Definition at line 1679 of file cJSON.c.

◆ get_decimal_point()

static unsigned char get_decimal_point ( void  )
static

Definition at line 249 of file cJSON.c.

◆ get_object_item()

static cJSON* get_object_item ( const cJSON *const  object,
const char *const  name,
const cJSON_bool  case_sensitive 
)
static

Definition at line 1703 of file cJSON.c.

◆ minify_string()

static void minify_string ( char **  input,
char **  output 
)
static

Definition at line 2543 of file cJSON.c.

◆ parse_array()

static cJSON_bool parse_array ( cJSON *const  item,
parse_buffer *const  input_buffer 
)
static

Definition at line 1314 of file cJSON.c.

◆ parse_hex4()

static unsigned parse_hex4 ( const unsigned char *const  input)
static

Definition at line 549 of file cJSON.c.

◆ parse_number()

static cJSON_bool parse_number ( cJSON *const  item,
parse_buffer *const  input_buffer 
)
static

Definition at line 279 of file cJSON.c.

◆ parse_object()

static cJSON_bool parse_object ( cJSON *const  item,
parse_buffer *const  input_buffer 
)
static

Definition at line 1456 of file cJSON.c.

◆ parse_string()

static cJSON_bool parse_string ( cJSON *const  item,
parse_buffer *const  input_buffer 
)
static

Definition at line 682 of file cJSON.c.

◆ parse_value()

static cJSON_bool parse_value ( cJSON *const  item,
parse_buffer *const  input_buffer 
)
static

Definition at line 1189 of file cJSON.c.

◆ print()

static unsigned char* print ( const cJSON *const  item,
cJSON_bool  format,
const internal_hooks *const  hooks 
)
static

Definition at line 1074 of file cJSON.c.

◆ print_array()

static cJSON_bool print_array ( const cJSON *const  item,
printbuffer *const  output_buffer 
)
static

Definition at line 1402 of file cJSON.c.

◆ print_number()

static cJSON_bool print_number ( const cJSON *const  item,
printbuffer *const  output_buffer 
)
static

Definition at line 488 of file cJSON.c.

◆ print_object()

static cJSON_bool print_object ( const cJSON *const  item,
printbuffer *const  output_buffer 
)
static

Definition at line 1559 of file cJSON.c.

◆ print_string()

static cJSON_bool print_string ( const cJSON *const  item,
printbuffer *const  p 
)
static

Definition at line 917 of file cJSON.c.

◆ print_string_ptr()

static cJSON_bool print_string_ptr ( const unsigned char *const  input,
printbuffer *const  output_buffer 
)
static

Definition at line 806 of file cJSON.c.

◆ print_value()

static cJSON_bool print_value ( const cJSON *const  item,
printbuffer *const  output_buffer 
)
static

Definition at line 1248 of file cJSON.c.

◆ replace_item_in_object()

static cJSON_bool replace_item_in_object ( cJSON object,
const char *  string,
cJSON replacement,
cJSON_bool  case_sensitive 
)
static

Definition at line 2141 of file cJSON.c.

◆ skip_multiline_comment()

static void skip_multiline_comment ( char **  input)
static

Definition at line 2532 of file cJSON.c.

◆ skip_oneline_comment()

static void skip_oneline_comment ( char **  input)
static

Definition at line 2521 of file cJSON.c.

◆ skip_utf8_bom()

static parse_buffer* skip_utf8_bom ( parse_buffer *const  buffer)
static

Definition at line 958 of file cJSON.c.

◆ suffix_object()

static void suffix_object ( cJSON prev,
cJSON item 
)
static

Definition at line 1750 of file cJSON.c.

◆ update_offset()

static void update_offset ( printbuffer *const  buffer)
static

Definition at line 471 of file cJSON.c.

◆ utf16_literal_to_utf8()

static unsigned char utf16_literal_to_utf8 ( const unsigned char *const  input_pointer,
const unsigned char *const  input_end,
unsigned char **  output_pointer 
)
static

Definition at line 578 of file cJSON.c.

Variable Documentation

◆ global_error

error global_error = {NULL, 0}
static

Definition at line 92 of file cJSON.c.

◆ global_hooks

internal_hooks global_hooks
static
Initial value:

Definition at line 170 of file cJSON.c.

internal_free
#define internal_free
Definition: cJSON.c:163
internal_malloc
#define internal_malloc
Definition: cJSON.c:162
internal_realloc
#define internal_realloc
Definition: cJSON.c:164


libaditof
Author(s):
autogenerated on Wed May 21 2025 02:07:02