Fossil SCM

Latest upstream cson - increases a unicode output buffer size after reports of certain MSVC version(s) complaining about it.

stephan 2018-01-09 20:34 trunk
Commit e508424e7d7863e1133d9ea2aa685ab374396cda38578ae8162a3da91fda1647
--- src/cson_amalgamation.c
+++ src/cson_amalgamation.c
@@ -19,14 +19,14 @@
1919
# define JSON_PARSER_DLL_API __declspec(dllexport)
2020
# else
2121
# define JSON_PARSER_DLL_API __declspec(dllimport)
2222
# endif
2323
# else
24
-# define JSON_PARSER_DLL_API
24
+# define JSON_PARSER_DLL_API
2525
# endif
2626
#else
27
-# define JSON_PARSER_DLL_API
27
+# define JSON_PARSER_DLL_API
2828
#endif
2929
3030
/* Determine the integer type use to parse non-floating point numbers */
3131
#ifdef _WIN32
3232
typedef __int64 JSON_int_t;
@@ -34,22 +34,22 @@
3434
#define JSON_PARSER_INTEGER_SPRINTF_TOKEN "%I64d"
3535
#elif (__STDC_VERSION__ >= 199901L) || (HAVE_LONG_LONG == 1)
3636
typedef long long JSON_int_t;
3737
#define JSON_PARSER_INTEGER_SSCANF_TOKEN "%lld"
3838
#define JSON_PARSER_INTEGER_SPRINTF_TOKEN "%lld"
39
-#else
39
+#else
4040
typedef long JSON_int_t;
4141
#define JSON_PARSER_INTEGER_SSCANF_TOKEN "%ld"
4242
#define JSON_PARSER_INTEGER_SPRINTF_TOKEN "%ld"
4343
#endif
4444
4545
4646
#ifdef __cplusplus
4747
extern "C" {
48
-#endif
48
+#endif
4949
50
-typedef enum
50
+typedef enum
5151
{
5252
JSON_E_NONE = 0,
5353
JSON_E_INVALID_CHAR,
5454
JSON_E_INVALID_KEYWORD,
5555
JSON_E_INVALID_ESCAPE_SEQUENCE,
@@ -60,11 +60,11 @@
6060
JSON_E_EXPECTED_KEY,
6161
JSON_E_EXPECTED_COLON,
6262
JSON_E_OUT_OF_MEMORY
6363
} JSON_error;
6464
65
-typedef enum
65
+typedef enum
6666
{
6767
JSON_T_NONE = 0,
6868
JSON_T_ARRAY_BEGIN,
6969
JSON_T_ARRAY_END,
7070
JSON_T_OBJECT_BEGIN,
@@ -80,33 +80,33 @@
8080
} JSON_type;
8181
8282
typedef struct JSON_value_struct {
8383
union {
8484
JSON_int_t integer_value;
85
-
85
+
8686
double float_value;
87
-
87
+
8888
struct {
8989
const char* value;
9090
size_t length;
9191
} str;
9292
} vu;
9393
} JSON_value;
9494
9595
typedef struct JSON_parser_struct* JSON_parser;
9696
97
-/*! \brief JSON parser callback
97
+/*! \brief JSON parser callback
9898
9999
\param ctx The pointer passed to new_JSON_parser.
100
- \param type An element of JSON_type but not JSON_T_NONE.
100
+ \param type An element of JSON_type but not JSON_T_NONE.
101101
\param value A representation of the parsed value. This parameter is NULL for
102102
JSON_T_ARRAY_BEGIN, JSON_T_ARRAY_END, JSON_T_OBJECT_BEGIN, JSON_T_OBJECT_END,
103103
JSON_T_NULL, JSON_T_TRUE, and JSON_T_FALSE. String values are always returned
104104
as zero-terminated C strings.
105105
106106
\return Non-zero if parsing should continue, else zero.
107
-*/
107
+*/
108108
typedef int (*JSON_parser_callback)(void* ctx, int type, const JSON_value* value);
109109
110110
111111
/**
112112
A typedef for allocator functions semantically compatible with malloc().
@@ -115,11 +115,11 @@
115115
/**
116116
A typedef for deallocator functions semantically compatible with free().
117117
*/
118118
typedef void (*JSON_free_t)(void* mem);
119119
120
-/*! \brief The structure used to configure a JSON parser object
120
+/*! \brief The structure used to configure a JSON parser object
121121
*/
122122
typedef struct {
123123
/** Pointer to a callback, called when the parser has something to tell
124124
the user. This parameter may be NULL. In this case the input is
125125
merely checked for validity.
@@ -176,17 +176,17 @@
176176
177177
\param config. Used to configure the parser.
178178
*/
179179
JSON_PARSER_DLL_API void init_JSON_config(JSON_config * config);
180180
181
-/*! \brief Create a JSON parser object
181
+/*! \brief Create a JSON parser object
182182
183183
\param config. Used to configure the parser. Set to NULL to use
184184
the default configuration. See init_JSON_config. Its contents are
185185
copied by this function, so it need not outlive the returned
186186
object.
187
-
187
+
188188
\return The parser object, which is owned by the caller and must eventually
189189
be freed by calling delete_JSON_parser().
190190
*/
191191
JSON_PARSER_DLL_API JSON_parser new_JSON_parser(JSON_config const* config);
192192
@@ -200,16 +200,16 @@
200200
JSON_PARSER_DLL_API int JSON_parser_char(JSON_parser jc, int next_char);
201201
202202
/*! \brief Finalize parsing.
203203
204204
Call this method once after all input characters have been consumed.
205
-
205
+
206206
\return Non-zero, if all parsed characters are valid JSON, zero otherwise.
207207
*/
208208
JSON_PARSER_DLL_API int JSON_parser_done(JSON_parser jc);
209209
210
-/*! \brief Determine if a given string is valid JSON white space
210
+/*! \brief Determine if a given string is valid JSON white space
211211
212212
\return Non-zero if the string is valid, zero otherwise.
213213
*/
214214
JSON_PARSER_DLL_API int JSON_parser_is_legal_white_space_string(const char* s);
215215
@@ -226,12 +226,12 @@
226226
JSON_PARSER_DLL_API int JSON_parser_reset(JSON_parser jc);
227227
228228
229229
#ifdef __cplusplus
230230
}
231
-#endif
232
-
231
+#endif
232
+
233233
234234
#endif /* JSON_PARSER_H */
235235
/* end file parser/JSON_parser.h */
236236
/* begin file parser/JSON_parser.c */
237237
/*
@@ -1431,11 +1431,11 @@
14311431
#if defined(__cplusplus)
14321432
extern "C" {
14331433
#endif
14341434
14351435
1436
-
1436
+
14371437
/**
14381438
This type holds the "vtbl" for type-specific operations when
14391439
working with cson_value objects.
14401440
14411441
All cson_values of a given logical type share a pointer to a single
@@ -1583,11 +1583,11 @@
15831583
*/
15841584
#define CSON_CAST(T,V) ((T*)((V)->value))
15851585
/**
15861586
Assumes V is a pointer to memory which is allocated as part of a
15871587
cson_value instance (the bytes immediately after that part).
1588
- Returns a pointer a cson_value by subtracting sizeof(cson_value)
1588
+ Returns a pointer a a cson_value by subtracting sizeof(cson_value)
15891589
from that address and casting it to a (cson_value*)
15901590
*/
15911591
#define CSON_VCAST(V) ((cson_value *)(((unsigned char *)(V))-sizeof(cson_value)))
15921592
15931593
/**
@@ -1607,11 +1607,11 @@
16071607
#define CSON_OBJ(V) CSON_CAST(cson_object,(V))
16081608
#define CSON_ARRAY(V) CSON_CAST(cson_array,(V))
16091609
16101610
/**
16111611
Holds special shared "constant" (though they are non-const)
1612
- values.
1612
+ values.
16131613
*/
16141614
static struct CSON_EMPTY_HOLDER_
16151615
{
16161616
char trueValue;
16171617
cson_string stringValue;
@@ -1620,17 +1620,17 @@
16201620
cson_string_empty_m
16211621
};
16221622
16231623
/**
16241624
Indexes into the CSON_SPECIAL_VALUES array.
1625
-
1625
+
16261626
If this enum changes in any way,
16271627
makes damned sure that CSON_SPECIAL_VALUES is updated
16281628
to match!!!
16291629
*/
16301630
enum CSON_INTERNAL_VALUES {
1631
-
1631
+
16321632
CSON_VAL_UNDEF = 0,
16331633
CSON_VAL_NULL = 1,
16341634
CSON_VAL_TRUE = 2,
16351635
CSON_VAL_FALSE = 3,
16361636
CSON_VAL_INT_0 = 4,
@@ -1642,11 +1642,11 @@
16421642
/**
16431643
Some "special" shared cson_value instances.
16441644
16451645
These values MUST be initialized in the order specified
16461646
by the CSON_INTERNAL_VALUES enum.
1647
-
1647
+
16481648
Note that they are not const because they are used as
16491649
shared-allocation objects in non-const contexts. However, the
16501650
public API provides no way to modifying them, and clients who
16511651
modify values directly are subject to The Wrath of Undefined
16521652
Behaviour.
@@ -1665,11 +1665,11 @@
16651665
16661666
/**
16671667
Returns non-0 (true) if m is one of our special
16681668
"built-in" values, e.g. from CSON_SPECIAL_VALUES and some
16691669
"empty" values.
1670
-
1670
+
16711671
If this returns true, m MUST NOT be free()d!
16721672
*/
16731673
static char cson_value_is_builtin( void const * m )
16741674
{
16751675
if((m >= (void const *)&CSON_EMPTY_HOLDER)
@@ -2183,11 +2183,11 @@
21832183
static int cson_value_list_visit( cson_value_list * self,
21842184
int (*visitor)(cson_value * obj, void * visitorState ),
21852185
void * visitorState );
21862186
#endif
21872187
#endif
2188
-
2188
+
21892189
#if 0
21902190
# define LIST_T cson_value_list
21912191
# define VALUE_T cson_value *
21922192
# define VALUE_T_IS_PTR 1
21932193
# define LIST_T cson_kvp_list
@@ -2362,11 +2362,11 @@
23622362
return cson_value_object_alloc();
23632363
}
23642364
23652365
cson_object * cson_new_object()
23662366
{
2367
-
2367
+
23682368
return cson_value_get_object( cson_value_new_object() );
23692369
}
23702370
23712371
cson_value * cson_value_new_array()
23722372
{
@@ -2608,11 +2608,11 @@
26082608
{
26092609
cson_int_t i = 0;
26102610
int rc = 0;
26112611
switch(val->api->typeID)
26122612
{
2613
- case CSON_TYPE_UNDEF:
2613
+ case CSON_TYPE_UNDEF:
26142614
case CSON_TYPE_NULL:
26152615
i = 0;
26162616
break;
26172617
case CSON_TYPE_BOOL: {
26182618
char b = 0;
@@ -2661,11 +2661,11 @@
26612661
{
26622662
cson_double_t d = 0.0;
26632663
int rc = 0;
26642664
switch(val->api->typeID)
26652665
{
2666
- case CSON_TYPE_UNDEF:
2666
+ case CSON_TYPE_UNDEF:
26672667
case CSON_TYPE_NULL:
26682668
d = 0;
26692669
break;
26702670
case CSON_TYPE_BOOL: {
26712671
char b = 0;
@@ -2791,11 +2791,11 @@
27912791
#if 0
27922792
/**
27932793
Removes and returns the last value from the given array,
27942794
shrinking its size by 1. Returns NULL if ar is NULL,
27952795
ar->list.count is 0, or the element at that index is NULL.
2796
-
2796
+
27972797
27982798
If removeRef is true then cson_value_free() is called to remove
27992799
ar's reference count for the value. In that case NULL is returned,
28002800
even if the object still has live references. If removeRef is false
28012801
then the caller takes over ownership of that reference count point.
@@ -2858,11 +2858,11 @@
28582858
#if !defined(NDEBUG) && CSON_VOID_PTR_IS_BIG
28592859
assert( sizeof(cson_int_t) <= sizeof(void *) );
28602860
#endif
28612861
if( c )
28622862
{
2863
- memcpy(CSON_INT(c), &v, sizeof(v));
2863
+ memcpy( CSON_INT(c), &v, sizeof(v) );
28642864
}
28652865
return c;
28662866
}
28672867
}
28682868
@@ -2877,11 +2877,11 @@
28772877
else
28782878
{
28792879
cson_value * c = cson_value_new(CSON_TYPE_DOUBLE,0);
28802880
if( c )
28812881
{
2882
- memcpy(CSON_DBL(c), &v, sizeof(v));
2882
+ memcpy( CSON_DBL(c), &v, sizeof(v) );
28832883
}
28842884
return c;
28852885
}
28862886
}
28872887
@@ -3068,11 +3068,11 @@
30683068
qsort( obj->kvp.list, obj->kvp.count, sizeof(cson_kvp*),
30693069
cson_kvp_cmp );
30703070
}
30713071
30723072
}
3073
-#endif
3073
+#endif
30743074
30753075
int cson_object_unset( cson_object * obj, char const * key )
30763076
{
30773077
if( ! obj || !key || !*key ) return cson_rc.ArgError;
30783078
else
@@ -3238,11 +3238,11 @@
32383238
using p->key. In any other case cson_rc.InternalError is returned.
32393239
32403240
Returns cson_rc.AllocError if an allocation fails.
32413241
32423242
Returns 0 on success. On error, parsing must be ceased immediately.
3243
-
3243
+
32443244
Ownership of val is ALWAYS TRANSFERED to this function. If this
32453245
function fails, val will be cleaned up and destroyed. (This
32463246
simplifies error handling in the core parser.)
32473247
*/
32483248
static int cson_parser_set_key( cson_parser * p, cson_value * val )
@@ -3485,11 +3485,11 @@
34853485
++p->totalKeyCount;
34863486
break;
34873487
}
34883488
case JSON_T_STRING: {
34893489
cson_value * v = cson_value_new_string( value->vu.str.value, value->vu.str.length );
3490
- rc = ( NULL == v )
3490
+ rc = ( NULL == v )
34913491
? cson_rc.AllocError
34923492
: cson_parser_push_value( p, v );
34933493
break;
34943494
}
34953495
default:
@@ -3532,11 +3532,11 @@
35323532
To properly take over ownership of the parser's root node on a
35333533
successful parse:
35343534
35353535
- Copy p->root's pointer and set p->root to NULL.
35363536
- Eventually free up p->root with cson_value_free().
3537
-
3537
+
35383538
If you do not set p->root to NULL, p->root will be freed along with
35393539
any other items inserted into it (or under it) during the parsing
35403540
process.
35413541
*/
35423542
static int cson_parser_clean( cson_parser * p )
@@ -3571,11 +3571,11 @@
35713571
int rc = 0;
35723572
unsigned int len = 1;
35733573
cson_parse_info info = info_ ? *info_ : cson_parse_info_empty;
35743574
cson_parser p = cson_parser_empty;
35753575
if( ! tgt || ! src ) return cson_rc.ArgError;
3576
-
3576
+
35773577
{
35783578
JSON_config jopt = {0};
35793579
init_JSON_config( &jopt );
35803580
jopt.allow_comments = opt.allowComments;
35813581
jopt.depth = opt.maxDepth;
@@ -3780,11 +3780,11 @@
37803780
unsigned char const * end = (unsigned char const *)(str ? (str + len) : NULL);
37813781
unsigned char const * next = NULL;
37823782
int ch;
37833783
unsigned char clen = 0;
37843784
char escChar[3] = {'\\',0,0};
3785
- enum { UBLen = 13 };
3785
+ enum { UBLen = 20 };
37863786
char ubuf[UBLen];
37873787
int rc = 0;
37883788
rc = f(state, "\"", 1 );
37893789
for( ; (pos < end) && (0 == rc); pos += clen )
37903790
{
@@ -4640,11 +4640,11 @@
46404640
#endif
46414641
#undef TRY_SHARING
46424642
cson_value_add_reference(rc);
46434643
return rc;
46444644
}
4645
-
4645
+
46464646
static cson_value * cson_value_clone_array( cson_value const * orig )
46474647
{
46484648
unsigned int i = 0;
46494649
cson_array const * asrc = cson_value_get_array( orig );
46504650
unsigned int alen = cson_array_length_get( asrc );
@@ -4680,11 +4680,11 @@
46804680
cson_value_free(cl)/*remove our artificial reference */;
46814681
}
46824682
}
46834683
return destV;
46844684
}
4685
-
4685
+
46864686
static cson_value * cson_value_clone_object( cson_value const * orig )
46874687
{
46884688
cson_object const * src = cson_value_get_object( orig );
46894689
cson_value * destV = NULL;
46904690
cson_object * dest = NULL;
@@ -4834,11 +4834,11 @@
48344834
}
48354835
case CSON_TYPE_STRING: {
48364836
cson_string const * jstr = cson_value_get_string(orig);
48374837
unsigned const int slen = cson_string_length_bytes( jstr );
48384838
assert( NULL != jstr );
4839
- v = cson_strdup( cson_string_cstr( jstr ), slen );
4839
+ v = cson_strdup( cson_string_cstr( jstr ), slen );
48404840
break;
48414841
}
48424842
case CSON_TYPE_INTEGER: {
48434843
char buf[BufSize] = {0};
48444844
if( 0 < sprintf( v, "%"CSON_INT_T_PFMT, cson_value_get_integer(orig)) )
@@ -4887,11 +4887,11 @@
48874887
}
48884888
case CSON_TYPE_STRING: {
48894889
cson_string const * jstr = cson_value_get_string(orig);
48904890
unsigned const int slen = cson_string_length_bytes( jstr );
48914891
assert( NULL != jstr );
4892
- v = cson_strdup( cson_string_cstr( jstr ), slen );
4892
+ v = cson_strdup( cson_string_cstr( jstr ), slen );
48934893
break;
48944894
}
48954895
case CSON_TYPE_INTEGER: {
48964896
char buf[BufSize] = {0};
48974897
if( 0 < sprintf( v, "%"CSON_INT_T_PFMT, cson_value_get_integer(orig)) )
@@ -5351,11 +5351,11 @@
53515351
int rc = 0;
53525352
int colCount = 0;
53535353
assert(st);
53545354
colCount = sqlite3_column_count(st);
53555355
if( colCount <= 0 ) return NULL;
5356
-
5356
+
53575357
aryV = cson_value_new_array();
53585358
if( ! aryV ) return NULL;
53595359
ary = cson_value_get_array(aryV);
53605360
assert(ary);
53615361
for( i = 0; (0 ==rc) && (i < colCount); ++i )
@@ -5491,11 +5491,11 @@
54915491
aryV = NULL;
54925492
end:
54935493
return aryV;
54945494
}
54955495
5496
-
5496
+
54975497
/**
54985498
Internal impl of cson_sqlite3_stmt_to_json() when the 'fat'
54995499
parameter is non-0.
55005500
*/
55015501
static int cson_sqlite3_stmt_to_json_fat( sqlite3_stmt * st, cson_value ** tgt )
@@ -5636,11 +5636,11 @@
56365636
int rc = sqlite3_prepare_v2( db, sql, -1, &st, NULL );
56375637
if( 0 != rc ) return cson_rc.IOError /* FIXME: Better error code? */;
56385638
rc = cson_sqlite3_stmt_to_json( st, tgt, fat );
56395639
sqlite3_finalize( st );
56405640
return rc;
5641
- }
5641
+ }
56425642
}
56435643
56445644
int cson_sqlite3_bind_value( sqlite3_stmt * st, int ndx, cson_value const * v )
56455645
{
56465646
int rc = 0;
56475647
--- src/cson_amalgamation.c
+++ src/cson_amalgamation.c
@@ -19,14 +19,14 @@
19 # define JSON_PARSER_DLL_API __declspec(dllexport)
20 # else
21 # define JSON_PARSER_DLL_API __declspec(dllimport)
22 # endif
23 # else
24 # define JSON_PARSER_DLL_API
25 # endif
26 #else
27 # define JSON_PARSER_DLL_API
28 #endif
29
30 /* Determine the integer type use to parse non-floating point numbers */
31 #ifdef _WIN32
32 typedef __int64 JSON_int_t;
@@ -34,22 +34,22 @@
34 #define JSON_PARSER_INTEGER_SPRINTF_TOKEN "%I64d"
35 #elif (__STDC_VERSION__ >= 199901L) || (HAVE_LONG_LONG == 1)
36 typedef long long JSON_int_t;
37 #define JSON_PARSER_INTEGER_SSCANF_TOKEN "%lld"
38 #define JSON_PARSER_INTEGER_SPRINTF_TOKEN "%lld"
39 #else
40 typedef long JSON_int_t;
41 #define JSON_PARSER_INTEGER_SSCANF_TOKEN "%ld"
42 #define JSON_PARSER_INTEGER_SPRINTF_TOKEN "%ld"
43 #endif
44
45
46 #ifdef __cplusplus
47 extern "C" {
48 #endif
49
50 typedef enum
51 {
52 JSON_E_NONE = 0,
53 JSON_E_INVALID_CHAR,
54 JSON_E_INVALID_KEYWORD,
55 JSON_E_INVALID_ESCAPE_SEQUENCE,
@@ -60,11 +60,11 @@
60 JSON_E_EXPECTED_KEY,
61 JSON_E_EXPECTED_COLON,
62 JSON_E_OUT_OF_MEMORY
63 } JSON_error;
64
65 typedef enum
66 {
67 JSON_T_NONE = 0,
68 JSON_T_ARRAY_BEGIN,
69 JSON_T_ARRAY_END,
70 JSON_T_OBJECT_BEGIN,
@@ -80,33 +80,33 @@
80 } JSON_type;
81
82 typedef struct JSON_value_struct {
83 union {
84 JSON_int_t integer_value;
85
86 double float_value;
87
88 struct {
89 const char* value;
90 size_t length;
91 } str;
92 } vu;
93 } JSON_value;
94
95 typedef struct JSON_parser_struct* JSON_parser;
96
97 /*! \brief JSON parser callback
98
99 \param ctx The pointer passed to new_JSON_parser.
100 \param type An element of JSON_type but not JSON_T_NONE.
101 \param value A representation of the parsed value. This parameter is NULL for
102 JSON_T_ARRAY_BEGIN, JSON_T_ARRAY_END, JSON_T_OBJECT_BEGIN, JSON_T_OBJECT_END,
103 JSON_T_NULL, JSON_T_TRUE, and JSON_T_FALSE. String values are always returned
104 as zero-terminated C strings.
105
106 \return Non-zero if parsing should continue, else zero.
107 */
108 typedef int (*JSON_parser_callback)(void* ctx, int type, const JSON_value* value);
109
110
111 /**
112 A typedef for allocator functions semantically compatible with malloc().
@@ -115,11 +115,11 @@
115 /**
116 A typedef for deallocator functions semantically compatible with free().
117 */
118 typedef void (*JSON_free_t)(void* mem);
119
120 /*! \brief The structure used to configure a JSON parser object
121 */
122 typedef struct {
123 /** Pointer to a callback, called when the parser has something to tell
124 the user. This parameter may be NULL. In this case the input is
125 merely checked for validity.
@@ -176,17 +176,17 @@
176
177 \param config. Used to configure the parser.
178 */
179 JSON_PARSER_DLL_API void init_JSON_config(JSON_config * config);
180
181 /*! \brief Create a JSON parser object
182
183 \param config. Used to configure the parser. Set to NULL to use
184 the default configuration. See init_JSON_config. Its contents are
185 copied by this function, so it need not outlive the returned
186 object.
187
188 \return The parser object, which is owned by the caller and must eventually
189 be freed by calling delete_JSON_parser().
190 */
191 JSON_PARSER_DLL_API JSON_parser new_JSON_parser(JSON_config const* config);
192
@@ -200,16 +200,16 @@
200 JSON_PARSER_DLL_API int JSON_parser_char(JSON_parser jc, int next_char);
201
202 /*! \brief Finalize parsing.
203
204 Call this method once after all input characters have been consumed.
205
206 \return Non-zero, if all parsed characters are valid JSON, zero otherwise.
207 */
208 JSON_PARSER_DLL_API int JSON_parser_done(JSON_parser jc);
209
210 /*! \brief Determine if a given string is valid JSON white space
211
212 \return Non-zero if the string is valid, zero otherwise.
213 */
214 JSON_PARSER_DLL_API int JSON_parser_is_legal_white_space_string(const char* s);
215
@@ -226,12 +226,12 @@
226 JSON_PARSER_DLL_API int JSON_parser_reset(JSON_parser jc);
227
228
229 #ifdef __cplusplus
230 }
231 #endif
232
233
234 #endif /* JSON_PARSER_H */
235 /* end file parser/JSON_parser.h */
236 /* begin file parser/JSON_parser.c */
237 /*
@@ -1431,11 +1431,11 @@
1431 #if defined(__cplusplus)
1432 extern "C" {
1433 #endif
1434
1435
1436
1437 /**
1438 This type holds the "vtbl" for type-specific operations when
1439 working with cson_value objects.
1440
1441 All cson_values of a given logical type share a pointer to a single
@@ -1583,11 +1583,11 @@
1583 */
1584 #define CSON_CAST(T,V) ((T*)((V)->value))
1585 /**
1586 Assumes V is a pointer to memory which is allocated as part of a
1587 cson_value instance (the bytes immediately after that part).
1588 Returns a pointer a cson_value by subtracting sizeof(cson_value)
1589 from that address and casting it to a (cson_value*)
1590 */
1591 #define CSON_VCAST(V) ((cson_value *)(((unsigned char *)(V))-sizeof(cson_value)))
1592
1593 /**
@@ -1607,11 +1607,11 @@
1607 #define CSON_OBJ(V) CSON_CAST(cson_object,(V))
1608 #define CSON_ARRAY(V) CSON_CAST(cson_array,(V))
1609
1610 /**
1611 Holds special shared "constant" (though they are non-const)
1612 values.
1613 */
1614 static struct CSON_EMPTY_HOLDER_
1615 {
1616 char trueValue;
1617 cson_string stringValue;
@@ -1620,17 +1620,17 @@
1620 cson_string_empty_m
1621 };
1622
1623 /**
1624 Indexes into the CSON_SPECIAL_VALUES array.
1625
1626 If this enum changes in any way,
1627 makes damned sure that CSON_SPECIAL_VALUES is updated
1628 to match!!!
1629 */
1630 enum CSON_INTERNAL_VALUES {
1631
1632 CSON_VAL_UNDEF = 0,
1633 CSON_VAL_NULL = 1,
1634 CSON_VAL_TRUE = 2,
1635 CSON_VAL_FALSE = 3,
1636 CSON_VAL_INT_0 = 4,
@@ -1642,11 +1642,11 @@
1642 /**
1643 Some "special" shared cson_value instances.
1644
1645 These values MUST be initialized in the order specified
1646 by the CSON_INTERNAL_VALUES enum.
1647
1648 Note that they are not const because they are used as
1649 shared-allocation objects in non-const contexts. However, the
1650 public API provides no way to modifying them, and clients who
1651 modify values directly are subject to The Wrath of Undefined
1652 Behaviour.
@@ -1665,11 +1665,11 @@
1665
1666 /**
1667 Returns non-0 (true) if m is one of our special
1668 "built-in" values, e.g. from CSON_SPECIAL_VALUES and some
1669 "empty" values.
1670
1671 If this returns true, m MUST NOT be free()d!
1672 */
1673 static char cson_value_is_builtin( void const * m )
1674 {
1675 if((m >= (void const *)&CSON_EMPTY_HOLDER)
@@ -2183,11 +2183,11 @@
2183 static int cson_value_list_visit( cson_value_list * self,
2184 int (*visitor)(cson_value * obj, void * visitorState ),
2185 void * visitorState );
2186 #endif
2187 #endif
2188
2189 #if 0
2190 # define LIST_T cson_value_list
2191 # define VALUE_T cson_value *
2192 # define VALUE_T_IS_PTR 1
2193 # define LIST_T cson_kvp_list
@@ -2362,11 +2362,11 @@
2362 return cson_value_object_alloc();
2363 }
2364
2365 cson_object * cson_new_object()
2366 {
2367
2368 return cson_value_get_object( cson_value_new_object() );
2369 }
2370
2371 cson_value * cson_value_new_array()
2372 {
@@ -2608,11 +2608,11 @@
2608 {
2609 cson_int_t i = 0;
2610 int rc = 0;
2611 switch(val->api->typeID)
2612 {
2613 case CSON_TYPE_UNDEF:
2614 case CSON_TYPE_NULL:
2615 i = 0;
2616 break;
2617 case CSON_TYPE_BOOL: {
2618 char b = 0;
@@ -2661,11 +2661,11 @@
2661 {
2662 cson_double_t d = 0.0;
2663 int rc = 0;
2664 switch(val->api->typeID)
2665 {
2666 case CSON_TYPE_UNDEF:
2667 case CSON_TYPE_NULL:
2668 d = 0;
2669 break;
2670 case CSON_TYPE_BOOL: {
2671 char b = 0;
@@ -2791,11 +2791,11 @@
2791 #if 0
2792 /**
2793 Removes and returns the last value from the given array,
2794 shrinking its size by 1. Returns NULL if ar is NULL,
2795 ar->list.count is 0, or the element at that index is NULL.
2796
2797
2798 If removeRef is true then cson_value_free() is called to remove
2799 ar's reference count for the value. In that case NULL is returned,
2800 even if the object still has live references. If removeRef is false
2801 then the caller takes over ownership of that reference count point.
@@ -2858,11 +2858,11 @@
2858 #if !defined(NDEBUG) && CSON_VOID_PTR_IS_BIG
2859 assert( sizeof(cson_int_t) <= sizeof(void *) );
2860 #endif
2861 if( c )
2862 {
2863 memcpy(CSON_INT(c), &v, sizeof(v));
2864 }
2865 return c;
2866 }
2867 }
2868
@@ -2877,11 +2877,11 @@
2877 else
2878 {
2879 cson_value * c = cson_value_new(CSON_TYPE_DOUBLE,0);
2880 if( c )
2881 {
2882 memcpy(CSON_DBL(c), &v, sizeof(v));
2883 }
2884 return c;
2885 }
2886 }
2887
@@ -3068,11 +3068,11 @@
3068 qsort( obj->kvp.list, obj->kvp.count, sizeof(cson_kvp*),
3069 cson_kvp_cmp );
3070 }
3071
3072 }
3073 #endif
3074
3075 int cson_object_unset( cson_object * obj, char const * key )
3076 {
3077 if( ! obj || !key || !*key ) return cson_rc.ArgError;
3078 else
@@ -3238,11 +3238,11 @@
3238 using p->key. In any other case cson_rc.InternalError is returned.
3239
3240 Returns cson_rc.AllocError if an allocation fails.
3241
3242 Returns 0 on success. On error, parsing must be ceased immediately.
3243
3244 Ownership of val is ALWAYS TRANSFERED to this function. If this
3245 function fails, val will be cleaned up and destroyed. (This
3246 simplifies error handling in the core parser.)
3247 */
3248 static int cson_parser_set_key( cson_parser * p, cson_value * val )
@@ -3485,11 +3485,11 @@
3485 ++p->totalKeyCount;
3486 break;
3487 }
3488 case JSON_T_STRING: {
3489 cson_value * v = cson_value_new_string( value->vu.str.value, value->vu.str.length );
3490 rc = ( NULL == v )
3491 ? cson_rc.AllocError
3492 : cson_parser_push_value( p, v );
3493 break;
3494 }
3495 default:
@@ -3532,11 +3532,11 @@
3532 To properly take over ownership of the parser's root node on a
3533 successful parse:
3534
3535 - Copy p->root's pointer and set p->root to NULL.
3536 - Eventually free up p->root with cson_value_free().
3537
3538 If you do not set p->root to NULL, p->root will be freed along with
3539 any other items inserted into it (or under it) during the parsing
3540 process.
3541 */
3542 static int cson_parser_clean( cson_parser * p )
@@ -3571,11 +3571,11 @@
3571 int rc = 0;
3572 unsigned int len = 1;
3573 cson_parse_info info = info_ ? *info_ : cson_parse_info_empty;
3574 cson_parser p = cson_parser_empty;
3575 if( ! tgt || ! src ) return cson_rc.ArgError;
3576
3577 {
3578 JSON_config jopt = {0};
3579 init_JSON_config( &jopt );
3580 jopt.allow_comments = opt.allowComments;
3581 jopt.depth = opt.maxDepth;
@@ -3780,11 +3780,11 @@
3780 unsigned char const * end = (unsigned char const *)(str ? (str + len) : NULL);
3781 unsigned char const * next = NULL;
3782 int ch;
3783 unsigned char clen = 0;
3784 char escChar[3] = {'\\',0,0};
3785 enum { UBLen = 13 };
3786 char ubuf[UBLen];
3787 int rc = 0;
3788 rc = f(state, "\"", 1 );
3789 for( ; (pos < end) && (0 == rc); pos += clen )
3790 {
@@ -4640,11 +4640,11 @@
4640 #endif
4641 #undef TRY_SHARING
4642 cson_value_add_reference(rc);
4643 return rc;
4644 }
4645
4646 static cson_value * cson_value_clone_array( cson_value const * orig )
4647 {
4648 unsigned int i = 0;
4649 cson_array const * asrc = cson_value_get_array( orig );
4650 unsigned int alen = cson_array_length_get( asrc );
@@ -4680,11 +4680,11 @@
4680 cson_value_free(cl)/*remove our artificial reference */;
4681 }
4682 }
4683 return destV;
4684 }
4685
4686 static cson_value * cson_value_clone_object( cson_value const * orig )
4687 {
4688 cson_object const * src = cson_value_get_object( orig );
4689 cson_value * destV = NULL;
4690 cson_object * dest = NULL;
@@ -4834,11 +4834,11 @@
4834 }
4835 case CSON_TYPE_STRING: {
4836 cson_string const * jstr = cson_value_get_string(orig);
4837 unsigned const int slen = cson_string_length_bytes( jstr );
4838 assert( NULL != jstr );
4839 v = cson_strdup( cson_string_cstr( jstr ), slen );
4840 break;
4841 }
4842 case CSON_TYPE_INTEGER: {
4843 char buf[BufSize] = {0};
4844 if( 0 < sprintf( v, "%"CSON_INT_T_PFMT, cson_value_get_integer(orig)) )
@@ -4887,11 +4887,11 @@
4887 }
4888 case CSON_TYPE_STRING: {
4889 cson_string const * jstr = cson_value_get_string(orig);
4890 unsigned const int slen = cson_string_length_bytes( jstr );
4891 assert( NULL != jstr );
4892 v = cson_strdup( cson_string_cstr( jstr ), slen );
4893 break;
4894 }
4895 case CSON_TYPE_INTEGER: {
4896 char buf[BufSize] = {0};
4897 if( 0 < sprintf( v, "%"CSON_INT_T_PFMT, cson_value_get_integer(orig)) )
@@ -5351,11 +5351,11 @@
5351 int rc = 0;
5352 int colCount = 0;
5353 assert(st);
5354 colCount = sqlite3_column_count(st);
5355 if( colCount <= 0 ) return NULL;
5356
5357 aryV = cson_value_new_array();
5358 if( ! aryV ) return NULL;
5359 ary = cson_value_get_array(aryV);
5360 assert(ary);
5361 for( i = 0; (0 ==rc) && (i < colCount); ++i )
@@ -5491,11 +5491,11 @@
5491 aryV = NULL;
5492 end:
5493 return aryV;
5494 }
5495
5496
5497 /**
5498 Internal impl of cson_sqlite3_stmt_to_json() when the 'fat'
5499 parameter is non-0.
5500 */
5501 static int cson_sqlite3_stmt_to_json_fat( sqlite3_stmt * st, cson_value ** tgt )
@@ -5636,11 +5636,11 @@
5636 int rc = sqlite3_prepare_v2( db, sql, -1, &st, NULL );
5637 if( 0 != rc ) return cson_rc.IOError /* FIXME: Better error code? */;
5638 rc = cson_sqlite3_stmt_to_json( st, tgt, fat );
5639 sqlite3_finalize( st );
5640 return rc;
5641 }
5642 }
5643
5644 int cson_sqlite3_bind_value( sqlite3_stmt * st, int ndx, cson_value const * v )
5645 {
5646 int rc = 0;
5647
--- src/cson_amalgamation.c
+++ src/cson_amalgamation.c
@@ -19,14 +19,14 @@
19 # define JSON_PARSER_DLL_API __declspec(dllexport)
20 # else
21 # define JSON_PARSER_DLL_API __declspec(dllimport)
22 # endif
23 # else
24 # define JSON_PARSER_DLL_API
25 # endif
26 #else
27 # define JSON_PARSER_DLL_API
28 #endif
29
30 /* Determine the integer type use to parse non-floating point numbers */
31 #ifdef _WIN32
32 typedef __int64 JSON_int_t;
@@ -34,22 +34,22 @@
34 #define JSON_PARSER_INTEGER_SPRINTF_TOKEN "%I64d"
35 #elif (__STDC_VERSION__ >= 199901L) || (HAVE_LONG_LONG == 1)
36 typedef long long JSON_int_t;
37 #define JSON_PARSER_INTEGER_SSCANF_TOKEN "%lld"
38 #define JSON_PARSER_INTEGER_SPRINTF_TOKEN "%lld"
39 #else
40 typedef long JSON_int_t;
41 #define JSON_PARSER_INTEGER_SSCANF_TOKEN "%ld"
42 #define JSON_PARSER_INTEGER_SPRINTF_TOKEN "%ld"
43 #endif
44
45
46 #ifdef __cplusplus
47 extern "C" {
48 #endif
49
50 typedef enum
51 {
52 JSON_E_NONE = 0,
53 JSON_E_INVALID_CHAR,
54 JSON_E_INVALID_KEYWORD,
55 JSON_E_INVALID_ESCAPE_SEQUENCE,
@@ -60,11 +60,11 @@
60 JSON_E_EXPECTED_KEY,
61 JSON_E_EXPECTED_COLON,
62 JSON_E_OUT_OF_MEMORY
63 } JSON_error;
64
65 typedef enum
66 {
67 JSON_T_NONE = 0,
68 JSON_T_ARRAY_BEGIN,
69 JSON_T_ARRAY_END,
70 JSON_T_OBJECT_BEGIN,
@@ -80,33 +80,33 @@
80 } JSON_type;
81
82 typedef struct JSON_value_struct {
83 union {
84 JSON_int_t integer_value;
85
86 double float_value;
87
88 struct {
89 const char* value;
90 size_t length;
91 } str;
92 } vu;
93 } JSON_value;
94
95 typedef struct JSON_parser_struct* JSON_parser;
96
97 /*! \brief JSON parser callback
98
99 \param ctx The pointer passed to new_JSON_parser.
100 \param type An element of JSON_type but not JSON_T_NONE.
101 \param value A representation of the parsed value. This parameter is NULL for
102 JSON_T_ARRAY_BEGIN, JSON_T_ARRAY_END, JSON_T_OBJECT_BEGIN, JSON_T_OBJECT_END,
103 JSON_T_NULL, JSON_T_TRUE, and JSON_T_FALSE. String values are always returned
104 as zero-terminated C strings.
105
106 \return Non-zero if parsing should continue, else zero.
107 */
108 typedef int (*JSON_parser_callback)(void* ctx, int type, const JSON_value* value);
109
110
111 /**
112 A typedef for allocator functions semantically compatible with malloc().
@@ -115,11 +115,11 @@
115 /**
116 A typedef for deallocator functions semantically compatible with free().
117 */
118 typedef void (*JSON_free_t)(void* mem);
119
120 /*! \brief The structure used to configure a JSON parser object
121 */
122 typedef struct {
123 /** Pointer to a callback, called when the parser has something to tell
124 the user. This parameter may be NULL. In this case the input is
125 merely checked for validity.
@@ -176,17 +176,17 @@
176
177 \param config. Used to configure the parser.
178 */
179 JSON_PARSER_DLL_API void init_JSON_config(JSON_config * config);
180
181 /*! \brief Create a JSON parser object
182
183 \param config. Used to configure the parser. Set to NULL to use
184 the default configuration. See init_JSON_config. Its contents are
185 copied by this function, so it need not outlive the returned
186 object.
187
188 \return The parser object, which is owned by the caller and must eventually
189 be freed by calling delete_JSON_parser().
190 */
191 JSON_PARSER_DLL_API JSON_parser new_JSON_parser(JSON_config const* config);
192
@@ -200,16 +200,16 @@
200 JSON_PARSER_DLL_API int JSON_parser_char(JSON_parser jc, int next_char);
201
202 /*! \brief Finalize parsing.
203
204 Call this method once after all input characters have been consumed.
205
206 \return Non-zero, if all parsed characters are valid JSON, zero otherwise.
207 */
208 JSON_PARSER_DLL_API int JSON_parser_done(JSON_parser jc);
209
210 /*! \brief Determine if a given string is valid JSON white space
211
212 \return Non-zero if the string is valid, zero otherwise.
213 */
214 JSON_PARSER_DLL_API int JSON_parser_is_legal_white_space_string(const char* s);
215
@@ -226,12 +226,12 @@
226 JSON_PARSER_DLL_API int JSON_parser_reset(JSON_parser jc);
227
228
229 #ifdef __cplusplus
230 }
231 #endif
232
233
234 #endif /* JSON_PARSER_H */
235 /* end file parser/JSON_parser.h */
236 /* begin file parser/JSON_parser.c */
237 /*
@@ -1431,11 +1431,11 @@
1431 #if defined(__cplusplus)
1432 extern "C" {
1433 #endif
1434
1435
1436
1437 /**
1438 This type holds the "vtbl" for type-specific operations when
1439 working with cson_value objects.
1440
1441 All cson_values of a given logical type share a pointer to a single
@@ -1583,11 +1583,11 @@
1583 */
1584 #define CSON_CAST(T,V) ((T*)((V)->value))
1585 /**
1586 Assumes V is a pointer to memory which is allocated as part of a
1587 cson_value instance (the bytes immediately after that part).
1588 Returns a pointer a a cson_value by subtracting sizeof(cson_value)
1589 from that address and casting it to a (cson_value*)
1590 */
1591 #define CSON_VCAST(V) ((cson_value *)(((unsigned char *)(V))-sizeof(cson_value)))
1592
1593 /**
@@ -1607,11 +1607,11 @@
1607 #define CSON_OBJ(V) CSON_CAST(cson_object,(V))
1608 #define CSON_ARRAY(V) CSON_CAST(cson_array,(V))
1609
1610 /**
1611 Holds special shared "constant" (though they are non-const)
1612 values.
1613 */
1614 static struct CSON_EMPTY_HOLDER_
1615 {
1616 char trueValue;
1617 cson_string stringValue;
@@ -1620,17 +1620,17 @@
1620 cson_string_empty_m
1621 };
1622
1623 /**
1624 Indexes into the CSON_SPECIAL_VALUES array.
1625
1626 If this enum changes in any way,
1627 makes damned sure that CSON_SPECIAL_VALUES is updated
1628 to match!!!
1629 */
1630 enum CSON_INTERNAL_VALUES {
1631
1632 CSON_VAL_UNDEF = 0,
1633 CSON_VAL_NULL = 1,
1634 CSON_VAL_TRUE = 2,
1635 CSON_VAL_FALSE = 3,
1636 CSON_VAL_INT_0 = 4,
@@ -1642,11 +1642,11 @@
1642 /**
1643 Some "special" shared cson_value instances.
1644
1645 These values MUST be initialized in the order specified
1646 by the CSON_INTERNAL_VALUES enum.
1647
1648 Note that they are not const because they are used as
1649 shared-allocation objects in non-const contexts. However, the
1650 public API provides no way to modifying them, and clients who
1651 modify values directly are subject to The Wrath of Undefined
1652 Behaviour.
@@ -1665,11 +1665,11 @@
1665
1666 /**
1667 Returns non-0 (true) if m is one of our special
1668 "built-in" values, e.g. from CSON_SPECIAL_VALUES and some
1669 "empty" values.
1670
1671 If this returns true, m MUST NOT be free()d!
1672 */
1673 static char cson_value_is_builtin( void const * m )
1674 {
1675 if((m >= (void const *)&CSON_EMPTY_HOLDER)
@@ -2183,11 +2183,11 @@
2183 static int cson_value_list_visit( cson_value_list * self,
2184 int (*visitor)(cson_value * obj, void * visitorState ),
2185 void * visitorState );
2186 #endif
2187 #endif
2188
2189 #if 0
2190 # define LIST_T cson_value_list
2191 # define VALUE_T cson_value *
2192 # define VALUE_T_IS_PTR 1
2193 # define LIST_T cson_kvp_list
@@ -2362,11 +2362,11 @@
2362 return cson_value_object_alloc();
2363 }
2364
2365 cson_object * cson_new_object()
2366 {
2367
2368 return cson_value_get_object( cson_value_new_object() );
2369 }
2370
2371 cson_value * cson_value_new_array()
2372 {
@@ -2608,11 +2608,11 @@
2608 {
2609 cson_int_t i = 0;
2610 int rc = 0;
2611 switch(val->api->typeID)
2612 {
2613 case CSON_TYPE_UNDEF:
2614 case CSON_TYPE_NULL:
2615 i = 0;
2616 break;
2617 case CSON_TYPE_BOOL: {
2618 char b = 0;
@@ -2661,11 +2661,11 @@
2661 {
2662 cson_double_t d = 0.0;
2663 int rc = 0;
2664 switch(val->api->typeID)
2665 {
2666 case CSON_TYPE_UNDEF:
2667 case CSON_TYPE_NULL:
2668 d = 0;
2669 break;
2670 case CSON_TYPE_BOOL: {
2671 char b = 0;
@@ -2791,11 +2791,11 @@
2791 #if 0
2792 /**
2793 Removes and returns the last value from the given array,
2794 shrinking its size by 1. Returns NULL if ar is NULL,
2795 ar->list.count is 0, or the element at that index is NULL.
2796
2797
2798 If removeRef is true then cson_value_free() is called to remove
2799 ar's reference count for the value. In that case NULL is returned,
2800 even if the object still has live references. If removeRef is false
2801 then the caller takes over ownership of that reference count point.
@@ -2858,11 +2858,11 @@
2858 #if !defined(NDEBUG) && CSON_VOID_PTR_IS_BIG
2859 assert( sizeof(cson_int_t) <= sizeof(void *) );
2860 #endif
2861 if( c )
2862 {
2863 memcpy( CSON_INT(c), &v, sizeof(v) );
2864 }
2865 return c;
2866 }
2867 }
2868
@@ -2877,11 +2877,11 @@
2877 else
2878 {
2879 cson_value * c = cson_value_new(CSON_TYPE_DOUBLE,0);
2880 if( c )
2881 {
2882 memcpy( CSON_DBL(c), &v, sizeof(v) );
2883 }
2884 return c;
2885 }
2886 }
2887
@@ -3068,11 +3068,11 @@
3068 qsort( obj->kvp.list, obj->kvp.count, sizeof(cson_kvp*),
3069 cson_kvp_cmp );
3070 }
3071
3072 }
3073 #endif
3074
3075 int cson_object_unset( cson_object * obj, char const * key )
3076 {
3077 if( ! obj || !key || !*key ) return cson_rc.ArgError;
3078 else
@@ -3238,11 +3238,11 @@
3238 using p->key. In any other case cson_rc.InternalError is returned.
3239
3240 Returns cson_rc.AllocError if an allocation fails.
3241
3242 Returns 0 on success. On error, parsing must be ceased immediately.
3243
3244 Ownership of val is ALWAYS TRANSFERED to this function. If this
3245 function fails, val will be cleaned up and destroyed. (This
3246 simplifies error handling in the core parser.)
3247 */
3248 static int cson_parser_set_key( cson_parser * p, cson_value * val )
@@ -3485,11 +3485,11 @@
3485 ++p->totalKeyCount;
3486 break;
3487 }
3488 case JSON_T_STRING: {
3489 cson_value * v = cson_value_new_string( value->vu.str.value, value->vu.str.length );
3490 rc = ( NULL == v )
3491 ? cson_rc.AllocError
3492 : cson_parser_push_value( p, v );
3493 break;
3494 }
3495 default:
@@ -3532,11 +3532,11 @@
3532 To properly take over ownership of the parser's root node on a
3533 successful parse:
3534
3535 - Copy p->root's pointer and set p->root to NULL.
3536 - Eventually free up p->root with cson_value_free().
3537
3538 If you do not set p->root to NULL, p->root will be freed along with
3539 any other items inserted into it (or under it) during the parsing
3540 process.
3541 */
3542 static int cson_parser_clean( cson_parser * p )
@@ -3571,11 +3571,11 @@
3571 int rc = 0;
3572 unsigned int len = 1;
3573 cson_parse_info info = info_ ? *info_ : cson_parse_info_empty;
3574 cson_parser p = cson_parser_empty;
3575 if( ! tgt || ! src ) return cson_rc.ArgError;
3576
3577 {
3578 JSON_config jopt = {0};
3579 init_JSON_config( &jopt );
3580 jopt.allow_comments = opt.allowComments;
3581 jopt.depth = opt.maxDepth;
@@ -3780,11 +3780,11 @@
3780 unsigned char const * end = (unsigned char const *)(str ? (str + len) : NULL);
3781 unsigned char const * next = NULL;
3782 int ch;
3783 unsigned char clen = 0;
3784 char escChar[3] = {'\\',0,0};
3785 enum { UBLen = 20 };
3786 char ubuf[UBLen];
3787 int rc = 0;
3788 rc = f(state, "\"", 1 );
3789 for( ; (pos < end) && (0 == rc); pos += clen )
3790 {
@@ -4640,11 +4640,11 @@
4640 #endif
4641 #undef TRY_SHARING
4642 cson_value_add_reference(rc);
4643 return rc;
4644 }
4645
4646 static cson_value * cson_value_clone_array( cson_value const * orig )
4647 {
4648 unsigned int i = 0;
4649 cson_array const * asrc = cson_value_get_array( orig );
4650 unsigned int alen = cson_array_length_get( asrc );
@@ -4680,11 +4680,11 @@
4680 cson_value_free(cl)/*remove our artificial reference */;
4681 }
4682 }
4683 return destV;
4684 }
4685
4686 static cson_value * cson_value_clone_object( cson_value const * orig )
4687 {
4688 cson_object const * src = cson_value_get_object( orig );
4689 cson_value * destV = NULL;
4690 cson_object * dest = NULL;
@@ -4834,11 +4834,11 @@
4834 }
4835 case CSON_TYPE_STRING: {
4836 cson_string const * jstr = cson_value_get_string(orig);
4837 unsigned const int slen = cson_string_length_bytes( jstr );
4838 assert( NULL != jstr );
4839 v = cson_strdup( cson_string_cstr( jstr ), slen );
4840 break;
4841 }
4842 case CSON_TYPE_INTEGER: {
4843 char buf[BufSize] = {0};
4844 if( 0 < sprintf( v, "%"CSON_INT_T_PFMT, cson_value_get_integer(orig)) )
@@ -4887,11 +4887,11 @@
4887 }
4888 case CSON_TYPE_STRING: {
4889 cson_string const * jstr = cson_value_get_string(orig);
4890 unsigned const int slen = cson_string_length_bytes( jstr );
4891 assert( NULL != jstr );
4892 v = cson_strdup( cson_string_cstr( jstr ), slen );
4893 break;
4894 }
4895 case CSON_TYPE_INTEGER: {
4896 char buf[BufSize] = {0};
4897 if( 0 < sprintf( v, "%"CSON_INT_T_PFMT, cson_value_get_integer(orig)) )
@@ -5351,11 +5351,11 @@
5351 int rc = 0;
5352 int colCount = 0;
5353 assert(st);
5354 colCount = sqlite3_column_count(st);
5355 if( colCount <= 0 ) return NULL;
5356
5357 aryV = cson_value_new_array();
5358 if( ! aryV ) return NULL;
5359 ary = cson_value_get_array(aryV);
5360 assert(ary);
5361 for( i = 0; (0 ==rc) && (i < colCount); ++i )
@@ -5491,11 +5491,11 @@
5491 aryV = NULL;
5492 end:
5493 return aryV;
5494 }
5495
5496
5497 /**
5498 Internal impl of cson_sqlite3_stmt_to_json() when the 'fat'
5499 parameter is non-0.
5500 */
5501 static int cson_sqlite3_stmt_to_json_fat( sqlite3_stmt * st, cson_value ** tgt )
@@ -5636,11 +5636,11 @@
5636 int rc = sqlite3_prepare_v2( db, sql, -1, &st, NULL );
5637 if( 0 != rc ) return cson_rc.IOError /* FIXME: Better error code? */;
5638 rc = cson_sqlite3_stmt_to_json( st, tgt, fat );
5639 sqlite3_finalize( st );
5640 return rc;
5641 }
5642 }
5643
5644 int cson_sqlite3_bind_value( sqlite3_stmt * st, int ndx, cson_value const * v )
5645 {
5646 int rc = 0;
5647
--- src/cson_amalgamation.h
+++ src/cson_amalgamation.h
@@ -59,11 +59,11 @@
5959
#define CSON_INT_T_PFMT "I64d"
6060
#elif (__STDC_VERSION__ >= 199901L) || (HAVE_LONG_LONG == 1)
6161
typedef long long cson_int_t;
6262
#define CSON_INT_T_SFMT "lld"
6363
#define CSON_INT_T_PFMT "lld"
64
-#else
64
+#else
6565
typedef long cson_int_t;
6666
#define CSON_INT_T_SFMT "ld"
6767
#define CSON_INT_T_PFMT "ld"
6868
#endif
6969
@@ -215,11 +215,11 @@
215215
Convenience typedef.
216216
*/
217217
typedef struct cson_value cson_value;
218218
219219
/** @struct cson_value
220
-
220
+
221221
The core value type of this API. It is opaque to clients, and
222222
only the cson public API should be used for setting or
223223
inspecting their values.
224224
225225
This class is opaque because stack-based usage can easily cause
@@ -231,11 +231,11 @@
231231
counting) as long as those insertions do not cause cycles. However,
232232
be very aware that such value re-use uses a reference to the
233233
original copy, meaning that if its value is changed once, it is
234234
changed everywhere. Also beware that multi-threaded write
235235
operations on such references leads to undefined behaviour.
236
-
236
+
237237
PLEASE read the ACHTUNGEN below...
238238
239239
ACHTUNG #1:
240240
241241
cson_values MUST NOT form cycles (e.g. via object or array
@@ -244,33 +244,33 @@
244244
Not abiding th Holy Law Of No Cycles will lead to double-frees and
245245
the like (i.e. undefined behaviour, likely crashes due to infinite
246246
recursion or stepping on invalid (freed) pointers).
247247
248248
ACHTUNG #2:
249
-
249
+
250250
ALL cson_values returned as non-const cson_value pointers from any
251251
public functions in the cson API are to be treated as if they are
252252
heap-allocated, and MUST be freed by client by doing ONE of:
253
-
253
+
254254
- Passing it to cson_value_free().
255
-
255
+
256256
- Adding it to an Object or Array, in which case the object/array
257257
takes over ownership. As of 20110323, a value may be inserted into
258258
a single container multiple times, or into multiple containers,
259259
in which case they all share ownership (via reference counting)
260260
of the original value (meaning any changes to it are visible in
261261
all references to it).
262
-
262
+
263263
Each call to cson_value_new_xxx() MUST eventually be followed up
264264
by one of those options.
265
-
265
+
266266
Some cson_value_new_XXX() implementations do not actually allocate
267267
memory, but this is an internal implementation detail. Client code
268268
MUST NOT rely on this behaviour and MUST treat each object
269269
returned by such a function as if it was a freshly-allocated copy
270270
(even if their pointer addresses are the same).
271
-
271
+
272272
ACHTUNG #3:
273273
274274
Note that ACHTUNG #2 tells us that we must always free (or transfer
275275
ownership of) all pointers returned bycson_value_new_xxx(), but
276276
that two calls to (e.g.) cson_value_new_bool(1) will (or might)
@@ -315,11 +315,11 @@
315315
if( 0 == rc ) {...success...}
316316
else if( cson_rc.ArgError == rc ) { ... some argument was wrong ... }
317317
else if( cson_rc.AllocError == rc ) { ... allocation error ... }
318318
...
319319
@endcode
320
-
320
+
321321
The entries named Parse_XXX are generally only returned by
322322
cson_parse() and friends.
323323
*/
324324
325325
/** @struct cson_rc_
@@ -472,11 +472,11 @@
472472
473473
/**
474474
Length, in bytes.
475475
*/
476476
unsigned int length;
477
-
477
+
478478
/**
479479
Error code of the parse run (0 for no error).
480480
*/
481481
int errorCode;
482482
@@ -523,11 +523,11 @@
523523
/**
524524
Specifies how to indent (or not) output. The values
525525
are:
526526
527527
(0) == no extra indentation.
528
-
528
+
529529
(1) == 1 TAB character for each level.
530530
531531
(>1) == that number of SPACES for each level.
532532
*/
533533
unsigned char indentation;
@@ -536,11 +536,11 @@
536536
Maximum object/array depth to traverse. Traversing deeply can
537537
be indicative of cycles in the object/array tree, and this
538538
value is used to figure out when to abort the traversal.
539539
*/
540540
unsigned short maxDepth;
541
-
541
+
542542
/**
543543
If true, a newline will be added to generated output,
544544
else not.
545545
*/
546546
char addNewline;
@@ -636,11 +636,11 @@
636636
637637
Must return 0 on success, non-0 on error (preferably a value from
638638
cson_rc).
639639
640640
These functions are called relatively often during the JSON-output
641
- process, and should try to be fast.
641
+ process, and should try to be fast.
642642
*/
643643
typedef int (*cson_data_dest_f)( void * state, void const * src, unsigned int n );
644644
645645
/**
646646
Reads JSON-formatted string data (in ASCII, UTF8, or UTF16), using the
@@ -664,15 +664,15 @@
664664
used.
665665
666666
The info argument may be NULL. If it is not NULL then the parser
667667
populates it with information which is useful in error
668668
reporting. Namely, it contains the line/column of parse errors.
669
-
669
+
670670
The srcState argument is ignored by this function but is passed on to src,
671671
so any output-destination-specific state can be stored there and accessed
672672
via the src callback.
673
-
673
+
674674
Non-parse error conditions include:
675675
676676
- (!tgt) or !src: cson_rc.ArgError
677677
- cson_rc.AllocError can happen at any time during the input phase
678678
@@ -725,11 +725,11 @@
725725
TODOs:
726726
727727
- Buffer the input in larger chunks. We currently read
728728
byte-by-byte, but i'm too tired to write/test the looping code for
729729
the buffering.
730
-
730
+
731731
@see cson_parse_FILE()
732732
@see cson_parse_string()
733733
*/
734734
int cson_parse( cson_value ** tgt, cson_data_source_f src, void * srcState,
735735
cson_parse_opt const * opt, cson_parse_info * info );
@@ -786,11 +786,11 @@
786786
The destState parameter is ignored by this function and is passed
787787
on to the dest function.
788788
789789
Returns 0 on success. On error, any amount of output might have been
790790
generated before the error was triggered.
791
-
791
+
792792
Example:
793793
794794
@code
795795
int rc = cson_output( myValue, cson_data_dest_FILE, stdout, NULL );
796796
// basically equivalent to: cson_output_FILE( myValue, stdout, NULL );
@@ -925,15 +925,15 @@
925925
/**
926926
Converts the given value to a boolean, using JavaScript semantics depending
927927
on the concrete type of val:
928928
929929
undef or null: false
930
-
930
+
931931
boolean: same
932
-
932
+
933933
integer, double: 0 or 0.0 == false, else true
934
-
934
+
935935
object, array: true
936936
937937
string: length-0 string is false, else true.
938938
939939
Returns 0 on success and assigns *v (if v is not NULL) to either 0 or 1.
@@ -945,18 +945,18 @@
945945
Similar to cson_value_fetch_bool(), but fetches an integer value.
946946
947947
The conversion, if any, depends on the concrete type of val:
948948
949949
NULL, null, undefined: *v is set to 0 and 0 is returned.
950
-
950
+
951951
string, object, array: *v is set to 0 and
952952
cson_rc.TypeError is returned. The error may normally be safely
953953
ignored, but it is provided for those wanted to know whether a direct
954954
conversion was possible.
955955
956956
integer: *v is set to the int value and 0 is returned.
957
-
957
+
958958
double: *v is set to the value truncated to int and 0 is returned.
959959
*/
960960
int cson_value_fetch_integer( cson_value const * val, cson_int_t * v );
961961
962962
/**
@@ -1084,11 +1084,11 @@
10841084
10851085
- The maximum number of bytes compared is the lesser of rhsLen and
10861086
the length of lhs. If the strings do not match, but compare equal
10871087
up to the just-described comparison length, the shorter string is
10881088
considered to be less-than the longer one.
1089
-
1089
+
10901090
- If lhs and rhs are both NULL, or both have a length of 0 then they will
10911091
compare equal.
10921092
10931093
- If lhs is null/length-0 but rhs is not then lhs is considered to be less-than
10941094
rhs.
@@ -1110,11 +1110,11 @@
11101110
Returns the length, in bytes, of str, or 0 if str is NULL. This is
11111111
an O(1) operation.
11121112
11131113
TODO: add cson_string_length_chars() (is O(N) unless we add another
11141114
member to store the char length).
1115
-
1115
+
11161116
@see cson_string_cstr()
11171117
*/
11181118
unsigned int cson_string_length_bytes( cson_string const * str );
11191119
11201120
/**
@@ -1207,11 +1207,11 @@
12071207
ar is expanded, if needed, to be able to hold at least (ndx+1)
12081208
items, and any new entries created by that expansion are empty
12091209
(NULL values).
12101210
12111211
On success, 0 is returned and ownership of v is transfered to ar.
1212
-
1212
+
12131213
On error ownership of v is NOT modified, and the caller may still
12141214
need to clean it up. For example, the following code will introduce
12151215
a leak if this function fails:
12161216
12171217
@code
@@ -1240,11 +1240,11 @@
12401240
12411241
This is functionally equivalent to
12421242
cson_array_set(ar,cson_array_length_get(ar),v), but this
12431243
implementation has slightly different array-preallocation policy
12441244
(it grows more eagerly).
1245
-
1245
+
12461246
Returns 0 on success, non-zero on error. Error cases include:
12471247
12481248
- ar or v are NULL: cson_rc.ArgError
12491249
12501250
- Array cannot be expanded to hold enough elements: cson_rc.AllocError.
@@ -1283,11 +1283,11 @@
12831283
cson_value * cson_new_bool(char v);
12841284
12851285
/**
12861286
Returns the special JSON "null" value. When outputing JSON,
12871287
its string representation is "null" (without the quotes).
1288
-
1288
+
12891289
See cson_value_new_bool() for notes regarding the returned
12901290
value's memory.
12911291
*/
12921292
cson_value * cson_value_null();
12931293
@@ -1323,16 +1323,16 @@
13231323
13241324
/**
13251325
Semantically the same as cson_value_new_bool(), but for strings.
13261326
This creates a JSON value which copies the first n bytes of str.
13271327
The string will automatically be NUL-terminated.
1328
-
1328
+
13291329
Note that if str is NULL or n is 0, this function still
13301330
returns non-NULL value representing that empty string.
1331
-
1331
+
13321332
Returns NULL on allocation error.
1333
-
1333
+
13341334
See cson_value_new_bool() for important information about the
13351335
returned memory.
13361336
*/
13371337
cson_value * cson_value_new_string( char const * str, unsigned int n );
13381338
@@ -1354,11 +1354,11 @@
13541354
This works like cson_value_new_object() but returns an Object
13551355
handle directly.
13561356
13571357
The value handle for the returned object can be fetched with
13581358
cson_object_value(theObject).
1359
-
1359
+
13601360
Ownership is transfered to the caller, who must eventually free it
13611361
by passing the Value handle (NOT the Object handle) to
13621362
cson_value_free() or passing ownership to a parent container.
13631363
13641364
Returns NULL on error (out of memory).
@@ -1419,11 +1419,11 @@
14191419
cson_value_add_reference(). Even if this function does not
14201420
immediately destroy the value, the value must be considered, from
14211421
the perspective of that client code, to have been
14221422
destroyed/invalidated by this call.
14231423
1424
-
1424
+
14251425
@see cson_value_new_object()
14261426
@see cson_value_new_array()
14271427
@see cson_value_add_reference()
14281428
*/
14291429
void cson_value_free(cson_value * v);
@@ -1445,11 +1445,11 @@
14451445
case, the key is set to the special null value.
14461446
14471447
The key may be encoded as ASCII or UTF8. Results are undefined
14481448
with other encodings, and the errors won't show up here, but may
14491449
show up later, e.g. during output.
1450
-
1450
+
14511451
Returns 0 on success, non-0 on error. It has the following error
14521452
cases:
14531453
14541454
- cson_rc.ArgError: obj or key are NULL or strlen(key) is 0.
14551455
@@ -1498,11 +1498,11 @@
14981498
*/
14991499
int cson_object_set_s( cson_object * obj, cson_string * key, cson_value * v );
15001500
15011501
/**
15021502
Removes a property from an object.
1503
-
1503
+
15041504
If obj contains the given key, it is removed and 0 is returned. If
15051505
it is not found, cson_rc.NotFoundError is returned (which can
15061506
normally be ignored by client code).
15071507
15081508
cson_rc.ArgError is returned if obj or key are NULL or key has
@@ -1569,33 +1569,33 @@
15691569
15701570
If it finds the given path, it returns the value by assiging *tgt
15711571
to it. If tgt is NULL then this function has no side-effects but
15721572
will return 0 if the given path is found within the object, so it can be used
15731573
to test for existence without fetching it.
1574
-
1574
+
15751575
Returns 0 if it finds an entry, cson_rc.NotFoundError if it finds
15761576
no item, and any other non-zero error code on a "real" error. Errors include:
15771577
15781578
- obj or path are NULL: cson_rc.ArgError
1579
-
1579
+
15801580
- separator is 0, or path is an empty string or contains only
15811581
separator characters: cson_rc.RangeError
15821582
15831583
- There is an upper limit on how long a single path component may
15841584
be (some "reasonable" internal size), and cson_rc.RangeError is
15851585
returned if that length is violated.
15861586
1587
-
1587
+
15881588
Limitations:
15891589
15901590
- It has no way to fetch data from arrays this way. i could
15911591
imagine, e.g., a path of "subobj.subArray.0" for
15921592
subobj.subArray[0], or "0.3.1" for [0][3][1]. But i'm too
15931593
lazy/tired to add this.
15941594
15951595
Example usage:
1596
-
1596
+
15971597
15981598
Assume we have a JSON structure which abstractly looks like:
15991599
16001600
@code
16011601
{"subobj":{"subsubobj":{"myValue":[1,2,3]}}}
@@ -1613,11 +1613,11 @@
16131613
"subobj/subsubobj/myValue" with separator='/' is equivalent the
16141614
path "subobj.subsubobj.myValue" with separator='.'. The value of 0
16151615
is not legal as a separator character because we cannot
16161616
distinguish that use from the real end-of-string without requiring
16171617
the caller to also pass in the length of the string.
1618
-
1618
+
16191619
Multiple successive separators in the list are collapsed into a
16201620
single separator for parsing purposes. e.g. the path "a...b...c"
16211621
(separator='.') is equivalent to "a.b.c".
16221622
16231623
@see cson_object_get_sub()
@@ -1700,11 +1700,11 @@
17001700
@see cson_object_iter_init()
17011701
@see cson_object_iter_next()
17021702
*/
17031703
struct cson_object_iterator
17041704
{
1705
-
1705
+
17061706
/** @internal
17071707
The underlying object.
17081708
*/
17091709
cson_object const * obj;
17101710
/** @internal
@@ -1771,11 +1771,11 @@
17711771
...
17721772
}
17731773
@endcode
17741774
17751775
There is no need to clean up an iterator, as it holds no dynamic resources.
1776
-
1776
+
17771777
@see cson_kvp_key()
17781778
@see cson_kvp_value()
17791779
*/
17801780
cson_kvp * cson_object_iter_next( cson_object_iterator * iter );
17811781
@@ -1863,11 +1863,11 @@
18631863
buf = cson_buffer_empty;
18641864
@endcode
18651865
18661866
(You might also need to store buf.used and buf.capacity,
18671867
depending on what you want to do with the memory.)
1868
-
1868
+
18691869
When doing so, the memory must eventually be passed to free()
18701870
to deallocate it.
18711871
*/
18721872
unsigned char * mem;
18731873
};
@@ -1894,11 +1894,11 @@
18941894
On error non-zero is returned. Errors include:
18951895
18961896
- Invalid arguments: cson_rc.ArgError
18971897
18981898
- Buffer cannot be expanded (runs out of memory): cson_rc.AllocError
1899
-
1899
+
19001900
Example usage:
19011901
19021902
@code
19031903
cson_buffer buf = cson_buffer_empty;
19041904
// optional: cson_buffer_reserve(&buf, 1024 * 10);
@@ -1918,13 +1918,13 @@
19181918
buf = cson_buffer_empty;
19191919
...
19201920
free(mem);
19211921
}
19221922
@endcode
1923
-
1923
+
19241924
@see cson_output()
1925
-
1925
+
19261926
*/
19271927
int cson_output_buffer( cson_value const * v, cson_buffer * buf,
19281928
cson_output_opt const * opt );
19291929
19301930
/**
@@ -1993,11 +1993,11 @@
19931993
calling cson_buffer_reserve(dest,0).
19941994
19951995
dest->mem might (and possibly will) be (re)allocated by this
19961996
function, so any pointers to it held from before this call might be
19971997
invalidated by this call.
1998
-
1998
+
19991999
On error non-0 is returned and dest has almost certainly been
20002000
modified but its state must be considered incomplete.
20012001
20022002
Errors include:
20032003
@@ -2042,11 +2042,11 @@
20422042
void * mem = buf.mem;
20432043
buf = cson_buffer_empty;
20442044
@endcode
20452045
20462046
In which case the memory must eventually be passed to free() to
2047
- free it.
2047
+ free it.
20482048
*/
20492049
int cson_buffer_fill_from( cson_buffer * dest, cson_data_source_f src, void * state );
20502050
20512051
20522052
/**
@@ -2072,11 +2072,11 @@
20722072
for other sharing points which added a reference.
20732073
20742074
Normally any such value handles would be invalidated when the
20752075
parent container(s) is/are cleaned up, but this function can be
20762076
used to effectively delay the cleanup.
2077
-
2077
+
20782078
This function, at its lowest level, increments the value's
20792079
reference count by 1.
20802080
20812081
To decrement the reference count, pass the value to
20822082
cson_value_free(), after which the value must be considered, from
@@ -2091,11 +2091,11 @@
20912091
errors long before the reference count could overflow (assuming
20922092
those reference counts come from container insertions, as opposed
20932093
to via this function).
20942094
20952095
Insider notes which clients really need to know:
2096
-
2096
+
20972097
For shared/constant value instances, such as those returned by
20982098
cson_value_true() and cson_value_null(), this function has no side
20992099
effects - it does not actually modify the reference count because
21002100
(A) those instances are shared across all client code and (B) those
21012101
objects are static and never get cleaned up. However, that is an
@@ -2173,11 +2173,11 @@
21732173
returned object will be of the same logical type as orig.
21742174
21752175
ACHTUNG: if orig contains any cyclic references at any depth level
21762176
this function will endlessly recurse. (Having _any_ cyclic
21772177
references violates this library's requirements.)
2178
-
2178
+
21792179
Returns NULL if orig is NULL or if cloning fails. Assuming that
21802180
orig is in a valid state, the only "likely" error case is that an
21812181
allocation fails while constructing the clone. In other words, if
21822182
cloning fails due to something other than an allocation error then
21832183
either orig is in an invalid state or there is a bug.
@@ -2278,11 +2278,11 @@
22782278
--key=VAL : Treats VAL as either a double, integer, or string.
22792279
22802280
--key= : Treats key as a JSON null (not literal NULL) value.
22812281
22822282
Arguments not starting with a dash are skipped.
2283
-
2283
+
22842284
Each key/value pair is inserted into an object. If a given key
22852285
appears more than once then only the final entry is actually
22862286
stored.
22872287
22882288
argc and argv are expected to be values from main() (or similar,
@@ -2434,22 +2434,22 @@
24342434
Integer, double, null, or string (TEXT and BLOB data, though not
24352435
all blob data is legal for a JSON string).
24362436
24372437
st must be a sqlite3_step()'d row and col must be a 0-based column
24382438
index within that result row.
2439
- */
2439
+ */
24402440
cson_value * cson_sqlite3_column_to_value( sqlite3_stmt * st, int col );
24412441
24422442
/**
24432443
Creates a JSON Array object containing the names of all columns
2444
- of the given prepared statement handle.
2445
-
2444
+ of the given prepared statement handle.
2445
+
24462446
Returns a new array value on success, which the caller owns. Its elements
24472447
are in the same order as in the underlying query.
24482448
24492449
On error NULL is returned.
2450
-
2450
+
24512451
st is not traversed or freed by this function - only the column
24522452
count and names are read.
24532453
*/
24542454
cson_value * cson_sqlite3_column_names( sqlite3_stmt * st );
24552455
@@ -2494,22 +2494,22 @@
24942494
*/
24952495
cson_value * cson_sqlite3_row_to_array( sqlite3_stmt * st );
24962496
/**
24972497
Converts the results of an sqlite3 SELECT statement to JSON,
24982498
in the form of a cson_value object tree.
2499
-
2499
+
25002500
st must be a prepared, but not yet traversed, SELECT query.
25012501
tgt must be a pointer to NULL (see the example below). If
25022502
either of those arguments are NULL, cson_rc.ArgError is returned.
2503
-
2503
+
25042504
This walks the query results and returns a JSON object which
25052505
has a different structure depending on the value of the 'fat'
25062506
argument.
2507
-
2508
-
2507
+
2508
+
25092509
If 'fat' is 0 then the structure is:
2510
-
2510
+
25112511
@code
25122512
{
25132513
"columns":["colName1",..."colNameN"],
25142514
"rows":[
25152515
[colVal0, ... colValN],
@@ -2516,16 +2516,16 @@
25162516
[colVal0, ... colValN],
25172517
...
25182518
]
25192519
}
25202520
@endcode
2521
-
2521
+
25222522
In the "non-fat" format the order of the columns and row values is
25232523
guaranteed to be the same as that of the underlying query.
2524
-
2524
+
25252525
If 'fat' is not 0 then the structure is:
2526
-
2526
+
25272527
@code
25282528
{
25292529
"columns":["colName1",..."colNameN"],
25302530
"rows":[
25312531
{"colName1":value1,..."colNameN":valueN},
@@ -2543,33 +2543,33 @@
25432543
25442544
On success it returns 0 and assigns *tgt to a newly-allocated
25452545
JSON object tree (using the above structure), which the caller owns.
25462546
If the query returns no rows, the "rows" value will be an empty
25472547
array, as opposed to null.
2548
-
2548
+
25492549
On error non-0 is returned and *tgt is not modified.
2550
-
2550
+
25512551
The error code cson_rc.IOError is used to indicate a db-level
25522552
error, and cson_rc.TypeError is returned if sqlite3_column_count(st)
25532553
returns 0 or less (indicating an invalid or non-SELECT statement).
2554
-
2554
+
25552555
The JSON data types are determined by the column type as reported
25562556
by sqlite3_column_type():
2557
-
2557
+
25582558
SQLITE_INTEGER: integer
2559
-
2559
+
25602560
SQLITE_FLOAT: double
2561
-
2561
+
25622562
SQLITE_TEXT or SQLITE_BLOB: string, and this will only work if
25632563
the data is UTF8 compatible.
2564
-
2564
+
25652565
If the db returns a literal or SQL NULL for a value it is converted
25662566
to a JSON null. If it somehow finds a column type it cannot handle,
25672567
the value is also converted to a NULL in the output.
25682568
25692569
Example
2570
-
2570
+
25712571
@code
25722572
cson_value * json = NULL;
25732573
int rc = cson_sqlite3_stmt_to_json( myStatement, &json, 1 );
25742574
if( 0 != rc ) { ... error ... }
25752575
else {
@@ -2603,14 +2603,14 @@
26032603
TODO: add Object support for named parameters.
26042604
26052605
Returns 0 on success, non-0 on error.
26062606
*/
26072607
int cson_sqlite3_bind_value( sqlite3_stmt * st, int ndx, cson_value const * v );
2608
-
2608
+
26092609
#if defined(__cplusplus)
26102610
} /*extern "C"*/
26112611
#endif
2612
-
2612
+
26132613
#endif /* CSON_ENABLE_SQLITE3 */
26142614
#endif /* WANDERINGHORSE_NET_CSON_SQLITE3_H_INCLUDED */
26152615
/* end file include/wh/cson/cson_sqlite3.h */
26162616
#endif /* FOSSIL_ENABLE_JSON */
26172617
--- src/cson_amalgamation.h
+++ src/cson_amalgamation.h
@@ -59,11 +59,11 @@
59 #define CSON_INT_T_PFMT "I64d"
60 #elif (__STDC_VERSION__ >= 199901L) || (HAVE_LONG_LONG == 1)
61 typedef long long cson_int_t;
62 #define CSON_INT_T_SFMT "lld"
63 #define CSON_INT_T_PFMT "lld"
64 #else
65 typedef long cson_int_t;
66 #define CSON_INT_T_SFMT "ld"
67 #define CSON_INT_T_PFMT "ld"
68 #endif
69
@@ -215,11 +215,11 @@
215 Convenience typedef.
216 */
217 typedef struct cson_value cson_value;
218
219 /** @struct cson_value
220
221 The core value type of this API. It is opaque to clients, and
222 only the cson public API should be used for setting or
223 inspecting their values.
224
225 This class is opaque because stack-based usage can easily cause
@@ -231,11 +231,11 @@
231 counting) as long as those insertions do not cause cycles. However,
232 be very aware that such value re-use uses a reference to the
233 original copy, meaning that if its value is changed once, it is
234 changed everywhere. Also beware that multi-threaded write
235 operations on such references leads to undefined behaviour.
236
237 PLEASE read the ACHTUNGEN below...
238
239 ACHTUNG #1:
240
241 cson_values MUST NOT form cycles (e.g. via object or array
@@ -244,33 +244,33 @@
244 Not abiding th Holy Law Of No Cycles will lead to double-frees and
245 the like (i.e. undefined behaviour, likely crashes due to infinite
246 recursion or stepping on invalid (freed) pointers).
247
248 ACHTUNG #2:
249
250 ALL cson_values returned as non-const cson_value pointers from any
251 public functions in the cson API are to be treated as if they are
252 heap-allocated, and MUST be freed by client by doing ONE of:
253
254 - Passing it to cson_value_free().
255
256 - Adding it to an Object or Array, in which case the object/array
257 takes over ownership. As of 20110323, a value may be inserted into
258 a single container multiple times, or into multiple containers,
259 in which case they all share ownership (via reference counting)
260 of the original value (meaning any changes to it are visible in
261 all references to it).
262
263 Each call to cson_value_new_xxx() MUST eventually be followed up
264 by one of those options.
265
266 Some cson_value_new_XXX() implementations do not actually allocate
267 memory, but this is an internal implementation detail. Client code
268 MUST NOT rely on this behaviour and MUST treat each object
269 returned by such a function as if it was a freshly-allocated copy
270 (even if their pointer addresses are the same).
271
272 ACHTUNG #3:
273
274 Note that ACHTUNG #2 tells us that we must always free (or transfer
275 ownership of) all pointers returned bycson_value_new_xxx(), but
276 that two calls to (e.g.) cson_value_new_bool(1) will (or might)
@@ -315,11 +315,11 @@
315 if( 0 == rc ) {...success...}
316 else if( cson_rc.ArgError == rc ) { ... some argument was wrong ... }
317 else if( cson_rc.AllocError == rc ) { ... allocation error ... }
318 ...
319 @endcode
320
321 The entries named Parse_XXX are generally only returned by
322 cson_parse() and friends.
323 */
324
325 /** @struct cson_rc_
@@ -472,11 +472,11 @@
472
473 /**
474 Length, in bytes.
475 */
476 unsigned int length;
477
478 /**
479 Error code of the parse run (0 for no error).
480 */
481 int errorCode;
482
@@ -523,11 +523,11 @@
523 /**
524 Specifies how to indent (or not) output. The values
525 are:
526
527 (0) == no extra indentation.
528
529 (1) == 1 TAB character for each level.
530
531 (>1) == that number of SPACES for each level.
532 */
533 unsigned char indentation;
@@ -536,11 +536,11 @@
536 Maximum object/array depth to traverse. Traversing deeply can
537 be indicative of cycles in the object/array tree, and this
538 value is used to figure out when to abort the traversal.
539 */
540 unsigned short maxDepth;
541
542 /**
543 If true, a newline will be added to generated output,
544 else not.
545 */
546 char addNewline;
@@ -636,11 +636,11 @@
636
637 Must return 0 on success, non-0 on error (preferably a value from
638 cson_rc).
639
640 These functions are called relatively often during the JSON-output
641 process, and should try to be fast.
642 */
643 typedef int (*cson_data_dest_f)( void * state, void const * src, unsigned int n );
644
645 /**
646 Reads JSON-formatted string data (in ASCII, UTF8, or UTF16), using the
@@ -664,15 +664,15 @@
664 used.
665
666 The info argument may be NULL. If it is not NULL then the parser
667 populates it with information which is useful in error
668 reporting. Namely, it contains the line/column of parse errors.
669
670 The srcState argument is ignored by this function but is passed on to src,
671 so any output-destination-specific state can be stored there and accessed
672 via the src callback.
673
674 Non-parse error conditions include:
675
676 - (!tgt) or !src: cson_rc.ArgError
677 - cson_rc.AllocError can happen at any time during the input phase
678
@@ -725,11 +725,11 @@
725 TODOs:
726
727 - Buffer the input in larger chunks. We currently read
728 byte-by-byte, but i'm too tired to write/test the looping code for
729 the buffering.
730
731 @see cson_parse_FILE()
732 @see cson_parse_string()
733 */
734 int cson_parse( cson_value ** tgt, cson_data_source_f src, void * srcState,
735 cson_parse_opt const * opt, cson_parse_info * info );
@@ -786,11 +786,11 @@
786 The destState parameter is ignored by this function and is passed
787 on to the dest function.
788
789 Returns 0 on success. On error, any amount of output might have been
790 generated before the error was triggered.
791
792 Example:
793
794 @code
795 int rc = cson_output( myValue, cson_data_dest_FILE, stdout, NULL );
796 // basically equivalent to: cson_output_FILE( myValue, stdout, NULL );
@@ -925,15 +925,15 @@
925 /**
926 Converts the given value to a boolean, using JavaScript semantics depending
927 on the concrete type of val:
928
929 undef or null: false
930
931 boolean: same
932
933 integer, double: 0 or 0.0 == false, else true
934
935 object, array: true
936
937 string: length-0 string is false, else true.
938
939 Returns 0 on success and assigns *v (if v is not NULL) to either 0 or 1.
@@ -945,18 +945,18 @@
945 Similar to cson_value_fetch_bool(), but fetches an integer value.
946
947 The conversion, if any, depends on the concrete type of val:
948
949 NULL, null, undefined: *v is set to 0 and 0 is returned.
950
951 string, object, array: *v is set to 0 and
952 cson_rc.TypeError is returned. The error may normally be safely
953 ignored, but it is provided for those wanted to know whether a direct
954 conversion was possible.
955
956 integer: *v is set to the int value and 0 is returned.
957
958 double: *v is set to the value truncated to int and 0 is returned.
959 */
960 int cson_value_fetch_integer( cson_value const * val, cson_int_t * v );
961
962 /**
@@ -1084,11 +1084,11 @@
1084
1085 - The maximum number of bytes compared is the lesser of rhsLen and
1086 the length of lhs. If the strings do not match, but compare equal
1087 up to the just-described comparison length, the shorter string is
1088 considered to be less-than the longer one.
1089
1090 - If lhs and rhs are both NULL, or both have a length of 0 then they will
1091 compare equal.
1092
1093 - If lhs is null/length-0 but rhs is not then lhs is considered to be less-than
1094 rhs.
@@ -1110,11 +1110,11 @@
1110 Returns the length, in bytes, of str, or 0 if str is NULL. This is
1111 an O(1) operation.
1112
1113 TODO: add cson_string_length_chars() (is O(N) unless we add another
1114 member to store the char length).
1115
1116 @see cson_string_cstr()
1117 */
1118 unsigned int cson_string_length_bytes( cson_string const * str );
1119
1120 /**
@@ -1207,11 +1207,11 @@
1207 ar is expanded, if needed, to be able to hold at least (ndx+1)
1208 items, and any new entries created by that expansion are empty
1209 (NULL values).
1210
1211 On success, 0 is returned and ownership of v is transfered to ar.
1212
1213 On error ownership of v is NOT modified, and the caller may still
1214 need to clean it up. For example, the following code will introduce
1215 a leak if this function fails:
1216
1217 @code
@@ -1240,11 +1240,11 @@
1240
1241 This is functionally equivalent to
1242 cson_array_set(ar,cson_array_length_get(ar),v), but this
1243 implementation has slightly different array-preallocation policy
1244 (it grows more eagerly).
1245
1246 Returns 0 on success, non-zero on error. Error cases include:
1247
1248 - ar or v are NULL: cson_rc.ArgError
1249
1250 - Array cannot be expanded to hold enough elements: cson_rc.AllocError.
@@ -1283,11 +1283,11 @@
1283 cson_value * cson_new_bool(char v);
1284
1285 /**
1286 Returns the special JSON "null" value. When outputing JSON,
1287 its string representation is "null" (without the quotes).
1288
1289 See cson_value_new_bool() for notes regarding the returned
1290 value's memory.
1291 */
1292 cson_value * cson_value_null();
1293
@@ -1323,16 +1323,16 @@
1323
1324 /**
1325 Semantically the same as cson_value_new_bool(), but for strings.
1326 This creates a JSON value which copies the first n bytes of str.
1327 The string will automatically be NUL-terminated.
1328
1329 Note that if str is NULL or n is 0, this function still
1330 returns non-NULL value representing that empty string.
1331
1332 Returns NULL on allocation error.
1333
1334 See cson_value_new_bool() for important information about the
1335 returned memory.
1336 */
1337 cson_value * cson_value_new_string( char const * str, unsigned int n );
1338
@@ -1354,11 +1354,11 @@
1354 This works like cson_value_new_object() but returns an Object
1355 handle directly.
1356
1357 The value handle for the returned object can be fetched with
1358 cson_object_value(theObject).
1359
1360 Ownership is transfered to the caller, who must eventually free it
1361 by passing the Value handle (NOT the Object handle) to
1362 cson_value_free() or passing ownership to a parent container.
1363
1364 Returns NULL on error (out of memory).
@@ -1419,11 +1419,11 @@
1419 cson_value_add_reference(). Even if this function does not
1420 immediately destroy the value, the value must be considered, from
1421 the perspective of that client code, to have been
1422 destroyed/invalidated by this call.
1423
1424
1425 @see cson_value_new_object()
1426 @see cson_value_new_array()
1427 @see cson_value_add_reference()
1428 */
1429 void cson_value_free(cson_value * v);
@@ -1445,11 +1445,11 @@
1445 case, the key is set to the special null value.
1446
1447 The key may be encoded as ASCII or UTF8. Results are undefined
1448 with other encodings, and the errors won't show up here, but may
1449 show up later, e.g. during output.
1450
1451 Returns 0 on success, non-0 on error. It has the following error
1452 cases:
1453
1454 - cson_rc.ArgError: obj or key are NULL or strlen(key) is 0.
1455
@@ -1498,11 +1498,11 @@
1498 */
1499 int cson_object_set_s( cson_object * obj, cson_string * key, cson_value * v );
1500
1501 /**
1502 Removes a property from an object.
1503
1504 If obj contains the given key, it is removed and 0 is returned. If
1505 it is not found, cson_rc.NotFoundError is returned (which can
1506 normally be ignored by client code).
1507
1508 cson_rc.ArgError is returned if obj or key are NULL or key has
@@ -1569,33 +1569,33 @@
1569
1570 If it finds the given path, it returns the value by assiging *tgt
1571 to it. If tgt is NULL then this function has no side-effects but
1572 will return 0 if the given path is found within the object, so it can be used
1573 to test for existence without fetching it.
1574
1575 Returns 0 if it finds an entry, cson_rc.NotFoundError if it finds
1576 no item, and any other non-zero error code on a "real" error. Errors include:
1577
1578 - obj or path are NULL: cson_rc.ArgError
1579
1580 - separator is 0, or path is an empty string or contains only
1581 separator characters: cson_rc.RangeError
1582
1583 - There is an upper limit on how long a single path component may
1584 be (some "reasonable" internal size), and cson_rc.RangeError is
1585 returned if that length is violated.
1586
1587
1588 Limitations:
1589
1590 - It has no way to fetch data from arrays this way. i could
1591 imagine, e.g., a path of "subobj.subArray.0" for
1592 subobj.subArray[0], or "0.3.1" for [0][3][1]. But i'm too
1593 lazy/tired to add this.
1594
1595 Example usage:
1596
1597
1598 Assume we have a JSON structure which abstractly looks like:
1599
1600 @code
1601 {"subobj":{"subsubobj":{"myValue":[1,2,3]}}}
@@ -1613,11 +1613,11 @@
1613 "subobj/subsubobj/myValue" with separator='/' is equivalent the
1614 path "subobj.subsubobj.myValue" with separator='.'. The value of 0
1615 is not legal as a separator character because we cannot
1616 distinguish that use from the real end-of-string without requiring
1617 the caller to also pass in the length of the string.
1618
1619 Multiple successive separators in the list are collapsed into a
1620 single separator for parsing purposes. e.g. the path "a...b...c"
1621 (separator='.') is equivalent to "a.b.c".
1622
1623 @see cson_object_get_sub()
@@ -1700,11 +1700,11 @@
1700 @see cson_object_iter_init()
1701 @see cson_object_iter_next()
1702 */
1703 struct cson_object_iterator
1704 {
1705
1706 /** @internal
1707 The underlying object.
1708 */
1709 cson_object const * obj;
1710 /** @internal
@@ -1771,11 +1771,11 @@
1771 ...
1772 }
1773 @endcode
1774
1775 There is no need to clean up an iterator, as it holds no dynamic resources.
1776
1777 @see cson_kvp_key()
1778 @see cson_kvp_value()
1779 */
1780 cson_kvp * cson_object_iter_next( cson_object_iterator * iter );
1781
@@ -1863,11 +1863,11 @@
1863 buf = cson_buffer_empty;
1864 @endcode
1865
1866 (You might also need to store buf.used and buf.capacity,
1867 depending on what you want to do with the memory.)
1868
1869 When doing so, the memory must eventually be passed to free()
1870 to deallocate it.
1871 */
1872 unsigned char * mem;
1873 };
@@ -1894,11 +1894,11 @@
1894 On error non-zero is returned. Errors include:
1895
1896 - Invalid arguments: cson_rc.ArgError
1897
1898 - Buffer cannot be expanded (runs out of memory): cson_rc.AllocError
1899
1900 Example usage:
1901
1902 @code
1903 cson_buffer buf = cson_buffer_empty;
1904 // optional: cson_buffer_reserve(&buf, 1024 * 10);
@@ -1918,13 +1918,13 @@
1918 buf = cson_buffer_empty;
1919 ...
1920 free(mem);
1921 }
1922 @endcode
1923
1924 @see cson_output()
1925
1926 */
1927 int cson_output_buffer( cson_value const * v, cson_buffer * buf,
1928 cson_output_opt const * opt );
1929
1930 /**
@@ -1993,11 +1993,11 @@
1993 calling cson_buffer_reserve(dest,0).
1994
1995 dest->mem might (and possibly will) be (re)allocated by this
1996 function, so any pointers to it held from before this call might be
1997 invalidated by this call.
1998
1999 On error non-0 is returned and dest has almost certainly been
2000 modified but its state must be considered incomplete.
2001
2002 Errors include:
2003
@@ -2042,11 +2042,11 @@
2042 void * mem = buf.mem;
2043 buf = cson_buffer_empty;
2044 @endcode
2045
2046 In which case the memory must eventually be passed to free() to
2047 free it.
2048 */
2049 int cson_buffer_fill_from( cson_buffer * dest, cson_data_source_f src, void * state );
2050
2051
2052 /**
@@ -2072,11 +2072,11 @@
2072 for other sharing points which added a reference.
2073
2074 Normally any such value handles would be invalidated when the
2075 parent container(s) is/are cleaned up, but this function can be
2076 used to effectively delay the cleanup.
2077
2078 This function, at its lowest level, increments the value's
2079 reference count by 1.
2080
2081 To decrement the reference count, pass the value to
2082 cson_value_free(), after which the value must be considered, from
@@ -2091,11 +2091,11 @@
2091 errors long before the reference count could overflow (assuming
2092 those reference counts come from container insertions, as opposed
2093 to via this function).
2094
2095 Insider notes which clients really need to know:
2096
2097 For shared/constant value instances, such as those returned by
2098 cson_value_true() and cson_value_null(), this function has no side
2099 effects - it does not actually modify the reference count because
2100 (A) those instances are shared across all client code and (B) those
2101 objects are static and never get cleaned up. However, that is an
@@ -2173,11 +2173,11 @@
2173 returned object will be of the same logical type as orig.
2174
2175 ACHTUNG: if orig contains any cyclic references at any depth level
2176 this function will endlessly recurse. (Having _any_ cyclic
2177 references violates this library's requirements.)
2178
2179 Returns NULL if orig is NULL or if cloning fails. Assuming that
2180 orig is in a valid state, the only "likely" error case is that an
2181 allocation fails while constructing the clone. In other words, if
2182 cloning fails due to something other than an allocation error then
2183 either orig is in an invalid state or there is a bug.
@@ -2278,11 +2278,11 @@
2278 --key=VAL : Treats VAL as either a double, integer, or string.
2279
2280 --key= : Treats key as a JSON null (not literal NULL) value.
2281
2282 Arguments not starting with a dash are skipped.
2283
2284 Each key/value pair is inserted into an object. If a given key
2285 appears more than once then only the final entry is actually
2286 stored.
2287
2288 argc and argv are expected to be values from main() (or similar,
@@ -2434,22 +2434,22 @@
2434 Integer, double, null, or string (TEXT and BLOB data, though not
2435 all blob data is legal for a JSON string).
2436
2437 st must be a sqlite3_step()'d row and col must be a 0-based column
2438 index within that result row.
2439 */
2440 cson_value * cson_sqlite3_column_to_value( sqlite3_stmt * st, int col );
2441
2442 /**
2443 Creates a JSON Array object containing the names of all columns
2444 of the given prepared statement handle.
2445
2446 Returns a new array value on success, which the caller owns. Its elements
2447 are in the same order as in the underlying query.
2448
2449 On error NULL is returned.
2450
2451 st is not traversed or freed by this function - only the column
2452 count and names are read.
2453 */
2454 cson_value * cson_sqlite3_column_names( sqlite3_stmt * st );
2455
@@ -2494,22 +2494,22 @@
2494 */
2495 cson_value * cson_sqlite3_row_to_array( sqlite3_stmt * st );
2496 /**
2497 Converts the results of an sqlite3 SELECT statement to JSON,
2498 in the form of a cson_value object tree.
2499
2500 st must be a prepared, but not yet traversed, SELECT query.
2501 tgt must be a pointer to NULL (see the example below). If
2502 either of those arguments are NULL, cson_rc.ArgError is returned.
2503
2504 This walks the query results and returns a JSON object which
2505 has a different structure depending on the value of the 'fat'
2506 argument.
2507
2508
2509 If 'fat' is 0 then the structure is:
2510
2511 @code
2512 {
2513 "columns":["colName1",..."colNameN"],
2514 "rows":[
2515 [colVal0, ... colValN],
@@ -2516,16 +2516,16 @@
2516 [colVal0, ... colValN],
2517 ...
2518 ]
2519 }
2520 @endcode
2521
2522 In the "non-fat" format the order of the columns and row values is
2523 guaranteed to be the same as that of the underlying query.
2524
2525 If 'fat' is not 0 then the structure is:
2526
2527 @code
2528 {
2529 "columns":["colName1",..."colNameN"],
2530 "rows":[
2531 {"colName1":value1,..."colNameN":valueN},
@@ -2543,33 +2543,33 @@
2543
2544 On success it returns 0 and assigns *tgt to a newly-allocated
2545 JSON object tree (using the above structure), which the caller owns.
2546 If the query returns no rows, the "rows" value will be an empty
2547 array, as opposed to null.
2548
2549 On error non-0 is returned and *tgt is not modified.
2550
2551 The error code cson_rc.IOError is used to indicate a db-level
2552 error, and cson_rc.TypeError is returned if sqlite3_column_count(st)
2553 returns 0 or less (indicating an invalid or non-SELECT statement).
2554
2555 The JSON data types are determined by the column type as reported
2556 by sqlite3_column_type():
2557
2558 SQLITE_INTEGER: integer
2559
2560 SQLITE_FLOAT: double
2561
2562 SQLITE_TEXT or SQLITE_BLOB: string, and this will only work if
2563 the data is UTF8 compatible.
2564
2565 If the db returns a literal or SQL NULL for a value it is converted
2566 to a JSON null. If it somehow finds a column type it cannot handle,
2567 the value is also converted to a NULL in the output.
2568
2569 Example
2570
2571 @code
2572 cson_value * json = NULL;
2573 int rc = cson_sqlite3_stmt_to_json( myStatement, &json, 1 );
2574 if( 0 != rc ) { ... error ... }
2575 else {
@@ -2603,14 +2603,14 @@
2603 TODO: add Object support for named parameters.
2604
2605 Returns 0 on success, non-0 on error.
2606 */
2607 int cson_sqlite3_bind_value( sqlite3_stmt * st, int ndx, cson_value const * v );
2608
2609 #if defined(__cplusplus)
2610 } /*extern "C"*/
2611 #endif
2612
2613 #endif /* CSON_ENABLE_SQLITE3 */
2614 #endif /* WANDERINGHORSE_NET_CSON_SQLITE3_H_INCLUDED */
2615 /* end file include/wh/cson/cson_sqlite3.h */
2616 #endif /* FOSSIL_ENABLE_JSON */
2617
--- src/cson_amalgamation.h
+++ src/cson_amalgamation.h
@@ -59,11 +59,11 @@
59 #define CSON_INT_T_PFMT "I64d"
60 #elif (__STDC_VERSION__ >= 199901L) || (HAVE_LONG_LONG == 1)
61 typedef long long cson_int_t;
62 #define CSON_INT_T_SFMT "lld"
63 #define CSON_INT_T_PFMT "lld"
64 #else
65 typedef long cson_int_t;
66 #define CSON_INT_T_SFMT "ld"
67 #define CSON_INT_T_PFMT "ld"
68 #endif
69
@@ -215,11 +215,11 @@
215 Convenience typedef.
216 */
217 typedef struct cson_value cson_value;
218
219 /** @struct cson_value
220
221 The core value type of this API. It is opaque to clients, and
222 only the cson public API should be used for setting or
223 inspecting their values.
224
225 This class is opaque because stack-based usage can easily cause
@@ -231,11 +231,11 @@
231 counting) as long as those insertions do not cause cycles. However,
232 be very aware that such value re-use uses a reference to the
233 original copy, meaning that if its value is changed once, it is
234 changed everywhere. Also beware that multi-threaded write
235 operations on such references leads to undefined behaviour.
236
237 PLEASE read the ACHTUNGEN below...
238
239 ACHTUNG #1:
240
241 cson_values MUST NOT form cycles (e.g. via object or array
@@ -244,33 +244,33 @@
244 Not abiding th Holy Law Of No Cycles will lead to double-frees and
245 the like (i.e. undefined behaviour, likely crashes due to infinite
246 recursion or stepping on invalid (freed) pointers).
247
248 ACHTUNG #2:
249
250 ALL cson_values returned as non-const cson_value pointers from any
251 public functions in the cson API are to be treated as if they are
252 heap-allocated, and MUST be freed by client by doing ONE of:
253
254 - Passing it to cson_value_free().
255
256 - Adding it to an Object or Array, in which case the object/array
257 takes over ownership. As of 20110323, a value may be inserted into
258 a single container multiple times, or into multiple containers,
259 in which case they all share ownership (via reference counting)
260 of the original value (meaning any changes to it are visible in
261 all references to it).
262
263 Each call to cson_value_new_xxx() MUST eventually be followed up
264 by one of those options.
265
266 Some cson_value_new_XXX() implementations do not actually allocate
267 memory, but this is an internal implementation detail. Client code
268 MUST NOT rely on this behaviour and MUST treat each object
269 returned by such a function as if it was a freshly-allocated copy
270 (even if their pointer addresses are the same).
271
272 ACHTUNG #3:
273
274 Note that ACHTUNG #2 tells us that we must always free (or transfer
275 ownership of) all pointers returned bycson_value_new_xxx(), but
276 that two calls to (e.g.) cson_value_new_bool(1) will (or might)
@@ -315,11 +315,11 @@
315 if( 0 == rc ) {...success...}
316 else if( cson_rc.ArgError == rc ) { ... some argument was wrong ... }
317 else if( cson_rc.AllocError == rc ) { ... allocation error ... }
318 ...
319 @endcode
320
321 The entries named Parse_XXX are generally only returned by
322 cson_parse() and friends.
323 */
324
325 /** @struct cson_rc_
@@ -472,11 +472,11 @@
472
473 /**
474 Length, in bytes.
475 */
476 unsigned int length;
477
478 /**
479 Error code of the parse run (0 for no error).
480 */
481 int errorCode;
482
@@ -523,11 +523,11 @@
523 /**
524 Specifies how to indent (or not) output. The values
525 are:
526
527 (0) == no extra indentation.
528
529 (1) == 1 TAB character for each level.
530
531 (>1) == that number of SPACES for each level.
532 */
533 unsigned char indentation;
@@ -536,11 +536,11 @@
536 Maximum object/array depth to traverse. Traversing deeply can
537 be indicative of cycles in the object/array tree, and this
538 value is used to figure out when to abort the traversal.
539 */
540 unsigned short maxDepth;
541
542 /**
543 If true, a newline will be added to generated output,
544 else not.
545 */
546 char addNewline;
@@ -636,11 +636,11 @@
636
637 Must return 0 on success, non-0 on error (preferably a value from
638 cson_rc).
639
640 These functions are called relatively often during the JSON-output
641 process, and should try to be fast.
642 */
643 typedef int (*cson_data_dest_f)( void * state, void const * src, unsigned int n );
644
645 /**
646 Reads JSON-formatted string data (in ASCII, UTF8, or UTF16), using the
@@ -664,15 +664,15 @@
664 used.
665
666 The info argument may be NULL. If it is not NULL then the parser
667 populates it with information which is useful in error
668 reporting. Namely, it contains the line/column of parse errors.
669
670 The srcState argument is ignored by this function but is passed on to src,
671 so any output-destination-specific state can be stored there and accessed
672 via the src callback.
673
674 Non-parse error conditions include:
675
676 - (!tgt) or !src: cson_rc.ArgError
677 - cson_rc.AllocError can happen at any time during the input phase
678
@@ -725,11 +725,11 @@
725 TODOs:
726
727 - Buffer the input in larger chunks. We currently read
728 byte-by-byte, but i'm too tired to write/test the looping code for
729 the buffering.
730
731 @see cson_parse_FILE()
732 @see cson_parse_string()
733 */
734 int cson_parse( cson_value ** tgt, cson_data_source_f src, void * srcState,
735 cson_parse_opt const * opt, cson_parse_info * info );
@@ -786,11 +786,11 @@
786 The destState parameter is ignored by this function and is passed
787 on to the dest function.
788
789 Returns 0 on success. On error, any amount of output might have been
790 generated before the error was triggered.
791
792 Example:
793
794 @code
795 int rc = cson_output( myValue, cson_data_dest_FILE, stdout, NULL );
796 // basically equivalent to: cson_output_FILE( myValue, stdout, NULL );
@@ -925,15 +925,15 @@
925 /**
926 Converts the given value to a boolean, using JavaScript semantics depending
927 on the concrete type of val:
928
929 undef or null: false
930
931 boolean: same
932
933 integer, double: 0 or 0.0 == false, else true
934
935 object, array: true
936
937 string: length-0 string is false, else true.
938
939 Returns 0 on success and assigns *v (if v is not NULL) to either 0 or 1.
@@ -945,18 +945,18 @@
945 Similar to cson_value_fetch_bool(), but fetches an integer value.
946
947 The conversion, if any, depends on the concrete type of val:
948
949 NULL, null, undefined: *v is set to 0 and 0 is returned.
950
951 string, object, array: *v is set to 0 and
952 cson_rc.TypeError is returned. The error may normally be safely
953 ignored, but it is provided for those wanted to know whether a direct
954 conversion was possible.
955
956 integer: *v is set to the int value and 0 is returned.
957
958 double: *v is set to the value truncated to int and 0 is returned.
959 */
960 int cson_value_fetch_integer( cson_value const * val, cson_int_t * v );
961
962 /**
@@ -1084,11 +1084,11 @@
1084
1085 - The maximum number of bytes compared is the lesser of rhsLen and
1086 the length of lhs. If the strings do not match, but compare equal
1087 up to the just-described comparison length, the shorter string is
1088 considered to be less-than the longer one.
1089
1090 - If lhs and rhs are both NULL, or both have a length of 0 then they will
1091 compare equal.
1092
1093 - If lhs is null/length-0 but rhs is not then lhs is considered to be less-than
1094 rhs.
@@ -1110,11 +1110,11 @@
1110 Returns the length, in bytes, of str, or 0 if str is NULL. This is
1111 an O(1) operation.
1112
1113 TODO: add cson_string_length_chars() (is O(N) unless we add another
1114 member to store the char length).
1115
1116 @see cson_string_cstr()
1117 */
1118 unsigned int cson_string_length_bytes( cson_string const * str );
1119
1120 /**
@@ -1207,11 +1207,11 @@
1207 ar is expanded, if needed, to be able to hold at least (ndx+1)
1208 items, and any new entries created by that expansion are empty
1209 (NULL values).
1210
1211 On success, 0 is returned and ownership of v is transfered to ar.
1212
1213 On error ownership of v is NOT modified, and the caller may still
1214 need to clean it up. For example, the following code will introduce
1215 a leak if this function fails:
1216
1217 @code
@@ -1240,11 +1240,11 @@
1240
1241 This is functionally equivalent to
1242 cson_array_set(ar,cson_array_length_get(ar),v), but this
1243 implementation has slightly different array-preallocation policy
1244 (it grows more eagerly).
1245
1246 Returns 0 on success, non-zero on error. Error cases include:
1247
1248 - ar or v are NULL: cson_rc.ArgError
1249
1250 - Array cannot be expanded to hold enough elements: cson_rc.AllocError.
@@ -1283,11 +1283,11 @@
1283 cson_value * cson_new_bool(char v);
1284
1285 /**
1286 Returns the special JSON "null" value. When outputing JSON,
1287 its string representation is "null" (without the quotes).
1288
1289 See cson_value_new_bool() for notes regarding the returned
1290 value's memory.
1291 */
1292 cson_value * cson_value_null();
1293
@@ -1323,16 +1323,16 @@
1323
1324 /**
1325 Semantically the same as cson_value_new_bool(), but for strings.
1326 This creates a JSON value which copies the first n bytes of str.
1327 The string will automatically be NUL-terminated.
1328
1329 Note that if str is NULL or n is 0, this function still
1330 returns non-NULL value representing that empty string.
1331
1332 Returns NULL on allocation error.
1333
1334 See cson_value_new_bool() for important information about the
1335 returned memory.
1336 */
1337 cson_value * cson_value_new_string( char const * str, unsigned int n );
1338
@@ -1354,11 +1354,11 @@
1354 This works like cson_value_new_object() but returns an Object
1355 handle directly.
1356
1357 The value handle for the returned object can be fetched with
1358 cson_object_value(theObject).
1359
1360 Ownership is transfered to the caller, who must eventually free it
1361 by passing the Value handle (NOT the Object handle) to
1362 cson_value_free() or passing ownership to a parent container.
1363
1364 Returns NULL on error (out of memory).
@@ -1419,11 +1419,11 @@
1419 cson_value_add_reference(). Even if this function does not
1420 immediately destroy the value, the value must be considered, from
1421 the perspective of that client code, to have been
1422 destroyed/invalidated by this call.
1423
1424
1425 @see cson_value_new_object()
1426 @see cson_value_new_array()
1427 @see cson_value_add_reference()
1428 */
1429 void cson_value_free(cson_value * v);
@@ -1445,11 +1445,11 @@
1445 case, the key is set to the special null value.
1446
1447 The key may be encoded as ASCII or UTF8. Results are undefined
1448 with other encodings, and the errors won't show up here, but may
1449 show up later, e.g. during output.
1450
1451 Returns 0 on success, non-0 on error. It has the following error
1452 cases:
1453
1454 - cson_rc.ArgError: obj or key are NULL or strlen(key) is 0.
1455
@@ -1498,11 +1498,11 @@
1498 */
1499 int cson_object_set_s( cson_object * obj, cson_string * key, cson_value * v );
1500
1501 /**
1502 Removes a property from an object.
1503
1504 If obj contains the given key, it is removed and 0 is returned. If
1505 it is not found, cson_rc.NotFoundError is returned (which can
1506 normally be ignored by client code).
1507
1508 cson_rc.ArgError is returned if obj or key are NULL or key has
@@ -1569,33 +1569,33 @@
1569
1570 If it finds the given path, it returns the value by assiging *tgt
1571 to it. If tgt is NULL then this function has no side-effects but
1572 will return 0 if the given path is found within the object, so it can be used
1573 to test for existence without fetching it.
1574
1575 Returns 0 if it finds an entry, cson_rc.NotFoundError if it finds
1576 no item, and any other non-zero error code on a "real" error. Errors include:
1577
1578 - obj or path are NULL: cson_rc.ArgError
1579
1580 - separator is 0, or path is an empty string or contains only
1581 separator characters: cson_rc.RangeError
1582
1583 - There is an upper limit on how long a single path component may
1584 be (some "reasonable" internal size), and cson_rc.RangeError is
1585 returned if that length is violated.
1586
1587
1588 Limitations:
1589
1590 - It has no way to fetch data from arrays this way. i could
1591 imagine, e.g., a path of "subobj.subArray.0" for
1592 subobj.subArray[0], or "0.3.1" for [0][3][1]. But i'm too
1593 lazy/tired to add this.
1594
1595 Example usage:
1596
1597
1598 Assume we have a JSON structure which abstractly looks like:
1599
1600 @code
1601 {"subobj":{"subsubobj":{"myValue":[1,2,3]}}}
@@ -1613,11 +1613,11 @@
1613 "subobj/subsubobj/myValue" with separator='/' is equivalent the
1614 path "subobj.subsubobj.myValue" with separator='.'. The value of 0
1615 is not legal as a separator character because we cannot
1616 distinguish that use from the real end-of-string without requiring
1617 the caller to also pass in the length of the string.
1618
1619 Multiple successive separators in the list are collapsed into a
1620 single separator for parsing purposes. e.g. the path "a...b...c"
1621 (separator='.') is equivalent to "a.b.c".
1622
1623 @see cson_object_get_sub()
@@ -1700,11 +1700,11 @@
1700 @see cson_object_iter_init()
1701 @see cson_object_iter_next()
1702 */
1703 struct cson_object_iterator
1704 {
1705
1706 /** @internal
1707 The underlying object.
1708 */
1709 cson_object const * obj;
1710 /** @internal
@@ -1771,11 +1771,11 @@
1771 ...
1772 }
1773 @endcode
1774
1775 There is no need to clean up an iterator, as it holds no dynamic resources.
1776
1777 @see cson_kvp_key()
1778 @see cson_kvp_value()
1779 */
1780 cson_kvp * cson_object_iter_next( cson_object_iterator * iter );
1781
@@ -1863,11 +1863,11 @@
1863 buf = cson_buffer_empty;
1864 @endcode
1865
1866 (You might also need to store buf.used and buf.capacity,
1867 depending on what you want to do with the memory.)
1868
1869 When doing so, the memory must eventually be passed to free()
1870 to deallocate it.
1871 */
1872 unsigned char * mem;
1873 };
@@ -1894,11 +1894,11 @@
1894 On error non-zero is returned. Errors include:
1895
1896 - Invalid arguments: cson_rc.ArgError
1897
1898 - Buffer cannot be expanded (runs out of memory): cson_rc.AllocError
1899
1900 Example usage:
1901
1902 @code
1903 cson_buffer buf = cson_buffer_empty;
1904 // optional: cson_buffer_reserve(&buf, 1024 * 10);
@@ -1918,13 +1918,13 @@
1918 buf = cson_buffer_empty;
1919 ...
1920 free(mem);
1921 }
1922 @endcode
1923
1924 @see cson_output()
1925
1926 */
1927 int cson_output_buffer( cson_value const * v, cson_buffer * buf,
1928 cson_output_opt const * opt );
1929
1930 /**
@@ -1993,11 +1993,11 @@
1993 calling cson_buffer_reserve(dest,0).
1994
1995 dest->mem might (and possibly will) be (re)allocated by this
1996 function, so any pointers to it held from before this call might be
1997 invalidated by this call.
1998
1999 On error non-0 is returned and dest has almost certainly been
2000 modified but its state must be considered incomplete.
2001
2002 Errors include:
2003
@@ -2042,11 +2042,11 @@
2042 void * mem = buf.mem;
2043 buf = cson_buffer_empty;
2044 @endcode
2045
2046 In which case the memory must eventually be passed to free() to
2047 free it.
2048 */
2049 int cson_buffer_fill_from( cson_buffer * dest, cson_data_source_f src, void * state );
2050
2051
2052 /**
@@ -2072,11 +2072,11 @@
2072 for other sharing points which added a reference.
2073
2074 Normally any such value handles would be invalidated when the
2075 parent container(s) is/are cleaned up, but this function can be
2076 used to effectively delay the cleanup.
2077
2078 This function, at its lowest level, increments the value's
2079 reference count by 1.
2080
2081 To decrement the reference count, pass the value to
2082 cson_value_free(), after which the value must be considered, from
@@ -2091,11 +2091,11 @@
2091 errors long before the reference count could overflow (assuming
2092 those reference counts come from container insertions, as opposed
2093 to via this function).
2094
2095 Insider notes which clients really need to know:
2096
2097 For shared/constant value instances, such as those returned by
2098 cson_value_true() and cson_value_null(), this function has no side
2099 effects - it does not actually modify the reference count because
2100 (A) those instances are shared across all client code and (B) those
2101 objects are static and never get cleaned up. However, that is an
@@ -2173,11 +2173,11 @@
2173 returned object will be of the same logical type as orig.
2174
2175 ACHTUNG: if orig contains any cyclic references at any depth level
2176 this function will endlessly recurse. (Having _any_ cyclic
2177 references violates this library's requirements.)
2178
2179 Returns NULL if orig is NULL or if cloning fails. Assuming that
2180 orig is in a valid state, the only "likely" error case is that an
2181 allocation fails while constructing the clone. In other words, if
2182 cloning fails due to something other than an allocation error then
2183 either orig is in an invalid state or there is a bug.
@@ -2278,11 +2278,11 @@
2278 --key=VAL : Treats VAL as either a double, integer, or string.
2279
2280 --key= : Treats key as a JSON null (not literal NULL) value.
2281
2282 Arguments not starting with a dash are skipped.
2283
2284 Each key/value pair is inserted into an object. If a given key
2285 appears more than once then only the final entry is actually
2286 stored.
2287
2288 argc and argv are expected to be values from main() (or similar,
@@ -2434,22 +2434,22 @@
2434 Integer, double, null, or string (TEXT and BLOB data, though not
2435 all blob data is legal for a JSON string).
2436
2437 st must be a sqlite3_step()'d row and col must be a 0-based column
2438 index within that result row.
2439 */
2440 cson_value * cson_sqlite3_column_to_value( sqlite3_stmt * st, int col );
2441
2442 /**
2443 Creates a JSON Array object containing the names of all columns
2444 of the given prepared statement handle.
2445
2446 Returns a new array value on success, which the caller owns. Its elements
2447 are in the same order as in the underlying query.
2448
2449 On error NULL is returned.
2450
2451 st is not traversed or freed by this function - only the column
2452 count and names are read.
2453 */
2454 cson_value * cson_sqlite3_column_names( sqlite3_stmt * st );
2455
@@ -2494,22 +2494,22 @@
2494 */
2495 cson_value * cson_sqlite3_row_to_array( sqlite3_stmt * st );
2496 /**
2497 Converts the results of an sqlite3 SELECT statement to JSON,
2498 in the form of a cson_value object tree.
2499
2500 st must be a prepared, but not yet traversed, SELECT query.
2501 tgt must be a pointer to NULL (see the example below). If
2502 either of those arguments are NULL, cson_rc.ArgError is returned.
2503
2504 This walks the query results and returns a JSON object which
2505 has a different structure depending on the value of the 'fat'
2506 argument.
2507
2508
2509 If 'fat' is 0 then the structure is:
2510
2511 @code
2512 {
2513 "columns":["colName1",..."colNameN"],
2514 "rows":[
2515 [colVal0, ... colValN],
@@ -2516,16 +2516,16 @@
2516 [colVal0, ... colValN],
2517 ...
2518 ]
2519 }
2520 @endcode
2521
2522 In the "non-fat" format the order of the columns and row values is
2523 guaranteed to be the same as that of the underlying query.
2524
2525 If 'fat' is not 0 then the structure is:
2526
2527 @code
2528 {
2529 "columns":["colName1",..."colNameN"],
2530 "rows":[
2531 {"colName1":value1,..."colNameN":valueN},
@@ -2543,33 +2543,33 @@
2543
2544 On success it returns 0 and assigns *tgt to a newly-allocated
2545 JSON object tree (using the above structure), which the caller owns.
2546 If the query returns no rows, the "rows" value will be an empty
2547 array, as opposed to null.
2548
2549 On error non-0 is returned and *tgt is not modified.
2550
2551 The error code cson_rc.IOError is used to indicate a db-level
2552 error, and cson_rc.TypeError is returned if sqlite3_column_count(st)
2553 returns 0 or less (indicating an invalid or non-SELECT statement).
2554
2555 The JSON data types are determined by the column type as reported
2556 by sqlite3_column_type():
2557
2558 SQLITE_INTEGER: integer
2559
2560 SQLITE_FLOAT: double
2561
2562 SQLITE_TEXT or SQLITE_BLOB: string, and this will only work if
2563 the data is UTF8 compatible.
2564
2565 If the db returns a literal or SQL NULL for a value it is converted
2566 to a JSON null. If it somehow finds a column type it cannot handle,
2567 the value is also converted to a NULL in the output.
2568
2569 Example
2570
2571 @code
2572 cson_value * json = NULL;
2573 int rc = cson_sqlite3_stmt_to_json( myStatement, &json, 1 );
2574 if( 0 != rc ) { ... error ... }
2575 else {
@@ -2603,14 +2603,14 @@
2603 TODO: add Object support for named parameters.
2604
2605 Returns 0 on success, non-0 on error.
2606 */
2607 int cson_sqlite3_bind_value( sqlite3_stmt * st, int ndx, cson_value const * v );
2608
2609 #if defined(__cplusplus)
2610 } /*extern "C"*/
2611 #endif
2612
2613 #endif /* CSON_ENABLE_SQLITE3 */
2614 #endif /* WANDERINGHORSE_NET_CSON_SQLITE3_H_INCLUDED */
2615 /* end file include/wh/cson/cson_sqlite3.h */
2616 #endif /* FOSSIL_ENABLE_JSON */
2617

Keyboard Shortcuts

Open search /
Next entry (timeline) j
Previous entry (timeline) k
Open focused entry Enter
Show this help ?
Toggle theme Top nav button