CToon C 0.6.1
A C99 TOON/JSON serialization library
Loading...
Searching...
No Matches
ctoon.h File Reference
#include <stdio.h>
#include <stdlib.h>
#include <stddef.h>
#include <limits.h>
#include <string.h>
#include <float.h>
Include dependency graph for ctoon.h:

Go to the source code of this file.

Data Structures

struct  ctoon_alc
 
struct  ctoon_read_err
 
struct  ctoon_write_err
 
struct  ctoon_write_options
 
struct  ctoon_arr_iter
 
struct  ctoon_obj_iter
 
struct  ctoon_mut_arr_iter
 
struct  ctoon_mut_obj_iter
 
struct  ctoon_ptr_err
 
struct  ctoon_ptr_ctx
 
struct  ctoon_patch_err
 
union  ctoon_val_uni
 
struct  ctoon_val
 
struct  ctoon_doc
 
struct  ctoon_mut_val
 
struct  ctoon_str_chunk
 
struct  ctoon_str_pool
 
struct  ctoon_val_chunk
 
struct  ctoon_val_pool
 
struct  ctoon_mut_doc
 

Macros

#define CTOON_MSC_VER   0
 
#define CTOON_GCC_VER   0
 
#define ctoon_gcc_available(major, minor, patch)   0
 
#define CTOON_IS_REAL_GCC   0
 
#define CTOON_STDC_VER   0
 
#define CTOON_CPP_VER   0
 
#define ctoon_has_builtin(x)   0
 
#define ctoon_has_attribute(x)   0
 
#define ctoon_has_feature(x)   0
 
#define ctoon_has_include(x)   0
 
#define ctoon_inline
 
#define ctoon_noinline
 
#define ctoon_align(x)
 
#define ctoon_likely(expr)   (expr)
 
#define ctoon_unlikely(expr)   (expr)
 
#define CTOON_HAS_CONSTANT_P   0
 
#define ctoon_constant_p(value)   0
 
#define ctoon_deprecated(msg)
 
#define ctoon_api
 
#define ctoon_api_inline   static ctoon_inline
 
#define __bool_true_false_are_defined   1
 
#define bool   unsigned char
 
#define true   1
 
#define false   0
 
#define CTOON_U64_TO_F64_NO_IMPL   0
 
#define CTOON_VERSION_MAJOR   0
 
#define CTOON_VERSION_MINOR   6
 
#define CTOON_VERSION_PATCH   1
 
#define CTOON_VERSION_ENCODE(maj, min, pat)   (((maj)*10000)+((min)*100)+(pat))
 
#define CTOON_VERSION    CTOON_VERSION_ENCODE(CTOON_VERSION_MAJOR,CTOON_VERSION_MINOR,CTOON_VERSION_PATCH)
 
#define CTOON_VERSION_HEX    ((CTOON_VERSION_MAJOR << 16) | (CTOON_VERSION_MINOR << 8) | CTOON_VERSION_PATCH)
 
#define _CTOON_VERSION_XSTR(a, b, c)   #a"."#b"."#c
 
#define _CTOON_VERSION_STR(a, b, c)   _CTOON_VERSION_XSTR(a,b,c)
 
#define CTOON_VERSION_STRING    _CTOON_VERSION_STR(CTOON_VERSION_MAJOR,CTOON_VERSION_MINOR,CTOON_VERSION_PATCH)
 
#define CTOON_TYPE_NONE   ((uint8_t)0) /* _____000 */
 
#define CTOON_TYPE_RAW   ((uint8_t)1) /* _____001 */
 
#define CTOON_TYPE_NULL   ((uint8_t)2) /* _____010 */
 
#define CTOON_TYPE_BOOL   ((uint8_t)3) /* _____011 */
 
#define CTOON_TYPE_NUM   ((uint8_t)4) /* _____100 */
 
#define CTOON_TYPE_STR   ((uint8_t)5) /* _____101 */
 
#define CTOON_TYPE_ARR   ((uint8_t)6) /* _____110 */
 
#define CTOON_TYPE_OBJ   ((uint8_t)7) /* _____111 */
 
#define CTOON_SUBTYPE_NONE   ((uint8_t)(0 << 3)) /* ___00___ */
 
#define CTOON_SUBTYPE_FALSE   ((uint8_t)(0 << 3)) /* ___00___ */
 
#define CTOON_SUBTYPE_TRUE   ((uint8_t)(1 << 3)) /* ___01___ */
 
#define CTOON_SUBTYPE_UINT   ((uint8_t)(0 << 3)) /* ___00___ */
 
#define CTOON_SUBTYPE_SINT   ((uint8_t)(1 << 3)) /* ___01___ */
 
#define CTOON_SUBTYPE_REAL   ((uint8_t)(2 << 3)) /* ___10___ */
 
#define CTOON_SUBTYPE_NOESC   ((uint8_t)(1 << 3)) /* ___01___ */
 
#define CTOON_TYPE_MASK   ((uint8_t)0x07) /* _____111 */
 
#define CTOON_TYPE_BIT   ((uint8_t)3)
 
#define CTOON_SUBTYPE_MASK   ((uint8_t)0x18) /* ___11___ */
 
#define CTOON_SUBTYPE_BIT   ((uint8_t)2)
 
#define CTOON_RESERVED_MASK   ((uint8_t)0xE0) /* 111_____ */
 
#define CTOON_RESERVED_BIT   ((uint8_t)3)
 
#define CTOON_TAG_MASK   ((uint8_t)0xFF) /* 11111111 */
 
#define CTOON_TAG_BIT   ((uint8_t)8)
 
#define CTOON_PADDING_SIZE   4
 
#define CTOON_WRITE_FP_FLAG_BITS   8
 
#define CTOON_WRITE_FP_PREC_BITS   4
 
#define CTOON_WRITE_FP_TO_FIXED(prec)
 
#define CTOON_WRITE_FP_TO_FLOAT   ((ctoon_write_flag)(1 << (32 - 5)))
 
#define ctoon_arr_foreach(arr, idx, max, val)
 
#define ctoon_obj_foreach(obj, idx, max, key, val)
 
#define ctoon_mut_arr_foreach(arr, idx, max, val)
 
#define ctoon_mut_obj_foreach(obj, idx, max, key, val)
 
#define ctoon_mut_val_one(func)
 
#define ctoon_mut_val_one_str(func)
 
#define ctoon_mut_arr_with_func(func)
 
#define ctoon_mut_obj_add_func(func)
 
#define ctoon_ptr_set_err(_code, _msg)
 

Typedefs

typedef uint8_t ctoon_type
 
typedef uint8_t ctoon_subtype
 
typedef struct ctoon_alc ctoon_alc
 
typedef struct ctoon_doc ctoon_doc
 
typedef struct ctoon_val ctoon_val
 
typedef struct ctoon_mut_doc ctoon_mut_doc
 
typedef struct ctoon_mut_val ctoon_mut_val
 
typedef uint32_t ctoon_read_flag
 
typedef uint32_t ctoon_read_code
 
typedef struct ctoon_read_err ctoon_read_err
 
typedef struct ctoon_incr_state ctoon_incr_state
 
typedef uint32_t ctoon_write_flag
 
typedef enum ctoon_delimiter ctoon_delimiter
 
typedef uint32_t ctoon_write_code
 
typedef struct ctoon_write_err ctoon_write_err
 
typedef struct ctoon_write_options ctoon_write_options
 
typedef struct ctoon_arr_iter ctoon_arr_iter
 
typedef struct ctoon_obj_iter ctoon_obj_iter
 
typedef struct ctoon_mut_arr_iter ctoon_mut_arr_iter
 
typedef struct ctoon_mut_obj_iter ctoon_mut_obj_iter
 
typedef uint32_t ctoon_ptr_code
 
typedef struct ctoon_ptr_err ctoon_ptr_err
 
typedef struct ctoon_ptr_ctx ctoon_ptr_ctx
 
typedef uint32_t ctoon_patch_code
 
typedef struct ctoon_patch_err ctoon_patch_err
 
typedef union ctoon_val_uni ctoon_val_uni
 
typedef struct ctoon_str_chunk ctoon_str_chunk
 
typedef struct ctoon_str_pool ctoon_str_pool
 
typedef struct ctoon_val_chunk ctoon_val_chunk
 
typedef struct ctoon_val_pool ctoon_val_pool
 

Enumerations

enum  ctoon_delimiter { CTOON_DELIMITER_COMMA = 0 , CTOON_DELIMITER_TAB , CTOON_DELIMITER_PIPE }
 

Functions

uint32_t ctoon_version (void)
 
unsigned char ctoon_alc_pool_init (ctoon_alc *alc, void *buf, size_t size)
 
ctoon_alcctoon_alc_dyn_new (void)
 
void ctoon_alc_dyn_free (ctoon_alc *alc)
 
unsigned char ctoon_locate_pos (const char *str, size_t len, size_t pos, size_t *line, size_t *col, size_t *chr)
 
ctoon_docctoon_read_opts (char *dat, size_t len, ctoon_read_flag flg, const ctoon_alc *alc, ctoon_read_err *err)
 
ctoon_docctoon_read_opts_indent (char *dat, size_t len, ctoon_read_flag flg, int indent_size, const ctoon_alc *alc, ctoon_read_err *err)
 
ctoon_docctoon_read_file (const char *path, ctoon_read_flag flg, const ctoon_alc *alc, ctoon_read_err *err)
 
ctoon_docctoon_read_fp (FILE *fp, ctoon_read_flag flg, const ctoon_alc *alc, ctoon_read_err *err)
 
static ctoon_docctoon_read (const char *dat, size_t len, ctoon_read_flag flg)
 
ctoon_incr_statectoon_incr_new (char *buf, size_t buf_len, ctoon_read_flag flg, const ctoon_alc *alc)
 
ctoon_docctoon_incr_read (ctoon_incr_state *state, size_t len, ctoon_read_err *err)
 
void ctoon_incr_free (ctoon_incr_state *state)
 
static size_t ctoon_read_max_memory_usage (size_t len, ctoon_read_flag flg)
 
const char * ctoon_read_number (const char *dat, ctoon_val *val, ctoon_read_flag flg, const ctoon_alc *alc, ctoon_read_err *err)
 
static const char * ctoon_mut_read_number (const char *dat, ctoon_mut_val *val, ctoon_read_flag flg, const ctoon_alc *alc, ctoon_read_err *err)
 
char * ctoon_write_opts (const ctoon_doc *doc, const ctoon_write_options *opts, const ctoon_alc *alc, size_t *len, ctoon_write_err *err)
 
static char * ctoon_write (const ctoon_doc *doc, size_t *len)
 
unsigned char ctoon_write_file (const char *path, const ctoon_doc *doc, const ctoon_write_options *opts, const ctoon_alc *alc, ctoon_write_err *err)
 
unsigned char ctoon_write_fp (FILE *fp, const ctoon_doc *doc, const ctoon_write_options *opts, const ctoon_alc *alc, ctoon_write_err *err)
 
char * ctoon_val_write_opts (const ctoon_val *val, const ctoon_write_options *opts, const ctoon_alc *alc, size_t *len, ctoon_write_err *err)
 
static char * ctoon_val_write (const ctoon_val *val, size_t *len)
 
char * ctoon_mut_write_opts (const ctoon_mut_doc *doc, const ctoon_write_options *opts, const ctoon_alc *alc, size_t *len, ctoon_write_err *err)
 
static char * ctoon_mut_write (const ctoon_mut_doc *doc, size_t *len)
 
unsigned char ctoon_mut_write_file (const char *path, const ctoon_mut_doc *doc, const ctoon_write_options *opts, const ctoon_alc *alc, ctoon_write_err *err)
 
unsigned char ctoon_mut_write_fp (FILE *fp, const ctoon_mut_doc *doc, const ctoon_write_options *opts, const ctoon_alc *alc, ctoon_write_err *err)
 
char * ctoon_mut_val_write_opts (const ctoon_mut_val *val, const ctoon_write_options *opts, const ctoon_alc *alc, size_t *len, ctoon_write_err *err)
 
static char * ctoon_mut_val_write (const ctoon_mut_val *val, size_t *len)
 
char * ctoon_write_number (const ctoon_val *val, char *buf)
 
char * ctoon_doc_to_json (const ctoon_doc *doc, int indent, ctoon_write_flag flags, const ctoon_alc *alc, size_t *len, ctoon_write_err *err)
 
char * ctoon_mut_doc_to_json (const ctoon_mut_doc *doc, int indent, ctoon_write_flag flags, const ctoon_alc *alc, size_t *len, ctoon_write_err *err)
 
static ctoon_valctoon_doc_get_root (ctoon_doc *doc)
 
static size_t ctoon_doc_get_read_size (ctoon_doc *doc)
 
static size_t ctoon_doc_get_val_count (ctoon_doc *doc)
 
static void ctoon_doc_free (ctoon_doc *doc)
 
static unsigned char ctoon_is_raw (ctoon_val *val)
 
static unsigned char ctoon_is_null (ctoon_val *val)
 
static unsigned char ctoon_is_true (ctoon_val *val)
 
static unsigned char ctoon_is_false (ctoon_val *val)
 
static unsigned char ctoon_is_bool (ctoon_val *val)
 
static unsigned char ctoon_is_uint (ctoon_val *val)
 
static unsigned char ctoon_is_sint (ctoon_val *val)
 
static unsigned char ctoon_is_int (ctoon_val *val)
 
static unsigned char ctoon_is_real (ctoon_val *val)
 
static unsigned char ctoon_is_num (ctoon_val *val)
 
static unsigned char ctoon_is_str (ctoon_val *val)
 
static unsigned char ctoon_is_arr (ctoon_val *val)
 
static unsigned char ctoon_is_obj (ctoon_val *val)
 
static unsigned char ctoon_is_ctn (ctoon_val *val)
 
static ctoon_type ctoon_get_type (ctoon_val *val)
 
static ctoon_subtype ctoon_get_subtype (ctoon_val *val)
 
static uint8_t ctoon_get_tag (ctoon_val *val)
 
static const char * ctoon_get_type_desc (ctoon_val *val)
 
static const char * ctoon_get_raw (ctoon_val *val)
 
static unsigned char ctoon_get_bool (ctoon_val *val)
 
static uint64_t ctoon_get_uint (ctoon_val *val)
 
static int64_t ctoon_get_sint (ctoon_val *val)
 
static int ctoon_get_int (ctoon_val *val)
 
static double ctoon_get_real (ctoon_val *val)
 
static double ctoon_get_num (ctoon_val *val)
 
static const char * ctoon_get_str (ctoon_val *val)
 
static size_t ctoon_get_len (ctoon_val *val)
 
static unsigned char ctoon_equals_str (ctoon_val *val, const char *str)
 
static unsigned char ctoon_equals_strn (ctoon_val *val, const char *str, size_t len)
 
static unsigned char ctoon_equals (ctoon_val *lhs, ctoon_val *rhs)
 
static unsigned char ctoon_set_raw (ctoon_val *val, const char *raw, size_t len)
 
static unsigned char ctoon_set_null (ctoon_val *val)
 
static unsigned char ctoon_set_bool (ctoon_val *val, unsigned char num)
 
static unsigned char ctoon_set_uint (ctoon_val *val, uint64_t num)
 
static unsigned char ctoon_set_sint (ctoon_val *val, int64_t num)
 
static unsigned char ctoon_set_int (ctoon_val *val, int num)
 
static unsigned char ctoon_set_float (ctoon_val *val, float num)
 
static unsigned char ctoon_set_double (ctoon_val *val, double num)
 
static unsigned char ctoon_set_real (ctoon_val *val, double num)
 
static unsigned char ctoon_set_fp_to_fixed (ctoon_val *val, int prec)
 
static unsigned char ctoon_set_fp_to_float (ctoon_val *val, unsigned char flt)
 
static unsigned char ctoon_set_str (ctoon_val *val, const char *str)
 
static unsigned char ctoon_set_strn (ctoon_val *val, const char *str, size_t len)
 
static unsigned char ctoon_set_str_noesc (ctoon_val *val, unsigned char noesc)
 
static size_t ctoon_arr_size (ctoon_val *arr)
 
static ctoon_valctoon_arr_get (ctoon_val *arr, size_t idx)
 
static ctoon_valctoon_arr_get_first (ctoon_val *arr)
 
static ctoon_valctoon_arr_get_last (ctoon_val *arr)
 
static unsigned char ctoon_arr_iter_init (ctoon_val *arr, ctoon_arr_iter *iter)
 
static ctoon_arr_iter ctoon_arr_iter_with (ctoon_val *arr)
 
static unsigned char ctoon_arr_iter_has_next (ctoon_arr_iter *iter)
 
static ctoon_valctoon_arr_iter_next (ctoon_arr_iter *iter)
 
static size_t ctoon_obj_size (ctoon_val *obj)
 
static ctoon_valctoon_obj_get (ctoon_val *obj, const char *key)
 
static ctoon_valctoon_obj_getn (ctoon_val *obj, const char *key, size_t key_len)
 
static unsigned char ctoon_obj_iter_init (ctoon_val *obj, ctoon_obj_iter *iter)
 
static ctoon_obj_iter ctoon_obj_iter_with (ctoon_val *obj)
 
static unsigned char ctoon_obj_iter_has_next (ctoon_obj_iter *iter)
 
static ctoon_valctoon_obj_iter_next (ctoon_obj_iter *iter)
 
static ctoon_valctoon_obj_iter_get_val (ctoon_val *key)
 
static ctoon_valctoon_obj_iter_get (ctoon_obj_iter *iter, const char *key)
 
static ctoon_valctoon_obj_iter_getn (ctoon_obj_iter *iter, const char *key, size_t key_len)
 
static ctoon_mut_valctoon_mut_doc_get_root (ctoon_mut_doc *doc)
 
static void ctoon_mut_doc_set_root (ctoon_mut_doc *doc, ctoon_mut_val *root)
 
unsigned char ctoon_mut_doc_set_str_pool_size (ctoon_mut_doc *doc, size_t len)
 
unsigned char ctoon_mut_doc_set_val_pool_size (ctoon_mut_doc *doc, size_t count)
 
void ctoon_mut_doc_free (ctoon_mut_doc *doc)
 
ctoon_mut_docctoon_mut_doc_new (const ctoon_alc *alc)
 
ctoon_mut_docctoon_doc_mut_copy (ctoon_doc *doc, const ctoon_alc *alc)
 
ctoon_mut_docctoon_mut_doc_mut_copy (ctoon_mut_doc *doc, const ctoon_alc *alc)
 
ctoon_mut_valctoon_val_mut_copy (ctoon_mut_doc *doc, ctoon_val *val)
 
ctoon_mut_valctoon_mut_val_mut_copy (ctoon_mut_doc *doc, ctoon_mut_val *val)
 
ctoon_docctoon_mut_doc_imut_copy (ctoon_mut_doc *doc, const ctoon_alc *alc)
 
ctoon_docctoon_mut_val_imut_copy (ctoon_mut_val *val, const ctoon_alc *alc)
 
static unsigned char ctoon_mut_is_raw (ctoon_mut_val *val)
 
static unsigned char ctoon_mut_is_null (ctoon_mut_val *val)
 
static unsigned char ctoon_mut_is_true (ctoon_mut_val *val)
 
static unsigned char ctoon_mut_is_false (ctoon_mut_val *val)
 
static unsigned char ctoon_mut_is_bool (ctoon_mut_val *val)
 
static unsigned char ctoon_mut_is_uint (ctoon_mut_val *val)
 
static unsigned char ctoon_mut_is_sint (ctoon_mut_val *val)
 
static unsigned char ctoon_mut_is_int (ctoon_mut_val *val)
 
static unsigned char ctoon_mut_is_real (ctoon_mut_val *val)
 
static unsigned char ctoon_mut_is_num (ctoon_mut_val *val)
 
static unsigned char ctoon_mut_is_str (ctoon_mut_val *val)
 
static unsigned char ctoon_mut_is_arr (ctoon_mut_val *val)
 
static unsigned char ctoon_mut_is_obj (ctoon_mut_val *val)
 
static unsigned char ctoon_mut_is_ctn (ctoon_mut_val *val)
 
static ctoon_type ctoon_mut_get_type (ctoon_mut_val *val)
 
static ctoon_subtype ctoon_mut_get_subtype (ctoon_mut_val *val)
 
static uint8_t ctoon_mut_get_tag (ctoon_mut_val *val)
 
static const char * ctoon_mut_get_type_desc (ctoon_mut_val *val)
 
static const char * ctoon_mut_get_raw (ctoon_mut_val *val)
 
static unsigned char ctoon_mut_get_bool (ctoon_mut_val *val)
 
static uint64_t ctoon_mut_get_uint (ctoon_mut_val *val)
 
static int64_t ctoon_mut_get_sint (ctoon_mut_val *val)
 
static int ctoon_mut_get_int (ctoon_mut_val *val)
 
static double ctoon_mut_get_real (ctoon_mut_val *val)
 
static double ctoon_mut_get_num (ctoon_mut_val *val)
 
static const char * ctoon_mut_get_str (ctoon_mut_val *val)
 
static size_t ctoon_mut_get_len (ctoon_mut_val *val)
 
static unsigned char ctoon_mut_equals_str (ctoon_mut_val *val, const char *str)
 
static unsigned char ctoon_mut_equals_strn (ctoon_mut_val *val, const char *str, size_t len)
 
static unsigned char ctoon_mut_equals (ctoon_mut_val *lhs, ctoon_mut_val *rhs)
 
static unsigned char ctoon_mut_set_raw (ctoon_mut_val *val, const char *raw, size_t len)
 
static unsigned char ctoon_mut_set_null (ctoon_mut_val *val)
 
static unsigned char ctoon_mut_set_bool (ctoon_mut_val *val, unsigned char num)
 
static unsigned char ctoon_mut_set_uint (ctoon_mut_val *val, uint64_t num)
 
static unsigned char ctoon_mut_set_sint (ctoon_mut_val *val, int64_t num)
 
static unsigned char ctoon_mut_set_int (ctoon_mut_val *val, int num)
 
static unsigned char ctoon_mut_set_float (ctoon_mut_val *val, float num)
 
static unsigned char ctoon_mut_set_double (ctoon_mut_val *val, double num)
 
static unsigned char ctoon_mut_set_real (ctoon_mut_val *val, double num)
 
static unsigned char ctoon_mut_set_fp_to_fixed (ctoon_mut_val *val, int prec)
 
static unsigned char ctoon_mut_set_fp_to_float (ctoon_mut_val *val, unsigned char flt)
 
static unsigned char ctoon_mut_set_str (ctoon_mut_val *val, const char *str)
 
static unsigned char ctoon_mut_set_strn (ctoon_mut_val *val, const char *str, size_t len)
 
static unsigned char ctoon_mut_set_str_noesc (ctoon_mut_val *val, unsigned char noesc)
 
static unsigned char ctoon_mut_set_arr (ctoon_mut_val *val)
 
static unsigned char ctoon_mut_set_obj (ctoon_mut_val *val)
 
static ctoon_mut_valctoon_mut_raw (ctoon_mut_doc *doc, const char *str)
 
static ctoon_mut_valctoon_mut_rawn (ctoon_mut_doc *doc, const char *str, size_t len)
 
static ctoon_mut_valctoon_mut_rawcpy (ctoon_mut_doc *doc, const char *str)
 
static ctoon_mut_valctoon_mut_rawncpy (ctoon_mut_doc *doc, const char *str, size_t len)
 
static ctoon_mut_valctoon_mut_null (ctoon_mut_doc *doc)
 
static ctoon_mut_valctoon_mut_true (ctoon_mut_doc *doc)
 
static ctoon_mut_valctoon_mut_false (ctoon_mut_doc *doc)
 
static ctoon_mut_valctoon_mut_bool (ctoon_mut_doc *doc, unsigned char val)
 
static ctoon_mut_valctoon_mut_uint (ctoon_mut_doc *doc, uint64_t num)
 
static ctoon_mut_valctoon_mut_sint (ctoon_mut_doc *doc, int64_t num)
 
static ctoon_mut_valctoon_mut_int (ctoon_mut_doc *doc, int64_t num)
 
static ctoon_mut_valctoon_mut_float (ctoon_mut_doc *doc, float num)
 
static ctoon_mut_valctoon_mut_double (ctoon_mut_doc *doc, double num)
 
static ctoon_mut_valctoon_mut_real (ctoon_mut_doc *doc, double num)
 
static ctoon_mut_valctoon_mut_str (ctoon_mut_doc *doc, const char *str)
 
static ctoon_mut_valctoon_mut_strn (ctoon_mut_doc *doc, const char *str, size_t len)
 
static ctoon_mut_valctoon_mut_strcpy (ctoon_mut_doc *doc, const char *str)
 
static ctoon_mut_valctoon_mut_strncpy (ctoon_mut_doc *doc, const char *str, size_t len)
 
static size_t ctoon_mut_arr_size (ctoon_mut_val *arr)
 
static ctoon_mut_valctoon_mut_arr_get (ctoon_mut_val *arr, size_t idx)
 
static ctoon_mut_valctoon_mut_arr_get_first (ctoon_mut_val *arr)
 
static ctoon_mut_valctoon_mut_arr_get_last (ctoon_mut_val *arr)
 
static unsigned char ctoon_mut_arr_iter_init (ctoon_mut_val *arr, ctoon_mut_arr_iter *iter)
 
static ctoon_mut_arr_iter ctoon_mut_arr_iter_with (ctoon_mut_val *arr)
 
static unsigned char ctoon_mut_arr_iter_has_next (ctoon_mut_arr_iter *iter)
 
static ctoon_mut_valctoon_mut_arr_iter_next (ctoon_mut_arr_iter *iter)
 
static ctoon_mut_valctoon_mut_arr_iter_remove (ctoon_mut_arr_iter *iter)
 
static ctoon_mut_valctoon_mut_arr (ctoon_mut_doc *doc)
 
static ctoon_mut_valctoon_mut_arr_with_bool (ctoon_mut_doc *doc, const unsigned char *vals, size_t count)
 
static ctoon_mut_valctoon_mut_arr_with_sint (ctoon_mut_doc *doc, const int64_t *vals, size_t count)
 
static ctoon_mut_valctoon_mut_arr_with_uint (ctoon_mut_doc *doc, const uint64_t *vals, size_t count)
 
static ctoon_mut_valctoon_mut_arr_with_real (ctoon_mut_doc *doc, const double *vals, size_t count)
 
static ctoon_mut_valctoon_mut_arr_with_sint8 (ctoon_mut_doc *doc, const int8_t *vals, size_t count)
 
static ctoon_mut_valctoon_mut_arr_with_sint16 (ctoon_mut_doc *doc, const int16_t *vals, size_t count)
 
static ctoon_mut_valctoon_mut_arr_with_sint32 (ctoon_mut_doc *doc, const int32_t *vals, size_t count)
 
static ctoon_mut_valctoon_mut_arr_with_sint64 (ctoon_mut_doc *doc, const int64_t *vals, size_t count)
 
static ctoon_mut_valctoon_mut_arr_with_uint8 (ctoon_mut_doc *doc, const uint8_t *vals, size_t count)
 
static ctoon_mut_valctoon_mut_arr_with_uint16 (ctoon_mut_doc *doc, const uint16_t *vals, size_t count)
 
static ctoon_mut_valctoon_mut_arr_with_uint32 (ctoon_mut_doc *doc, const uint32_t *vals, size_t count)
 
static ctoon_mut_valctoon_mut_arr_with_uint64 (ctoon_mut_doc *doc, const uint64_t *vals, size_t count)
 
static ctoon_mut_valctoon_mut_arr_with_float (ctoon_mut_doc *doc, const float *vals, size_t count)
 
static ctoon_mut_valctoon_mut_arr_with_double (ctoon_mut_doc *doc, const double *vals, size_t count)
 
static ctoon_mut_valctoon_mut_arr_with_str (ctoon_mut_doc *doc, const char **vals, size_t count)
 
static ctoon_mut_valctoon_mut_arr_with_strn (ctoon_mut_doc *doc, const char **vals, const size_t *lens, size_t count)
 
static ctoon_mut_valctoon_mut_arr_with_strcpy (ctoon_mut_doc *doc, const char **vals, size_t count)
 
static ctoon_mut_valctoon_mut_arr_with_strncpy (ctoon_mut_doc *doc, const char **vals, const size_t *lens, size_t count)
 
static unsigned char ctoon_mut_arr_insert (ctoon_mut_val *arr, ctoon_mut_val *val, size_t idx)
 
static unsigned char ctoon_mut_arr_append (ctoon_mut_val *arr, ctoon_mut_val *val)
 
static unsigned char ctoon_mut_arr_prepend (ctoon_mut_val *arr, ctoon_mut_val *val)
 
static ctoon_mut_valctoon_mut_arr_replace (ctoon_mut_val *arr, size_t idx, ctoon_mut_val *val)
 
static ctoon_mut_valctoon_mut_arr_remove (ctoon_mut_val *arr, size_t idx)
 
static ctoon_mut_valctoon_mut_arr_remove_first (ctoon_mut_val *arr)
 
static ctoon_mut_valctoon_mut_arr_remove_last (ctoon_mut_val *arr)
 
static unsigned char ctoon_mut_arr_remove_range (ctoon_mut_val *arr, size_t idx, size_t len)
 
static unsigned char ctoon_mut_arr_clear (ctoon_mut_val *arr)
 
static unsigned char ctoon_mut_arr_rotate (ctoon_mut_val *arr, size_t idx)
 
static unsigned char ctoon_mut_arr_add_val (ctoon_mut_val *arr, ctoon_mut_val *val)
 
static unsigned char ctoon_mut_arr_add_null (ctoon_mut_doc *doc, ctoon_mut_val *arr)
 
static unsigned char ctoon_mut_arr_add_true (ctoon_mut_doc *doc, ctoon_mut_val *arr)
 
static unsigned char ctoon_mut_arr_add_false (ctoon_mut_doc *doc, ctoon_mut_val *arr)
 
static unsigned char ctoon_mut_arr_add_bool (ctoon_mut_doc *doc, ctoon_mut_val *arr, unsigned char val)
 
static unsigned char ctoon_mut_arr_add_uint (ctoon_mut_doc *doc, ctoon_mut_val *arr, uint64_t num)
 
static unsigned char ctoon_mut_arr_add_sint (ctoon_mut_doc *doc, ctoon_mut_val *arr, int64_t num)
 
static unsigned char ctoon_mut_arr_add_int (ctoon_mut_doc *doc, ctoon_mut_val *arr, int64_t num)
 
static unsigned char ctoon_mut_arr_add_float (ctoon_mut_doc *doc, ctoon_mut_val *arr, float num)
 
static unsigned char ctoon_mut_arr_add_double (ctoon_mut_doc *doc, ctoon_mut_val *arr, double num)
 
static unsigned char ctoon_mut_arr_add_real (ctoon_mut_doc *doc, ctoon_mut_val *arr, double num)
 
static unsigned char ctoon_mut_arr_add_str (ctoon_mut_doc *doc, ctoon_mut_val *arr, const char *str)
 
static unsigned char ctoon_mut_arr_add_strn (ctoon_mut_doc *doc, ctoon_mut_val *arr, const char *str, size_t len)
 
static unsigned char ctoon_mut_arr_add_strcpy (ctoon_mut_doc *doc, ctoon_mut_val *arr, const char *str)
 
static unsigned char ctoon_mut_arr_add_strncpy (ctoon_mut_doc *doc, ctoon_mut_val *arr, const char *str, size_t len)
 
static ctoon_mut_valctoon_mut_arr_add_arr (ctoon_mut_doc *doc, ctoon_mut_val *arr)
 
static ctoon_mut_valctoon_mut_arr_add_obj (ctoon_mut_doc *doc, ctoon_mut_val *arr)
 
static size_t ctoon_mut_obj_size (ctoon_mut_val *obj)
 
static ctoon_mut_valctoon_mut_obj_get (ctoon_mut_val *obj, const char *key)
 
static ctoon_mut_valctoon_mut_obj_getn (ctoon_mut_val *obj, const char *key, size_t key_len)
 
static unsigned char ctoon_mut_obj_iter_init (ctoon_mut_val *obj, ctoon_mut_obj_iter *iter)
 
static ctoon_mut_obj_iter ctoon_mut_obj_iter_with (ctoon_mut_val *obj)
 
static unsigned char ctoon_mut_obj_iter_has_next (ctoon_mut_obj_iter *iter)
 
static ctoon_mut_valctoon_mut_obj_iter_next (ctoon_mut_obj_iter *iter)
 
static ctoon_mut_valctoon_mut_obj_iter_get_val (ctoon_mut_val *key)
 
