Changes in lib/json.h [5d749ad:7a80925]
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
lib/json.h
r5d749ad r7a80925 1 1 2 /* vim: set et ts=3 sw=3 ft=c:3 * 4 * Copyright (C) 2012 James McLaughlin et al. All rights reserved.2 /* vim: set et ts=3 sw=3 sts=3 ft=c: 3 * 4 * Copyright (C) 2012, 2013, 2014 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_t 39 #ifndef _MSC_VER 40 #include <inttypes.h> 41 #define json_int_t int64_t 42 #else 43 #define json_int_t __int64 44 #endif 45 #endif 46 47 #include <stdlib.h> 48 38 49 #ifdef __cplusplus 39 50 … … 50 61 int settings; 51 62 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 52 71 } json_settings; 53 72 54 #define json_ relaxed_commas173 #define json_enable_comments 0x01 55 74 56 75 typedef enum … … 78 97 { 79 98 int boolean; 80 long longinteger;99 json_int_t integer; 81 100 double dbl; 82 101 … … 95 114 { 96 115 json_char * name; 116 unsigned int name_length; 117 97 118 struct _json_value * value; 98 119 99 120 } * values; 121 122 #if defined(__cplusplus) && __cplusplus >= 201103L 123 decltype(values) begin () const 124 { return values; 125 } 126 decltype(values) end () const 127 { return values + length; 128 } 129 #endif 100 130 101 131 } object; … … 106 136 struct _json_value ** values; 107 137 138 #if defined(__cplusplus) && __cplusplus >= 201103L 139 decltype(values) begin () const 140 { return values; 141 } 142 decltype(values) end () const 143 { return values + length; 144 } 145 #endif 146 108 147 } array; 109 148 … … 163 202 } 164 203 165 inline operator long () const 166 { return u.integer; 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 }; 167 217 } 168 218 169 219 inline operator bool () const 170 { return u.boolean != 0; 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 }; 171 240 } 172 241 … … 175 244 } json_value; 176 245 177 json_value * json_parse 178 (const json_char * json); 179 180 json_value * json_parse_ex 181 (json_settings * settings, const json_char * json, char * error); 246 json_value * json_parse (const json_char * json, 247 size_t length); 248 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); 182 254 183 255 void json_value_free (json_value *); 256 257 258 /* Not usually necessary, unless you used a custom mem_alloc and now want to 259 * use a custom mem_free. 260 */ 261 void json_value_free_ex (json_settings * settings, 262 json_value *); 184 263 185 264
Note: See TracChangeset
for help on using the changeset viewer.