Changes in lib/json.h [7a80925:5d749ad]
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
lib/json.h
r7a80925 r5d749ad 1 1 2 /* vim: set et ts=3 sw=3 sts=3ft=c:2 /* vim: set et ts=3 sw=3 ft=c: 3 3 * 4 * Copyright (C) 2012 , 2013, 2014James McLaughlin et al. All rights reserved.4 * Copyright (C) 2012 James McLaughlin et al. All rights reserved. 5 5 * https://github.com/udp/json-parser 6 6 * … … 36 36 #endif 37 37 38 #ifndef json_int_t39 #ifndef _MSC_VER40 #include <inttypes.h>41 #define json_int_t int64_t42 #else43 #define json_int_t __int6444 #endif45 #endif46 47 #include <stdlib.h>48 49 38 #ifdef __cplusplus 50 39 … … 61 50 int settings; 62 51 63 /* Custom allocator support (leave null to use malloc/free)64 */65 66 void * (* mem_alloc) (size_t, int zero, void * user_data);67 void (* mem_free) (void *, void * user_data);68 69 void * user_data; /* will be passed to mem_alloc and mem_free */70 71 52 } json_settings; 72 53 73 #define json_ enable_comments 0x0154 #define json_relaxed_commas 1 74 55 75 56 typedef enum … … 97 78 { 98 79 int boolean; 99 json_int_tinteger;80 long long integer; 100 81 double dbl; 101 82 … … 114 95 { 115 96 json_char * name; 116 unsigned int name_length;117 118 97 struct _json_value * value; 119 98 120 99 } * values; 121 122 #if defined(__cplusplus) && __cplusplus >= 201103L123 decltype(values) begin () const124 { return values;125 }126 decltype(values) end () const127 { return values + length;128 }129 #endif130 100 131 101 } object; … … 135 105 unsigned int length; 136 106 struct _json_value ** values; 137 138 #if defined(__cplusplus) && __cplusplus >= 201103L139 decltype(values) begin () const140 { return values;141 }142 decltype(values) end () const143 { return values + length;144 }145 #endif146 107 147 108 } array; … … 202 163 } 203 164 204 inline operator json_int_t () const 205 { 206 switch (type) 207 { 208 case json_integer: 209 return u.integer; 210 211 case json_double: 212 return (json_int_t) u.dbl; 213 214 default: 215 return 0; 216 }; 165 inline operator long () const 166 { return u.integer; 217 167 } 218 168 219 169 inline operator bool () const 220 { 221 if (type != json_boolean) 222 return false; 223 224 return u.boolean != 0; 225 } 226 227 inline operator double () const 228 { 229 switch (type) 230 { 231 case json_integer: 232 return (double) u.integer; 233 234 case json_double: 235 return u.dbl; 236 237 default: 238 return 0; 239 }; 170 { return u.boolean != 0; 240 171 } 241 172 … … 244 175 } json_value; 245 176 246 json_value * json_parse (const json_char * json,247 size_t length);177 json_value * json_parse 178 (const json_char * json); 248 179 249 #define json_error_max 128 250 json_value * json_parse_ex (json_settings * settings, 251 const json_char * json, 252 size_t length, 253 char * error); 180 json_value * json_parse_ex 181 (json_settings * settings, const json_char * json, char * error); 254 182 255 183 void json_value_free (json_value *); 256 257 258 /* Not usually necessary, unless you used a custom mem_alloc and now want to259 * use a custom mem_free.260 */261 void json_value_free_ex (json_settings * settings,262 json_value *);263 184 264 185
Note: See TracChangeset
for help on using the changeset viewer.