static ctoon_mut_valctoon_mut_obj_iter_remove (ctoon_mut_obj_iter *iter)
 
static ctoon_mut_valctoon_mut_obj_iter_get (ctoon_mut_obj_iter *iter, const char *key)
 
static ctoon_mut_valctoon_mut_obj_iter_getn (ctoon_mut_obj_iter *iter, const char *key, size_t key_len)
 
static ctoon_mut_valctoon_mut_obj (ctoon_mut_doc *doc)
 
static ctoon_mut_valctoon_mut_obj_with_str (ctoon_mut_doc *doc, const char **keys, const char **vals, size_t count)
 
static ctoon_mut_valctoon_mut_obj_with_kv (ctoon_mut_doc *doc, const char **kv_pairs, size_t pair_count)
 
static unsigned char ctoon_mut_obj_add (ctoon_mut_val *obj, ctoon_mut_val *key, ctoon_mut_val *val)
 
static unsigned char ctoon_mut_obj_put (ctoon_mut_val *obj, ctoon_mut_val *key, ctoon_mut_val *val)
 
static unsigned char ctoon_mut_obj_insert (ctoon_mut_val *obj, ctoon_mut_val *key, ctoon_mut_val *val, size_t idx)
 
static ctoon_mut_valctoon_mut_obj_remove (ctoon_mut_val *obj, ctoon_mut_val *key)
 
static ctoon_mut_valctoon_mut_obj_remove_key (ctoon_mut_val *obj, const char *key)
 
static ctoon_mut_valctoon_mut_obj_remove_keyn (ctoon_mut_val *obj, const char *key, size_t key_len)
 
static unsigned char ctoon_mut_obj_clear (ctoon_mut_val *obj)
 
static unsigned char ctoon_mut_obj_replace (ctoon_mut_val *obj, ctoon_mut_val *key, ctoon_mut_val *val)
 
static unsigned char ctoon_mut_obj_rotate (ctoon_mut_val *obj, size_t idx)
 
static unsigned char ctoon_mut_obj_add_null (ctoon_mut_doc *doc, ctoon_mut_val *obj, const char *key)
 
static unsigned char ctoon_mut_obj_add_true (ctoon_mut_doc *doc, ctoon_mut_val *obj, const char *key)
 
static unsigned char ctoon_mut_obj_add_false (ctoon_mut_doc *doc, ctoon_mut_val *obj, const char *key)
 
static unsigned char ctoon_mut_obj_add_bool (ctoon_mut_doc *doc, ctoon_mut_val *obj, const char *key, unsigned char val)
 
static unsigned char ctoon_mut_obj_add_uint (ctoon_mut_doc *doc, ctoon_mut_val *obj, const char *key, uint64_t val)
 
static unsigned char ctoon_mut_obj_add_sint (ctoon_mut_doc *doc, ctoon_mut_val *obj, const char *key, int64_t val)
 
static unsigned char ctoon_mut_obj_add_int (ctoon_mut_doc *doc, ctoon_mut_val *obj, const char *key, int64_t val)
 
static unsigned char ctoon_mut_obj_add_float (ctoon_mut_doc *doc, ctoon_mut_val *obj, const char *key, float val)
 
static unsigned char ctoon_mut_obj_add_double (ctoon_mut_doc *doc, ctoon_mut_val *obj, const char *key, double val)
 
static unsigned char ctoon_mut_obj_add_real (ctoon_mut_doc *doc, ctoon_mut_val *obj, const char *key, double val)
 
static unsigned char ctoon_mut_obj_add_str (ctoon_mut_doc *doc, ctoon_mut_val *obj, const char *key, const char *val)
 
static unsigned char ctoon_mut_obj_add_strn (ctoon_mut_doc *doc, ctoon_mut_val *obj, const char *key, const char *val, size_t len)
 
static unsigned char ctoon_mut_obj_add_strcpy (ctoon_mut_doc *doc, ctoon_mut_val *obj, const char *key, const char *val)
 
static unsigned char ctoon_mut_obj_add_strncpy (ctoon_mut_doc *doc, ctoon_mut_val *obj, const char *key, const char *val, size_t len)
 
static ctoon_mut_valctoon_mut_obj_add_arr (ctoon_mut_doc *doc, ctoon_mut_val *obj, const char *key)
 
static ctoon_mut_valctoon_mut_obj_add_obj (ctoon_mut_doc *doc, ctoon_mut_val *obj, const char *key)
 
static unsigned char ctoon_mut_obj_add_val (ctoon_mut_doc *doc, ctoon_mut_val *obj, const char *key, ctoon_mut_val *val)
 
static ctoon_mut_valctoon_mut_obj_remove_str (ctoon_mut_val *obj, const char *key)
 
static ctoon_mut_valctoon_mut_obj_remove_strn (ctoon_mut_val *obj, const char *key, size_t len)
 
static unsigned char ctoon_mut_obj_rename_key (ctoon_mut_doc *doc, ctoon_mut_val *obj, const char *key, const char *new_key)
 
static unsigned char ctoon_mut_obj_rename_keyn (ctoon_mut_doc *doc, ctoon_mut_val *obj, const char *key, size_t len, const char *new_key, size_t new_len)
 
static ctoon_valctoon_doc_ptr_get (ctoon_doc *doc, const char *ptr)
 
static ctoon_valctoon_doc_ptr_getn (ctoon_doc *doc, const char *ptr, size_t len)
 
static ctoon_valctoon_doc_ptr_getx (ctoon_doc *doc, const char *ptr, size_t len, ctoon_ptr_err *err)
 
static ctoon_valctoon_ptr_get (ctoon_val *val, const char *ptr)
 
static ctoon_valctoon_ptr_getn (ctoon_val *val, const char *ptr, size_t len)
 
static ctoon_valctoon_ptr_getx (ctoon_val *val, const char *ptr, size_t len, ctoon_ptr_err *err)
 
static ctoon_mut_valctoon_mut_doc_ptr_get (ctoon_mut_doc *doc, const char *ptr)
 
static ctoon_mut_valctoon_mut_doc_ptr_getn (ctoon_mut_doc *doc, const char *ptr, size_t len)
 
static ctoon_mut_valctoon_mut_doc_ptr_getx (ctoon_mut_doc *doc, const char *ptr, size_t len, ctoon_ptr_ctx *ctx, ctoon_ptr_err *err)
 
static ctoon_mut_valctoon_mut_ptr_get (ctoon_mut_val *val, const char *ptr)
 
static ctoon_mut_valctoon_mut_ptr_getn (ctoon_mut_val *val, const char *ptr, size_t len)
 
static ctoon_mut_valctoon_mut_ptr_getx (ctoon_mut_val *val, const char *ptr, size_t len, ctoon_ptr_ctx *ctx, ctoon_ptr_err *err)
 
static unsigned char ctoon_mut_doc_ptr_add (ctoon_mut_doc *doc, const char *ptr, ctoon_mut_val *new_val)
 
static unsigned char ctoon_mut_doc_ptr_addn (ctoon_mut_doc *doc, const char *ptr, size_t len, ctoon_mut_val *new_val)
 
static unsigned char ctoon_mut_doc_ptr_addx (ctoon_mut_doc *doc, const char *ptr, size_t len, ctoon_mut_val *new_val, unsigned char create_parent, ctoon_ptr_ctx *ctx, ctoon_ptr_err *err)
 
static unsigned char ctoon_mut_ptr_add (ctoon_mut_val *val, const char *ptr, ctoon_mut_val *new_val, ctoon_mut_doc *doc)
 
static unsigned char ctoon_mut_ptr_addn (ctoon_mut_val *val, const char *ptr, size_t len, ctoon_mut_val *new_val, ctoon_mut_doc *doc)
 
static unsigned char ctoon_mut_ptr_addx (ctoon_mut_val *val, const char *ptr, size_t len, ctoon_mut_val *new_val, ctoon_mut_doc *doc, unsigned char create_parent, ctoon_ptr_ctx *ctx, ctoon_ptr_err *err)
 
static unsigned char ctoon_mut_doc_ptr_set (ctoon_mut_doc *doc, const char *ptr, ctoon_mut_val *new_val)
 
static unsigned char ctoon_mut_doc_ptr_setn (ctoon_mut_doc *doc, const char *ptr, size_t len, ctoon_mut_val *new_val)
 
static unsigned char ctoon_mut_doc_ptr_setx (ctoon_mut_doc *doc, const char *ptr, size_t len, ctoon_mut_val *new_val, unsigned char create_parent, ctoon_ptr_ctx *ctx, ctoon_ptr_err *err)
 
static unsigned char ctoon_mut_ptr_set (ctoon_mut_val *val, const char *ptr, ctoon_mut_val *new_val, ctoon_mut_doc *doc)
 
static unsigned char ctoon_mut_ptr_setn (ctoon_mut_val *val, const char *ptr, size_t len, ctoon_mut_val *new_val, ctoon_mut_doc *doc)
 
static unsigned char ctoon_mut_ptr_setx (ctoon_mut_val *val, const char *ptr, size_t len, ctoon_mut_val *new_val, ctoon_mut_doc *doc, unsigned char create_parent, ctoon_ptr_ctx *ctx, ctoon_ptr_err *err)
 
static ctoon_mut_valctoon_mut_doc_ptr_replace (ctoon_mut_doc *doc, const char *ptr, ctoon_mut_val *new_val)
 
static ctoon_mut_valctoon_mut_doc_ptr_replacen (ctoon_mut_doc *doc, const char *ptr, size_t len, ctoon_mut_val *new_val)
 
static ctoon_mut_valctoon_mut_doc_ptr_replacex (ctoon_mut_doc *doc, const char *ptr, size_t len, ctoon_mut_val *new_val, ctoon_ptr_ctx *ctx, ctoon_ptr_err *err)
 
static ctoon_mut_valctoon_mut_ptr_replace (ctoon_mut_val *val, const char *ptr, ctoon_mut_val *new_val)
 
static ctoon_mut_valctoon_mut_ptr_replacen (ctoon_mut_val *val, const char *ptr, size_t len, ctoon_mut_val *new_val)
 
static ctoon_mut_valctoon_mut_ptr_replacex (ctoon_mut_val *val, const char *ptr, size_t len, ctoon_mut_val *new_val, ctoon_ptr_ctx *ctx, ctoon_ptr_err *err)
 
static ctoon_mut_valctoon_mut_doc_ptr_remove (ctoon_mut_doc *doc, const char *ptr)
 
static ctoon_mut_valctoon_mut_doc_ptr_removen (ctoon_mut_doc *doc, const char *ptr, size_t len)
 
static ctoon_mut_valctoon_mut_doc_ptr_removex (ctoon_mut_doc *doc, const char *ptr, size_t len, ctoon_ptr_ctx *ctx, ctoon_ptr_err *err)
 
static ctoon_mut_valctoon_mut_ptr_remove (ctoon_mut_val *val, const char *ptr)
 
static ctoon_mut_valctoon_mut_ptr_removen (ctoon_mut_val *val, const char *ptr, size_t len)
 
static ctoon_mut_valctoon_mut_ptr_removex (ctoon_mut_val *val, const char *ptr, size_t len, ctoon_ptr_ctx *ctx, ctoon_ptr_err *err)
 
static unsigned char ctoon_ptr_ctx_append (ctoon_ptr_ctx *ctx, ctoon_mut_val *key, ctoon_mut_val *val)
 
static unsigned char ctoon_ptr_ctx_replace (ctoon_ptr_ctx *ctx, ctoon_mut_val *val)
 
static unsigned char ctoon_ptr_ctx_remove (ctoon_ptr_ctx *ctx)
 
ctoon_mut_valctoon_patch (ctoon_mut_doc *doc, ctoon_val *orig, ctoon_val *patch, ctoon_patch_err *err)
 
ctoon_mut_valctoon_mut_patch (ctoon_mut_doc *doc, ctoon_mut_val *orig, ctoon_mut_val *patch, ctoon_patch_err *err)
 
ctoon_mut_valctoon_merge_patch (ctoon_mut_doc *doc, ctoon_val *orig, ctoon_val *patch)
 
ctoon_mut_valctoon_mut_merge_patch (ctoon_mut_doc *doc, ctoon_mut_val *orig, ctoon_mut_val *patch)
 
static unsigned char unsafe_ctoon_is_str_noesc (const char *str, size_t len)
 
static double unsafe_ctoon_u64_to_f64 (uint64_t num)
 
static ctoon_type unsafe_ctoon_get_type (void *val)
 
static ctoon_subtype unsafe_ctoon_get_subtype (void *val)
 
static uint8_t unsafe_ctoon_get_tag (void *val)
 
static unsigned char unsafe_ctoon_is_raw (void *val)
 
static unsigned char unsafe_ctoon_is_null (void *val)
 
static unsigned char unsafe_ctoon_is_bool (void *val)
 
static unsigned char unsafe_ctoon_is_num (void *val)
 
static unsigned char unsafe_ctoon_is_str (void *val)
 
static unsigned char unsafe_ctoon_is_arr (void *val)
 
static unsigned char unsafe_ctoon_is_obj (void *val)
 
static unsigned char unsafe_ctoon_is_ctn (void *val)
 
static unsigned char unsafe_ctoon_is_uint (void *val)
 
static unsigned char unsafe_ctoon_is_sint (void *val)
 
static unsigned char unsafe_ctoon_is_int (void *val)
 
static unsigned char unsafe_ctoon_is_real (void *val)
 
static unsigned char unsafe_ctoon_is_true (void *val)
 
static unsigned char unsafe_ctoon_is_false (void *val)
 
static unsigned char unsafe_ctoon_arr_is_flat (ctoon_val *val)
 
static const char * unsafe_ctoon_get_raw (void *val)
 
static unsigned char unsafe_ctoon_get_bool (void *val)
 
static uint64_t unsafe_ctoon_get_uint (void *val)
 
static int64_t unsafe_ctoon_get_sint (void *val)
 
static int unsafe_ctoon_get_int (void *val)
 
static double unsafe_ctoon_get_real (void *val)
 
static double unsafe_ctoon_get_num (void *val)
 
static const char * unsafe_ctoon_get_str (void *val)
 
static size_t unsafe_ctoon_get_len (void *val)
 
static ctoon_valunsafe_ctoon_get_first (ctoon_val *ctn)
 
static ctoon_valunsafe_ctoon_get_next (ctoon_val *val)
 
static unsigned char unsafe_ctoon_equals_strn (void *val, const char *str, size_t len)
 
static unsigned char unsafe_ctoon_equals_str (void *val, const char *str)
 
static void unsafe_ctoon_set_type (void *val, ctoon_type type, ctoon_subtype subtype)
 
static void unsafe_ctoon_set_len (void *val, size_t len)
 
static void unsafe_ctoon_set_tag (void *val, ctoon_type type, ctoon_subtype subtype, size_t len)
 
static void unsafe_ctoon_inc_len (void *val)
 
static void unsafe_ctoon_set_raw (void *val, const char *raw, size_t len)
 
static void unsafe_ctoon_set_null (void *val)
 
static void unsafe_ctoon_set_bool (void *val, unsigned char num)
 
static void unsafe_ctoon_set_uint (void *val, uint64_t num)
 
static void unsafe_ctoon_set_sint (void *val, int64_t num)
 
static void unsafe_ctoon_set_fp_to_fixed (void *val, int prec)
 
static void unsafe_ctoon_set_fp_to_float (void *val, unsigned char flt)
 
static void unsafe_ctoon_set_float (void *val, float num)
 
static void unsafe_ctoon_set_double (void *val, double num)
 
static void unsafe_ctoon_set_real (void *val, double num)
 
static void unsafe_ctoon_set_str_noesc (void *val, unsigned char noesc)
 
static void unsafe_ctoon_set_strn (void *val, const char *str, size_t len)
 
static void unsafe_ctoon_set_str (void *val, const char *str)
 
static void unsafe_ctoon_set_arr (void *val, size_t size)
 
static void unsafe_ctoon_set_obj (void *val, size_t size)
 
unsigned char unsafe_ctoon_equals (ctoon_val *lhs, ctoon_val *rhs)
 
unsigned char unsafe_ctoon_str_pool_grow (ctoon_str_pool *pool, const ctoon_alc *alc, size_t len)
 
unsigned char unsafe_ctoon_val_pool_grow (ctoon_val_pool *pool, const ctoon_alc *alc, size_t count)
 
static char * unsafe_ctoon_mut_str_alc (ctoon_mut_doc *doc, size_t len)
 
static char * unsafe_ctoon_mut_strncpy (ctoon_mut_doc *doc, const char *str, size_t len)
 
static ctoon_mut_valunsafe_ctoon_mut_val (ctoon_mut_doc *doc, size_t count)
 
unsigned char unsafe_ctoon_mut_equals (ctoon_mut_val *lhs, ctoon_mut_val *rhs)
 
static void unsafe_ctoon_mut_obj_add (ctoon_mut_val *obj, ctoon_mut_val *key, ctoon_mut_val *val, size_t len)
 
static ctoon_mut_valunsafe_ctoon_mut_obj_remove (ctoon_mut_val *obj, const char *key, size_t key_len)
 
static unsigned char unsafe_ctoon_mut_obj_replace (ctoon_mut_val *obj, ctoon_mut_val *key, ctoon_mut_val *val)
 
static void unsafe_ctoon_mut_obj_rotate (ctoon_mut_val *obj, size_t idx)
 
ctoon_valunsafe_ctoon_ptr_getx (ctoon_val *val, const char *ptr, size_t len, ctoon_ptr_err *err)
 
ctoon_mut_valunsafe_ctoon_mut_ptr_getx (ctoon_mut_val *val, const char *ptr, size_t len, ctoon_ptr_ctx *ctx, ctoon_ptr_err *err)
 
unsigned char unsafe_ctoon_mut_ptr_putx (ctoon_mut_val *val, const char *ptr, size_t len, ctoon_mut_val *new_val, ctoon_mut_doc *doc, unsigned char create_parent, unsigned char insert_new, ctoon_ptr_ctx *ctx, ctoon_ptr_err *err)
 
ctoon_mut_valunsafe_ctoon_mut_ptr_replacex (ctoon_mut_val *val, const char *ptr, size_t len, ctoon_mut_val *new_val, ctoon_ptr_ctx *ctx, ctoon_ptr_err *err)
 
ctoon_mut_valunsafe_ctoon_mut_ptr_removex (ctoon_mut_val *val, const char *ptr, size_t len, ctoon_ptr_ctx *ctx, ctoon_ptr_err *err)
 
static unsigned char ctoon_ptr_get_bool (ctoon_val *root, const char *ptr, unsigned char *value)
 
static unsigned char ctoon_ptr_get_uint (ctoon_val *root, const char *ptr, uint64_t *value)
 
static unsigned char ctoon_ptr_get_sint (ctoon_val *root, const char *ptr, int64_t *value)
 
static unsigned char ctoon_ptr_get_real (ctoon_val *root, const char *ptr, double *value)
 
static unsigned char ctoon_ptr_get_num (ctoon_val *root, const char *ptr, double *value)
 
static unsigned char ctoon_ptr_get_str (ctoon_val *root, const char *ptr, const char **value)
 
static ctoon_valctoon_doc_get_pointer (ctoon_doc *doc, const char *ptr)
 
static ctoon_valctoon_doc_get_pointern (ctoon_doc *doc, const char *ptr, size_t len)
 
static ctoon_mut_valctoon_mut_doc_get_pointer (ctoon_mut_doc *doc, const char *ptr)
 
static ctoon_mut_valctoon_mut_doc_get_pointern (ctoon_mut_doc *doc, const char *ptr, size_t len)
 
static ctoon_valctoon_get_pointer (ctoon_val *val, const char *ptr)
 
static ctoon_valctoon_get_pointern (ctoon_val *val, const char *ptr, size_t len)
 
static ctoon_mut_valctoon_mut_get_pointer (ctoon_mut_val *val, const char *ptr)
 
static ctoon_mut_valctoon_mut_get_pointern (ctoon_mut_val *val, const char *ptr, size_t len)
 
static ctoon_valunsafe_ctoon_get_pointer (ctoon_val *val, const char *ptr, size_t len)
 
static ctoon_mut_valunsafe_ctoon_mut_get_pointer (ctoon_mut_val *val, const char *ptr, size_t len)
 

Variables

static const ctoon_read_flag CTOON_READ_NOFLAG = 0
 
static const ctoon_read_flag CTOON_READ_INSITU = 1 << 0
 
static const ctoon_read_flag CTOON_READ_STOP_WHEN_DONE = 1 << 1
 
static const ctoon_read_flag CTOON_READ_ALLOW_TRAILING_COMMAS = 1 << 2
 
static const ctoon_read_flag CTOON_READ_ALLOW_COMMENTS = 1 << 3
 
static const ctoon_read_flag CTOON_READ_ALLOW_INF_AND_NAN = 1 << 4
 
static const ctoon_read_flag CTOON_READ_NUMBER_AS_RAW = 1 << 5
 
static const ctoon_read_flag CTOON_READ_ALLOW_INVALID_UNICODE = 1 << 6
 
static const ctoon_read_flag CTOON_READ_BIGNUM_AS_RAW = 1 << 7
 
static const ctoon_read_flag CTOON_READ_ALLOW_BOM = 1 << 8
 
static const ctoon_read_flag CTOON_READ_ALLOW_EXT_NUMBER = 1 << 9
 
static const ctoon_read_flag CTOON_READ_ALLOW_EXT_ESCAPE = 1 << 10
 
static const ctoon_read_flag CTOON_READ_ALLOW_EXT_WHITESPACE = 1 << 11
 
static const ctoon_read_flag CTOON_READ_ALLOW_SINGLE_QUOTED_STR = 1 << 12
 
static const ctoon_read_flag CTOON_READ_ALLOW_UNQUOTED_KEY = 1 << 13
 
static const ctoon_read_flag CTOON_READ_TOON5
 
static const ctoon_read_code CTOON_READ_SUCCESS = 0
 
static const ctoon_read_code CTOON_READ_ERROR_INVALID_PARAMETER = 1
 
static const ctoon_read_code CTOON_READ_ERROR_MEMORY_ALLOCATION = 2
 
static const ctoon_read_code CTOON_READ_ERROR_EMPTY_CONTENT = 3
 
static const ctoon_read_code CTOON_READ_ERROR_UNEXPECTED_CONTENT = 4
 
static const ctoon_read_code CTOON_READ_ERROR_UNEXPECTED_END = 5
 
static const ctoon_read_code CTOON_READ_ERROR_UNEXPECTED_CHARACTER = 6
 
static const ctoon_read_code CTOON_READ_ERROR_TOON_STRUCTURE = 7
 
static const ctoon_read_code CTOON_READ_ERROR_INVALID_COMMENT = 8
 
static const ctoon_read_code CTOON_READ_ERROR_INVALID_NUMBER = 9
 
static const ctoon_read_code CTOON_READ_ERROR_INVALID_STRING = 10
 
static const ctoon_read_code CTOON_READ_ERROR_LITERAL = 11
 
static const ctoon_read_code CTOON_READ_ERROR_FILE_OPEN = 12
 
static const ctoon_read_code CTOON_READ_ERROR_FILE_READ = 13
 
static const ctoon_read_code CTOON_READ_ERROR_MORE = 14
 
static const ctoon_read_code CTOON_READ_ERROR_DEPTH = 15
 
static const ctoon_write_flag CTOON_WRITE_NOFLAG = 0
 
static const ctoon_write_flag CTOON_WRITE_ESCAPE_UNICODE = 1 << 1
 
static const ctoon_write_flag CTOON_WRITE_ESCAPE_SLASHES = 1 << 2
 
static const ctoon_write_flag CTOON_WRITE_ALLOW_INF_AND_NAN = 1 << 3
 
static const ctoon_write_flag CTOON_WRITE_INF_AND_NAN_AS_NULL = 1 << 4
 
static const ctoon_write_flag CTOON_WRITE_ALLOW_INVALID_UNICODE = 1 << 5
 
static const ctoon_write_flag CTOON_WRITE_LENGTH_MARKER = 1 << 6
 
static const ctoon_write_flag CTOON_WRITE_NEWLINE_AT_END = 1 << 7
 
static const ctoon_write_code CTOON_WRITE_SUCCESS = 0
 
static const ctoon_write_code CTOON_WRITE_ERROR_INVALID_PARAMETER = 1
 
static const ctoon_write_code CTOON_WRITE_ERROR_MEMORY_ALLOCATION = 2
 
static const ctoon_write_code CTOON_WRITE_ERROR_INVALID_VALUE_TYPE = 3
 
static const ctoon_write_code CTOON_WRITE_ERROR_NAN_OR_INF = 4
 
static const ctoon_write_code CTOON_WRITE_ERROR_FILE_OPEN = 5
 
static const ctoon_write_code CTOON_WRITE_ERROR_FILE_WRITE = 6
 
static const ctoon_write_code CTOON_WRITE_ERROR_INVALID_STRING = 7
 
static const ctoon_ptr_code CTOON_PTR_ERR_NONE = 0
 
static const ctoon_ptr_code CTOON_PTR_ERR_PARAMETER = 1
 
static const ctoon_ptr_code CTOON_PTR_ERR_SYNTAX = 2
 
static const ctoon_ptr_code CTOON_PTR_ERR_RESOLVE = 3
 
static const ctoon_ptr_code CTOON_PTR_ERR_NULL_ROOT = 4
 
static const ctoon_ptr_code CTOON_PTR_ERR_SET_ROOT = 5
 
static const ctoon_ptr_code CTOON_PTR_ERR_MEMORY_ALLOCATION = 6
 
static const ctoon_patch_code CTOON_PATCH_SUCCESS = 0
 
static const ctoon_patch_code CTOON_PATCH_ERROR_INVALID_PARAMETER = 1
 
static const ctoon_patch_code CTOON_PATCH_ERROR_MEMORY_ALLOCATION = 2
 
static const ctoon_patch_code CTOON_PATCH_ERROR_INVALID_OPERATION = 3
 
static const ctoon_patch_code CTOON_PATCH_ERROR_MISSING_KEY = 4
 
static const ctoon_patch_code CTOON_PATCH_ERROR_INVALID_MEMBER = 5
 
static const ctoon_patch_code CTOON_PATCH_ERROR_EQUAL = 6
 
static const ctoon_patch_code CTOON_PATCH_ERROR_POINTER = 7
 

Detailed Description

Date
2025-11-04
Author
Mohammad Razeiei

Definition in file ctoon.h.

Macro Definition Documentation

◆ __bool_true_false_are_defined

#define __bool_true_false_are_defined   1

stdint (C89 compatible) stdbool (C89 compatible)

Definition at line 435 of file ctoon.h.

◆ _CTOON_VERSION_STR

#define _CTOON_VERSION_STR (   a,
  b,
 
)    _CTOON_VERSION_XSTR(a,b,c)

Definition at line 505 of file ctoon.h.

◆ _CTOON_VERSION_XSTR

#define _CTOON_VERSION_XSTR (   a,
  b,
 
)    #a"."#b"."#c

Definition at line 504 of file ctoon.h.

◆ bool

#define bool   unsigned char

Definition at line 446 of file ctoon.h.

◆ ctoon_align

#define ctoon_align (   x)

align for compiler

Definition at line 282 of file ctoon.h.

◆ ctoon_api

#define ctoon_api

function export

Definition at line 344 of file ctoon.h.

◆ ctoon_api_inline

#define ctoon_api_inline   static ctoon_inline

inline function export

Definition at line 350 of file ctoon.h.

◆ ctoon_arr_foreach

#define ctoon_arr_foreach (   arr,
  idx,
  max,
  val 
)
Value:
for ((idx) = 0, \
(max) = ctoon_arr_size(arr), \
(val) = ctoon_arr_get_first(arr); \
(idx) < (max); \
(idx)++, \
(val) = unsafe_ctoon_get_next(val))
static ctoon_val * unsafe_ctoon_get_next(ctoon_val *val)
Definition ctoon.h:4759
static size_t ctoon_arr_size(ctoon_val *arr)
Definition ctoon.h:5161
static ctoon_val * ctoon_arr_get_first(ctoon_val *arr)
Definition ctoon.h:5180

Macro for iterating over an array. It works like iterator, but with a more intuitive API.

Example

size_t idx, max;
ctoon_val *val;
ctoon_arr_foreach(arr, idx, max, val) {
your_func(idx, val);
}
#define ctoon_arr_foreach(arr, idx, max, val)
Definition ctoon.h:1817

Definition at line 1817 of file ctoon.h.

◆ ctoon_constant_p

#define ctoon_constant_p (   value)    0

Definition at line 313 of file ctoon.h.

◆ CTOON_CPP_VER

#define CTOON_CPP_VER   0

C++ version

Definition at line 206 of file ctoon.h.

◆ ctoon_deprecated

#define ctoon_deprecated (   msg)

deprecate warning

Definition at line 327 of file ctoon.h.

◆ ctoon_gcc_available

#define ctoon_gcc_available (   major,
  minor,
  patch 
)    0

Definition at line 182 of file ctoon.h.

◆ CTOON_GCC_VER

#define CTOON_GCC_VER   0

compiler version (GCC)

Definition at line 181 of file ctoon.h.

◆ ctoon_has_attribute

#define ctoon_has_attribute (   x)    0

compiler attribute check (since gcc 5.0, clang 2.9, icc 17)

Definition at line 223 of file ctoon.h.

◆ ctoon_has_builtin

#define ctoon_has_builtin (   x)    0

compiler builtin check (since gcc 10.0, clang 2.6, icc 2021)

Definition at line 214 of file ctoon.h.

◆ CTOON_HAS_CONSTANT_P

#define CTOON_HAS_CONSTANT_P   0

compile-time constant check for compiler

Definition at line 312 of file ctoon.h.

◆ ctoon_has_feature

#define ctoon_has_feature (   x)    0

compiler feature check (since clang 2.6, icc 17)

Definition at line 232 of file ctoon.h.

◆ ctoon_has_include

#define ctoon_has_include (   x)    0

include check (since gcc 5.0, clang 2.7, icc 16, msvc 2017 15.3)

Definition at line 241 of file ctoon.h.

◆ ctoon_inline

#define ctoon_inline

inline for compiler

Definition at line 258 of file ctoon.h.

◆ CTOON_IS_REAL_GCC

#define CTOON_IS_REAL_GCC   0

real gcc check

Definition at line 192 of file ctoon.h.

◆ ctoon_likely

#define ctoon_likely (   expr)    (expr)

likely for compiler

Definition at line 292 of file ctoon.h.

◆ CTOON_MSC_VER

#define CTOON_MSC_VER   0

compiler version (MSVC)

Definition at line 165 of file ctoon.h.

◆ ctoon_mut_arr_foreach

#define ctoon_mut_arr_foreach (   arr,
  idx,
  max,
  val 
)
Value:
for ((idx) = 0, \
(max) = ctoon_mut_arr_size(arr), \
(val) = ctoon_mut_arr_get_first(arr); \
(idx) < (max); \
(idx)++, \
(val) = (val)->next)
static size_t ctoon_mut_arr_size(ctoon_mut_val *arr)
Definition ctoon.h:5869
static ctoon_mut_val * ctoon_mut_arr_get_first(ctoon_mut_val *arr)
Definition ctoon.h:5883

Macro for iterating over an array. It works like iterator, but with a more intuitive API.

Warning
You should not modify the array while iterating over it.

Example

size_t idx, max;
ctoon_mut_arr_foreach(arr, idx, max, val) {
your_func(idx, val);
}
#define ctoon_mut_arr_foreach(arr, idx, max, val)
Definition ctoon.h:2552

Definition at line 2552 of file ctoon.h.

◆ ctoon_mut_arr_with_func

#define ctoon_mut_arr_with_func (   func)
Value:
if (ctoon_likely(doc && ((0 < count && count < \
(~(size_t)0) / sizeof(ctoon_mut_val) && vals) || count == 0))) { \
ctoon_mut_val *arr = unsafe_ctoon_mut_val(doc, 1 + count); \
if (ctoon_likely(arr)) { \
arr->tag = ((uint64_t)count << CTOON_TAG_BIT) | CTOON_TYPE_ARR; \
if (count > 0) { \
size_t i; \
for (i = 0; i < count; i++) { \
ctoon_mut_val *val = arr + i + 1; \
func \
val->next = val + 1; \
} \
arr[count].next = arr + 1; \
arr->uni.ptr = arr + count; \
} \
return arr; \
} \
} \
return NULL
#define CTOON_TAG_BIT
Definition ctoon.h:571
#define CTOON_TYPE_ARR
Definition ctoon.h:535
#define ctoon_likely(expr)
Definition ctoon.h:292
static ctoon_mut_val * unsafe_ctoon_mut_val(ctoon_mut_doc *doc, size_t count)
Definition ctoon.h:5451
ctoon_mut_val * next
Definition ctoon.h:5364
uint64_t tag
Definition ctoon.h:5362
ctoon_val_uni uni
Definition ctoon.h:5363
void * ptr
Definition ctoon.h:4529

Definition at line 5976 of file ctoon.h.

◆ ctoon_mut_obj_add_func

#define ctoon_mut_obj_add_func (   func)
Value:
if (ctoon_likely(doc && ctoon_mut_is_obj(obj) && _key)) { \
if (ctoon_likely(key)) { \
size_t len = unsafe_ctoon_get_len(obj); \
ctoon_mut_val *val = key + 1; \
size_t key_len = strlen(_key); \
bool noesc = unsafe_ctoon_is_str_noesc(_key, key_len); \
key->tag = CTOON_TYPE_STR; \
key->tag |= (uint64_t)strlen(_key) << CTOON_TAG_BIT; \
key->uni.str = _key; \
func \
unsafe_ctoon_mut_obj_add(obj, key, val, len); \
return true; \
} \
} \
return false
static unsigned char ctoon_mut_is_obj(ctoon_mut_val *val)
Definition ctoon.h:5535
#define CTOON_SUBTYPE_NOESC
Definition ctoon.h:554
#define CTOON_SUBTYPE_NONE
Definition ctoon.h:542
static unsigned char unsafe_ctoon_is_str_noesc(const char *str, size_t len)
Definition ctoon.h:4575
#define CTOON_TYPE_STR
Definition ctoon.h:533
static size_t unsafe_ctoon_get_len(void *val)
Definition ctoon.h:4751
const char * str
Definition ctoon.h:4528

Definition at line 6914 of file ctoon.h.

◆ ctoon_mut_obj_foreach

#define ctoon_mut_obj_foreach (   obj,
  idx,
  max,
  key,
  val 
)
Value:
for ((idx) = 0, \
(max) = ctoon_mut_obj_size(obj), \
(key) = (max) ? ((ctoon_mut_val *)(obj)->uni.ptr)->next->next : NULL, \
(val) = (key) ? (key)->next : NULL; \
(idx) < (max); \
(idx)++, \
(key) = (val)->next, \
(val) = (key)->next)
static size_t ctoon_mut_obj_size(ctoon_mut_val *obj)
Definition ctoon.h:6521

Macro for iterating over an object. It works like iterator, but with a more intuitive API.

Warning
You should not modify the object while iterating over it.

Example

size_t idx, max;
ctoon_mut_val *key, *val;
ctoon_mut_obj_foreach(obj, idx, max, key, val) {
your_func(key, val);
}
#define ctoon_mut_obj_foreach(obj, idx, max, key, val)
Definition ctoon.h:3424

Definition at line 3424 of file ctoon.h.

◆ ctoon_mut_val_one

#define ctoon_mut_val_one (   func)
Value:
if (ctoon_likely(doc)) { \
if (ctoon_likely(val)) { \
func \
return val; \
} \
} \
return NULL

Definition at line 5728 of file ctoon.h.

◆ ctoon_mut_val_one_str

#define ctoon_mut_val_one_str (   func)
Value:
if (ctoon_likely(doc && str)) { \
if (ctoon_likely(val)) { \
func \
return val; \
} \
} \
return NULL

Definition at line 5738 of file ctoon.h.

◆ ctoon_noinline

#define ctoon_noinline

noinline for compiler

Definition at line 269 of file ctoon.h.

◆ ctoon_obj_foreach

#define ctoon_obj_foreach (   obj,
  idx,
  max,
  key,
  val 
)
Value:
for ((idx) = 0, \
(max) = ctoon_obj_size(obj), \
(key) = (obj) ? unsafe_ctoon_get_first(obj) : NULL, \
(val) = (key) + 1; \
(idx) < (max); \
(idx)++, \
(key) = unsafe_ctoon_get_next(val), \
(val) = (key) + 1)
static size_t ctoon_obj_size(ctoon_val *obj)
Definition ctoon.h:5250
static ctoon_val * unsafe_ctoon_get_first(ctoon_val *ctn)
Definition ctoon.h:4755

Macro for iterating over an object. It works like iterator, but with a more intuitive API.

Example

size_t idx, max;
ctoon_val *key, *val;
ctoon_obj_foreach(obj, idx, max, key, val) {
your_func(key, val);
}
#define ctoon_obj_foreach(obj, idx, max, key, val)
Definition ctoon.h:1988

Definition at line 1988 of file ctoon.h.

◆ CTOON_PADDING_SIZE

#define CTOON_PADDING_SIZE   4

Padding size for TOON reader.

Definition at line 574 of file ctoon.h.

◆ ctoon_ptr_set_err

#define ctoon_ptr_set_err (   _code,
  _msg 
)
Value:
do { \
if (err) { \
err->code = CTOON_PTR_ERR_##_code; \
err->msg = _msg; \
err->pos = 0; \
} \
} while(false)

Definition at line 7141 of file ctoon.h.

◆ CTOON_RESERVED_BIT

#define CTOON_RESERVED_BIT   ((uint8_t)3)

The number of reserved bits.

Definition at line 567 of file ctoon.h.

◆ CTOON_RESERVED_MASK

#define CTOON_RESERVED_MASK   ((uint8_t)0xE0) /* 111_____ */

The mask used to extract the reserved bits of a TOON value.

Definition at line 565 of file ctoon.h.

◆ CTOON_STDC_VER

#define CTOON_STDC_VER   0

C version (STDC)

Definition at line 199 of file ctoon.h.

◆ CTOON_SUBTYPE_BIT

#define CTOON_SUBTYPE_BIT   ((uint8_t)2)

The number of bits used by the subtype.

Definition at line 563 of file ctoon.h.

◆ CTOON_SUBTYPE_FALSE

#define CTOON_SUBTYPE_FALSE   ((uint8_t)(0 << 3)) /* ___00___ */

False subtype: false literal.

Definition at line 544 of file ctoon.h.

◆ CTOON_SUBTYPE_MASK

#define CTOON_SUBTYPE_MASK   ((uint8_t)0x18) /* ___11___ */

The mask used to extract the subtype of a TOON value.

Definition at line 561 of file ctoon.h.

◆ CTOON_SUBTYPE_NOESC

#define CTOON_SUBTYPE_NOESC   ((uint8_t)(1 << 3)) /* ___01___ */

String that do not need to be escaped for writing (internal use).

Definition at line 554 of file ctoon.h.

◆ CTOON_SUBTYPE_NONE

#define CTOON_SUBTYPE_NONE   ((uint8_t)(0 << 3)) /* ___00___ */

No subtype.

Definition at line 542 of file ctoon.h.

◆ CTOON_SUBTYPE_REAL

#define CTOON_SUBTYPE_REAL   ((uint8_t)(2 << 3)) /* ___10___ */

Real number subtype: double.

Definition at line 552 of file ctoon.h.

◆ CTOON_SUBTYPE_SINT

#define CTOON_SUBTYPE_SINT   ((uint8_t)(1 << 3)) /* ___01___ */

Signed integer subtype: int64_t.

Definition at line 550 of file ctoon.h.

◆ CTOON_SUBTYPE_TRUE

#define CTOON_SUBTYPE_TRUE   ((uint8_t)(1 << 3)) /* ___01___ */

True subtype: true literal.

Definition at line 546 of file ctoon.h.

◆ CTOON_SUBTYPE_UINT

#define CTOON_SUBTYPE_UINT   ((uint8_t)(0 << 3)) /* ___00___ */

Unsigned integer subtype: uint64_t.

Definition at line 548 of file ctoon.h.

◆ CTOON_TAG_BIT

#define CTOON_TAG_BIT   ((uint8_t)8)

The number of bits used by the tag.

Definition at line 571 of file ctoon.h.

◆ CTOON_TAG_MASK

#define CTOON_TAG_MASK   ((uint8_t)0xFF) /* 11111111 */

The mask used to extract the tag of a TOON value.

Definition at line 569 of file ctoon.h.

◆ CTOON_TYPE_ARR

#define CTOON_TYPE_ARR   ((uint8_t)6) /* _____110 */

Array type, no subtype.

Definition at line 535 of file ctoon.h.

◆ CTOON_TYPE_BIT

#define CTOON_TYPE_BIT   ((uint8_t)3)

The number of bits used by the type.

Definition at line 559 of file ctoon.h.

◆ CTOON_TYPE_BOOL

#define CTOON_TYPE_BOOL   ((uint8_t)3) /* _____011 */

Boolean type, subtype: TRUE, FALSE.

Definition at line 529 of file ctoon.h.

◆ CTOON_TYPE_MASK

#define CTOON_TYPE_MASK   ((uint8_t)0x07) /* _____111 */

The mask used to extract the type of a TOON value.

Definition at line 557 of file ctoon.h.

◆ CTOON_TYPE_NONE

#define CTOON_TYPE_NONE   ((uint8_t)0) /* _____000 */

No type, invalid.

Definition at line 523 of file ctoon.h.

◆ CTOON_TYPE_NULL

#define CTOON_TYPE_NULL   ((uint8_t)2) /* _____010 */

Null type: null literal, no subtype.

Definition at line 527 of file ctoon.h.

◆ CTOON_TYPE_NUM

#define CTOON_TYPE_NUM   ((uint8_t)4) /* _____100 */

Number type, subtype: UINT, SINT, REAL.

Definition at line 531 of file ctoon.h.

◆ CTOON_TYPE_OBJ

#define CTOON_TYPE_OBJ   ((uint8_t)7) /* _____111 */

Object type, no subtype.

Definition at line 537 of file ctoon.h.

◆ CTOON_TYPE_RAW

#define CTOON_TYPE_RAW   ((uint8_t)1) /* _____001 */

Raw string type, no subtype.

Definition at line 525 of file ctoon.h.

◆ CTOON_TYPE_STR

#define CTOON_TYPE_STR   ((uint8_t)5) /* _____101 */

String type, subtype: NONE, NOESC.

Definition at line 533 of file ctoon.h.

◆ CTOON_U64_TO_F64_NO_IMPL

#define CTOON_U64_TO_F64_NO_IMPL   0

char bit check Microsoft Visual C++ 6.0 doesn't support converting number from u64 to f64: error C2520: conversion from unsigned __int64 to double not implemented.

Definition at line 467 of file ctoon.h.

◆ ctoon_unlikely

#define ctoon_unlikely (   expr)    (expr)

unlikely for compiler

Definition at line 302 of file ctoon.h.

◆ CTOON_VERSION

Definition at line 496 of file ctoon.h.

◆ CTOON_VERSION_ENCODE

#define CTOON_VERSION_ENCODE (   maj,
  min,
  pat 
)    (((maj)*10000)+((min)*100)+(pat))

Definition at line 495 of file ctoon.h.

◆ CTOON_VERSION_HEX

#define CTOON_VERSION_HEX    ((CTOON_VERSION_MAJOR << 16) | (CTOON_VERSION_MINOR << 8) | CTOON_VERSION_PATCH)

The version of ctoon in hex: (major << 16) | (minor << 8) | (patch).

Definition at line 500 of file ctoon.h.

◆ CTOON_VERSION_MAJOR

#define CTOON_VERSION_MAJOR   0

The major version of ctoon.

Definition at line 487 of file ctoon.h.

◆ CTOON_VERSION_MINOR

#define CTOON_VERSION_MINOR   6

The minor version of ctoon.

Definition at line 490 of file ctoon.h.

◆ CTOON_VERSION_PATCH

#define CTOON_VERSION_PATCH   1

The patch version of ctoon.

Definition at line 493 of file ctoon.h.

◆ CTOON_VERSION_STRING

The version string of ctoon, e.g. "0.2.0".

Definition at line 508 of file ctoon.h.

◆ CTOON_WRITE_FP_FLAG_BITS

#define CTOON_WRITE_FP_FLAG_BITS   8

Highest 8 bits of ctoon_write_flag are reserved for floating-point format control (same encoding as yyjson for ABI compatibility).

Definition at line 1225 of file ctoon.h.

◆ CTOON_WRITE_FP_PREC_BITS

#define CTOON_WRITE_FP_PREC_BITS   4

Definition at line 1226 of file ctoon.h.

◆ CTOON_WRITE_FP_TO_FIXED

#define CTOON_WRITE_FP_TO_FIXED (   prec)
Value:
(uint32_t)((uint32_t)(prec)) << (32 - 4) ))
uint32_t ctoon_write_flag
Definition ctoon.h:1195

Write floating-point as fixed notation with prec decimal places (1-15).

Definition at line 1229 of file ctoon.h.

◆ CTOON_WRITE_FP_TO_FLOAT

#define CTOON_WRITE_FP_TO_FLOAT   ((ctoon_write_flag)(1 << (32 - 5)))

Write floating-point as single-precision float.

Definition at line 1233 of file ctoon.h.

◆ false

#define false   0

Definition at line 448 of file ctoon.h.

◆ true

#define true   1

Definition at line 447 of file ctoon.h.

Typedef Documentation

◆ ctoon_alc

typedef struct ctoon_alc ctoon_alc

A memory allocator.

Typically you don't need to use it, unless you want to customize your own memory allocator.

◆ ctoon_arr_iter

A TOON array iterator.

Example

ctoon_val *val;
while ((val = ctoon_arr_iter_next(&iter))) {
your_func(val);
}
static ctoon_arr_iter ctoon_arr_iter_with(ctoon_val *arr)
Definition ctoon.h:5223
static ctoon_val * ctoon_arr_iter_next(ctoon_arr_iter *iter)
Definition ctoon.h:5233

◆ ctoon_delimiter

Array value delimiter used during encoding.

◆ ctoon_doc

typedef struct ctoon_doc ctoon_doc

An immutable document for reading TOON. This document holds memory for all its TOON values and strings. When it is no longer used, the user should call ctoon_doc_free() to free its memory.

Definition at line 695 of file ctoon.h.

◆ ctoon_incr_state

Opaque state for incremental TOON reader.

Definition at line 1036 of file ctoon.h.

◆ ctoon_mut_arr_iter

A mutable TOON array iterator.

Warning
You should not modify the array while iterating over it, but you can use ctoon_mut_arr_iter_remove() to remove current value.

Example

while ((val = ctoon_mut_arr_iter_next(&iter))) {
your_func(val);
if (your_val_is_unused(val)) {
}
}
static ctoon_mut_val * ctoon_mut_arr_iter_next(ctoon_mut_arr_iter *iter)
Definition ctoon.h:5930
static ctoon_mut_val * ctoon_mut_arr_iter_remove(ctoon_mut_arr_iter *iter)
Definition ctoon.h:5942
static ctoon_mut_arr_iter ctoon_mut_arr_iter_with(ctoon_mut_val *arr)
Definition ctoon.h:5919

◆ ctoon_mut_doc

typedef struct ctoon_mut_doc ctoon_mut_doc

A mutable document for building TOON. This document holds memory for all its TOON values and strings. When it is no longer used, the user should call ctoon_mut_doc_free() to free its memory.

Definition at line 709 of file ctoon.h.

◆ ctoon_mut_obj_iter

A mutable TOON object iterator.

Warning
You should not modify the object while iterating over it, but you can use ctoon_mut_obj_iter_remove() to remove current value.

Example

ctoon_mut_val *key, *val;
while ((key = ctoon_mut_obj_iter_next(&iter))) {
your_func(key, val);
if (your_val_is_unused(key, val)) {
}
}
static ctoon_mut_val * ctoon_mut_obj_iter_get_val(ctoon_mut_val *key)
Definition ctoon.h:6587
static ctoon_mut_val * ctoon_mut_obj_iter_remove(ctoon_mut_obj_iter *iter)
Definition ctoon.h:6592
static ctoon_mut_val * ctoon_mut_obj_iter_next(ctoon_mut_obj_iter *iter)
Definition ctoon.h:6575
static ctoon_mut_obj_iter ctoon_mut_obj_iter_with(ctoon_mut_val *obj)
Definition ctoon.h:6564

If the ordering of the keys is known at compile-time, you can use this method to speed up value lookups:

// {"k1":1, "k2": 3, "k3": 3}
ctoon_mut_val *key, *val;
static ctoon_mut_val * ctoon_mut_obj_iter_get(ctoon_mut_obj_iter *iter, const char *key)
Definition ctoon.h:6609
See also
ctoon_mut_obj_iter_get() and ctoon_mut_obj_iter_getn()

◆ ctoon_mut_val

typedef struct ctoon_mut_val ctoon_mut_val

A mutable value for building TOON. A TOON Value has the same lifetime as its document. The memory is held by its document and and cannot be freed alone.

Definition at line 716 of file ctoon.h.

◆ ctoon_obj_iter

A TOON object iterator.

Example

ctoon_val *key, *val;
while ((key = ctoon_obj_iter_next(&iter))) {
your_func(key, val);
}
static ctoon_val * ctoon_obj_iter_get_val(ctoon_val *key)
Definition ctoon.h:5312
static ctoon_val * ctoon_obj_iter_next(ctoon_obj_iter *iter)
Definition ctoon.h:5302
static ctoon_obj_iter ctoon_obj_iter_with(ctoon_val *obj)
Definition ctoon.h:5292

If the ordering of the keys is known at compile-time, you can use this method to speed up value lookups:

// {"k1":1, "k2": 3, "k3": 3}
ctoon_val *key, *val;
ctoon_val *v1 = ctoon_obj_iter_get(&iter, "k1");
ctoon_val *v3 = ctoon_obj_iter_get(&iter, "k3");
static ctoon_val * ctoon_obj_iter_get(ctoon_obj_iter *iter, const char *key)
Definition ctoon.h:5316
See also
ctoon_obj_iter_get() and ctoon_obj_iter_getn()

◆ ctoon_patch_code

typedef uint32_t ctoon_patch_code

Result code for TOON patch.

Definition at line 4424 of file ctoon.h.

◆ ctoon_patch_err

Error information for TOON patch.

◆ ctoon_ptr_code

typedef uint32_t ctoon_ptr_code

TOON Pointer error code.

Definition at line 3839 of file ctoon.h.

◆ ctoon_ptr_ctx

typedef struct ctoon_ptr_ctx ctoon_ptr_ctx

A context for TOON pointer operation.

This struct stores the context of TOON Pointer operation result. The struct can be used with three helper functions: ctx_append(), ctx_replace(), and ctx_remove(), which perform the corresponding operations on the container without re-parsing the TOON Pointer.

For example:

// doc before: {"a":[0,1,null]}
// ptr: "/a/2"
val = ctoon_mut_doc_ptr_getx(doc, ptr, strlen(ptr), &ctx, &err);
if (ctoon_is_null(val)) {
}
// doc after: {"a":[0,1]}
static unsigned char ctoon_ptr_ctx_remove(ctoon_ptr_ctx *ctx)
Definition ctoon.h:7762
static unsigned char ctoon_is_null(ctoon_val *val)
Definition ctoon.h:4920
static ctoon_mut_val * ctoon_mut_doc_ptr_getx(ctoon_mut_doc *doc, const char *ptr, size_t len, ctoon_ptr_ctx *ctx, ctoon_ptr_err *err)
Definition ctoon.h:7256

◆ ctoon_ptr_err

typedef struct ctoon_ptr_err ctoon_ptr_err

Error information for TOON pointer.

◆ ctoon_read_code

typedef uint32_t ctoon_read_code

Result code for TOON reader.

Definition at line 833 of file ctoon.h.

◆ ctoon_read_err

Error information for TOON reader.

◆ ctoon_read_flag

typedef uint32_t ctoon_read_flag

Run-time options for TOON reader.

Definition at line 725 of file ctoon.h.

◆ ctoon_str_chunk

A memory chunk in string memory pool.

◆ ctoon_str_pool

A memory pool to hold all strings in a mutable document.

◆ ctoon_subtype

typedef uint8_t ctoon_subtype

Subtype of a TOON value (2 bit).

Definition at line 540 of file ctoon.h.

◆ ctoon_type

typedef uint8_t ctoon_type

Type of a TOON value (3 bit).

Definition at line 521 of file ctoon.h.

◆ ctoon_val

typedef struct ctoon_val ctoon_val

An immutable value for reading TOON. A TOON Value has the same lifetime as its document. The memory is held by its document and and cannot be freed alone.

Definition at line 702 of file ctoon.h.

◆ ctoon_val_chunk

A memory chunk in value memory pool. sizeof(ctoon_val_chunk) should not larger than sizeof(ctoon_mut_val).

◆ ctoon_val_pool

A memory pool to hold all values in a mutable document.

◆ ctoon_val_uni

Payload of a TOON value (8 bytes).

◆ ctoon_write_code

typedef uint32_t ctoon_write_code

Result codes for the TOON writer.

Definition at line 1244 of file ctoon.h.

◆ ctoon_write_err

Error information for TOON writer.

◆ ctoon_write_flag

typedef uint32_t ctoon_write_flag

Run-time flags for TOON writer.

Definition at line 1195 of file ctoon.h.

◆ ctoon_write_options

Full options for ctoon_write_opts / ctoon_val_write_opts.

Enumeration Type Documentation

◆ ctoon_delimiter

Array value delimiter used during encoding.

Enumerator
CTOON_DELIMITER_COMMA 

, (default)

CTOON_DELIMITER_TAB 

\t

CTOON_DELIMITER_PIPE 

|

Definition at line 1237 of file ctoon.h.

Function Documentation

◆ ctoon_alc_dyn_free()

void ctoon_alc_dyn_free ( ctoon_alc alc)

Free a dynamic allocator which is created by ctoon_alc_dyn_new().

Parameters
alcThe dynamic allocator to be destroyed.

◆ ctoon_alc_dyn_new()

ctoon_alc * ctoon_alc_dyn_new ( void  )

A dynamic allocator.

This allocator has a similar usage to the pool allocator above. However, when there is not enough memory, this allocator will dynamically request more memory using libc's malloc function, and frees it all at once when it is destroyed.

Returns
A new dynamic allocator, or NULL if memory allocation failed.
Note
The returned value should be freed with ctoon_alc_dyn_free().
Warning
This Allocator is not thread-safe.

◆ ctoon_alc_pool_init()

unsigned char ctoon_alc_pool_init ( ctoon_alc alc,
void *  buf,
size_t  size 
)

A pool allocator uses fixed length pre-allocated memory.

This allocator may be used to avoid malloc/realloc calls. The pre-allocated memory should be held by the caller. The maximum amount of memory required to read a TOON can be calculated using the ctoon_read_max_memory_usage() function, but the amount of memory required to write a TOON cannot be directly calculated.

This is not a general-purpose allocator. It is designed to handle a single TOON data at a time. If it is used for overly complex memory tasks, such as parsing multiple TOON documents using the same allocator but releasing only a few of them, it may cause memory fragmentation, resulting in performance degradation and memory waste.

Parameters
alcThe allocator to be initialized. If this parameter is NULL, the function will fail and return false. If buf or size is invalid, this will be set to an empty allocator.
bufThe buffer memory for this allocator. If this parameter is NULL, the function will fail and return false.
sizeThe size of buf, in bytes. If this parameter is less than 8 words (32/64 bytes on 32/64-bit OS), the function will fail and return false.
Returns
true if the alc has been successfully initialized.

Example

// parse TOON with stack memory
char buf[1024];
ctoon_alc_pool_init(&alc, buf, 1024);
const char *json = "{\"name\":\"Helvetica\",\"size\":16}"
ctoon_doc *doc = ctoon_read_opts(json, strlen(json), 0, &alc, NULL);
// the memory of `doc` is on the stack
ctoon_doc * ctoon_read_opts(char *dat, size_t len, ctoon_read_flag flg, const ctoon_alc *alc, ctoon_read_err *err)
unsigned char ctoon_alc_pool_init(ctoon_alc *alc, void *buf, size_t size)
Warning
This Allocator is not thread-safe.

◆ ctoon_arr_get()

static ctoon_val * ctoon_arr_get ( ctoon_val arr,
size_t  idx 
)
static

Returns the element at the specified position in this array. Returns NULL if array is NULL/empty or the index is out of bounds.

Warning
This function takes a linear search time if array is not flat. For example: [1,{},3] is flat, [1,[2],3] is not flat.

Definition at line 5165 of file ctoon.h.

◆ ctoon_arr_get_first()

static ctoon_val * ctoon_arr_get_first ( ctoon_val arr)
static

Returns the first element of this array. Returns NULL if arr is NULL/empty or type is not array.

Definition at line 5180 of file ctoon.h.

◆ ctoon_arr_get_last()

static ctoon_val * ctoon_arr_get_last ( ctoon_val arr)
static

Returns the last element of this array. Returns NULL if arr is NULL/empty or type is not array.

Warning
This function takes a linear search time if array is not flat. For example: [1,{},3] is flat, [1,[2],3] is not flat.

Definition at line 5189 of file ctoon.h.

◆ ctoon_arr_iter_has_next()

static unsigned char ctoon_arr_iter_has_next ( ctoon_arr_iter iter)
static

Returns whether the iteration has more elements. If iter is NULL, this function will return false.

Definition at line 5229 of file ctoon.h.

◆ ctoon_arr_iter_init()

static unsigned char ctoon_arr_iter_init ( ctoon_val arr,
ctoon_arr_iter iter 
)
static

Initialize an iterator for this array.

Parameters
arrThe array to be iterated over. If this parameter is NULL or not an array, iter will be set to empty.
iterThe iterator to be initialized. If this parameter is NULL, the function will fail and return false.
Returns
true if the iter has been successfully initialized.
Note
The iterator does not need to be destroyed.

Definition at line 5211 of file ctoon.h.

◆ ctoon_arr_iter_next()

static ctoon_val * ctoon_arr_iter_next ( ctoon_arr_iter iter)
static

Returns the next element in the iteration, or NULL on end. If iter is NULL, this function will return NULL.

Definition at line 5233 of file ctoon.h.

◆ ctoon_arr_iter_with()

static ctoon_arr_iter ctoon_arr_iter_with ( ctoon_val arr)
static

Create an iterator with an array , same as ctoon_arr_iter_init().

Parameters
arrThe array to be iterated over. If this parameter is NULL or not an array, an empty iterator will returned.
Returns
A new iterator for the array.
Note
The iterator does not need to be destroyed.

Definition at line 5223 of file ctoon.h.

◆ ctoon_arr_size()

static size_t ctoon_arr_size ( ctoon_val arr)
static

Returns the number of elements in this array. Returns 0 if arr is NULL or type is not array.

Definition at line 5161 of file ctoon.h.

◆ ctoon_doc_free()

static void ctoon_doc_free ( ctoon_doc doc)
static

Release the TOON document and free the memory. After calling this function, the doc and all values from the doc are no longer available. This function will do nothing if the doc is NULL.

Definition at line 4901 of file ctoon.h.

◆ ctoon_doc_get_pointer()

static ctoon_val * ctoon_doc_get_pointer ( ctoon_doc doc,
const char *  ptr 
)
static
Deprecated:
renamed to ctoon_doc_ptr_get

Definition at line 7905 of file ctoon.h.

◆ ctoon_doc_get_pointern()

static ctoon_val * ctoon_doc_get_pointern ( ctoon_doc doc,
const char *  ptr,
size_t  len 
)
static
Deprecated:
renamed to ctoon_doc_ptr_getn

Definition at line 7912 of file ctoon.h.

◆ ctoon_doc_get_read_size()

static size_t ctoon_doc_get_read_size ( ctoon_doc doc)
static

Returns read size of input TOON data. Returns 0 if doc is NULL. For example: the read size of [1,2,3] is 7 bytes.

Definition at line 4893 of file ctoon.h.

◆ ctoon_doc_get_root()

static ctoon_val * ctoon_doc_get_root ( ctoon_doc doc)
static

Returns the root value of this TOON document. Returns NULL if doc is NULL.

Definition at line 4889 of file ctoon.h.

◆ ctoon_doc_get_val_count()

static size_t ctoon_doc_get_val_count ( ctoon_doc doc)
static

Returns total value count in this TOON document. Returns 0 if doc is NULL. For example: the value count of [1,2,3] is 4.

Definition at line 4897 of file ctoon.h.

◆ ctoon_doc_mut_copy()

ctoon_mut_doc * ctoon_doc_mut_copy ( ctoon_doc doc,
const ctoon_alc alc 
)

Copies and returns a new mutable document from input, returns NULL on error. This makes a deep-copy on the immutable document. If allocator is NULL, the default allocator will be used.

Note
imut_doc -> mut_doc.

◆ ctoon_doc_ptr_get()

static ctoon_val * ctoon_doc_ptr_get ( ctoon_doc doc,
const char *  ptr 
)
static

Get value by a TOON Pointer.

Parameters
docThe TOON document to be queried.
ptrThe TOON pointer string (UTF-8 with null-terminator).
Returns
The value referenced by the TOON pointer. NULL if doc or ptr is NULL, or the TOON pointer cannot be resolved.

Definition at line 7182 of file ctoon.h.

◆ ctoon_doc_ptr_getn()

static ctoon_val * ctoon_doc_ptr_getn ( ctoon_doc doc,
const char *  ptr,
size_t  len 
)
static

Get value by a TOON Pointer.

Parameters
docThe TOON document to be queried.
ptrThe TOON pointer string (UTF-8, null-terminator is not required).
lenThe length of ptr in bytes.
Returns
The value referenced by the TOON pointer. NULL if doc or ptr is NULL, or the TOON pointer cannot be resolved.

Definition at line 7188 of file ctoon.h.

◆ ctoon_doc_ptr_getx()

static ctoon_val * ctoon_doc_ptr_getx ( ctoon_doc doc,
const char *  ptr,
size_t  len,
ctoon_ptr_err err 
)
static

Get value by a TOON Pointer.

Parameters
docThe TOON document to be queried.
ptrThe TOON pointer string (UTF-8, null-terminator is not required).
lenThe length of ptr in bytes.
errA pointer to store the error information, or NULL if not needed.
Returns
The value referenced by the TOON pointer. NULL if doc or ptr is NULL, or the TOON pointer cannot be resolved.

Definition at line 7193 of file ctoon.h.

◆ ctoon_doc_to_json()

char * ctoon_doc_to_json ( const ctoon_doc doc,
int  indent,
ctoon_write_flag  flags,
const ctoon_alc alc,
size_t *  len,
ctoon_write_err err 
)

Serialize a document to a JSON string.

The flags parameter accepts the same CTOON_WRITE_* flags used by the TOON writer (e.g. CTOON_WRITE_ESCAPE_UNICODE, CTOON_WRITE_ALLOW_INF_AND_NAN, CTOON_WRITE_INF_AND_NAN_AS_NULL). Note: flags that are TOON-specific (e.g. CTOON_WRITE_LENGTH_MARKER) are silently ignored.

Parameters
docThe document to serialize. Must not be NULL.
indentSpaces per indent level. 0 = compact (no whitespace).
flagsCTOON_WRITE_* flags (subset shared with JSON).
alcCustom allocator, or NULL for the default.
lenIf not NULL, receives the byte length of the result (not counting the null terminator).
errIf not NULL, receives error details on failure.
Returns
Heap-allocated null-terminated JSON string, or NULL on failure. The caller must free() the returned pointer.

◆ ctoon_equals()

static unsigned char ctoon_equals ( ctoon_val lhs,
ctoon_val rhs 
)
static

Returns whether two TOON values are equal (deep compare). Returns false if input is NULL.

Note
the result may be inaccurate if object has duplicate keys.
Warning
This function is recursive and may cause a stack overflow if the object level is too deep.

Definition at line 5062 of file ctoon.h.

◆ ctoon_equals_str()

static unsigned char ctoon_equals_str ( ctoon_val val,
const char *  str 
)
static

Returns whether the TOON value is equals to a string. Returns false if input is NULL or type is not string.

Definition at line 5043 of file ctoon.h.

◆ ctoon_equals_strn()

static unsigned char ctoon_equals_strn ( ctoon_val val,
const char *  str,
size_t  len 
)
static

Returns whether the TOON value is equals to a string. The str should be a UTF-8 string, null-terminator is not required. Returns false if input is NULL or type is not string.

Definition at line 5051 of file ctoon.h.

◆ ctoon_get_bool()

static unsigned char ctoon_get_bool ( ctoon_val val)
static

Returns the content if the value is bool. Returns false if val is NULL or type is not bool.

Definition at line 5011 of file ctoon.h.

◆ ctoon_get_int()

static int ctoon_get_int ( ctoon_val val)
static

Returns the content and cast to int. Returns 0 if val is NULL or type is not integer(sint/uint).

Definition at line 5023 of file ctoon.h.

◆ ctoon_get_len()

static size_t ctoon_get_len ( ctoon_val val)
static

Returns the content length (string length, array size, object size. Returns 0 if val is NULL or type is not string/array/object.

Definition at line 5039 of file ctoon.h.

◆ ctoon_get_num()

static double ctoon_get_num ( ctoon_val val)
static

Returns the content and typecast to double if the value is number. Returns 0.0 if val is NULL or type is not number(uint/sint/real).

Definition at line 5031 of file ctoon.h.

◆ ctoon_get_pointer()

static ctoon_val * ctoon_get_pointer ( ctoon_val val,
const char *  ptr 
)
static
Deprecated:
renamed to ctoon_ptr_get

Definition at line 7934 of file ctoon.h.

◆ ctoon_get_pointern()

static ctoon_val * ctoon_get_pointern ( ctoon_val val,
const char *  ptr,
size_t  len 
)
static
Deprecated:
renamed to ctoon_ptr_getn

Definition at line 7941 of file ctoon.h.

◆ ctoon_get_raw()

static const char * ctoon_get_raw ( ctoon_val val)
static

Returns the content if the value is raw. Returns NULL if val is NULL or type is not raw.

Definition at line 5007 of file ctoon.h.

◆ ctoon_get_real()

static double ctoon_get_real ( ctoon_val val)
static

Returns the content if the value is real number, or 0.0 on error. Returns 0.0 if val is NULL or type is not real(double).

Definition at line 5027 of file ctoon.h.

◆ ctoon_get_sint()

static int64_t ctoon_get_sint ( ctoon_val val)
static

Returns the content and cast to int64_t. Returns 0 if val is NULL or type is not integer(sint/uint).

Definition at line 5019 of file ctoon.h.

◆ ctoon_get_str()

static const char * ctoon_get_str ( ctoon_val val)
static

Returns the content if the value is string. Returns NULL if val is NULL or type is not string.

Definition at line 5035 of file ctoon.h.

◆ ctoon_get_subtype()

static ctoon_subtype ctoon_get_subtype ( ctoon_val val)
static

Returns the TOON value's subtype. Returns CTOON_SUBTYPE_NONE if val is NULL.

Definition at line 4982 of file ctoon.h.

◆ ctoon_get_tag()

static uint8_t ctoon_get_tag ( ctoon_val val)
static

Returns the TOON value's tag. Returns 0 if val is NULL.

Definition at line 4986 of file ctoon.h.

◆ ctoon_get_type()

static ctoon_type ctoon_get_type ( ctoon_val val)
static

Returns the TOON value's type. Returns CTOON_TYPE_NONE if val is NULL.

Definition at line 4978 of file ctoon.h.

◆ ctoon_get_type_desc()

static const char * ctoon_get_type_desc ( ctoon_val val)
static

Returns the TOON value's type description. The return value should be one of these strings: "raw", "null", "string", "array", "object", "true", "false", "uint", "sint", "real", "unknown".

Definition at line 4990 of file ctoon.h.

◆ ctoon_get_uint()

static uint64_t ctoon_get_uint ( ctoon_val val)
static

Returns the content and cast to uint64_t. Returns 0 if val is NULL or type is not integer(sint/uint).

Definition at line 5015 of file ctoon.h.

◆ ctoon_incr_free()

void ctoon_incr_free ( ctoon_incr_state state)

Release the incremental read state and free the memory.

◆ ctoon_incr_new()

ctoon_incr_state * ctoon_incr_new ( char *  buf,
size_t  buf_len,
ctoon_read_flag  flg,
const ctoon_alc alc 
)

Initialize state for incremental read.

To read a large TOON document incrementally:

  1. Call ctoon_incr_new() to create the state for incremental reading.
  2. Call ctoon_incr_read() repeatedly.
  3. Call ctoon_incr_free() to free the state.

Note: The incremental TOON reader only supports standard TOON. Flags for non-standard features (e.g. comments, trailing commas) are ignored.

Parameters
bufThe TOON data, null-terminator is not required. If this parameter is NULL, the function will fail and return NULL.
buf_lenThe length of the TOON data in buf. If use CTOON_READ_INSITU, buf_len should not include the padding size.
flgThe TOON read options. Multiple options can be combined with | operator.
alcThe memory allocator used by TOON reader. Pass NULL to use the libc's default allocator.
Returns
A state for incremental reading. It should be freed with ctoon_incr_free(). NULL is returned if memory allocation fails.

◆ ctoon_incr_read()

ctoon_doc * ctoon_incr_read ( ctoon_incr_state state,
size_t  len,
ctoon_read_err err 
)

Performs incremental read of up to len bytes.

If NULL is returned and err->code is set to CTOON_READ_ERROR_MORE, it indicates that more data is required to continue parsing. Then, call this function again with incremented len. Continue until a document is returned or an error other than CTOON_READ_ERROR_MORE is returned.

Note: Parsing in very small increments is not efficient. An increment of several kilobytes or megabytes is recommended.

Parameters
stateThe state for incremental reading, created using ctoon_incr_new().
lenThe number of bytes of TOON data available to parse. If this parameter is 0, the function will fail and return NULL.
errA pointer to receive error information.
Returns
A new TOON document, or NULL if an error occurs. When the document is no longer needed, it should be freed with ctoon_doc_free().

◆ ctoon_is_arr()

static unsigned char ctoon_is_arr ( ctoon_val val)
static

Returns whether the TOON value is array. Returns false if val is NULL.

Definition at line 4960 of file ctoon.h.

◆ ctoon_is_bool()

static unsigned char ctoon_is_bool ( ctoon_val val)
static

Returns whether the TOON value is bool (true/false). Returns false if val is NULL.

Definition at line 4932 of file ctoon.h.

◆ ctoon_is_ctn()

static unsigned char ctoon_is_ctn ( ctoon_val val)
static

Returns whether the TOON value is container (array/object). Returns false if val is NULL.

Definition at line 4968 of file ctoon.h.

◆ ctoon_is_false()

static unsigned char ctoon_is_false ( ctoon_val val)
static

Returns whether the TOON value is false. Returns false if val is NULL.

Definition at line 4928 of file ctoon.h.

◆ ctoon_is_int()

static unsigned char ctoon_is_int ( ctoon_val val)
static

Returns whether the TOON value is integer (uint64_t/int64_t). Returns false if val is NULL.

Definition at line 4944 of file ctoon.h.

◆ ctoon_is_null()

static unsigned char ctoon_is_null ( ctoon_val val)
static

Returns whether the TOON value is null. Returns false if val is NULL.

Definition at line 4920 of file ctoon.h.

◆ ctoon_is_num()

static unsigned char ctoon_is_num ( ctoon_val val)
static

Returns whether the TOON value is number (uint64_t/int64_t/double). Returns false if val is NULL.

Definition at line 4952 of file ctoon.h.

◆ ctoon_is_obj()

static unsigned char ctoon_is_obj ( ctoon_val val)
static

Returns whether the TOON value is object. Returns false if val is NULL.

Definition at line 4964 of file ctoon.h.

◆ ctoon_is_raw()

static unsigned char ctoon_is_raw ( ctoon_val val)
static

Returns whether the TOON value is raw. Returns false if val is NULL.

Definition at line 4916 of file ctoon.h.

◆ ctoon_is_real()

static unsigned char ctoon_is_real ( ctoon_val val)
static

Returns whether the TOON value is real number (double). Returns false if val is NULL.

Definition at line 4948 of file ctoon.h.

◆ ctoon_is_sint()

static unsigned char ctoon_is_sint ( ctoon_val val)
static

Returns whether the TOON value is signed integer (int64_t). Returns false if val is NULL.

Definition at line 4940 of file ctoon.h.

◆ ctoon_is_str()

static unsigned char ctoon_is_str ( ctoon_val val)
static

Returns whether the TOON value is string. Returns false if val is NULL.

Definition at line 4956 of file ctoon.h.

◆ ctoon_is_true()

static unsigned char ctoon_is_true ( ctoon_val val)
static

Returns whether the TOON value is true. Returns false if val is NULL.

Definition at line 4924 of file ctoon.h.

◆ ctoon_is_uint()

static unsigned char ctoon_is_uint ( ctoon_val val)
static

Returns whether the TOON value is unsigned integer (uint64_t). Returns false if val is NULL.

Definition at line 4936 of file ctoon.h.

◆ ctoon_locate_pos()

unsigned char ctoon_locate_pos ( const char *  str,
size_t  len,
size_t  pos,
size_t *  line,
size_t *  col,
size_t *  chr 
)

Locate the line and column number for a byte position in a string. This can be used to get better description for error position.

Parameters
strThe input string.
lenThe byte length of the input string.
posThe byte position within the input string.
lineA pointer to receive the line number, starting from 1.
colA pointer to receive the column number, starting from 1.
chrA pointer to receive the character index, starting from 0.
Returns
true on success, false if str is NULL or pos is out of bounds.
Note
Line/column/character are calculated based on Unicode characters for compatibility with text editors. For multi-byte UTF-8 characters, the returned value may not directly correspond to the byte position.

◆ ctoon_merge_patch()

ctoon_mut_val * ctoon_merge_patch ( ctoon_mut_doc doc,
ctoon_val orig,
ctoon_val patch 
)

Creates and returns a merge-patched TOON value (RFC 7386). The memory of the returned value is allocated by the doc. Returns NULL if the patch could not be applied.

Warning
This function is recursive and may cause a stack overflow if the object level is too deep.

◆ ctoon_mut_arr()

static ctoon_mut_val * ctoon_mut_arr ( ctoon_mut_doc doc)
static

Creates and returns an empty mutable array.

Parameters
docA mutable document, used for memory allocation only.
Returns
The new array. NULL if input is NULL or memory allocation failed.

Definition at line 5965 of file ctoon.h.

◆ ctoon_mut_arr_add_arr()

static ctoon_mut_val * ctoon_mut_arr_add_arr ( ctoon_mut_doc doc,
ctoon_mut_val arr 
)
static

Creates and adds a new array at the end of the array.

Parameters
docThe doc is only used for memory allocation.
arrThe array to which the value is to be inserted. Returns false if it is NULL or not an array.
Returns
The new array, or NULL on error.

Definition at line 6497 of file ctoon.h.

◆ ctoon_mut_arr_add_bool()

static unsigned char ctoon_mut_arr_add_bool ( ctoon_mut_doc doc,
ctoon_mut_val arr,
unsigned char  val 
)
static

Adds a bool value at the end of the array.

Parameters
docThe doc is only used for memory allocation.
arrThe array to which the value is to be inserted. Returns false if it is NULL or not an array.
valThe bool value to be added.
Returns
Whether successful.

Definition at line 6387 of file ctoon.h.

◆ ctoon_mut_arr_add_double()

static unsigned char ctoon_mut_arr_add_double ( ctoon_mut_doc doc,
ctoon_mut_val arr,
double  num 
)
static

Adds a double value at the end of the array.

Parameters
docThe doc is only used for memory allocation.
arrThe array to which the value is to be inserted. Returns false if it is NULL or not an array.
numThe number to be added.
Returns
Whether successful.

Definition at line 6437 of file ctoon.h.

◆ ctoon_mut_arr_add_false()

static unsigned char ctoon_mut_arr_add_false ( ctoon_mut_doc doc,
ctoon_mut_val arr 
)
static

Adds a false value at the end of the array.

Parameters
docThe doc is only used for memory allocation.
arrThe array to which the value is to be inserted. Returns false if it is NULL or not an array.
Returns
Whether successful.

Definition at line 6378 of file ctoon.h.

◆ ctoon_mut_arr_add_float()

static unsigned char ctoon_mut_arr_add_float ( ctoon_mut_doc doc,
ctoon_mut_val arr,
float  num 
)
static

Adds a float value at the end of the array.

Parameters
docThe doc is only used for memory allocation.
arrThe array to which the value is to be inserted. Returns false if it is NULL or not an array.
numThe number to be added.
Returns
Whether successful.

Definition at line 6427 of file ctoon.h.

◆ ctoon_mut_arr_add_int()

static unsigned char ctoon_mut_arr_add_int ( ctoon_mut_doc doc,
ctoon_mut_val arr,
int64_t  num 
)
static

Adds an integer value at the end of the array.

Parameters
docThe doc is only used for memory allocation.
arrThe array to which the value is to be inserted. Returns false if it is NULL or not an array.
numThe number to be added.
Returns
Whether successful.

Definition at line 6417 of file ctoon.h.

◆ ctoon_mut_arr_add_null()

static unsigned char ctoon_mut_arr_add_null ( ctoon_mut_doc doc,
ctoon_mut_val arr 
)
static

Adds a null value at the end of the array.

Parameters
docThe doc is only used for memory allocation.
arrThe array to which the value is to be inserted. Returns false if it is NULL or not an array.
Returns
Whether successful.

Definition at line 6360 of file ctoon.h.

◆ ctoon_mut_arr_add_obj()

static ctoon_mut_val * ctoon_mut_arr_add_obj ( ctoon_mut_doc doc,
ctoon_mut_val arr 
)
static

Creates and adds a new object at the end of the array.

Parameters
docThe doc is only used for memory allocation.
arrThe array to which the value is to be inserted. Returns false if it is NULL or not an array.
Returns
The new object, or NULL on error.

Definition at line 6506 of file ctoon.h.

◆ ctoon_mut_arr_add_real()

static unsigned char ctoon_mut_arr_add_real ( ctoon_mut_doc doc,
ctoon_mut_val arr,
double  num 
)
static

Adds a double value at the end of the array.

Parameters
docThe doc is only used for memory allocation.
arrThe array to which the value is to be inserted. Returns false if it is NULL or not an array.
numThe number to be added.
Returns
Whether successful.

Definition at line 6447 of file ctoon.h.

◆ ctoon_mut_arr_add_sint()

static unsigned char ctoon_mut_arr_add_sint ( ctoon_mut_doc doc,
ctoon_mut_val arr,
int64_t  num 
)
static

Adds a signed integer value at the end of the array.

Parameters
docThe doc is only used for memory allocation.
arrThe array to which the value is to be inserted. Returns false if it is NULL or not an array.
numThe number to be added.
Returns
Whether successful.

Definition at line 6407 of file ctoon.h.

◆ ctoon_mut_arr_add_str()

static unsigned char ctoon_mut_arr_add_str ( ctoon_mut_doc doc,
ctoon_mut_val arr,
const char *  str 
)
static

Adds a string value at the end of the array (no copy).

Parameters
docThe doc is only used for memory allocation.
arrThe array to which the value is to be inserted. Returns false if it is NULL or not an array.
strA null-terminated UTF-8 string.
Returns
Whether successful.
Warning
The input string is not copied, you should keep this string unmodified for the lifetime of this TOON document.

Definition at line 6457 of file ctoon.h.

◆ ctoon_mut_arr_add_strcpy()

static unsigned char ctoon_mut_arr_add_strcpy ( ctoon_mut_doc doc,
ctoon_mut_val arr,
const char *  str 
)
static

Adds a string value at the end of the array (copied).

Parameters
docThe doc is only used for memory allocation.
arrThe array to which the value is to be inserted. Returns false if it is NULL or not an array.
strA null-terminated UTF-8 string.
Returns
Whether successful.

Definition at line 6477 of file ctoon.h.

◆ ctoon_mut_arr_add_strn()

static unsigned char ctoon_mut_arr_add_strn ( ctoon_mut_doc doc,
ctoon_mut_val arr,
const char *  str,
size_t  len 
)
static

Adds a string value at the end of the array (no copy).

Parameters
docThe doc is only used for memory allocation.
arrThe array to which the value is to be inserted. Returns false if it is NULL or not an array.
strA UTF-8 string, null-terminator is not required.
lenThe length of the string, in bytes.
Returns
Whether successful.
Warning
The input string is not copied, you should keep this string unmodified for the lifetime of this TOON document.

Definition at line 6467 of file ctoon.h.

◆ ctoon_mut_arr_add_strncpy()

static unsigned char ctoon_mut_arr_add_strncpy ( ctoon_mut_doc doc,
ctoon_mut_val arr,
const char *  str,
size_t  len 
)
static

Adds a string value at the end of the array (copied).

Parameters
docThe doc is only used for memory allocation.
arrThe array to which the value is to be inserted. Returns false if it is NULL or not an array.
strA UTF-8 string, null-terminator is not required.
lenThe length of the string, in bytes.
Returns
Whether successful.

Definition at line 6487 of file ctoon.h.

◆ ctoon_mut_arr_add_true()

static unsigned char ctoon_mut_arr_add_true ( ctoon_mut_doc doc,
ctoon_mut_val arr 
)
static

Adds a true value at the end of the array.

Parameters
docThe doc is only used for memory allocation.
arrThe array to which the value is to be inserted. Returns false if it is NULL or not an array.
Returns
Whether successful.

Definition at line 6369 of file ctoon.h.

◆ ctoon_mut_arr_add_uint()

static unsigned char ctoon_mut_arr_add_uint ( ctoon_mut_doc doc,
ctoon_mut_val arr,
uint64_t  num 
)
static

Adds an unsigned integer value at the end of the array.

Parameters
docThe doc is only used for memory allocation.
arrThe array to which the value is to be inserted. Returns false if it is NULL or not an array.
numThe number to be added.
Returns
Whether successful.

Definition at line 6397 of file ctoon.h.

◆ ctoon_mut_arr_add_val()

static unsigned char ctoon_mut_arr_add_val ( ctoon_mut_val arr,
ctoon_mut_val val 
)
static

Adds a value at the end of the array.

Parameters
arrThe array to which the value is to be inserted. Returns false if it is NULL or not an array.
valThe value to be inserted. Returns false if it is NULL.
Returns
Whether successful.

Definition at line 6355 of file ctoon.h.

◆ ctoon_mut_arr_append()

static unsigned char ctoon_mut_arr_append ( ctoon_mut_val arr,
ctoon_mut_val val 
)
static

Inserts a value at the end of the array.

Parameters
arrThe array to which the value is to be inserted. Returns false if it is NULL or not an array.
valThe value to be inserted. Returns false if it is NULL.
Returns
Whether successful.

Definition at line 6176 of file ctoon.h.

◆ ctoon_mut_arr_clear()

static unsigned char ctoon_mut_arr_clear ( ctoon_mut_val arr)
static

Removes all values in this array.

Parameters
arrThe array from which all of the values are to be removed. Returns false if it is NULL or not an array.
Returns
Whether successful.

Definition at line 6329 of file ctoon.h.

◆ ctoon_mut_arr_get()

static ctoon_mut_val * ctoon_mut_arr_get ( ctoon_mut_val arr,
size_t  idx 
)
static

Returns the element at the specified position in this array. Returns NULL if array is NULL/empty or the index is out of bounds.

Warning
This function takes a linear search time.

Definition at line 5873 of file ctoon.h.

◆ ctoon_mut_arr_get_first()

static ctoon_mut_val * ctoon_mut_arr_get_first ( ctoon_mut_val arr)
static

Returns the first element of this array. Returns NULL if arr is NULL/empty or type is not array.

Definition at line 5883 of file ctoon.h.

◆ ctoon_mut_arr_get_last()

static ctoon_mut_val * ctoon_mut_arr_get_last ( ctoon_mut_val arr)
static

Returns the last element of this array. Returns NULL if arr is NULL/empty or type is not array.

Definition at line 5891 of file ctoon.h.

◆ ctoon_mut_arr_insert()

static unsigned char ctoon_mut_arr_insert ( ctoon_mut_val arr,
ctoon_mut_val val,
size_t  idx 
)
static

Inserts a value into an array at a given index.

Parameters
arrThe array to which the value is to be inserted. Returns false if it is NULL or not an array.
valThe value to be inserted. Returns false if it is NULL.
idxThe index to which to insert the new value. Returns false if the index is out of range.
Returns
Whether successful.
Warning
This function takes a linear search time.

Definition at line 6145 of file ctoon.h.

◆ ctoon_mut_arr_iter_has_next()

static unsigned char ctoon_mut_arr_iter_has_next ( ctoon_mut_arr_iter iter)
static

Returns whether the iteration has more elements. If iter is NULL, this function will return false.

Definition at line 5926 of file ctoon.h.

◆ ctoon_mut_arr_iter_init()

static unsigned char ctoon_mut_arr_iter_init ( ctoon_mut_val arr,
ctoon_mut_arr_iter iter 
)
static

Initialize an iterator for this array.

Parameters
arrThe array to be iterated over. If this parameter is NULL or not an array, iter will be set to empty.
iterThe iterator to be initialized. If this parameter is NULL, the function will fail and return false.
Returns
true if the iter has been successfully initialized.
Note
The iterator does not need to be destroyed.

Definition at line 5905 of file ctoon.h.

◆ ctoon_mut_arr_iter_next()

static ctoon_mut_val * ctoon_mut_arr_iter_next ( ctoon_mut_arr_iter iter)
static

Returns the next element in the iteration, or NULL on end. If iter is NULL, this function will return NULL.

Definition at line 5930 of file ctoon.h.

◆ ctoon_mut_arr_iter_remove()

static ctoon_mut_val * ctoon_mut_arr_iter_remove ( ctoon_mut_arr_iter iter)
static

Removes and returns current element in the iteration. If iter is NULL, this function will return NULL.

Definition at line 5942 of file ctoon.h.

◆ ctoon_mut_arr_iter_with()

static ctoon_mut_arr_iter ctoon_mut_arr_iter_with ( ctoon_mut_val arr)
static

Create an iterator with an array , same as ctoon_mut_arr_iter_init().

Parameters
arrThe array to be iterated over. If this parameter is NULL or not an array, an empty iterator will returned.
Returns
A new iterator for the array.
Note
The iterator does not need to be destroyed.

Definition at line 5919 of file ctoon.h.

◆ ctoon_mut_arr_prepend()

static unsigned char ctoon_mut_arr_prepend ( ctoon_mut_val arr,
ctoon_mut_val val 
)
static

Inserts a value at the head of the array.

Parameters
arrThe array to which the value is to be inserted. Returns false if it is NULL or not an array.
valThe value to be inserted. Returns false if it is NULL.
Returns
Whether successful.

Definition at line 6195 of file ctoon.h.

◆ ctoon_mut_arr_remove()

static ctoon_mut_val * ctoon_mut_arr_remove ( ctoon_mut_val arr,
size_t  idx 
)
static

Removes and returns a value at index.

Parameters
arrThe array from which the value is to be removed. Returns false if it is NULL or not an array.
idxThe index from which to remove the value. Returns false if the index is out of range.
Returns
Old value, or NULL on error.
Warning
This function takes a linear search time.

Definition at line 6242 of file ctoon.h.

◆ ctoon_mut_arr_remove_first()

static ctoon_mut_val * ctoon_mut_arr_remove_first ( ctoon_mut_val arr)
static

Removes and returns the first value in this array.

Parameters
arrThe array from which the value is to be removed. Returns false if it is NULL or not an array.
Returns
The first value, or NULL on error.

Definition at line 6266 of file ctoon.h.

◆ ctoon_mut_arr_remove_last()

static ctoon_mut_val * ctoon_mut_arr_remove_last ( ctoon_mut_val arr)
static

Removes and returns the last value in this array.

Parameters
arrThe array from which the value is to be removed. Returns false if it is NULL or not an array.
Returns
The last value, or NULL on error.

Definition at line 6285 of file ctoon.h.

◆ ctoon_mut_arr_remove_range()

static unsigned char ctoon_mut_arr_remove_range ( ctoon_mut_val arr,
size_t  idx,
size_t  len 
)
static

Removes all values within a specified range in the array.

Parameters
arrThe array from which the value is to be removed. Returns false if it is NULL or not an array.
idxThe start index of the range (0 is the first).
lenThe number of items in the range (can be 0).
Returns
Whether successful.
Warning
This function takes a linear search time.

Definition at line 6307 of file ctoon.h.

◆ ctoon_mut_arr_replace()

static ctoon_mut_val * ctoon_mut_arr_replace ( ctoon_mut_val arr,
size_t  idx,
ctoon_mut_val val 
)
static

Replaces a value at index and returns old value.

Parameters
arrThe array to which the value is to be replaced. Returns false if it is NULL or not an array.
idxThe index to which to replace the value. Returns false if the index is out of range.
valThe new value to replace. Returns false if it is NULL.
Returns
Old value, or NULL on error.
Warning
This function takes a linear search time.

Definition at line 6214 of file ctoon.h.

◆ ctoon_mut_arr_rotate()

static unsigned char ctoon_mut_arr_rotate ( ctoon_mut_val arr,
size_t  idx 
)
static

Rotates values in this array for the given number of times. For example: [1,2,3,4,5] rotate 2 is [3,4,5,1,2].

Parameters
arrThe array to be rotated.
idxIndex (or times) to rotate.
Warning
This function takes a linear search time.

Definition at line 6337 of file ctoon.h.

◆ ctoon_mut_arr_size()

static size_t ctoon_mut_arr_size ( ctoon_mut_val arr)
static

Returns the number of elements in this array. Returns 0 if arr is NULL or type is not array.

Definition at line 5869 of file ctoon.h.

◆ ctoon_mut_arr_with_bool()

static ctoon_mut_val * ctoon_mut_arr_with_bool ( ctoon_mut_doc doc,
const unsigned char *  vals,
size_t  count 
)
static

Creates and returns a new mutable array with the given boolean values.

Parameters
docA mutable document, used for memory allocation only. If this parameter is NULL, the function will fail and return NULL.
valsA C array of boolean values.
countThe value count. If this value is 0, an empty array will return.
Returns
The new array. NULL if input is invalid or memory allocation failed.

Example

const bool vals[3] = { true, false, true };
static ctoon_mut_val * ctoon_mut_arr_with_bool(ctoon_mut_doc *doc, const unsigned char *vals, size_t count)
Definition ctoon.h:5997

Definition at line 5997 of file ctoon.h.

◆ ctoon_mut_arr_with_double()

static ctoon_mut_val * ctoon_mut_arr_with_double ( ctoon_mut_doc doc,
const double *  vals,
size_t  count 
)
static

Creates and returns a new mutable array with the given double numbers.

Parameters
docA mutable document, used for memory allocation only. If this parameter is NULL, the function will fail and return NULL.
valsA C array of double numbers.
countThe number count. If this value is 0, an empty array will return.
Returns
The new array. NULL if input is invalid or memory allocation failed.

Example

const double vals[3] = { -1.0, 0.0, 1.0 };
static ctoon_mut_val * ctoon_mut_arr_with_double(ctoon_mut_doc *doc, const double *vals, size_t count)
Definition ctoon.h:6084

Definition at line 6084 of file ctoon.h.

◆ ctoon_mut_arr_with_float()

static ctoon_mut_val * ctoon_mut_arr_with_float ( ctoon_mut_doc doc,
const float *  vals,
size_t  count 
)
static

Creates and returns a new mutable array with the given float numbers.

Parameters
docA mutable document, used for memory allocation only. If this parameter is NULL, the function will fail and return NULL.
valsA C array of float numbers.
countThe number count. If this value is 0, an empty array will return.
Returns
The new array. NULL if input is invalid or memory allocation failed.

Example

const float vals[3] = { -1.0f, 0.0f, 1.0f };
static ctoon_mut_val * ctoon_mut_arr_with_float(ctoon_mut_doc *doc, const float *vals, size_t count)
Definition ctoon.h:6077

Definition at line 6077 of file ctoon.h.

◆ ctoon_mut_arr_with_real()

static ctoon_mut_val * ctoon_mut_arr_with_real ( ctoon_mut_doc doc,
const double *  vals,
size_t  count 
)
static

Creates and returns a new mutable array with the given real numbers.

Parameters
docA mutable document, used for memory allocation only. If this parameter is NULL, the function will fail and return NULL.
valsA C array of real numbers.
countThe number count. If this value is 0, an empty array will return.
Returns
The new array. NULL if input is invalid or memory allocation failed.

Example

const double vals[3] = { 0.1, 0.2, 0.3 };
static ctoon_mut_val * ctoon_mut_arr_with_real(ctoon_mut_doc *doc, const double *vals, size_t count)
Definition ctoon.h:6014

Definition at line 6014 of file ctoon.h.

◆ ctoon_mut_arr_with_sint()

static ctoon_mut_val * ctoon_mut_arr_with_sint ( ctoon_mut_doc doc,
const int64_t *  vals,
size_t  count 
)
static

Creates and returns a new mutable array with the given sint numbers.

Parameters
docA mutable document, used for memory allocation only. If this parameter is NULL, the function will fail and return NULL.
valsA C array of sint numbers.
countThe number count. If this value is 0, an empty array will return.
Returns
The new array. NULL if input is invalid or memory allocation failed.

Example

const int64_t vals[3] = { -1, 0, 1 };
static ctoon_mut_val * ctoon_mut_arr_with_sint64(ctoon_mut_doc *doc, const int64_t *vals, size_t count)
Definition ctoon.h:6042

Definition at line 6004 of file ctoon.h.

◆ ctoon_mut_arr_with_sint16()

static ctoon_mut_val * ctoon_mut_arr_with_sint16 ( ctoon_mut_doc doc,
const int16_t *  vals,
size_t  count 
)
static

Creates and returns a new mutable array with the given int16 numbers.

Parameters
docA mutable document, used for memory allocation only. If this parameter is NULL, the function will fail and return NULL.
valsA C array of int16 numbers.
countThe number count. If this value is 0, an empty array will return.
Returns
The new array. NULL if input is invalid or memory allocation failed.

Example

const int16_t vals[3] = { -1, 0, 1 };
static ctoon_mut_val * ctoon_mut_arr_with_sint16(ctoon_mut_doc *doc, const int16_t *vals, size_t count)
Definition ctoon.h:6028

Definition at line 6028 of file ctoon.h.

◆ ctoon_mut_arr_with_sint32()

static ctoon_mut_val * ctoon_mut_arr_with_sint32 ( ctoon_mut_doc doc,
const int32_t *  vals,
size_t  count 
)
static

Creates and returns a new mutable array with the given int32 numbers.

Parameters
docA mutable document, used for memory allocation only. If this parameter is NULL, the function will fail and return NULL.
valsA C array of int32 numbers.
countThe number count. If this value is 0, an empty array will return.
Returns
The new array. NULL if input is invalid or memory allocation failed.

Example

const int32_t vals[3] = { -1, 0, 1 };
static ctoon_mut_val * ctoon_mut_arr_with_sint32(ctoon_mut_doc *doc, const int32_t *vals, size_t count)
Definition ctoon.h:6035

Definition at line 6035 of file ctoon.h.

◆ ctoon_mut_arr_with_sint64()

static ctoon_mut_val * ctoon_mut_arr_with_sint64 ( ctoon_mut_doc doc,
const int64_t *  vals,
size_t  count 
)
static

Creates and returns a new mutable array with the given int64 numbers.

Parameters
docA mutable document, used for memory allocation only. If this parameter is NULL, the function will fail and return NULL.
valsA C array of int64 numbers.
countThe number count. If this value is 0, an empty array will return.
Returns
The new array. NULL if input is invalid or memory allocation failed.

Example

const int64_t vals[3] = { -1, 0, 1 };

Definition at line 6042 of file ctoon.h.

◆ ctoon_mut_arr_with_sint8()

static ctoon_mut_val * ctoon_mut_arr_with_sint8 ( ctoon_mut_doc doc,
const int8_t *  vals,
size_t  count 
)
static

Creates and returns a new mutable array with the given int8 numbers.

Parameters
docA mutable document, used for memory allocation only. If this parameter is NULL, the function will fail and return NULL.
valsA C array of int8 numbers.
countThe number count. If this value is 0, an empty array will return.
Returns
The new array. NULL if input is invalid or memory allocation failed.

Example

const int8_t vals[3] = { -1, 0, 1 };
static ctoon_mut_val * ctoon_mut_arr_with_sint8(ctoon_mut_doc *doc, const int8_t *vals, size_t count)
Definition ctoon.h:6021

Definition at line 6021 of file ctoon.h.

◆ ctoon_mut_arr_with_str()

static ctoon_mut_val * ctoon_mut_arr_with_str ( ctoon_mut_doc doc,
const char **  vals,
size_t  count 
)
static

Creates and returns a new mutable array with the given strings, these strings will not be copied.

Parameters
docA mutable document, used for memory allocation only. If this parameter is NULL, the function will fail and return NULL.
valsA C array of UTF-8 null-terminator strings. If this array contains NULL, the function will fail and return NULL.
countThe number of values in vals. If this value is 0, an empty array will return.
Returns
The new array. NULL if input is invalid or memory allocation failed.
Warning
The input strings are not copied, you should keep these strings unmodified for the lifetime of this TOON document. If these strings will be modified, you should use ctoon_mut_arr_with_strcpy() instead.

Example

const char *vals[3] = { "a", "b", "c" };
static ctoon_mut_val * ctoon_mut_arr_with_str(ctoon_mut_doc *doc, const char **vals, size_t count)
Definition ctoon.h:6091

Definition at line 6091 of file ctoon.h.

◆ ctoon_mut_arr_with_strcpy()

static ctoon_mut_val * ctoon_mut_arr_with_strcpy ( ctoon_mut_doc doc,
const char **  vals,
size_t  count 
)
static

Creates and returns a new mutable array with the given strings, these strings will be copied.

Parameters
docA mutable document, used for memory allocation only. If this parameter is NULL, the function will fail and return NULL.
valsA C array of UTF-8 null-terminator strings. If this array contains NULL, the function will fail and return NULL.
countThe number of values in vals. If this value is 0, an empty array will return.
Returns
The new array. NULL if input is invalid or memory allocation failed.

Example

const char *vals[3] = { "a", "b", "c" };
static ctoon_mut_val * ctoon_mut_arr_with_strcpy(ctoon_mut_doc *doc, const char **vals, size_t count)
Definition ctoon.h:6108

Definition at line 6108 of file ctoon.h.

◆ ctoon_mut_arr_with_strn()

static ctoon_mut_val * ctoon_mut_arr_with_strn ( ctoon_mut_doc doc,
const char **  vals,
const size_t *  lens,
size_t  count 
)
static

Creates and returns a new mutable array with the given strings and string lengths, these strings will not be copied.

Parameters
docA mutable document, used for memory allocation only. If this parameter is NULL, the function will fail and return NULL.
valsA C array of UTF-8 strings, null-terminator is not required. If this array contains NULL, the function will fail and return NULL.
lensA C array of string lengths, in bytes.
countThe number of strings in vals. If this value is 0, an empty array will return.
Returns
The new array. NULL if input is invalid or memory allocation failed.
Warning
The input strings are not copied, you should keep these strings unmodified for the lifetime of this TOON document. If these strings will be modified, you should use ctoon_mut_arr_with_strncpy() instead.

Example

const char *vals[3] = { "a", "bb", "c" };
const size_t lens[3] = { 1, 2, 1 };
ctoon_mut_val *arr = ctoon_mut_arr_with_strn(doc, vals, lens, 3);
static ctoon_mut_val * ctoon_mut_arr_with_strn(ctoon_mut_doc *doc, const char **vals, const size_t *lens, size_t count)
Definition ctoon.h:6099

Definition at line 6099 of file ctoon.h.

◆ ctoon_mut_arr_with_strncpy()

static ctoon_mut_val * ctoon_mut_arr_with_strncpy ( ctoon_mut_doc doc,
const char **  vals,
const size_t *  lens,
size_t  count 
)
static

Creates and returns a new mutable array with the given strings and string lengths, these strings will be copied.

Parameters
docA mutable document, used for memory allocation only. If this parameter is NULL, the function will fail and return NULL.
valsA C array of UTF-8 strings, null-terminator is not required. If this array contains NULL, the function will fail and return NULL.
lensA C array of string lengths, in bytes.
countThe number of strings in vals. If this value is 0, an empty array will return.
Returns
The new array. NULL if input is invalid or memory allocation failed.

Example

const char *vals[3] = { "a", "bb", "c" };
const size_t lens[3] = { 1, 2, 1 };
ctoon_mut_val *arr = ctoon_mut_arr_with_strn(doc, vals, lens, 3);

Definition at line 6122 of file ctoon.h.

◆ ctoon_mut_arr_with_uint()

static ctoon_mut_val * ctoon_mut_arr_with_uint ( ctoon_mut_doc doc,
const uint64_t *  vals,
size_t  count 
)
static

Creates and returns a new mutable array with the given uint numbers.

Parameters
docA mutable document, used for memory allocation only. If this parameter is NULL, the function will fail and return NULL.
valsA C array of uint numbers.
countThe number count. If this value is 0, an empty array will return.
Returns
The new array. NULL if input is invalid or memory allocation failed.

Example

const uint64_t vals[3] = { 0, 1, 0 };
static ctoon_mut_val * ctoon_mut_arr_with_uint(ctoon_mut_doc *doc, const uint64_t *vals, size_t count)
Definition ctoon.h:6009

Definition at line 6009 of file ctoon.h.

◆ ctoon_mut_arr_with_uint16()

static ctoon_mut_val * ctoon_mut_arr_with_uint16 ( ctoon_mut_doc doc,
const uint16_t *  vals,
size_t  count 
)
static

Creates and returns a new mutable array with the given uint16 numbers.

Parameters
docA mutable document, used for memory allocation only. If this parameter is NULL, the function will fail and return NULL.
valsA C array of uint16 numbers.
countThe number count. If this value is 0, an empty array will return.
Returns
The new array. NULL if input is invalid or memory allocation failed.

Example

const uint16_t vals[3] = { 0, 1, 0 };
static ctoon_mut_val * ctoon_mut_arr_with_uint16(ctoon_mut_doc *doc, const uint16_t *vals, size_t count)
Definition ctoon.h:6056

Definition at line 6056 of file ctoon.h.

◆ ctoon_mut_arr_with_uint32()

static ctoon_mut_val * ctoon_mut_arr_with_uint32 ( ctoon_mut_doc doc,
const uint32_t *  vals,
size_t  count 
)
static

Creates and returns a new mutable array with the given uint32 numbers.

Parameters
docA mutable document, used for memory allocation only. If this parameter is NULL, the function will fail and return NULL.
valsA C array of uint32 numbers.
countThe number count. If this value is 0, an empty array will return.
Returns
The new array. NULL if input is invalid or memory allocation failed.

Example

const uint32_t vals[3] = { 0, 1, 0 };
static ctoon_mut_val * ctoon_mut_arr_with_uint32(ctoon_mut_doc *doc, const uint32_t *vals, size_t count)
Definition ctoon.h:6063

Definition at line 6063 of file ctoon.h.

◆ ctoon_mut_arr_with_uint64()

static ctoon_mut_val * ctoon_mut_arr_with_uint64 ( ctoon_mut_doc doc,
const uint64_t *  vals,
size_t  count 
)
static

Creates and returns a new mutable array with the given uint64 numbers.

Parameters
docA mutable document, used for memory allocation only. If this parameter is NULL, the function will fail and return NULL.
valsA C array of uint64 numbers.
countThe number count. If this value is 0, an empty array will return.
Returns
The new array. NULL if input is invalid or memory allocation failed.

Example

const uint64_t vals[3] = { 0, 1, 0 };
static ctoon_mut_val * ctoon_mut_arr_with_uint64(ctoon_mut_doc *doc, const uint64_t *vals, size_t count)
Definition ctoon.h:6070

Definition at line 6070 of file ctoon.h.

◆ ctoon_mut_arr_with_uint8()

static ctoon_mut_val * ctoon_mut_arr_with_uint8 ( ctoon_mut_doc doc,
const uint8_t *  vals,
size_t  count 
)
static

Creates and returns a new mutable array with the given uint8 numbers.

Parameters
docA mutable document, used for memory allocation only. If this parameter is NULL, the function will fail and return NULL.
valsA C array of uint8 numbers.
countThe number count. If this value is 0, an empty array will return.
Returns
The new array. NULL if input is invalid or memory allocation failed.

Example

const uint8_t vals[3] = { 0, 1, 0 };
static ctoon_mut_val * ctoon_mut_arr_with_uint8(ctoon_mut_doc *doc, const uint8_t *vals, size_t count)
Definition ctoon.h:6049

Definition at line 6049 of file ctoon.h.

◆ ctoon_mut_bool()

static ctoon_mut_val * ctoon_mut_bool ( ctoon_mut_doc doc,
unsigned char  val 
)
static

Creates and returns a bool value, returns NULL on error.

Definition at line 5791 of file ctoon.h.

◆ ctoon_mut_doc_free()

void ctoon_mut_doc_free ( ctoon_mut_doc doc)

Release the TOON document and free the memory. After calling this function, the doc and all values from the doc are no longer available. This function will do nothing if the doc is NULL.

◆ ctoon_mut_doc_get_pointer()

static ctoon_mut_val * ctoon_mut_doc_get_pointer ( ctoon_mut_doc doc,
const char *  ptr 
)
static
Deprecated:
renamed to ctoon_mut_doc_ptr_get

Definition at line 7920 of file ctoon.h.

◆ ctoon_mut_doc_get_pointern()

static ctoon_mut_val * ctoon_mut_doc_get_pointern ( ctoon_mut_doc doc,
const char *  ptr,
size_t  len 
)
static
Deprecated:
renamed to ctoon_mut_doc_ptr_getn

Definition at line 7927 of file ctoon.h.

◆ ctoon_mut_doc_get_root()

static ctoon_mut_val * ctoon_mut_doc_get_root ( ctoon_mut_doc doc)
static

Returns the root value of this TOON document. Returns NULL if doc is NULL.

Definition at line 5472 of file ctoon.h.

◆ ctoon_mut_doc_imut_copy()

ctoon_doc * ctoon_mut_doc_imut_copy ( ctoon_mut_doc doc,
const ctoon_alc alc 
)

Copies and returns a new immutable document from input, returns NULL on error. This makes a deep-copy on the mutable document. The returned document should be freed with ctoon_doc_free().

Note
mut_doc -> imut_doc.
Warning
This function is recursive and may cause a stack overflow if the object level is too deep.

◆ ctoon_mut_doc_mut_copy()

ctoon_mut_doc * ctoon_mut_doc_mut_copy ( ctoon_mut_doc doc,
const ctoon_alc alc 
)

Copies and returns a new mutable document from input, returns NULL on error. This makes a deep-copy on the mutable document. If allocator is NULL, the default allocator will be used.

Note
mut_doc -> mut_doc.

◆ ctoon_mut_doc_new()

ctoon_mut_doc * ctoon_mut_doc_new ( const ctoon_alc alc)

Creates and returns a new mutable TOON document, returns NULL on error. If allocator is NULL, the default allocator will be used.

◆ ctoon_mut_doc_ptr_add()

static unsigned char ctoon_mut_doc_ptr_add ( ctoon_mut_doc doc,
const char *  ptr,
ctoon_mut_val new_val 
)
static

Add (insert) value by a TOON pointer.

Parameters
docThe target TOON document.
ptrThe TOON pointer string (UTF-8 with null-terminator).
new_valThe value to be added.
Returns
true if TOON pointer is valid and new value is added, false otherwise.
Note
The parent nodes will be created if they do not exist.

Definition at line 7316 of file ctoon.h.

◆ ctoon_mut_doc_ptr_addn()

static unsigned char ctoon_mut_doc_ptr_addn ( ctoon_mut_doc doc,
const char *  ptr,
size_t  len,
ctoon_mut_val new_val 
)
static

Add (insert) value by a TOON pointer.

Parameters
docThe target TOON document.
ptrThe TOON pointer string (UTF-8, null-terminator is not required).
lenThe length of ptr in bytes.
new_valThe value to be added.
Returns
true if TOON pointer is valid and new value is added, false otherwise.
Note
The parent nodes will be created if they do not exist.

Definition at line 7323 of file ctoon.h.

◆ ctoon_mut_doc_ptr_addx()

static unsigned char ctoon_mut_doc_ptr_addx ( ctoon_mut_doc doc,
const char *  ptr,
size_t  len,
ctoon_mut_val new_val,
unsigned char  create_parent,
ctoon_ptr_ctx ctx,
ctoon_ptr_err err 
)
static

Add (insert) value by a TOON pointer.

Parameters
docThe target TOON document.
ptrThe TOON pointer string (UTF-8, null-terminator is not required).
lenThe length of ptr in bytes.
new_valThe value to be added.
create_parentWhether to create parent nodes if not exist.
ctxA pointer to store the result context, or NULL if not needed.
errA pointer to store the error information, or NULL if not needed.
Returns
true if TOON pointer is valid and new value is added, false otherwise.

Definition at line 7330 of file ctoon.h.

◆ ctoon_mut_doc_ptr_get()

static ctoon_mut_val * ctoon_mut_doc_ptr_get ( ctoon_mut_doc doc,
const char *  ptr 
)
static

Get value by a TOON Pointer.

Parameters
docThe TOON document to be queried.
ptrThe TOON pointer string (UTF-8 with null-terminator).
Returns
The value referenced by the TOON pointer. NULL if doc or ptr is NULL, or the TOON pointer cannot be resolved.

Definition at line 7244 of file ctoon.h.

◆ ctoon_mut_doc_ptr_getn()

static ctoon_mut_val * ctoon_mut_doc_ptr_getn ( ctoon_mut_doc doc,
const char *  ptr,
size_t  len 
)
static

Get value by a TOON Pointer.

Parameters
docThe TOON document to be queried.
ptrThe TOON pointer string (UTF-8, null-terminator is not required).
lenThe length of ptr in bytes.
Returns
The value referenced by the TOON pointer. NULL if doc or ptr is NULL, or the TOON pointer cannot be resolved.

Definition at line 7250 of file ctoon.h.

◆ ctoon_mut_doc_ptr_getx()

static ctoon_mut_val * ctoon_mut_doc_ptr_getx ( ctoon_mut_doc doc,
const char *  ptr,
size_t  len,
ctoon_ptr_ctx ctx,
ctoon_ptr_err err 
)
static

Get value by a TOON Pointer.

Parameters
docThe TOON document to be queried.
ptrThe TOON pointer string (UTF-8, null-terminator is not required).
lenThe length of ptr in bytes.
ctxA pointer to store the result context, or NULL if not needed.
errA pointer to store the error information, or NULL if not needed.
Returns
The value referenced by the TOON pointer. NULL if doc or ptr is NULL, or the TOON pointer cannot be resolved.

Definition at line 7256 of file ctoon.h.

◆ ctoon_mut_doc_ptr_remove()

static ctoon_mut_val * ctoon_mut_doc_ptr_remove ( ctoon_mut_doc doc,
const char *  ptr 
)
static

Remove value by a TOON pointer.

Parameters
docThe target TOON document.
ptrThe TOON pointer string (UTF-8 with null-terminator).
Returns
The removed value, or NULL on error.

Definition at line 7602 of file ctoon.h.

◆ ctoon_mut_doc_ptr_removen()

static ctoon_mut_val * ctoon_mut_doc_ptr_removen ( ctoon_mut_doc doc,
const char *  ptr,
size_t  len 
)
static

Remove value by a TOON pointer.

Parameters
docThe target TOON document.
ptrThe TOON pointer string (UTF-8, null-terminator is not required).
lenThe length of ptr in bytes.
Returns
The removed value, or NULL on error.

Definition at line 7608 of file ctoon.h.

◆ ctoon_mut_doc_ptr_removex()

static ctoon_mut_val * ctoon_mut_doc_ptr_removex ( ctoon_mut_doc doc,
const char *  ptr,
size_t  len,
ctoon_ptr_ctx ctx,
ctoon_ptr_err err 
)
static

Remove value by a TOON pointer.

Parameters
docThe target TOON document.
ptrThe TOON pointer string (UTF-8, null-terminator is not required).
lenThe length of ptr in bytes.
ctxA pointer to store the result context, or NULL if not needed.
errA pointer to store the error information, or NULL if not needed.
Returns
The removed value, or NULL on error.

Definition at line 7613 of file ctoon.h.

◆ ctoon_mut_doc_ptr_replace()

static ctoon_mut_val * ctoon_mut_doc_ptr_replace ( ctoon_mut_doc doc,
const char *  ptr,
ctoon_mut_val new_val 
)
static

Replace value by a TOON pointer.

Parameters
docThe target TOON document.
ptrThe TOON pointer string (UTF-8 with null-terminator).
new_valThe new value to replace the old one.
Returns
The old value that was replaced, or NULL if not found.

Definition at line 7525 of file ctoon.h.

◆ ctoon_mut_doc_ptr_replacen()

static ctoon_mut_val * ctoon_mut_doc_ptr_replacen ( ctoon_mut_doc doc,
const char *  ptr,
size_t  len,
ctoon_mut_val new_val 
)
static

Replace value by a TOON pointer.

Parameters
docThe target TOON document.
ptrThe TOON pointer string (UTF-8, null-terminator is not required).
lenThe length of ptr in bytes.
new_valThe new value to replace the old one.
Returns
The old value that was replaced, or NULL if not found.

Definition at line 7531 of file ctoon.h.

◆ ctoon_mut_doc_ptr_replacex()

static ctoon_mut_val * ctoon_mut_doc_ptr_replacex ( ctoon_mut_doc doc,
const char *  ptr,
size_t  len,
ctoon_mut_val new_val,
ctoon_ptr_ctx ctx,
ctoon_ptr_err err 
)
static

Replace value by a TOON pointer.

Parameters
docThe target TOON document.
ptrThe TOON pointer string (UTF-8, null-terminator is not required).
lenThe length of ptr in bytes.
new_valThe new value to replace the old one.
ctxA pointer to store the result context, or NULL if not needed.
errA pointer to store the error information, or NULL if not needed.
Returns
The old value that was replaced, or NULL if not found.

Definition at line 7536 of file ctoon.h.

◆ ctoon_mut_doc_ptr_set()

static unsigned char ctoon_mut_doc_ptr_set ( ctoon_mut_doc doc,
const char *  ptr,
ctoon_mut_val new_val 
)
static

Set value by a TOON pointer.

Parameters
docThe target TOON document.
ptrThe TOON pointer string (UTF-8 with null-terminator).
new_valThe value to be set, pass NULL to remove.
Returns
true if TOON pointer is valid and new value is set, false otherwise.
Note
The parent nodes will be created if they do not exist. If the target value already exists, it will be replaced by the new value.

Definition at line 7418 of file ctoon.h.

◆ ctoon_mut_doc_ptr_setn()

static unsigned char ctoon_mut_doc_ptr_setn ( ctoon_mut_doc doc,
const char *  ptr,
size_t  len,
ctoon_mut_val new_val 
)
static

Set value by a TOON pointer.

Parameters
docThe target TOON document.
ptrThe TOON pointer string (UTF-8, null-terminator is not required).
lenThe length of ptr in bytes.
new_valThe value to be set, pass NULL to remove.
Returns
true if TOON pointer is valid and new value is set, false otherwise.
Note
The parent nodes will be created if they do not exist. If the target value already exists, it will be replaced by the new value.

Definition at line 7425 of file ctoon.h.

◆ ctoon_mut_doc_ptr_setx()

static unsigned char ctoon_mut_doc_ptr_setx ( ctoon_mut_doc doc,
const char *  ptr,
size_t  len,
ctoon_mut_val new_val,
unsigned char  create_parent,
ctoon_ptr_ctx ctx,
ctoon_ptr_err err 
)
static

Set value by a TOON pointer.

Parameters
docThe target TOON document.
ptrThe TOON pointer string (UTF-8, null-terminator is not required).
lenThe length of ptr in bytes.
new_valThe value to be set, pass NULL to remove.
create_parentWhether to create parent nodes if not exist.
ctxA pointer to store the result context, or NULL if not needed.
errA pointer to store the error information, or NULL if not needed.
Returns
true if TOON pointer is valid and new value is set, false otherwise.
Note
If the target value already exists, it will be replaced by the new value.

Definition at line 7431 of file ctoon.h.

◆ ctoon_mut_doc_set_root()

static void ctoon_mut_doc_set_root ( ctoon_mut_doc doc,
ctoon_mut_val root 
)
static

Sets the root value of this TOON document. Pass NULL to clear root value of the document.

Definition at line 5476 of file ctoon.h.

◆ ctoon_mut_doc_set_str_pool_size()

unsigned char ctoon_mut_doc_set_str_pool_size ( ctoon_mut_doc doc,
size_t  len 
)

Set the string pool size for a mutable document. This function does not allocate memory immediately, but uses the size when the next memory allocation is needed.

If the caller knows the approximate bytes of strings that the document needs to store (e.g. copy string with ctoon_mut_strcpy function), setting a larger size can avoid multiple memory allocations and improve performance.

Parameters
docThe mutable document.
lenThe desired string pool size in bytes (total string length).
Returns
true if successful, false if size is 0 or overflow.

◆ ctoon_mut_doc_set_val_pool_size()

unsigned char ctoon_mut_doc_set_val_pool_size ( ctoon_mut_doc doc,
size_t  count 
)

Set the value pool size for a mutable document. This function does not allocate memory immediately, but uses the size when the next memory allocation is needed.

If the caller knows the approximate number of values that the document needs to store (e.g. create new value with ctoon_mut_xxx functions), setting a larger size can avoid multiple memory allocations and improve performance.

Parameters
docThe mutable document.
countThe desired value pool size (number of ctoon_mut_val).
Returns
true if successful, false if size is 0 or overflow.

◆ ctoon_mut_doc_to_json()

char * ctoon_mut_doc_to_json ( const ctoon_mut_doc doc,
int  indent,
ctoon_write_flag  flags,
const ctoon_alc alc,
size_t *  len,
ctoon_write_err err 
)

Serialize a mutable document to a JSON string.

Internally converts the mutable circular-linked-list layout to the flat immutable arena layout (one O(n) pass), then serializes. Prefer ctoon_doc_to_json / ctoon_write_json when the document is already immutable to avoid the extra copy.

Parameters
docThe mutable document to serialize. Must not be NULL.
indentSpaces per indent level. 0 = compact (no whitespace).
flagsCTOON_WRITE_* flags (subset shared with JSON).
alcCustom allocator, or NULL for the default.
lenIf not NULL, receives the byte length of the result (not counting the null terminator).
errIf not NULL, receives error details on failure.
Returns
Heap-allocated null-terminated JSON string, or NULL on failure. The caller must free() the returned pointer.

◆ ctoon_mut_double()

static ctoon_mut_val * ctoon_mut_double ( ctoon_mut_doc doc,
double  num 
)
static

Creates and returns a double number value, returns NULL on error.

Definition at line 5816 of file ctoon.h.

◆ ctoon_mut_equals()

static unsigned char ctoon_mut_equals ( ctoon_mut_val lhs,
ctoon_mut_val rhs 
)
static

Returns whether two TOON values are equal (deep compare). Returns false if input is NULL.

Note
the result may be inaccurate if object has duplicate keys.
Warning
This function is recursive and may cause a stack overflow if the object level is too deep.

Definition at line 5614 of file ctoon.h.

◆ ctoon_mut_equals_str()

static unsigned char ctoon_mut_equals_str ( ctoon_mut_val val,
const char *  str 
)
static

Returns whether the TOON value is equals to a string. The str should be a null-terminated UTF-8 string. Returns false if input is NULL or type is not string.

Definition at line 5601 of file ctoon.h.

◆ ctoon_mut_equals_strn()

static unsigned char ctoon_mut_equals_strn ( ctoon_mut_val val,
const char *  str,
size_t  len 
)
static

Returns whether the TOON value is equals to a string. The str should be a UTF-8 string, null-terminator is not required. Returns false if input is NULL or type is not string.

Definition at line 5606 of file ctoon.h.

◆ ctoon_mut_false()

static ctoon_mut_val * ctoon_mut_false ( ctoon_mut_doc doc)
static

Creates and returns a false value, returns NULL on error.

Definition at line 5787 of file ctoon.h.

◆ ctoon_mut_float()

static ctoon_mut_val * ctoon_mut_float ( ctoon_mut_doc doc,
float  num 
)
static

Creates and returns a float number value, returns NULL on error.

Definition at line 5811 of file ctoon.h.

◆ ctoon_mut_get_bool()

static unsigned char ctoon_mut_get_bool ( ctoon_mut_val val)
static

Returns the content if the value is bool. Returns NULL if val is NULL or type is not bool.

Definition at line 5569 of file ctoon.h.

◆ ctoon_mut_get_int()

static int ctoon_mut_get_int ( ctoon_mut_val val)
static

Returns the content and cast to int. Returns 0 if val is NULL or type is not integer(sint/uint).

Definition at line 5581 of file ctoon.h.

◆ ctoon_mut_get_len()

static size_t ctoon_mut_get_len ( ctoon_mut_val val)
static

Returns the content length (string length, array size, object size. Returns 0 if val is NULL or type is not string/array/object.

Definition at line 5597 of file ctoon.h.

◆ ctoon_mut_get_num()

static double ctoon_mut_get_num ( ctoon_mut_val val)
static

Returns the content and typecast to double if the value is number. Returns 0.0 if val is NULL or type is not number(uint/sint/real).

Definition at line 5589 of file ctoon.h.

◆ ctoon_mut_get_pointer()

static ctoon_mut_val * ctoon_mut_get_pointer ( ctoon_mut_val val,
const char *  ptr 
)
static
Deprecated:
renamed to ctoon_mut_ptr_get

Definition at line 7949 of file ctoon.h.

◆ ctoon_mut_get_pointern()

static ctoon_mut_val * ctoon_mut_get_pointern ( ctoon_mut_val val,
const char *  ptr,
size_t  len 
)
static
Deprecated:
renamed to ctoon_mut_ptr_getn

Definition at line 7956 of file ctoon.h.

◆ ctoon_mut_get_raw()

static const char * ctoon_mut_get_raw ( ctoon_mut_val val)
static

Returns the content if the value is raw. Returns NULL if val is NULL or type is not raw.

Definition at line 5565 of file ctoon.h.

◆ ctoon_mut_get_real()

static double ctoon_mut_get_real ( ctoon_mut_val val)
static

Returns the content if the value is real number. Returns 0.0 if val is NULL or type is not real(double).

Definition at line 5585 of file ctoon.h.

◆ ctoon_mut_get_sint()

static int64_t ctoon_mut_get_sint ( ctoon_mut_val val)
static

Returns the content and cast to int64_t. Returns 0 if val is NULL or type is not integer(sint/uint).

Definition at line 5577 of file ctoon.h.

◆ ctoon_mut_get_str()

static const char * ctoon_mut_get_str ( ctoon_mut_val val)
static

Returns the content if the value is string. Returns NULL if val is NULL or type is not string.

Definition at line 5593 of file ctoon.h.

◆ ctoon_mut_get_subtype()

static ctoon_subtype ctoon_mut_get_subtype ( ctoon_mut_val val)
static

Returns the TOON value's subtype. Returns CTOON_SUBTYPE_NONE if val is NULL.

Definition at line 5553 of file ctoon.h.

◆ ctoon_mut_get_tag()

static uint8_t ctoon_mut_get_tag ( ctoon_mut_val val)
static

Returns the TOON value's tag. Returns 0 if val is NULL.

Definition at line 5557 of file ctoon.h.

◆ ctoon_mut_get_type()

static ctoon_type ctoon_mut_get_type ( ctoon_mut_val val)
static

Returns the TOON value's type. Returns CTOON_TYPE_NONE if val is NULL.

Definition at line 5549 of file ctoon.h.

◆ ctoon_mut_get_type_desc()

static const char * ctoon_mut_get_type_desc ( ctoon_mut_val val)
static

Returns the TOON value's type description. The return value should be one of these strings: "raw", "null", "string", "array", "object", "true", "false", "uint", "sint", "real", "unknown".

Definition at line 5561 of file ctoon.h.

◆ ctoon_mut_get_uint()

static uint64_t ctoon_mut_get_uint ( ctoon_mut_val val)
static

Returns the content and cast to uint64_t. Returns 0 if val is NULL or type is not integer(sint/uint).

Definition at line 5573 of file ctoon.h.

◆ ctoon_mut_int()

static ctoon_mut_val * ctoon_mut_int ( ctoon_mut_doc doc,
int64_t  num 
)
static

Creates and returns a signed integer value, returns NULL on error.

Definition at line 5806 of file ctoon.h.

◆ ctoon_mut_is_arr()

static unsigned char ctoon_mut_is_arr ( ctoon_mut_val val)
static

Returns whether the TOON value is array. Returns false if val is NULL.

Definition at line 5531 of file ctoon.h.

◆ ctoon_mut_is_bool()

static unsigned char ctoon_mut_is_bool ( ctoon_mut_val val)
static

Returns whether the TOON value is bool (true/false). Returns false if val is NULL.

Definition at line 5503 of file ctoon.h.

◆ ctoon_mut_is_ctn()

static unsigned char ctoon_mut_is_ctn ( ctoon_mut_val val)
static

Returns whether the TOON value is container (array/object). Returns false if val is NULL.

Definition at line 5539 of file ctoon.h.

◆ ctoon_mut_is_false()

static unsigned char ctoon_mut_is_false ( ctoon_mut_val val)
static

Returns whether the TOON value is false. Returns false if val is NULL.

Definition at line 5499 of file ctoon.h.

◆ ctoon_mut_is_int()

static unsigned char ctoon_mut_is_int ( ctoon_mut_val val)
static

Returns whether the TOON value is integer (uint64_t/int64_t). Returns false if val is NULL.

Definition at line 5515 of file ctoon.h.

◆ ctoon_mut_is_null()

static unsigned char ctoon_mut_is_null ( ctoon_mut_val val)
static

Returns whether the TOON value is null. Returns false if val is NULL.

Definition at line 5491 of file ctoon.h.

◆ ctoon_mut_is_num()

static unsigned char ctoon_mut_is_num ( ctoon_mut_val val)
static

Returns whether the TOON value is number (uint/sint/real). Returns false if val is NULL.

Definition at line 5523 of file ctoon.h.

◆ ctoon_mut_is_obj()

static unsigned char ctoon_mut_is_obj ( ctoon_mut_val val)
static

Returns whether the TOON value is object. Returns false if val is NULL.

Definition at line 5535 of file ctoon.h.

◆ ctoon_mut_is_raw()

static unsigned char ctoon_mut_is_raw ( ctoon_mut_val val)
static

Returns whether the TOON value is raw. Returns false if val is NULL.

Definition at line 5487 of file ctoon.h.

◆ ctoon_mut_is_real()

static unsigned char ctoon_mut_is_real ( ctoon_mut_val val)
static

Returns whether the TOON value is real number (double). Returns false if val is NULL.

Definition at line 5519 of file ctoon.h.

◆ ctoon_mut_is_sint()

static unsigned char ctoon_mut_is_sint ( ctoon_mut_val val)
static

Returns whether the TOON value is signed integer (int64_t). Returns false if val is NULL.

Definition at line 5511 of file ctoon.h.

◆ ctoon_mut_is_str()

static unsigned char ctoon_mut_is_str ( ctoon_mut_val val)
static

Returns whether the TOON value is string. Returns false if val is NULL.

Definition at line 5527 of file ctoon.h.

◆ ctoon_mut_is_true()

static unsigned char ctoon_mut_is_true ( ctoon_mut_val val)
static

Returns whether the TOON value is true. Returns false if val is NULL.

Definition at line 5495 of file ctoon.h.

◆ ctoon_mut_is_uint()

static unsigned char ctoon_mut_is_uint ( ctoon_mut_val val)
static

Returns whether the TOON value is unsigned integer (uint64_t). Returns false if val is NULL.

Definition at line 5507 of file ctoon.h.

◆ ctoon_mut_merge_patch()

ctoon_mut_val * ctoon_mut_merge_patch ( ctoon_mut_doc doc,
ctoon_mut_val orig,
ctoon_mut_val patch 
)

Creates and returns a merge-patched TOON value (RFC 7386). The memory of the returned value is allocated by the doc. Returns NULL if the patch could not be applied.

Warning
This function is recursive and may cause a stack overflow if the object level is too deep.

◆ ctoon_mut_null()

static ctoon_mut_val * ctoon_mut_null ( ctoon_mut_doc doc)
static

Creates and returns a null value, returns NULL on error.

Definition at line 5779 of file ctoon.h.

◆ ctoon_mut_obj()

static ctoon_mut_val * ctoon_mut_obj ( ctoon_mut_doc doc)
static

Creates and returns a mutable object, returns NULL on error.

Definition at line 6641 of file ctoon.h.

◆ ctoon_mut_obj_add()

static unsigned char ctoon_mut_obj_add ( ctoon_mut_val obj,
ctoon_mut_val key,
ctoon_mut_val val 
)
static

Adds a key-value pair at the end of the object. This function allows duplicated key in one object.

Parameters
objThe object to which the new key-value pair is to be added.
keyThe key, should be a string which is created by ctoon_mut_str(), ctoon_mut_strn(), ctoon_mut_strcpy() or ctoon_mut_strncpy().
valThe value to add to the object.
Returns
Whether successful.

Definition at line 6795 of file ctoon.h.

◆ ctoon_mut_obj_add_arr()

static ctoon_mut_val * ctoon_mut_obj_add_arr ( ctoon_mut_doc doc,
ctoon_mut_val obj,
const char *  key 
)
static

Creates and adds a new array to the target object. The key should be a null-terminated UTF-8 string. This function allows duplicated key in one object.

Warning
The key string is not copied, you should keep these strings unmodified for the lifetime of this TOON document.
Returns
The new array, or NULL on error.

Definition at line 7052 of file ctoon.h.

◆ ctoon_mut_obj_add_bool()

static unsigned char ctoon_mut_obj_add_bool ( ctoon_mut_doc doc,
ctoon_mut_val obj,
const char *  key,
unsigned char  val 
)
static

Adds a bool value at the end of the object. The key should be a null-terminated UTF-8 string. This function allows duplicated key in one object.

Warning
The key string is not copied, you should keep the string unmodified for the lifetime of this TOON document.

Definition at line 6951 of file ctoon.h.

◆ ctoon_mut_obj_add_double()

static unsigned char ctoon_mut_obj_add_double ( ctoon_mut_doc doc,
ctoon_mut_val obj,
const char *  key,
double  val 
)
static

Adds a double value at the end of the object. The key should be a null-terminated UTF-8 string. This function allows duplicated key in one object.

Warning
The key string is not copied, you should keep the string unmodified for the lifetime of this TOON document.

Definition at line 6986 of file ctoon.h.

◆ ctoon_mut_obj_add_false()

static unsigned char ctoon_mut_obj_add_false ( ctoon_mut_doc doc,
ctoon_mut_val obj,
const char *  key 
)
static

Adds a false value at the end of the object. The key should be a null-terminated UTF-8 string. This function allows duplicated key in one object.

Warning
The key string is not copied, you should keep the string unmodified for the lifetime of this TOON document.

Definition at line 6945 of file ctoon.h.

◆ ctoon_mut_obj_add_float()

static unsigned char ctoon_mut_obj_add_float ( ctoon_mut_doc doc,
ctoon_mut_val obj,
const char *  key,
float  val 
)
static

Adds a float value at the end of the object. The key should be a null-terminated UTF-8 string. This function allows duplicated key in one object.

Warning
The key string is not copied, you should keep the string unmodified for the lifetime of this TOON document.

Definition at line 6979 of file ctoon.h.

◆ ctoon_mut_obj_add_int()

static unsigned char ctoon_mut_obj_add_int ( ctoon_mut_doc doc,
ctoon_mut_val obj,
const char *  key,
int64_t  val 
)
static

Adds an int value at the end of the object. The key should be a null-terminated UTF-8 string. This function allows duplicated key in one object.

Warning
The key string is not copied, you should keep the string unmodified for the lifetime of this TOON document.

Definition at line 6972 of file ctoon.h.

◆ ctoon_mut_obj_add_null()

static unsigned char ctoon_mut_obj_add_null ( ctoon_mut_doc doc,
ctoon_mut_val obj,
const char *  key 
)
static

Adds a null value at the end of the object. The key should be a null-terminated UTF-8 string. This function allows duplicated key in one object.

Warning
The key string is not copied, you should keep the string unmodified for the lifetime of this TOON document.

Definition at line 6933 of file ctoon.h.

◆ ctoon_mut_obj_add_obj()

static ctoon_mut_val * ctoon_mut_obj_add_obj ( ctoon_mut_doc doc,
ctoon_mut_val obj,
const char *  key 
)
static

Creates and adds a new object to the target object. The key should be a null-terminated UTF-8 string. This function allows duplicated key in one object.

Warning
The key string is not copied, you should keep these strings unmodified for the lifetime of this TOON document.
Returns
The new object, or NULL on error.

Definition at line 7060 of file ctoon.h.

◆ ctoon_mut_obj_add_real()

static unsigned char ctoon_mut_obj_add_real ( ctoon_mut_doc doc,
ctoon_mut_val obj,
const char *  key,
double  val 
)
static

Adds a real value at the end of the object. The key should be a null-terminated UTF-8 string. This function allows duplicated key in one object.

Warning
The key string is not copied, you should keep the string unmodified for the lifetime of this TOON document.

Definition at line 6993 of file ctoon.h.

◆ ctoon_mut_obj_add_sint()

static unsigned char ctoon_mut_obj_add_sint ( ctoon_mut_doc doc,
ctoon_mut_val obj,
const char *  key,
int64_t  val 
)
static

Adds a signed integer value at the end of the object. The key should be a null-terminated UTF-8 string. This function allows duplicated key in one object.

Warning
The key string is not copied, you should keep the string unmodified for the lifetime of this TOON document.

Definition at line 6965 of file ctoon.h.

◆ ctoon_mut_obj_add_str()

static unsigned char ctoon_mut_obj_add_str ( ctoon_mut_doc doc,
ctoon_mut_val obj,
const char *  key,
const char *  val 
)
static

Adds a string value at the end of the object. The key and val should be null-terminated UTF-8 strings. This function allows duplicated key in one object.

Warning
The key/value strings are not copied, you should keep these strings unmodified for the lifetime of this TOON document.

Definition at line 7000 of file ctoon.h.

◆ ctoon_mut_obj_add_strcpy()

static unsigned char ctoon_mut_obj_add_strcpy ( ctoon_mut_doc doc,
ctoon_mut_val obj,
const char *  key,
const char *  val 
)
static

Adds a string value at the end of the object. The key and val should be null-terminated UTF-8 strings. The value string is copied. This function allows duplicated key in one object.

Warning
The key string is not copied, you should keep the string unmodified for the lifetime of this TOON document.

Definition at line 7026 of file ctoon.h.

◆ ctoon_mut_obj_add_strn()

static unsigned char ctoon_mut_obj_add_strn ( ctoon_mut_doc doc,
ctoon_mut_val obj,
const char *  key,
const char *  val,
size_t  len 
)
static

Adds a string value at the end of the object. The key should be a null-terminated UTF-8 string. The val should be a UTF-8 string, null-terminator is not required. The len should be the length of the val, in bytes. This function allows duplicated key in one object.

Warning
The key/value strings are not copied, you should keep these strings unmodified for the lifetime of this TOON document.

Definition at line 7014 of file ctoon.h.

◆ ctoon_mut_obj_add_strncpy()

static unsigned char ctoon_mut_obj_add_strncpy ( ctoon_mut_doc doc,
ctoon_mut_val obj,
const char *  key,
const char *  val,
size_t  len 
)
static

Adds a string value at the end of the object. The key should be a null-terminated UTF-8 string. The val should be a UTF-8 string, null-terminator is not required. The len should be the length of the val, in bytes. This function allows duplicated key in one object.

Warning
The key strings are not copied, you should keep these strings unmodified for the lifetime of this TOON document.

Definition at line 7039 of file ctoon.h.

◆ ctoon_mut_obj_add_true()

static unsigned char ctoon_mut_obj_add_true ( ctoon_mut_doc doc,
ctoon_mut_val obj,
const char *  key 
)
static

Adds a true value at the end of the object. The key should be a null-terminated UTF-8 string. This function allows duplicated key in one object.

Warning
The key string is not copied, you should keep the string unmodified for the lifetime of this TOON document.

Definition at line 6939 of file ctoon.h.

◆ ctoon_mut_obj_add_uint()

static unsigned char ctoon_mut_obj_add_uint ( ctoon_mut_doc doc,
ctoon_mut_val obj,
const char *  key,
uint64_t  val 
)
static

Adds an unsigned integer value at the end of the object. The key should be a null-terminated UTF-8 string. This function allows duplicated key in one object.

Warning
The key string is not copied, you should keep the string unmodified for the lifetime of this TOON document.

Definition at line 6958 of file ctoon.h.

◆ ctoon_mut_obj_add_val()

static unsigned char ctoon_mut_obj_add_val ( ctoon_mut_doc doc,
ctoon_mut_val obj,
const char *  key,
ctoon_mut_val val 
)
static

Adds a TOON value at the end of the object. The key should be a null-terminated UTF-8 string. This function allows duplicated key in one object.

Warning
The key string is not copied, you should keep the string unmodified for the lifetime of this TOON document.

Definition at line 7068 of file ctoon.h.

◆ ctoon_mut_obj_clear()

static unsigned char ctoon_mut_obj_clear ( ctoon_mut_val obj)
static

Removes all key-value pairs in this object.

Parameters
objThe object from which all of the values are to be removed.
Returns
Whether successful.

Definition at line 6880 of file ctoon.h.

◆ ctoon_mut_obj_get()

static ctoon_mut_val * ctoon_mut_obj_get ( ctoon_mut_val obj,
const char *  key 
)
static

Returns the value to which the specified key is mapped. Returns NULL if this object contains no mapping for the key. Returns NULL if obj/key is NULL, or type is not object.

The key should be a null-terminated UTF-8 string.

Warning
This function takes a linear search time.

Definition at line 6525 of file ctoon.h.

◆ ctoon_mut_obj_getn()

static ctoon_mut_val * ctoon_mut_obj_getn ( ctoon_mut_val obj,
const char *  key,
size_t  key_len 
)
static

Returns the value to which the specified key is mapped. Returns NULL if this object contains no mapping for the key. Returns NULL if obj/key is NULL, or type is not object.

The key should be a UTF-8 string, null-terminator is not required. The key_len should be the length of the key, in bytes.

Warning
This function takes a linear search time.

Definition at line 6530 of file ctoon.h.

◆ ctoon_mut_obj_insert()

static unsigned char ctoon_mut_obj_insert ( ctoon_mut_val obj,
ctoon_mut_val key,
ctoon_mut_val val,
size_t  idx 
)
static

Inserts a key-value pair to the object at the given position. This function allows duplicated key in one object.

Parameters
objThe object to which the new key-value pair is to be added.
keyThe key, should be a string which is created by ctoon_mut_str(), ctoon_mut_strn(), ctoon_mut_strcpy() or ctoon_mut_strncpy().
valThe value to add to the object.
idxThe index to which to insert the new pair.
Returns
Whether successful.

Definition at line 6832 of file ctoon.h.

◆ ctoon_mut_obj_iter_get()

static ctoon_mut_val * ctoon_mut_obj_iter_get ( ctoon_mut_obj_iter iter,
const char *  key 
)
static

Iterates to a specified key and returns the value.

This function does the same thing as ctoon_mut_obj_get(), but is much faster if the ordering of the keys is known at compile-time and you are using the same order to look up the values. If the key exists in this object, then the iterator will stop at the next key, otherwise the iterator will not change and NULL is returned.

Parameters
iterThe object iterator, should not be NULL.
keyThe key, should be a UTF-8 string with null-terminator.
Returns
The value to which the specified key is mapped. NULL if this object contains no mapping for the key or input is invalid.
Warning
This function takes a linear search time if the key is not nearby.

Definition at line 6609 of file ctoon.h.

◆ ctoon_mut_obj_iter_get_val()

static ctoon_mut_val * ctoon_mut_obj_iter_get_val ( ctoon_mut_val key)
static

Returns the value for key inside the iteration. If iter is NULL, this function will return NULL.

Definition at line 6587 of file ctoon.h.

◆ ctoon_mut_obj_iter_getn()

static ctoon_mut_val * ctoon_mut_obj_iter_getn ( ctoon_mut_obj_iter iter,
const char *  key,
size_t  key_len 
)
static

Iterates to a specified key and returns the value.

This function does the same thing as ctoon_mut_obj_getn() but is much faster if the ordering of the keys is known at compile-time and you are using the same order to look up the values. If the key exists in this object, then the iterator will stop at the next key, otherwise the iterator will not change and NULL is returned.

Parameters
iterThe object iterator, should not be NULL.
keyThe key, should be a UTF-8 string, null-terminator is not required.
key_lenThe the length of key, in bytes.
Returns
The value to which the specified key is mapped. NULL if this object contains no mapping for the key or input is invalid.
Warning
This function takes a linear search time if the key is not nearby.

Definition at line 6614 of file ctoon.h.

◆ ctoon_mut_obj_iter_has_next()

static unsigned char ctoon_mut_obj_iter_has_next ( ctoon_mut_obj_iter iter)
static

Returns whether the iteration has more elements. If iter is NULL, this function will return false.

Definition at line 6571 of file ctoon.h.

◆ ctoon_mut_obj_iter_init()

static unsigned char ctoon_mut_obj_iter_init ( ctoon_mut_val obj,
ctoon_mut_obj_iter iter 
)
static

Initialize an iterator for this object.

Parameters
objThe object to be iterated over. If this parameter is NULL or not an array, iter will be set to empty.
iterThe iterator to be initialized. If this parameter is NULL, the function will fail and return false.
Returns
true if the iter has been successfully initialized.
Note
The iterator does not need to be destroyed.

Definition at line 6550 of file ctoon.h.

◆ ctoon_mut_obj_iter_next()

static ctoon_mut_val * ctoon_mut_obj_iter_next ( ctoon_mut_obj_iter iter)
static

Returns the next key in the iteration, or NULL on end. If iter is NULL, this function will return NULL.

Definition at line 6575 of file ctoon.h.

◆ ctoon_mut_obj_iter_remove()

static ctoon_mut_val * ctoon_mut_obj_iter_remove ( ctoon_mut_obj_iter iter)
static

Removes current key-value pair in the iteration, returns the removed value. If iter is NULL, this function will return NULL.

Definition at line 6592 of file ctoon.h.

◆ ctoon_mut_obj_iter_with()

static ctoon_mut_obj_iter ctoon_mut_obj_iter_with ( ctoon_mut_val obj)
static

Create an iterator with an object, same as ctoon_obj_iter_init().

Parameters
objThe object to be iterated over. If this parameter is NULL or not an object, an empty iterator will returned.
Returns
A new iterator for the object.
Note
The iterator does not need to be destroyed.

Definition at line 6564 of file ctoon.h.

◆ ctoon_mut_obj_put()

static unsigned char ctoon_mut_obj_put ( ctoon_mut_val obj,
ctoon_mut_val key,
ctoon_mut_val val 
)
static

Sets a key-value pair at the end of the object. This function may remove all key-value pairs for the given key before add.

Parameters
objThe object to which the new key-value pair is to be added.
keyThe key, should be a string which is created by ctoon_mut_str(), ctoon_mut_strn(), ctoon_mut_strcpy() or ctoon_mut_strncpy().
valThe value to add to the object. If this value is null, the behavior is same as ctoon_mut_obj_remove().
Returns
Whether successful.

Definition at line 6806 of file ctoon.h.

◆ ctoon_mut_obj_remove()

static ctoon_mut_val * ctoon_mut_obj_remove ( ctoon_mut_val obj,
ctoon_mut_val key 
)
static

Removes all key-value pair from the object with given key.

Parameters
objThe object from which the key-value pair is to be removed.
keyThe key, should be a string value.
Returns
The first matched value, or NULL if no matched value.
Warning
This function takes a linear search time.

Definition at line 6854 of file ctoon.h.

◆ ctoon_mut_obj_remove_key()

static ctoon_mut_val * ctoon_mut_obj_remove_key ( ctoon_mut_val obj,
const char *  key 
)
static

Removes all key-value pair from the object with given key.

Parameters
objThe object from which the key-value pair is to be removed.
keyThe key, should be a UTF-8 string with null-terminator.
Returns
The first matched value, or NULL if no matched value.
Warning
This function takes a linear search time.

Definition at line 6863 of file ctoon.h.

◆ ctoon_mut_obj_remove_keyn()

static ctoon_mut_val * ctoon_mut_obj_remove_keyn ( ctoon_mut_val obj,
const char *  key,
size_t  key_len 
)
static

Removes all key-value pair from the object with given key.

Parameters
objThe object from which the key-value pair is to be removed.
keyThe key, should be a UTF-8 string, null-terminator is not required.
key_lenThe length of the key.
Returns
The first matched value, or NULL if no matched value.
Warning
This function takes a linear search time.

Definition at line 6872 of file ctoon.h.

◆ ctoon_mut_obj_remove_str()

static ctoon_mut_val * ctoon_mut_obj_remove_str ( ctoon_mut_val obj,
const char *  key 
)
static

Removes all key-value pairs for the given key. Returns the first value to which the specified key is mapped or NULL if this object contains no mapping for the key. The key should be a null-terminated UTF-8 string.

Warning
This function takes a linear search time.

Definition at line 7078 of file ctoon.h.

◆ ctoon_mut_obj_remove_strn()

static ctoon_mut_val * ctoon_mut_obj_remove_strn ( ctoon_mut_val obj,
const char *  key,
size_t  len 
)
static

Removes all key-value pairs for the given key. Returns the first value to which the specified key is mapped or NULL if this object contains no mapping for the key. The key should be a UTF-8 string, null-terminator is not required. The len should be the length of the key, in bytes.

Warning
This function takes a linear search time.

Definition at line 7083 of file ctoon.h.

◆ ctoon_mut_obj_rename_key()

static unsigned char ctoon_mut_obj_rename_key ( ctoon_mut_doc doc,
ctoon_mut_val obj,
const char *  key,
const char *  new_key 
)
static

Replaces all matching keys with the new key. Returns true if at least one key was renamed. The key and new_key should be a null-terminated UTF-8 string. The new_key is copied and held by doc.

Warning
This function takes a linear search time. If new_key already exists, it will cause duplicate keys.

Definition at line 7101 of file ctoon.h.

◆ ctoon_mut_obj_rename_keyn()

static unsigned char ctoon_mut_obj_rename_keyn ( ctoon_mut_doc doc,
ctoon_mut_val obj,
const char *  key,
size_t  len,
const char *  new_key,
size_t  new_len 
)
static

Replaces all matching keys with the new key. Returns true if at least one key was renamed. The key and new_key should be a UTF-8 string, null-terminator is not required. The new_key is copied and held by doc.

Warning
This function takes a linear search time. If new_key already exists, it will cause duplicate keys.

Definition at line 7110 of file ctoon.h.

◆ ctoon_mut_obj_replace()

static unsigned char ctoon_mut_obj_replace ( ctoon_mut_val obj,
ctoon_mut_val key,
ctoon_mut_val val 
)
static

Replaces value from the object with given key. If the key is not exist, or the value is NULL, it will fail.

Parameters
objThe object to which the value is to be replaced.
keyThe key, should be a string value.
valThe value to replace into the object.
Returns
Whether successful.
Warning
This function takes a linear search time.

Definition at line 6888 of file ctoon.h.

◆ ctoon_mut_obj_rotate()

static unsigned char ctoon_mut_obj_rotate ( ctoon_mut_val obj,
size_t  idx 
)
static

Rotates key-value pairs in the object for the given number of times. For example: {"a":1,"b":2,"c":3,"d":4} rotate 1 is {"b":2,"c":3,"d":4,"a":1}.

Parameters
objThe object to be rotated.
idxIndex (or times) to rotate.
Returns
Whether successful.
Warning
This function takes a linear search time.

Definition at line 6898 of file ctoon.h.

◆ ctoon_mut_obj_size()

static size_t ctoon_mut_obj_size ( ctoon_mut_val obj)
static

Returns the number of key-value pairs in this object. Returns 0 if obj is NULL or type is not object.

Definition at line 6521 of file ctoon.h.

◆ ctoon_mut_obj_with_kv()

static ctoon_mut_val * ctoon_mut_obj_with_kv ( ctoon_mut_doc doc,
const char **  kv_pairs,
size_t  pair_count 
)
static

Creates and returns a mutable object with key-value pairs and pair count, returns NULL on error. The keys and values are not copied. The strings should be a null-terminated UTF-8 string.

Warning
The input string is not copied, you should keep this string unmodified for the lifetime of this TOON document.

Example

const char *kv_pairs[4] = { "id", "01", "name", "Harry" };
ctoon_mut_val *obj = ctoon_mut_obj_with_kv(doc, kv_pairs, 2);
static ctoon_mut_val * ctoon_mut_obj_with_kv(ctoon_mut_doc *doc, const char **kv_pairs, size_t pair_count)
Definition ctoon.h:6683

Definition at line 6683 of file ctoon.h.

◆ ctoon_mut_obj_with_str()

static ctoon_mut_val * ctoon_mut_obj_with_str ( ctoon_mut_doc doc,
const char **  keys,
const char **  vals,
size_t  count 
)
static

Creates and returns a mutable object with keys and values, returns NULL on error. The keys and values are not copied. The strings should be a null-terminated UTF-8 string.

Warning
The input string is not copied, you should keep this string unmodified for the lifetime of this TOON document.

Example

const char *keys[2] = { "id", "name" };
const char *vals[2] = { "01", "Harry" };
ctoon_mut_val *obj = ctoon_mut_obj_with_str(doc, keys, vals, 2);
static ctoon_mut_val * ctoon_mut_obj_with_str(ctoon_mut_doc *doc, const char **keys, const char **vals, size_t count)
Definition ctoon.h:6652

Definition at line 6652 of file ctoon.h.

◆ ctoon_mut_patch()

ctoon_mut_val * ctoon_mut_patch ( ctoon_mut_doc doc,
ctoon_mut_val orig,
ctoon_mut_val patch,
ctoon_patch_err err 
)

Creates and returns a patched TOON value (RFC 6902). The memory of the returned value is allocated by the doc. The err is used to receive error information, pass NULL if not needed. Returns NULL if the patch could not be applied.

◆ ctoon_mut_ptr_add()

static unsigned char ctoon_mut_ptr_add ( ctoon_mut_val val,
const char *  ptr,
ctoon_mut_val new_val,
ctoon_mut_doc doc 
)
static

Add (insert) value by a TOON pointer.

Parameters
valThe target TOON value.
ptrThe TOON pointer string (UTF-8 with null-terminator).
docOnly used to create new values when needed.
new_valThe value to be added.
Returns
true if TOON pointer is valid and new value is added, false otherwise.
Note
The parent nodes will be created if they do not exist.

Definition at line 7377 of file ctoon.h.

◆ ctoon_mut_ptr_addn()

static unsigned char ctoon_mut_ptr_addn ( ctoon_mut_val val,
const char *  ptr,
size_t  len,
ctoon_mut_val new_val,
ctoon_mut_doc doc 
)
static

Add (insert) value by a TOON pointer.

Parameters
valThe target TOON value.
ptrThe TOON pointer string (UTF-8, null-terminator is not required).
lenThe length of ptr in bytes.
docOnly used to create new values when needed.
new_valThe value to be added.
Returns
true if TOON pointer is valid and new value is added, false otherwise.
Note
The parent nodes will be created if they do not exist.

Definition at line 7385 of file ctoon.h.

◆ ctoon_mut_ptr_addx()

static unsigned char ctoon_mut_ptr_addx ( ctoon_mut_val val,
const char *  ptr,
size_t  len,
ctoon_mut_val new_val,
ctoon_mut_doc doc,
unsigned char  create_parent,
ctoon_ptr_ctx ctx,
ctoon_ptr_err err 
)
static

Add (insert) value by a TOON pointer.

Parameters
valThe target TOON value.
ptrThe TOON pointer string (UTF-8, null-terminator is not required).
lenThe length of ptr in bytes.
docOnly used to create new values when needed.
new_valThe value to be added.
create_parentWhether to create parent nodes if not exist.
ctxA pointer to store the result context, or NULL if not needed.
errA pointer to store the error information, or NULL if not needed.
Returns
true if TOON pointer is valid and new value is added, false otherwise.

Definition at line 7392 of file ctoon.h.

◆ ctoon_mut_ptr_get()

static ctoon_mut_val * ctoon_mut_ptr_get ( ctoon_mut_val val,
const char *  ptr 
)
static

Get value by a TOON Pointer.

Parameters
valThe TOON value to be queried.
ptrThe TOON pointer string (UTF-8 with null-terminator).
Returns
The value referenced by the TOON pointer. NULL if val or ptr is NULL, or the TOON pointer cannot be resolved.

Definition at line 7282 of file ctoon.h.

◆ ctoon_mut_ptr_getn()

static ctoon_mut_val * ctoon_mut_ptr_getn ( ctoon_mut_val val,
const char *  ptr,
size_t  len 
)
static

Get value by a TOON Pointer.

Parameters
valThe TOON value to be queried.
ptrThe TOON pointer string (UTF-8, null-terminator is not required).
lenThe length of ptr in bytes.
Returns
The value referenced by the TOON pointer. NULL if val or ptr is NULL, or the TOON pointer cannot be resolved.

Definition at line 7288 of file ctoon.h.

◆ ctoon_mut_ptr_getx()

static ctoon_mut_val * ctoon_mut_ptr_getx ( ctoon_mut_val val,
const char *  ptr,
size_t  len,
ctoon_ptr_ctx ctx,
ctoon_ptr_err err 
)
static

Get value by a TOON Pointer.

Parameters
valThe TOON value to be queried.
ptrThe TOON pointer string (UTF-8, null-terminator is not required).
lenThe length of ptr in bytes.
ctxA pointer to store the result context, or NULL if not needed.
errA pointer to store the error information, or NULL if not needed.
Returns
The value referenced by the TOON pointer. NULL if val or ptr is NULL, or the TOON pointer cannot be resolved.

Definition at line 7294 of file ctoon.h.

◆ ctoon_mut_ptr_remove()

static ctoon_mut_val * ctoon_mut_ptr_remove ( ctoon_mut_val val,
const char *  ptr 
)
static

Remove value by a TOON pointer.

Parameters
valThe target TOON value.
ptrThe TOON pointer string (UTF-8 with null-terminator).
Returns
The removed value, or NULL on error.

Definition at line 7641 of file ctoon.h.

◆ ctoon_mut_ptr_removen()

static ctoon_mut_val * ctoon_mut_ptr_removen ( ctoon_mut_val val,
const char *  ptr,
size_t  len 
)
static

Remove value by a TOON pointer.

Parameters
valThe target TOON value.
ptrThe TOON pointer string (UTF-8, null-terminator is not required).
lenThe length of ptr in bytes.
Returns
The removed value, or NULL on error.

Definition at line 7647 of file ctoon.h.

◆ ctoon_mut_ptr_removex()

static ctoon_mut_val * ctoon_mut_ptr_removex ( ctoon_mut_val val,
const char *  ptr,
size_t  len,
ctoon_ptr_ctx ctx,
ctoon_ptr_err err 
)
static

Remove value by a TOON pointer.

Parameters
valThe target TOON value.
ptrThe TOON pointer string (UTF-8, null-terminator is not required).
lenThe length of ptr in bytes.
ctxA pointer to store the result context, or NULL if not needed.
errA pointer to store the error information, or NULL if not needed.
Returns
The removed value, or NULL on error.

Definition at line 7653 of file ctoon.h.

◆ ctoon_mut_ptr_replace()

static ctoon_mut_val * ctoon_mut_ptr_replace ( ctoon_mut_val val,
const char *  ptr,
ctoon_mut_val new_val 
)
static

Replace value by a TOON pointer.

Parameters
valThe target TOON value.
ptrThe TOON pointer string (UTF-8 with null-terminator).
new_valThe new value to replace the old one.
Returns
The old value that was replaced, or NULL if not found.

Definition at line 7569 of file ctoon.h.

◆ ctoon_mut_ptr_replacen()

static ctoon_mut_val * ctoon_mut_ptr_replacen ( ctoon_mut_val val,
const char *  ptr,
size_t  len,
ctoon_mut_val new_val 
)
static

Replace value by a TOON pointer.

Parameters
valThe target TOON value.
ptrThe TOON pointer string (UTF-8, null-terminator is not required).
lenThe length of ptr in bytes.
new_valThe new value to replace the old one.
Returns
The old value that was replaced, or NULL if not found.

Definition at line 7575 of file ctoon.h.

◆ ctoon_mut_ptr_replacex()

static ctoon_mut_val * ctoon_mut_ptr_replacex ( ctoon_mut_val val,
const char *  ptr,
size_t  len,
ctoon_mut_val new_val,
ctoon_ptr_ctx ctx,
ctoon_ptr_err err 
)
static

Replace value by a TOON pointer.

Parameters
valThe target TOON value.
ptrThe TOON pointer string (UTF-8, null-terminator is not required).
lenThe length of ptr in bytes.
new_valThe new value to replace the old one.
ctxA pointer to store the result context, or NULL if not needed.
errA pointer to store the error information, or NULL if not needed.
Returns
The old value that was replaced, or NULL if not found.

Definition at line 7580 of file ctoon.h.

◆ ctoon_mut_ptr_set()

static unsigned char ctoon_mut_ptr_set ( ctoon_mut_val val,
const char *  ptr,
ctoon_mut_val new_val,
ctoon_mut_doc doc 
)
static

Set value by a TOON pointer.

Parameters
valThe target TOON value.
ptrThe TOON pointer string (UTF-8 with null-terminator).
new_valThe value to be set, pass NULL to remove.
docOnly used to create new values when needed.
Returns
true if TOON pointer is valid and new value is set, false otherwise.
Note
The parent nodes will be created if they do not exist. If the target value already exists, it will be replaced by the new value.

Definition at line 7481 of file ctoon.h.

◆ ctoon_mut_ptr_setn()

static unsigned char ctoon_mut_ptr_setn ( ctoon_mut_val val,
const char *  ptr,
size_t  len,
ctoon_mut_val new_val,
ctoon_mut_doc doc 
)
static

Set value by a TOON pointer.

Parameters
valThe target TOON value.
ptrThe TOON pointer string (UTF-8, null-terminator is not required).
lenThe length of ptr in bytes.
new_valThe value to be set, pass NULL to remove.
docOnly used to create new values when needed.
Returns
true if TOON pointer is valid and new value is set, false otherwise.
Note
The parent nodes will be created if they do not exist. If the target value already exists, it will be replaced by the new value.

Definition at line 7489 of file ctoon.h.

◆ ctoon_mut_ptr_setx()

static unsigned char ctoon_mut_ptr_setx ( ctoon_mut_val val,
const char *  ptr,
size_t  len,
ctoon_mut_val new_val,
ctoon_mut_doc doc,
unsigned char  create_parent,
ctoon_ptr_ctx ctx,
ctoon_ptr_err err 
)
static

Set value by a TOON pointer.

Parameters
valThe target TOON value.
ptrThe TOON pointer string (UTF-8, null-terminator is not required).
lenThe length of ptr in bytes.
new_valThe value to be set, pass NULL to remove.
docOnly used to create new values when needed.
create_parentWhether to create parent nodes if not exist.
ctxA pointer to store the result context, or NULL if not needed.
errA pointer to store the error information, or NULL if not needed.
Returns
true if TOON pointer is valid and new value is set, false otherwise.
Note
If the target value already exists, it will be replaced by the new value.

Definition at line 7496 of file ctoon.h.

◆ ctoon_mut_raw()

static ctoon_mut_val * ctoon_mut_raw ( ctoon_mut_doc doc,
const char *  str 
)
static

Creates and returns a raw value, returns NULL on error. The str should be a null-terminated UTF-8 string.

Warning
The input string is not copied, you should keep this string unmodified for the lifetime of this TOON document.

Definition at line 5748 of file ctoon.h.

◆ ctoon_mut_rawcpy()

static ctoon_mut_val * ctoon_mut_rawcpy ( ctoon_mut_doc doc,
const char *  str 
)
static

Creates and returns a raw value, returns NULL on error. The str should be a null-terminated UTF-8 string. The input string is copied and held by the document.

Definition at line 5759 of file ctoon.h.

◆ ctoon_mut_rawn()

static ctoon_mut_val * ctoon_mut_rawn ( ctoon_mut_doc doc,
const char *  str,
size_t  len 
)
static

Creates and returns a raw value, returns NULL on error. The str should be a UTF-8 string, null-terminator is not required.

Warning
The input string is not copied, you should keep this string unmodified for the lifetime of this TOON document.

Definition at line 5753 of file ctoon.h.

◆ ctoon_mut_rawncpy()

static ctoon_mut_val * ctoon_mut_rawncpy ( ctoon_mut_doc doc,
const char *  str,
size_t  len 
)
static

Creates and returns a raw value, returns NULL on error. The str should be a UTF-8 string, null-terminator is not required. The input string is copied and held by the document.

Definition at line 5769 of file ctoon.h.

◆ ctoon_mut_read_number()

static const char * ctoon_mut_read_number ( const char *  dat,
ctoon_mut_val val,
ctoon_read_flag  flg,
const ctoon_alc alc,
ctoon_read_err err 
)
static

Same as ctoon_read_number().

Definition at line 1178 of file ctoon.h.

References ctoon_read_number().

◆ ctoon_mut_real()

static ctoon_mut_val * ctoon_mut_real ( ctoon_mut_doc doc,
double  num 
)
static

Creates and returns a real number value, returns NULL on error.

Definition at line 5821 of file ctoon.h.

◆ ctoon_mut_set_arr()

static unsigned char ctoon_mut_set_arr ( ctoon_mut_val val)
static

Set the value to array. Returns false if input is NULL.

Warning
This function should not be used on an existing object or array.

Definition at line 5710 of file ctoon.h.

◆ ctoon_mut_set_bool()

static unsigned char ctoon_mut_set_bool ( ctoon_mut_val val,
unsigned char  num 
)
static

Set the value to bool. Returns false if input is NULL.

Warning
This function should not be used on an existing object or array.

Definition at line 5633 of file ctoon.h.

◆ ctoon_mut_set_double()

static unsigned char ctoon_mut_set_double ( ctoon_mut_val val,
double  num 
)
static

Set the value to double. Returns false if input is NULL.

Warning
This function should not be used on an existing object or array.

Definition at line 5663 of file ctoon.h.

◆ ctoon_mut_set_float()

static unsigned char ctoon_mut_set_float ( ctoon_mut_val val,
float  num 
)
static

Set the value to float. Returns false if input is NULL.

Warning
This function should not be used on an existing object or array.

Definition at line 5657 of file ctoon.h.

◆ ctoon_mut_set_fp_to_fixed()

static unsigned char ctoon_mut_set_fp_to_fixed ( ctoon_mut_val val,
int  prec 
)
static

Set the floating-point number's output format to fixed-point notation. Returns false if input is NULL or val is not real type.

See also
CTOON_WRITE_FP_TO_FIXED flag.
Warning
This will modify the immutable value, use with caution.

Definition at line 5675 of file ctoon.h.

◆ ctoon_mut_set_fp_to_float()

static unsigned char ctoon_mut_set_fp_to_float ( ctoon_mut_val val,
unsigned char  flt 
)
static

Set the floating-point number's output format to single-precision. Returns false if input is NULL or val is not real type.

See also
CTOON_WRITE_FP_TO_FLOAT flag.
Warning
This will modify the immutable value, use with caution.

Definition at line 5682 of file ctoon.h.

◆ ctoon_mut_set_int()

static unsigned char ctoon_mut_set_int ( ctoon_mut_val val,
int  num 
)
static

Set the value to int. Returns false if input is NULL.

Warning
This function should not be used on an existing object or array.

Definition at line 5651 of file ctoon.h.

◆ ctoon_mut_set_null()

static unsigned char ctoon_mut_set_null ( ctoon_mut_val val)
static

Set the value to null. Returns false if input is NULL.

Warning
This function should not be used on an existing object or array.

Definition at line 5627 of file ctoon.h.

◆ ctoon_mut_set_obj()

static unsigned char ctoon_mut_set_obj ( ctoon_mut_val val)
static

Set the value to array. Returns false if input is NULL.

Warning
This function should not be used on an existing object or array.

Definition at line 5716 of file ctoon.h.

◆ ctoon_mut_set_raw()

static unsigned char ctoon_mut_set_raw ( ctoon_mut_val val,
const char *  raw,
size_t  len 
)
static

Set the value to raw. Returns false if input is NULL.

Warning
This function should not be used on an existing object or array.

Definition at line 5620 of file ctoon.h.

◆ ctoon_mut_set_real()

static unsigned char ctoon_mut_set_real ( ctoon_mut_val val,
double  num 
)
static

Set the value to real. Returns false if input is NULL.

Warning
This function should not be used on an existing object or array.

Definition at line 5669 of file ctoon.h.

◆ ctoon_mut_set_sint()

static unsigned char ctoon_mut_set_sint ( ctoon_mut_val val,
int64_t  num 
)
static

Set the value to sint. Returns false if input is NULL.

Warning
This function should not be used on an existing object or array.

Definition at line 5645 of file ctoon.h.

◆ ctoon_mut_set_str()

static unsigned char ctoon_mut_set_str ( ctoon_mut_val val,
const char *  str 
)
static

Set the value to string (null-terminated). Returns false if input is NULL.

Warning
This function should not be used on an existing object or array.

Definition at line 5689 of file ctoon.h.

◆ ctoon_mut_set_str_noesc()

static unsigned char ctoon_mut_set_str_noesc ( ctoon_mut_val val,
unsigned char  noesc 
)
static

Marks this string as not needing to be escaped during TOON writing. This can be used to avoid the overhead of escaping if the string contains only characters that do not require escaping. Returns false if input is NULL or val is not string.

See also
CTOON_SUBTYPE_NOESC subtype.
Warning
This will modify the immutable value, use with caution.

Definition at line 5703 of file ctoon.h.

◆ ctoon_mut_set_strn()

static unsigned char ctoon_mut_set_strn ( ctoon_mut_val val,
const char *  str,
size_t  len 
)
static

Set the value to string (with length). Returns false if input is NULL.

Warning
This function should not be used on an existing object or array.

Definition at line 5696 of file ctoon.h.

◆ ctoon_mut_set_uint()

static unsigned char ctoon_mut_set_uint ( ctoon_mut_val val,
uint64_t  num 
)
static

Set the value to uint. Returns false if input is NULL.

Warning
This function should not be used on an existing object or array.

Definition at line 5639 of file ctoon.h.

◆ ctoon_mut_sint()

static ctoon_mut_val * ctoon_mut_sint ( ctoon_mut_doc doc,
int64_t  num 
)
static

Creates and returns a signed integer value, returns NULL on error.

Definition at line 5801 of file ctoon.h.

◆ ctoon_mut_str()

static ctoon_mut_val * ctoon_mut_str ( ctoon_mut_doc doc,
const char *  str 
)
static

Creates and returns a string value, returns NULL on error. The str should be a null-terminated UTF-8 string.

Warning
The input string is not copied, you should keep this string unmodified for the lifetime of this TOON document.

Definition at line 5826 of file ctoon.h.

◆ ctoon_mut_strcpy()

static ctoon_mut_val * ctoon_mut_strcpy ( ctoon_mut_doc doc,
const char *  str 
)
static

Creates and returns a string value, returns NULL on error. The str should be a null-terminated UTF-8 string. The input string is copied and held by the document.

Definition at line 5837 of file ctoon.h.

◆ ctoon_mut_strn()

static ctoon_mut_val * ctoon_mut_strn ( ctoon_mut_doc doc,
const char *  str,
size_t  len 
)
static

Creates and returns a string value, returns NULL on error. The str should be a UTF-8 string, null-terminator is not required.

Warning
The input string is not copied, you should keep this string unmodified for the lifetime of this TOON document.

Definition at line 5831 of file ctoon.h.

◆ ctoon_mut_strncpy()

static ctoon_mut_val * ctoon_mut_strncpy ( ctoon_mut_doc doc,
const char *  str,
size_t  len 
)
static

Creates and returns a string value, returns NULL on error. The str should be a UTF-8 string, null-terminator is not required. The input string is copied and held by the document.

Definition at line 5850 of file ctoon.h.

◆ ctoon_mut_true()

static ctoon_mut_val * ctoon_mut_true ( ctoon_mut_doc doc)
static

Creates and returns a true value, returns NULL on error.

Definition at line 5783 of file ctoon.h.

◆ ctoon_mut_uint()

static ctoon_mut_val * ctoon_mut_uint ( ctoon_mut_doc doc,
uint64_t  num 
)
static

Creates and returns an unsigned integer value, returns NULL on error.

Definition at line 5796 of file ctoon.h.

◆ ctoon_mut_val_imut_copy()

ctoon_doc * ctoon_mut_val_imut_copy ( ctoon_mut_val val,
const ctoon_alc alc 
)

Copies and returns a new immutable document from input, returns NULL on error. This makes a deep-copy on the mutable value. The returned document should be freed with ctoon_doc_free().

Note
mut_val -> imut_doc.
Warning
This function is recursive and may cause a stack overflow if the object level is too deep.

◆ ctoon_mut_val_mut_copy()

ctoon_mut_val * ctoon_mut_val_mut_copy ( ctoon_mut_doc doc,
ctoon_mut_val val 
)

Copies and returns a new mutable value from input, returns NULL on error. This makes a deep-copy on the mutable value. The memory was managed by mutable document.

Note
mut_val -> mut_val.
Warning
This function is recursive and may cause a stack overflow if the object level is too deep.

◆ ctoon_mut_val_write()

static char * ctoon_mut_val_write ( const ctoon_mut_val val,
size_t *  len 
)
static

Definition at line 1345 of file ctoon.h.

References ctoon_mut_val_write_opts().

◆ ctoon_mut_val_write_opts()

char * ctoon_mut_val_write_opts ( const ctoon_mut_val val,
const ctoon_write_options opts,
const ctoon_alc alc,
size_t *  len,
ctoon_write_err err 
)

Referenced by ctoon_mut_val_write().

◆ ctoon_mut_write()

static char * ctoon_mut_write ( const ctoon_mut_doc doc,
size_t *  len 
)
static

Definition at line 1323 of file ctoon.h.

References ctoon_mut_write_opts().

◆ ctoon_mut_write_file()

unsigned char ctoon_mut_write_file ( const char *  path,
const ctoon_mut_doc doc,
const ctoon_write_options opts,
const ctoon_alc alc,
ctoon_write_err err 
)

◆ ctoon_mut_write_fp()

unsigned char ctoon_mut_write_fp ( FILE *  fp,
const ctoon_mut_doc doc,
const ctoon_write_options opts,
const ctoon_alc alc,
ctoon_write_err err 
)

◆ ctoon_mut_write_opts()

char * ctoon_mut_write_opts ( const ctoon_mut_doc doc,
const ctoon_write_options opts,
const ctoon_alc alc,
size_t *  len,
ctoon_write_err err 
)

Write a mutable document to TOON string with full options.

Referenced by ctoon_mut_write().

◆ ctoon_obj_get()

static ctoon_val * ctoon_obj_get ( ctoon_val obj,
const char *  key 
)
static

Returns the value to which the specified key is mapped. Returns NULL if this object contains no mapping for the key. Returns NULL if obj/key is NULL, or type is not object.

The key should be a null-terminated UTF-8 string.

Warning
This function takes a linear search time.

Definition at line 5254 of file ctoon.h.

◆ ctoon_obj_getn()

static ctoon_val * ctoon_obj_getn ( ctoon_val obj,
const char *  key,
size_t  key_len 
)
static

Returns the value to which the specified key is mapped. Returns NULL if this object contains no mapping for the key. Returns NULL if obj/key is NULL, or type is not object.

The key should be a UTF-8 string, null-terminator is not required. The key_len should be the length of the key, in bytes.

Warning
This function takes a linear search time.

Definition at line 5259 of file ctoon.h.

◆ ctoon_obj_iter_get()

static ctoon_val * ctoon_obj_iter_get ( ctoon_obj_iter iter,
const char *  key 
)
static

Iterates to a specified key and returns the value.

This function does the same thing as ctoon_obj_get(), but is much faster if the ordering of the keys is known at compile-time and you are using the same order to look up the values. If the key exists in this object, then the iterator will stop at the next key, otherwise the iterator will not change and NULL is returned.

Parameters
iterThe object iterator, should not be NULL.
keyThe key, should be a UTF-8 string with null-terminator.
Returns
The value to which the specified key is mapped. NULL if this object contains no mapping for the key or input is invalid.
Warning
This function takes a linear search time if the key is not nearby.

Definition at line 5316 of file ctoon.h.

◆ ctoon_obj_iter_get_val()

static ctoon_val * ctoon_obj_iter_get_val ( ctoon_val key)
static

Returns the value for key inside the iteration. If iter is NULL, this function will return NULL.

Definition at line 5312 of file ctoon.h.

◆ ctoon_obj_iter_getn()

static ctoon_val * ctoon_obj_iter_getn ( ctoon_obj_iter iter,
const char *  key,
size_t  key_len 
)
static

Iterates to a specified key and returns the value.

This function does the same thing as ctoon_obj_getn(), but is much faster if the ordering of the keys is known at compile-time and you are using the same order to look up the values. If the key exists in this object, then the iterator will stop at the next key, otherwise the iterator will not change and NULL is returned.

Parameters
iterThe object iterator, should not be NULL.
keyThe key, should be a UTF-8 string, null-terminator is not required.
key_lenThe the length of key, in bytes.
Returns
The value to which the specified key is mapped. NULL if this object contains no mapping for the key or input is invalid.
Warning
This function takes a linear search time if the key is not nearby.

Definition at line 5321 of file ctoon.h.

◆ ctoon_obj_iter_has_next()

static unsigned char ctoon_obj_iter_has_next ( ctoon_obj_iter iter)
static

Returns whether the iteration has more elements. If iter is NULL, this function will return false.

Definition at line 5298 of file ctoon.h.

◆ ctoon_obj_iter_init()

static unsigned char ctoon_obj_iter_init ( ctoon_val obj,
ctoon_obj_iter iter 
)
static

Initialize an iterator for this object.

Parameters
objThe object to be iterated over. If this parameter is NULL or not an object, iter will be set to empty.
iterThe iterator to be initialized. If this parameter is NULL, the function will fail and return false.
Returns
true if the iter has been successfully initialized.
Note
The iterator does not need to be destroyed.

Definition at line 5279 of file ctoon.h.

◆ ctoon_obj_iter_next()

static ctoon_val * ctoon_obj_iter_next ( ctoon_obj_iter iter)
static

Returns the next key in the iteration, or NULL on end. If iter is NULL, this function will return NULL.

Definition at line 5302 of file ctoon.h.

◆ ctoon_obj_iter_with()

static ctoon_obj_iter ctoon_obj_iter_with ( ctoon_val obj)
static

Create an iterator with an object, same as ctoon_obj_iter_init().

Parameters
objThe object to be iterated over. If this parameter is NULL or not an object, an empty iterator will returned.
Returns
A new iterator for the object.
Note
The iterator does not need to be destroyed.

Definition at line 5292 of file ctoon.h.

◆ ctoon_obj_size()

static size_t ctoon_obj_size ( ctoon_val obj)
static

Returns the number of key-value pairs in this object. Returns 0 if obj is NULL or type is not object.

Definition at line 5250 of file ctoon.h.

◆ ctoon_patch()

ctoon_mut_val * ctoon_patch ( ctoon_mut_doc doc,
ctoon_val orig,
ctoon_val patch,
ctoon_patch_err err 
)

Creates and returns a patched TOON value (RFC 6902). The memory of the returned value is allocated by the doc. The err is used to receive error information, pass NULL if not needed. Returns NULL if the patch could not be applied.

◆ ctoon_ptr_ctx_append()

static unsigned char ctoon_ptr_ctx_append ( ctoon_ptr_ctx ctx,
ctoon_mut_val key,
ctoon_mut_val val 
)
static

Append value by TOON pointer context.

Parameters
ctxThe context from the ctoon_mut_ptr_xxx() calls.
keyNew key if ctx->ctn is object, or NULL if ctx->ctn is array.
valNew value to be added.
Returns
true on success or false on fail.

Definition at line 7676 of file ctoon.h.

◆ ctoon_ptr_ctx_remove()

static unsigned char ctoon_ptr_ctx_remove ( ctoon_ptr_ctx ctx)
static

Remove value by TOON pointer context.

Parameters
ctxThe context from the ctoon_mut_ptr_xxx() calls.
Returns
true on success or false on fail.
Note
If success, the old value will be returned via ctx->old.

Definition at line 7762 of file ctoon.h.

◆ ctoon_ptr_ctx_replace()

static unsigned char ctoon_ptr_ctx_replace ( ctoon_ptr_ctx ctx,
ctoon_mut_val val 
)
static

Replace value by TOON pointer context.

Parameters
ctxThe context from the ctoon_mut_ptr_xxx() calls.
valNew value to be replaced.
Returns
true on success or false on fail.
Note
If success, the old value will be returned via ctx->old.

Definition at line 7730 of file ctoon.h.

◆ ctoon_ptr_get()

static ctoon_val * ctoon_ptr_get ( ctoon_val val,
const char *  ptr 
)
static

Get value by a TOON Pointer.

Parameters
valThe TOON value to be queried.
ptrThe TOON pointer string (UTF-8 with null-terminator).
Returns
The value referenced by the TOON pointer. NULL if val or ptr is NULL, or the TOON pointer cannot be resolved.

Definition at line 7215 of file ctoon.h.

◆ ctoon_ptr_get_bool()

static unsigned char ctoon_ptr_get_bool ( ctoon_val root,
const char *  ptr,
unsigned char *  value 
)
static

Set provided value if the TOON Pointer (RFC 6901) exists and is type bool. Returns true if value at ptr exists and is the correct type, otherwise false.

Definition at line 7804 of file ctoon.h.

◆ ctoon_ptr_get_num()

static unsigned char ctoon_ptr_get_num ( ctoon_val root,
const char *  ptr,
double *  value 
)
static

Set provided value if the TOON Pointer (RFC 6901) exists and is type sint, uint or real. Returns true if value at ptr exists and is the correct type, otherwise false.

Definition at line 7871 of file ctoon.h.

◆ ctoon_ptr_get_real()

static unsigned char ctoon_ptr_get_real ( ctoon_val root,
const char *  ptr,
double *  value 
)
static

Set provided value if the TOON Pointer (RFC 6901) exists and is type real. Returns true if value at ptr exists and is the correct type, otherwise false.

Definition at line 7855 of file ctoon.h.

◆ ctoon_ptr_get_sint()

static unsigned char ctoon_ptr_get_sint ( ctoon_val root,
const char *  ptr,
int64_t *  value 
)
static

Set provided value if the TOON Pointer (RFC 6901) exists and is an integer that fits in int64_t. Returns true if successful, otherwise false.

Definition at line 7837 of file ctoon.h.

◆ ctoon_ptr_get_str()

static unsigned char ctoon_ptr_get_str ( ctoon_val root,
const char *  ptr,
const char **  value 
)
static

Set provided value if the TOON Pointer (RFC 6901) exists and is type string. Returns true if value at ptr exists and is the correct type, otherwise false.

Definition at line 7886 of file ctoon.h.

◆ ctoon_ptr_get_uint()

static unsigned char ctoon_ptr_get_uint ( ctoon_val root,
const char *  ptr,
uint64_t *  value 
)
static

Set provided value if the TOON Pointer (RFC 6901) exists and is an integer that fits in uint64_t. Returns true if successful, otherwise false.

Definition at line 7819 of file ctoon.h.

◆ ctoon_ptr_getn()

static ctoon_val * ctoon_ptr_getn ( ctoon_val val,
const char *  ptr,
size_t  len 
)
static

Get value by a TOON Pointer.

Parameters
valThe TOON value to be queried.
ptrThe TOON pointer string (UTF-8, null-terminator is not required).
lenThe length of ptr in bytes.
Returns
The value referenced by the TOON pointer. NULL if val or ptr is NULL, or the TOON pointer cannot be resolved.

Definition at line 7221 of file ctoon.h.

◆ ctoon_ptr_getx()

static ctoon_val * ctoon_ptr_getx ( ctoon_val val,
const char *  ptr,
size_t  len,
ctoon_ptr_err err 
)
static

Get value by a TOON Pointer.

Parameters
valThe TOON value to be queried.
ptrThe TOON pointer string (UTF-8, null-terminator is not required).
lenThe length of ptr in bytes.
errA pointer to store the error information, or NULL if not needed.
Returns
The value referenced by the TOON pointer. NULL if val or ptr is NULL, or the TOON pointer cannot be resolved.

Definition at line 7226 of file ctoon.h.

◆ ctoon_read()

static ctoon_doc * ctoon_read ( const char *  dat,
size_t  len,
ctoon_read_flag  flg 
)
static

Read a TOON string.

This function is thread-safe.

Parameters
datThe TOON data (UTF-8 without BOM), null-terminator is not required. If this parameter is NULL, the function will fail and return NULL.
lenThe length of TOON data in bytes. If this parameter is 0, the function will fail and return NULL.
flgThe TOON read options. Multiple options can be combined with | operator. 0 means no options.
Returns
A new TOON document, or NULL if an error occurs. When it's no longer needed, it should be freed with ctoon_doc_free().

Definition at line 1023 of file ctoon.h.

References ctoon_read_opts().

◆ ctoon_read_file()

ctoon_doc * ctoon_read_file ( const char *  path,
ctoon_read_flag  flg,
const ctoon_alc alc,
ctoon_read_err err 
)

Read a TOON file.

This function is thread-safe when:

  1. The file is not modified by other threads.
  2. The alc is thread-safe or NULL.
Parameters
pathThe TOON file's path. This should be a null-terminated string using the system's native encoding. If this path is NULL or invalid, the function will fail and return NULL.
flgThe TOON read options. Multiple options can be combined with | operator. 0 means no options.
alcThe memory allocator used by TOON reader. Pass NULL to use the libc's default allocator.
errA pointer to receive error information. Pass NULL if you don't need error information.
Returns
A new TOON document, or NULL if an error occurs. When it's no longer needed, it should be freed with ctoon_doc_free().
Warning
On 32-bit operating system, files larger than 2GB may fail to read.

◆ ctoon_read_fp()

ctoon_doc * ctoon_read_fp ( FILE *  fp,
ctoon_read_flag  flg,
const ctoon_alc alc,
ctoon_read_err err 
)

Read TOON from a file pointer.

Parameters
fpThe file pointer. The data will be read from the current position of the FILE to the end. If this fp is NULL or invalid, the function will fail and return NULL.
flgThe TOON read options. Multiple options can be combined with | operator. 0 means no options.
alcThe memory allocator used by TOON reader. Pass NULL to use the libc's default allocator.
errA pointer to receive error information. Pass NULL if you don't need error information.
Returns
A new TOON document, or NULL if an error occurs. When it's no longer needed, it should be freed with ctoon_doc_free().
Warning
On 32-bit operating system, files larger than 2GB may fail to read.

◆ ctoon_read_max_memory_usage()

static size_t ctoon_read_max_memory_usage ( size_t  len,
ctoon_read_flag  flg 
)
static

Returns the size of maximum memory usage to read a TOON data.

You may use this value to avoid malloc() or calloc() call inside the reader to get better performance, or read multiple TOON with one piece of memory.

Parameters
lenThe length of TOON data in bytes.
flgThe TOON read options.
Returns
The maximum memory size to read this TOON, or 0 if overflow.

Example

// read multiple TOON with same pre-allocated memory
char *dat1, *dat2, *dat3; // TOON data
size_t len1, len2, len3; // TOON length
size_t max_len = MAX(len1, MAX(len2, len3));
ctoon_doc *doc;
// use one allocator for multiple TOON
size_t size = ctoon_read_max_memory_usage(max_len, 0);
void *buf = malloc(size);
ctoon_alc_pool_init(&alc, buf, size);
// no more alloc() or realloc() call during reading
doc = ctoon_read_opts(dat1, len1, 0, &alc, NULL);
doc = ctoon_read_opts(dat2, len2, 0, &alc, NULL);
doc = ctoon_read_opts(dat3, len3, 0, &alc, NULL);
free(buf);
static size_t ctoon_read_max_memory_usage(size_t len, ctoon_read_flag flg)
Definition ctoon.h:1130
static void ctoon_doc_free(ctoon_doc *doc)
Definition ctoon.h:4901
See also
ctoon_alc_pool_init()

Definition at line 1130 of file ctoon.h.

References CTOON_READ_INSITU, and CTOON_READ_STOP_WHEN_DONE.

◆ ctoon_read_number()

const char * ctoon_read_number ( const char *  dat,
ctoon_val val,
ctoon_read_flag  flg,
const ctoon_alc alc,
ctoon_read_err err 
)

Read a TOON number.

This function is thread-safe when data is not modified by other threads.

Parameters
datThe TOON data (UTF-8 without BOM), null-terminator is required. If this parameter is NULL, the function will fail and return NULL.
valThe output value where result is stored. If this parameter is NULL, the function will fail and return NULL. The value will hold either UINT or SINT or REAL number;
flgThe TOON read options. Multiple options can be combined with | operator. 0 means no options. Supports CTOON_READ_NUMBER_AS_RAW and CTOON_READ_ALLOW_INF_AND_NAN.
alcThe memory allocator used for long number. It is only used when the built-in floating point reader is disabled. Pass NULL to use the libc's default allocator.
errA pointer to receive error information. Pass NULL if you don't need error information.
Returns
If successful, a pointer to the character after the last character used in the conversion, NULL if an error occurs.

Referenced by ctoon_mut_read_number().

◆ ctoon_read_opts()

ctoon_doc * ctoon_read_opts ( char *  dat,
size_t  len,
ctoon_read_flag  flg,
const ctoon_alc alc,
ctoon_read_err err 
)

Read TOON with options.

This function is thread-safe when:

  1. The dat is not modified by other threads.
  2. The alc is thread-safe or NULL.
Parameters
datThe TOON data (UTF-8 without BOM), null-terminator is not required. If this parameter is NULL, the function will fail and return NULL. The dat will not be modified without the flag CTOON_READ_INSITU, so you can pass a const char * string and case it to char * if you don't use the CTOON_READ_INSITU flag.
lenThe length of TOON data in bytes. If this parameter is 0, the function will fail and return NULL.
flgThe TOON read options. Multiple options can be combined with | operator. 0 means no options.
alcThe memory allocator used by TOON reader. Pass NULL to use the libc's default allocator.
errA pointer to receive error information. Pass NULL if you don't need error information.
Returns
A new TOON document, or NULL if an error occurs. When it's no longer needed, it should be freed with ctoon_doc_free().

Referenced by ctoon_read().

◆ ctoon_read_opts_indent()

ctoon_doc * ctoon_read_opts_indent ( char *  dat,
size_t  len,
ctoon_read_flag  flg,
int  indent_size,
const ctoon_alc alc,
ctoon_read_err err 
)

Read TOON with options and a custom indent size (spec §12 "indentSize").

Same as ctoon_read_opts(), but lets the caller override the number of spaces that count as one indentation level when decoding (default 2, and what ctoon_read_opts() always uses). Pass indent_size <= 0 to fall back to the default of 2.

Parameters
datThe TOON data (UTF-8 without BOM), null-terminator is not required. If this parameter is NULL, the function will fail and return NULL. The dat will not be modified without the flag CTOON_READ_INSITU, so you can pass a const char * string and case it to char * if you don't use the CTOON_READ_INSITU flag.
lenThe length of TOON data in bytes. If this parameter is 0, the function will fail and return NULL.
flgThe TOON read options. Multiple options can be combined with | operator. 0 means no options.
indent_sizeSpaces per indentation level. Must match how the document being read was actually indented, or depths will be computed incorrectly (or, in strict mode, indentation that isn't an exact multiple of this value is rejected).
alcThe memory allocator used by TOON reader. Pass NULL to use the libc's default allocator.
errA pointer to receive error information. Pass NULL if you don't need error information.
Returns
A new TOON document, or NULL if an error occurs. When it's no longer needed, it should be freed with ctoon_doc_free().

◆ ctoon_set_bool()

static unsigned char ctoon_set_bool ( ctoon_val val,
unsigned char  num 
)
static

Set the value to bool. Returns false if input is NULL or val is object or array.

Warning
This will modify the immutable value, use with caution.

Definition at line 5080 of file ctoon.h.

◆ ctoon_set_double()

static unsigned char ctoon_set_double ( ctoon_val val,
double  num 
)
static

Set the value to double. Returns false if input is NULL or val is object or array.

Warning
This will modify the immutable value, use with caution.

Definition at line 5110 of file ctoon.h.

◆ ctoon_set_float()

static unsigned char ctoon_set_float ( ctoon_val val,
float  num 
)
static

Set the value to float. Returns false if input is NULL or val is object or array.

Warning
This will modify the immutable value, use with caution.

Definition at line 5104 of file ctoon.h.

◆ ctoon_set_fp_to_fixed()

static unsigned char ctoon_set_fp_to_fixed ( ctoon_val val,
int  prec 
)
static

Set the floating-point number's output format to fixed-point notation. Returns false if input is NULL or val is not real type.

See also
CTOON_WRITE_FP_TO_FIXED flag.
Warning
This will modify the immutable value, use with caution.

Definition at line 5122 of file ctoon.h.

◆ ctoon_set_fp_to_float()

static unsigned char ctoon_set_fp_to_float ( ctoon_val val,
unsigned char  flt 
)
static

Set the floating-point number's output format to single-precision. Returns false if input is NULL or val is not real type.

See also
CTOON_WRITE_FP_TO_FLOAT flag.
Warning
This will modify the immutable value, use with caution.

Definition at line 5128 of file ctoon.h.

◆ ctoon_set_int()

static unsigned char ctoon_set_int ( ctoon_val val,
int  num 
)
static

Set the value to int. Returns false if input is NULL or val is object or array.

Warning
This will modify the immutable value, use with caution.

Definition at line 5098 of file ctoon.h.

◆ ctoon_set_null()

static unsigned char ctoon_set_null ( ctoon_val val)
static

Set the value to null. Returns false if input is NULL or val is object or array.

Warning
This will modify the immutable value, use with caution.

Definition at line 5074 of file ctoon.h.

◆ ctoon_set_raw()

static unsigned char ctoon_set_raw ( ctoon_val val,
const char *  raw,
size_t  len 
)
static

Set the value to raw. Returns false if input is NULL or val is object or array.

Warning
This will modify the immutable value, use with caution.

Definition at line 5067 of file ctoon.h.

◆ ctoon_set_real()

static unsigned char ctoon_set_real ( ctoon_val val,
double  num 
)
static

Set the value to real. Returns false if input is NULL or val is object or array.

Warning
This will modify the immutable value, use with caution.

Definition at line 5116 of file ctoon.h.

◆ ctoon_set_sint()

static unsigned char ctoon_set_sint ( ctoon_val val,
int64_t  num 
)
static

Set the value to sint. Returns false if input is NULL or val is object or array.

Warning
This will modify the immutable value, use with caution.

Definition at line 5092 of file ctoon.h.

◆ ctoon_set_str()

static unsigned char ctoon_set_str ( ctoon_val val,
const char *  str 
)
static

Set the value to string (null-terminated). Returns false if input is NULL or val is object or array.

Warning
This will modify the immutable value, use with caution.

Definition at line 5134 of file ctoon.h.

◆ ctoon_set_str_noesc()

static unsigned char ctoon_set_str_noesc ( ctoon_val val,
unsigned char  noesc 
)
static

Marks this string as not needing to be escaped during TOON writing. This can be used to avoid the overhead of escaping if the string contains only characters that do not require escaping. Returns false if input is NULL or val is not string.

See also
CTOON_SUBTYPE_NOESC subtype.
Warning
This will modify the immutable value, use with caution.

Definition at line 5149 of file ctoon.h.

◆ ctoon_set_strn()

static unsigned char ctoon_set_strn ( ctoon_val val,
const char *  str,
size_t  len 
)
static

Set the value to string (with length). Returns false if input is NULL or val is object or array.

Warning
This will modify the immutable value, use with caution.

Definition at line 5141 of file ctoon.h.

◆ ctoon_set_uint()

static unsigned char ctoon_set_uint ( ctoon_val val,
uint64_t  num 
)
static

Set the value to uint. Returns false if input is NULL or val is object or array.

Warning
This will modify the immutable value, use with caution.

Definition at line 5086 of file ctoon.h.

◆ ctoon_val_mut_copy()

ctoon_mut_val * ctoon_val_mut_copy ( ctoon_mut_doc doc,
ctoon_val val 
)

Copies and returns a new mutable value from input, returns NULL on error. This makes a deep-copy on the immutable value. The memory was managed by mutable document.

Note
imut_val -> mut_val.

◆ ctoon_val_write()

static char * ctoon_val_write ( const ctoon_val val,
size_t *  len 
)
static

Definition at line 1312 of file ctoon.h.

References ctoon_val_write_opts().

◆ ctoon_val_write_opts()

char * ctoon_val_write_opts ( const ctoon_val val,
const ctoon_write_options opts,
const ctoon_alc alc,
size_t *  len,
ctoon_write_err err 
)

Write a single value (not a full document) to TOON string with options.

Referenced by ctoon_val_write().

◆ ctoon_version()

uint32_t ctoon_version ( void  )

The version of ctoon in hex, same as CTOON_VERSION_HEX.

◆ ctoon_write()

static char * ctoon_write ( const ctoon_doc doc,
size_t *  len 
)
static

Write a document with default options (indent=2, comma delimiter).

Definition at line 1287 of file ctoon.h.

References ctoon_write_opts().

◆ ctoon_write_file()

unsigned char ctoon_write_file ( const char *  path,
const ctoon_doc doc,
const ctoon_write_options opts,
const ctoon_alc alc,
ctoon_write_err err 
)

Write a document to file with full options.

◆ ctoon_write_fp()

unsigned char ctoon_write_fp ( FILE *  fp,
const ctoon_doc doc,
const ctoon_write_options opts,
const ctoon_alc alc,
ctoon_write_err err 
)

Write a document to file pointer with full options.

◆ ctoon_write_number()

char * ctoon_write_number ( const ctoon_val val,
char *  buf 
)

Write a TOON number value to a buffer (at least 40 bytes).

◆ ctoon_write_opts()

char * ctoon_write_opts ( const ctoon_doc doc,
const ctoon_write_options opts,
const ctoon_alc alc,
size_t *  len,
ctoon_write_err err 
)

Write a document to TOON string with full options.

Parameters
docThe TOON document.
optsWrite options (NULL = defaults: indent=2, comma delimiter).
alcAllocator, or NULL for libc default.
lenReceives output byte length (not including null-terminator); may be NULL.
errReceives error info; may be NULL.
Returns
Heap-allocated null-terminated TOON string, or NULL on error. Caller must free() the result (or use alc->free).

Referenced by ctoon_write().

◆ unsafe_ctoon_arr_is_flat()

static unsigned char unsafe_ctoon_arr_is_flat ( ctoon_val val)
static

Definition at line 4704 of file ctoon.h.

◆ unsafe_ctoon_equals()

unsigned char unsafe_ctoon_equals ( ctoon_val lhs,
ctoon_val rhs 
)

◆ unsafe_ctoon_equals_str()

static unsigned char unsafe_ctoon_equals_str ( void *  val,
const char *  str 
)
static

Definition at line 4772 of file ctoon.h.

◆ unsafe_ctoon_equals_strn()

static unsigned char unsafe_ctoon_equals_strn ( void *  val,
const char *  str,
size_t  len 
)
static

Definition at line 4766 of file ctoon.h.

◆ unsafe_ctoon_get_bool()

static unsigned char unsafe_ctoon_get_bool ( void *  val)
static

Definition at line 4714 of file ctoon.h.

◆ unsafe_ctoon_get_first()

static ctoon_val * unsafe_ctoon_get_first ( ctoon_val ctn)
static

Definition at line 4755 of file ctoon.h.

◆ unsafe_ctoon_get_int()

static int unsafe_ctoon_get_int ( void *  val)
static

Definition at line 4727 of file ctoon.h.

◆ unsafe_ctoon_get_len()

static size_t unsafe_ctoon_get_len ( void *  val)
static

Definition at line 4751 of file ctoon.h.

◆ unsafe_ctoon_get_next()

static ctoon_val * unsafe_ctoon_get_next ( ctoon_val val)
static

Definition at line 4759 of file ctoon.h.

◆ unsafe_ctoon_get_num()

static double unsafe_ctoon_get_num ( void *  val)
static

Definition at line 4735 of file ctoon.h.

◆ unsafe_ctoon_get_pointer()

static ctoon_val * unsafe_ctoon_get_pointer ( ctoon_val val,
const char *  ptr,
size_t  len 
)
static
Deprecated:
renamed to ctoon_mut_ptr_getn

Definition at line 7964 of file ctoon.h.

◆ unsafe_ctoon_get_raw()

static const char * unsafe_ctoon_get_raw ( void *  val)
static

Definition at line 4710 of file ctoon.h.

◆ unsafe_ctoon_get_real()

static double unsafe_ctoon_get_real ( void *  val)
static

Definition at line 4731 of file ctoon.h.

◆ unsafe_ctoon_get_sint()

static int64_t unsafe_ctoon_get_sint ( void *  val)
static

Definition at line 4723 of file ctoon.h.

◆ unsafe_ctoon_get_str()

static const char * unsafe_ctoon_get_str ( void *  val)
static

Definition at line 4747 of file ctoon.h.

◆ unsafe_ctoon_get_subtype()

static ctoon_subtype unsafe_ctoon_get_subtype ( void *  val)
static

Definition at line 4630 of file ctoon.h.

◆ unsafe_ctoon_get_tag()

static uint8_t unsafe_ctoon_get_tag ( void *  val)
static

Definition at line 4635 of file ctoon.h.

◆ unsafe_ctoon_get_type()

static ctoon_type unsafe_ctoon_get_type ( void *  val)
static

Definition at line 4625 of file ctoon.h.

◆ unsafe_ctoon_get_uint()

static uint64_t unsafe_ctoon_get_uint ( void *  val)
static

Definition at line 4719 of file ctoon.h.

◆ unsafe_ctoon_inc_len()

static void unsafe_ctoon_inc_len ( void *  val)
static

Definition at line 4798 of file ctoon.h.

◆ unsafe_ctoon_is_arr()

static unsigned char unsafe_ctoon_is_arr ( void *  val)
static

Definition at line 4660 of file ctoon.h.

◆ unsafe_ctoon_is_bool()

static unsigned char unsafe_ctoon_is_bool ( void *  val)
static

Definition at line 4648 of file ctoon.h.

◆ unsafe_ctoon_is_ctn()

static unsigned char unsafe_ctoon_is_ctn ( void *  val)
static

Definition at line 4668 of file ctoon.h.

◆ unsafe_ctoon_is_false()

static unsigned char unsafe_ctoon_is_false ( void *  val)
static

Definition at line 4699 of file ctoon.h.

◆ unsafe_ctoon_is_int()

static unsigned char unsafe_ctoon_is_int ( void *  val)
static

Definition at line 4683 of file ctoon.h.

◆ unsafe_ctoon_is_null()

static unsigned char unsafe_ctoon_is_null ( void *  val)
static

Definition at line 4644 of file ctoon.h.

◆ unsafe_ctoon_is_num()

static unsigned char unsafe_ctoon_is_num ( void *  val)
static

Definition at line 4652 of file ctoon.h.

◆ unsafe_ctoon_is_obj()

static unsigned char unsafe_ctoon_is_obj ( void *  val)
static

Definition at line 4664 of file ctoon.h.

◆ unsafe_ctoon_is_raw()

static unsigned char unsafe_ctoon_is_raw ( void *  val)
static

Definition at line 4640 of file ctoon.h.

◆ unsafe_ctoon_is_real()

static unsigned char unsafe_ctoon_is_real ( void *  val)
static

Definition at line 4689 of file ctoon.h.

◆ unsafe_ctoon_is_sint()

static unsigned char unsafe_ctoon_is_sint ( void *  val)
static

Definition at line 4678 of file ctoon.h.

◆ unsafe_ctoon_is_str()

static unsigned char unsafe_ctoon_is_str ( void *  val)
static

Definition at line 4656 of file ctoon.h.

◆ unsafe_ctoon_is_str_noesc()

static unsigned char unsafe_ctoon_is_str_noesc ( const char *  str,
size_t  len 
)
static

Definition at line 4575 of file ctoon.h.

References ctoon_constant_p.

◆ unsafe_ctoon_is_true()

static unsigned char unsafe_ctoon_is_true ( void *  val)
static

Definition at line 4694 of file ctoon.h.

◆ unsafe_ctoon_is_uint()

static unsigned char unsafe_ctoon_is_uint ( void *  val)
static

Definition at line 4673 of file ctoon.h.

◆ unsafe_ctoon_mut_equals()

unsigned char unsafe_ctoon_mut_equals ( ctoon_mut_val lhs,
ctoon_mut_val rhs 
)

◆ unsafe_ctoon_mut_get_pointer()

static ctoon_mut_val * unsafe_ctoon_mut_get_pointer ( ctoon_mut_val val,
const char *  ptr,
size_t  len 
)
static
Deprecated:
renamed to unsafe_ctoon_mut_ptr_getx

Definition at line 7973 of file ctoon.h.

◆ unsafe_ctoon_mut_obj_add()

static void unsafe_ctoon_mut_obj_add ( ctoon_mut_val obj,
ctoon_mut_val key,
ctoon_mut_val val,
size_t  len 
)
static

Definition at line 6721 of file ctoon.h.

◆ unsafe_ctoon_mut_obj_remove()

static ctoon_mut_val * unsafe_ctoon_mut_obj_remove ( ctoon_mut_val obj,
const char *  key,
size_t  key_len 
)
static

Definition at line 6738 of file ctoon.h.

◆ unsafe_ctoon_mut_obj_replace()

static unsigned char unsafe_ctoon_mut_obj_replace ( ctoon_mut_val obj,
ctoon_mut_val key,
ctoon_mut_val val 
)
static

Definition at line 6766 of file ctoon.h.

◆ unsafe_ctoon_mut_obj_rotate()

static void unsafe_ctoon_mut_obj_rotate ( ctoon_mut_val obj,
size_t  idx 
)
static

Definition at line 6788 of file ctoon.h.

◆ unsafe_ctoon_mut_ptr_getx()

ctoon_mut_val * unsafe_ctoon_mut_ptr_getx ( ctoon_mut_val val,
const char *  ptr,
size_t  len,
ctoon_ptr_ctx ctx,
ctoon_ptr_err err 
)

◆ unsafe_ctoon_mut_ptr_putx()

unsigned char unsafe_ctoon_mut_ptr_putx ( ctoon_mut_val val,
const char *  ptr,
size_t  len,
ctoon_mut_val new_val,
ctoon_mut_doc doc,
unsigned char  create_parent,
unsigned char  insert_new,
ctoon_ptr_ctx ctx,
ctoon_ptr_err err 
)

◆ unsafe_ctoon_mut_ptr_removex()

ctoon_mut_val * unsafe_ctoon_mut_ptr_removex ( ctoon_mut_val val,
const char *  ptr,
size_t  len,
ctoon_ptr_ctx ctx,
ctoon_ptr_err err 
)

◆ unsafe_ctoon_mut_ptr_replacex()

ctoon_mut_val * unsafe_ctoon_mut_ptr_replacex ( ctoon_mut_val val,
const char *  ptr,
size_t  len,
ctoon_mut_val new_val,
ctoon_ptr_ctx ctx,
ctoon_ptr_err err 
)

◆ unsafe_ctoon_mut_str_alc()

static char * unsafe_ctoon_mut_str_alc ( ctoon_mut_doc doc,
size_t  len 
)
static

Definition at line 5427 of file ctoon.h.

◆ unsafe_ctoon_mut_strncpy()

static char * unsafe_ctoon_mut_strncpy ( ctoon_mut_doc doc,
const char *  str,
size_t  len 
)
static

Definition at line 5442 of file ctoon.h.

◆ unsafe_ctoon_mut_val()

static ctoon_mut_val * unsafe_ctoon_mut_val ( ctoon_mut_doc doc,
size_t  count 
)
static

Definition at line 5451 of file ctoon.h.

◆ unsafe_ctoon_ptr_getx()

ctoon_val * unsafe_ctoon_ptr_getx ( ctoon_val val,
const char *  ptr,
size_t  len,
ctoon_ptr_err err 
)

◆ unsafe_ctoon_set_arr()

static void unsafe_ctoon_set_arr ( void *  val,
size_t  size 
)
static

Definition at line 4875 of file ctoon.h.

◆ unsafe_ctoon_set_bool()

static void unsafe_ctoon_set_bool ( void *  val,
unsigned char  num 
)
static

Definition at line 4814 of file ctoon.h.

◆ unsafe_ctoon_set_double()

static void unsafe_ctoon_set_double ( void *  val,
double  num 
)
static

Definition at line 4846 of file ctoon.h.

◆ unsafe_ctoon_set_float()

static void unsafe_ctoon_set_float ( void *  val,
float  num 
)
static

Definition at line 4840 of file ctoon.h.

◆ unsafe_ctoon_set_fp_to_fixed()

static void unsafe_ctoon_set_fp_to_fixed ( void *  val,
int  prec 
)
static

Definition at line 4829 of file ctoon.h.

◆ unsafe_ctoon_set_fp_to_float()

static void unsafe_ctoon_set_fp_to_float ( void *  val,
unsigned char  flt 
)
static

Definition at line 4834 of file ctoon.h.

◆ unsafe_ctoon_set_len()

static void unsafe_ctoon_set_len ( void *  val,
size_t  len 
)
static

Definition at line 4784 of file ctoon.h.

◆ unsafe_ctoon_set_null()

static void unsafe_ctoon_set_null ( void *  val)
static

Definition at line 4810 of file ctoon.h.

◆ unsafe_ctoon_set_obj()

static void unsafe_ctoon_set_obj ( void *  val,
size_t  size 
)
static

Definition at line 4879 of file ctoon.h.

◆ unsafe_ctoon_set_raw()

static void unsafe_ctoon_set_raw ( void *  val,
const char *  raw,
size_t  len 
)
static

Definition at line 4804 of file ctoon.h.

◆ unsafe_ctoon_set_real()

static void unsafe_ctoon_set_real ( void *  val,
double  num 
)
static

Definition at line 4851 of file ctoon.h.

◆ unsafe_ctoon_set_sint()

static void unsafe_ctoon_set_sint ( void *  val,
int64_t  num 
)
static

Definition at line 4824 of file ctoon.h.

◆ unsafe_ctoon_set_str()

static void unsafe_ctoon_set_str ( void *  val,
const char *  str 
)
static

Definition at line 4867 of file ctoon.h.

◆ unsafe_ctoon_set_str_noesc()

static void unsafe_ctoon_set_str_noesc ( void *  val,
unsigned char  noesc 
)
static

Definition at line 4856 of file ctoon.h.

◆ unsafe_ctoon_set_strn()

static void unsafe_ctoon_set_strn ( void *  val,
const char *  str,
size_t  len 
)
static

Definition at line 4861 of file ctoon.h.

◆ unsafe_ctoon_set_tag()

static void unsafe_ctoon_set_tag ( void *  val,
ctoon_type  type,
ctoon_subtype  subtype,
size_t  len 
)
static

Definition at line 4790 of file ctoon.h.

◆ unsafe_ctoon_set_type()

static void unsafe_ctoon_set_type ( void *  val,
ctoon_type  type,
ctoon_subtype  subtype 
)
static

Definition at line 4776 of file ctoon.h.

◆ unsafe_ctoon_set_uint()

static void unsafe_ctoon_set_uint ( void *  val,
uint64_t  num 
)
static

Definition at line 4819 of file ctoon.h.

◆ unsafe_ctoon_str_pool_grow()

unsigned char unsafe_ctoon_str_pool_grow ( ctoon_str_pool pool,
const ctoon_alc alc,
size_t  len 
)

◆ unsafe_ctoon_u64_to_f64()

static double unsafe_ctoon_u64_to_f64 ( uint64_t  num)
static

Definition at line 4612 of file ctoon.h.

◆ unsafe_ctoon_val_pool_grow()

unsigned char unsafe_ctoon_val_pool_grow ( ctoon_val_pool pool,
const ctoon_alc alc,
size_t  count 
)

Variable Documentation

◆ CTOON_PATCH_ERROR_EQUAL

const ctoon_patch_code CTOON_PATCH_ERROR_EQUAL = 6
static

TOON patch operation test not equal.

Definition at line 4445 of file ctoon.h.

◆ CTOON_PATCH_ERROR_INVALID_MEMBER

const ctoon_patch_code CTOON_PATCH_ERROR_INVALID_MEMBER = 5
static

TOON patch operation member is invalid.

Definition at line 4442 of file ctoon.h.

◆ CTOON_PATCH_ERROR_INVALID_OPERATION

const ctoon_patch_code CTOON_PATCH_ERROR_INVALID_OPERATION = 3
static

TOON patch operation is not object type.

Definition at line 4436 of file ctoon.h.

◆ CTOON_PATCH_ERROR_INVALID_PARAMETER

const ctoon_patch_code CTOON_PATCH_ERROR_INVALID_PARAMETER = 1
static

Invalid parameter, such as NULL input or non-array patch.

Definition at line 4430 of file ctoon.h.

◆ CTOON_PATCH_ERROR_MEMORY_ALLOCATION

const ctoon_patch_code CTOON_PATCH_ERROR_MEMORY_ALLOCATION = 2
static

Memory allocation failure occurs.

Definition at line 4433 of file ctoon.h.

◆ CTOON_PATCH_ERROR_MISSING_KEY

const ctoon_patch_code CTOON_PATCH_ERROR_MISSING_KEY = 4
static

TOON patch operation is missing a required key.

Definition at line 4439 of file ctoon.h.

◆ CTOON_PATCH_ERROR_POINTER

const ctoon_patch_code CTOON_PATCH_ERROR_POINTER = 7
static

TOON patch operation failed on TOON pointer.

Definition at line 4448 of file ctoon.h.

◆ CTOON_PATCH_SUCCESS

const ctoon_patch_code CTOON_PATCH_SUCCESS = 0
static

Success, no error.

Definition at line 4427 of file ctoon.h.

◆ CTOON_PTR_ERR_MEMORY_ALLOCATION

const ctoon_ptr_code CTOON_PTR_ERR_MEMORY_ALLOCATION = 6
static

The memory allocation failed and a new value could not be created.

Definition at line 3860 of file ctoon.h.

◆ CTOON_PTR_ERR_NONE

const ctoon_ptr_code CTOON_PTR_ERR_NONE = 0
static

No TOON pointer error.

Definition at line 3842 of file ctoon.h.

◆ CTOON_PTR_ERR_NULL_ROOT

const ctoon_ptr_code CTOON_PTR_ERR_NULL_ROOT = 4
static

Document's root is NULL, but it is required for the function call.

Definition at line 3854 of file ctoon.h.

◆ CTOON_PTR_ERR_PARAMETER

const ctoon_ptr_code CTOON_PTR_ERR_PARAMETER = 1
static

Invalid input parameter, such as NULL input.

Definition at line 3845 of file ctoon.h.

◆ CTOON_PTR_ERR_RESOLVE

const ctoon_ptr_code CTOON_PTR_ERR_RESOLVE = 3
static

TOON pointer resolve failed, such as index out of range, key not found.

Definition at line 3851 of file ctoon.h.

◆ CTOON_PTR_ERR_SET_ROOT

const ctoon_ptr_code CTOON_PTR_ERR_SET_ROOT = 5
static

Cannot set root as the target is not a document.

Definition at line 3857 of file ctoon.h.

◆ CTOON_PTR_ERR_SYNTAX

const ctoon_ptr_code CTOON_PTR_ERR_SYNTAX = 2
static

TOON pointer syntax error, such as invalid escape, token no prefix.

Definition at line 3848 of file ctoon.h.

◆ CTOON_READ_ALLOW_BOM

const ctoon_read_flag CTOON_READ_ALLOW_BOM = 1 << 8
static

Allow UTF-8 BOM and skip it before parsing if any (non-standard).

Definition at line 782 of file ctoon.h.

◆ CTOON_READ_ALLOW_COMMENTS

const ctoon_read_flag CTOON_READ_ALLOW_COMMENTS = 1 << 3
static

Allow C-style single-line and mult-line comments (non-standard).

Definition at line 755 of file ctoon.h.

◆ CTOON_READ_ALLOW_EXT_ESCAPE

const ctoon_read_flag CTOON_READ_ALLOW_EXT_ESCAPE = 1 << 10
static

Allow extended escape sequences in strings (non-standard):

  • Additional escapes: \a, \e, \v, \', \?, \0.
  • Hex escapes: \xNN, such as \x7B.
  • Line continuation: backslash followed by line terminator sequences.
  • Unknown escape: if backslash is followed by an unsupported character, the backslash will be removed and the character will be kept as-is. However, \1-\9 will still trigger an error.

Definition at line 797 of file ctoon.h.

◆ CTOON_READ_ALLOW_EXT_NUMBER

const ctoon_read_flag CTOON_READ_ALLOW_EXT_NUMBER = 1 << 9
static

Allow extended number formats (non-standard):

  • Hexadecimal numbers, such as 0x7B.
  • Numbers with leading or trailing decimal point, such as .123, 123..
  • Numbers with a leading plus sign, such as +123.

Definition at line 788 of file ctoon.h.

◆ CTOON_READ_ALLOW_EXT_WHITESPACE

const ctoon_read_flag CTOON_READ_ALLOW_EXT_WHITESPACE = 1 << 11
static

Allow extended whitespace characters (non-standard):

  • Vertical tab \v and form feed \f.
  • Line separator \u2028 and paragraph separator \u2029.
  • Non-breaking space \xA0.
  • Byte order mark: \uFEFF.
  • Other Unicode characters in the Zs (Separator, space) category.

Definition at line 805 of file ctoon.h.

◆ CTOON_READ_ALLOW_INF_AND_NAN

const ctoon_read_flag CTOON_READ_ALLOW_INF_AND_NAN = 1 << 4
static

Allow inf/nan number and literal, case-insensitive, such as 1e999, NaN, inf, -Infinity (non-standard).

Definition at line 759 of file ctoon.h.

◆ CTOON_READ_ALLOW_INVALID_UNICODE

const ctoon_read_flag CTOON_READ_ALLOW_INVALID_UNICODE = 1 << 6
static

Allow reading invalid unicode when parsing string values (non-standard). Invalid characters will be allowed to appear in the string values, but invalid escape sequences will still be reported as errors. This flag does not affect the performance of correctly encoded strings.

Warning
Strings in TOON values may contain incorrect encoding when this option is used, you need to handle these strings carefully to avoid security risks.

Definition at line 773 of file ctoon.h.

◆ CTOON_READ_ALLOW_SINGLE_QUOTED_STR

const ctoon_read_flag CTOON_READ_ALLOW_SINGLE_QUOTED_STR = 1 << 12
static

Allow strings enclosed in single quotes (non-standard), such as 'ab'.

Definition at line 808 of file ctoon.h.

◆ CTOON_READ_ALLOW_TRAILING_COMMAS

const ctoon_read_flag CTOON_READ_ALLOW_TRAILING_COMMAS = 1 << 2
static

Allow single trailing comma at the end of an object or array, such as [1,2,3,], {"a":1,"b":2,} (non-standard).

Definition at line 752 of file ctoon.h.

◆ CTOON_READ_ALLOW_UNQUOTED_KEY

const ctoon_read_flag CTOON_READ_ALLOW_UNQUOTED_KEY = 1 << 13
static

Allow object keys without quotes (non-standard), such as {a:1,b:2}. This extends the ECMAScript IdentifierName rule by allowing any non-whitespace character with code point above U+007F.

Definition at line 813 of file ctoon.h.

◆ CTOON_READ_BIGNUM_AS_RAW

const ctoon_read_flag CTOON_READ_BIGNUM_AS_RAW = 1 << 7
static

Read big numbers as raw strings. These big numbers include integers that cannot be represented by int64_t and uint64_t, and floating-point numbers that cannot be represented by finite double. The flag will be overridden by CTOON_READ_NUMBER_AS_RAW flag.

Definition at line 779 of file ctoon.h.

◆ CTOON_READ_ERROR_DEPTH

const ctoon_read_code CTOON_READ_ERROR_DEPTH = 15
static

Read depth limit exceeded.

Definition at line 881 of file ctoon.h.

◆ CTOON_READ_ERROR_EMPTY_CONTENT

const ctoon_read_code CTOON_READ_ERROR_EMPTY_CONTENT = 3
static

Input TOON string is empty.

Definition at line 845 of file ctoon.h.

◆ CTOON_READ_ERROR_FILE_OPEN

const ctoon_read_code CTOON_READ_ERROR_FILE_OPEN = 12
static

Failed to open a file.

Definition at line 872 of file ctoon.h.

◆ CTOON_READ_ERROR_FILE_READ

const ctoon_read_code CTOON_READ_ERROR_FILE_READ = 13
static

Failed to read a file.

Definition at line 875 of file ctoon.h.

◆ CTOON_READ_ERROR_INVALID_COMMENT

const ctoon_read_code CTOON_READ_ERROR_INVALID_COMMENT = 8
static

Invalid comment, deprecated, use UNEXPECTED_END for unclosed comment.

Definition at line 860 of file ctoon.h.

◆ CTOON_READ_ERROR_INVALID_NUMBER

const ctoon_read_code CTOON_READ_ERROR_INVALID_NUMBER = 9
static

Invalid number, such as 123.e12, 000.

Definition at line 863 of file ctoon.h.

◆ CTOON_READ_ERROR_INVALID_PARAMETER

const ctoon_read_code CTOON_READ_ERROR_INVALID_PARAMETER = 1
static

Invalid parameter, such as NULL input string or 0 input length.

Definition at line 839 of file ctoon.h.

◆ CTOON_READ_ERROR_INVALID_STRING

const ctoon_read_code CTOON_READ_ERROR_INVALID_STRING = 10
static

Invalid string, such as invalid escaped character inside a string.

Definition at line 866 of file ctoon.h.

◆ CTOON_READ_ERROR_LITERAL

const ctoon_read_code CTOON_READ_ERROR_LITERAL = 11
static

Invalid TOON literal, such as truu.

Definition at line 869 of file ctoon.h.

◆ CTOON_READ_ERROR_MEMORY_ALLOCATION

const ctoon_read_code CTOON_READ_ERROR_MEMORY_ALLOCATION = 2
static

Memory allocation failed.

Definition at line 842 of file ctoon.h.

◆ CTOON_READ_ERROR_MORE

const ctoon_read_code CTOON_READ_ERROR_MORE = 14
static

Incomplete input during incremental parsing; parsing state is preserved.

Definition at line 878 of file ctoon.h.

◆ CTOON_READ_ERROR_TOON_STRUCTURE

const ctoon_read_code CTOON_READ_ERROR_TOON_STRUCTURE = 7
static

Invalid TOON structure, such as [1,].

Definition at line 857 of file ctoon.h.

◆ CTOON_READ_ERROR_UNEXPECTED_CHARACTER

const ctoon_read_code CTOON_READ_ERROR_UNEXPECTED_CHARACTER = 6
static

Unexpected character inside the document, such as [abc].

Definition at line 854 of file ctoon.h.

◆ CTOON_READ_ERROR_UNEXPECTED_CONTENT

const ctoon_read_code CTOON_READ_ERROR_UNEXPECTED_CONTENT = 4
static

Unexpected content after document, such as [123]abc.

Definition at line 848 of file ctoon.h.

◆ CTOON_READ_ERROR_UNEXPECTED_END

const ctoon_read_code CTOON_READ_ERROR_UNEXPECTED_END = 5
static

Unexpected end of input, the parsed part is valid, such as [123.

Definition at line 851 of file ctoon.h.

◆ CTOON_READ_INSITU

const ctoon_read_flag CTOON_READ_INSITU = 1 << 0
static

Read the input data in-situ. This option allows the reader to modify and use input data to store string values, which can increase reading speed slightly. The caller should hold the input data before free the document. The input data must be padded by at least CTOON_PADDING_SIZE bytes. For example: [1,2] should be [1,2]\0\0\0\0, input length should be 5.

Definition at line 743 of file ctoon.h.

Referenced by ctoon_read_max_memory_usage().

◆ CTOON_READ_NOFLAG

const ctoon_read_flag CTOON_READ_NOFLAG = 0
static

Default option (RFC 8259 compliant):

  • Read positive integer as uint64_t.
  • Read negative integer as int64_t.
  • Read floating-point number as double with round-to-nearest mode.
  • Read integer which cannot fit in uint64_t or int64_t as double.
  • Report error if double number is infinity.
  • Report error if string contains invalid UTF-8 character or BOM.
  • Report error on trailing commas, comments, inf and nan literals.

Definition at line 735 of file ctoon.h.

◆ CTOON_READ_NUMBER_AS_RAW

const ctoon_read_flag CTOON_READ_NUMBER_AS_RAW = 1 << 5
static

Read all numbers as raw strings (value with CTOON_TYPE_RAW type), inf/nan literal is also read as raw with ALLOW_INF_AND_NAN flag.

Definition at line 763 of file ctoon.h.

◆ CTOON_READ_STOP_WHEN_DONE

const ctoon_read_flag CTOON_READ_STOP_WHEN_DONE = 1 << 1
static

Stop when done instead of issuing an error if there's additional content after a TOON document. This option may be used to parse small pieces of TOON in larger data, such as NDTOON.

Definition at line 748 of file ctoon.h.

Referenced by ctoon_read_max_memory_usage().

◆ CTOON_READ_SUCCESS

const ctoon_read_code CTOON_READ_SUCCESS = 0
static

Success, no error.

Definition at line 836 of file ctoon.h.

◆ CTOON_READ_TOON5

const ctoon_read_flag CTOON_READ_TOON5
static
Initial value:
=
(1 << 2) |
(1 << 3) |
(1 << 4) |
(1 << 9) |
(1 << 10) |
(1 << 11) |
(1 << 12) |
(1 << 13)

Allow TOON5 format, see: [https://json5.org]. This flag supports all TOON5 features with some additional extensions:

  • Accepts more escape sequences than TOON5 (e.g. \a, \e).
  • Unquoted keys are not limited to ECMAScript IdentifierName.
  • Allow case-insensitive NaN, Inf and Infinity literals.

Definition at line 820 of file ctoon.h.

◆ CTOON_WRITE_ALLOW_INF_AND_NAN

const ctoon_write_flag CTOON_WRITE_ALLOW_INF_AND_NAN = 1 << 3
static

Write inf and nan as 'Infinity' and 'NaN' literals (non-standard).

Definition at line 1207 of file ctoon.h.

◆ CTOON_WRITE_ALLOW_INVALID_UNICODE

const ctoon_write_flag CTOON_WRITE_ALLOW_INVALID_UNICODE = 1 << 5
static

Allow invalid unicode bytes to be copied as-is.

Definition at line 1213 of file ctoon.h.

◆ CTOON_WRITE_ERROR_FILE_OPEN

const ctoon_write_code CTOON_WRITE_ERROR_FILE_OPEN = 5
static

Definition at line 1250 of file ctoon.h.

◆ CTOON_WRITE_ERROR_FILE_WRITE

const ctoon_write_code CTOON_WRITE_ERROR_FILE_WRITE = 6
static

Definition at line 1251 of file ctoon.h.

◆ CTOON_WRITE_ERROR_INVALID_PARAMETER

const ctoon_write_code CTOON_WRITE_ERROR_INVALID_PARAMETER = 1
static

Definition at line 1246 of file ctoon.h.

◆ CTOON_WRITE_ERROR_INVALID_STRING

const ctoon_write_code CTOON_WRITE_ERROR_INVALID_STRING = 7
static

Definition at line 1252 of file ctoon.h.

◆ CTOON_WRITE_ERROR_INVALID_VALUE_TYPE

const ctoon_write_code CTOON_WRITE_ERROR_INVALID_VALUE_TYPE = 3
static

Definition at line 1248 of file ctoon.h.

◆ CTOON_WRITE_ERROR_MEMORY_ALLOCATION

const ctoon_write_code CTOON_WRITE_ERROR_MEMORY_ALLOCATION = 2
static

Definition at line 1247 of file ctoon.h.

◆ CTOON_WRITE_ERROR_NAN_OR_INF

const ctoon_write_code CTOON_WRITE_ERROR_NAN_OR_INF = 4
static

Definition at line 1249 of file ctoon.h.

◆ CTOON_WRITE_ESCAPE_SLASHES

const ctoon_write_flag CTOON_WRITE_ESCAPE_SLASHES = 1 << 2
static

Escape '/' as '\/'.

Definition at line 1204 of file ctoon.h.

◆ CTOON_WRITE_ESCAPE_UNICODE

const ctoon_write_flag CTOON_WRITE_ESCAPE_UNICODE = 1 << 1
static

Escape unicode as \uXXXX, making output ASCII-only.

Definition at line 1201 of file ctoon.h.

◆ CTOON_WRITE_INF_AND_NAN_AS_NULL

const ctoon_write_flag CTOON_WRITE_INF_AND_NAN_AS_NULL = 1 << 4
static

Write inf and nan as null literal (overrides ALLOW_INF_AND_NAN).

Definition at line 1210 of file ctoon.h.

◆ CTOON_WRITE_LENGTH_MARKER

const ctoon_write_flag CTOON_WRITE_LENGTH_MARKER = 1 << 6
static

Prefix array lengths with '#': items[#3]: ...

Definition at line 1216 of file ctoon.h.

◆ CTOON_WRITE_NEWLINE_AT_END

const ctoon_write_flag CTOON_WRITE_NEWLINE_AT_END = 1 << 7
static

Add a trailing newline at the end of output.

Definition at line 1219 of file ctoon.h.

◆ CTOON_WRITE_NOFLAG

const ctoon_write_flag CTOON_WRITE_NOFLAG = 0
static

Default: write canonical TOON, report error on inf/nan, no unicode escape.

Definition at line 1198 of file ctoon.h.

◆ CTOON_WRITE_SUCCESS

const ctoon_write_code CTOON_WRITE_SUCCESS = 0
static

Definition at line 1245 of file ctoon.h.