Subversion Repositories Kolibri OS

Rev

Rev 8553 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
8553 superturbo 1
 
2
 *
3
 * Copyright (C) 2012, 2013, 2014 James McLaughlin et al.  All rights reserved.
4
 * https://github.com/udp/json-parser
5
 *
6
 * Redistribution and use in source and binary forms, with or without
7
 * modification, are permitted provided that the following conditions
8
 * are met:
9
 *
10
 * 1. Redistributions of source code must retain the above copyright
11
 *   notice, this list of conditions and the following disclaimer.
12
 *
13
 * 2. Redistributions in binary form must reproduce the above copyright
14
 *   notice, this list of conditions and the following disclaimer in the
15
 *   documentation and/or other materials provided with the distribution.
16
 *
17
 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
18
 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20
 * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
21
 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22
 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23
 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24
 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25
 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26
 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27
 * SUCH DAMAGE.
28
 */
29
30
 
31
#define _JSON_H
32
33
 
34
   #define json_char char
35
#endif
36
37
 
38
   #ifndef _MSC_VER
39
      #include 
8735 turbocat 40
      #define json_int_t int64_t
8553 superturbo 41
   #else
42
      #define json_int_t __int64
43
   #endif
44
#endif
45
46
 
47
48
 
49
50
 
51
52
 
53
   {
54
55
 
56
57
 
58
{
59
   unsigned long max_memory;
60
   int settings;
61
62
 
63
    */
64
65
 
66
   void (* mem_free) (void *, void * user_data);
67
68
 
69
70
 
71
72
 
73
74
 
75
76
 
77
{
78
   json_none,
79
   json_object,
80
   json_array,
81
   json_integer,
82
   json_double,
83
   json_string,
84
   json_boolean,
85
   json_null
86
87
 
88
89
 
90
91
 
92
{
93
    json_char * name;
94
    unsigned int name_length;
95
96
 
97
98
 
99
100
 
101
{
102
   struct _json_value * parent;
103
104
 
105
106
 
107
   {
108
      int boolean;
109
      json_int_t integer;
110
      double dbl;
111
112
 
113
      {
114
         unsigned int length;
115
         json_char * ptr; /* null terminated */
116
117
 
118
119
 
120
      {
121
         unsigned int length;
122
123
 
124
125
 
126
         decltype(values) begin () const
127
         {  return values;
128
         }
129
         decltype(values) end () const
130
         {  return values + length;
131
         }
132
         #endif
133
134
 
135
136
 
137
      {
138
         unsigned int length;
139
         struct _json_value ** values;
140
141
 
142
         decltype(values) begin () const
143
         {  return values;
144
         }
145
         decltype(values) end () const
146
         {  return values + length;
147
         }
148
         #endif
149
150
 
151
152
 
153
154
 
155
   {
156
      struct _json_value * next_alloc;
157
      void * object_mem;
158
159
 
160
161
 
162
163
 
164
       */
165
      unsigned int line, col;
166
167
 
168
169
 
170
 
171
172
 
173
174
 
175
176
 
177
         {  memset (this, 0, sizeof (_json_value));
178
         }
179
180
 
181
         {
182
            if (type != json_array || index < 0
183
                     || ((unsigned int) index) >= u.array.length)
184
            {
185
               return json_value_none;
186
            }
187
188
 
189
         }
190
191
 
192
         {
193
            if (type != json_object)
194
               return json_value_none;
195
196
 
197
               if (!strcmp (u.object.values [i].name, index))
198
                  return *u.object.values [i].value;
199
200
 
201
         }
202
203
 
204
         {
205
            switch (type)
206
            {
207
               case json_string:
208
                  return u.string.ptr;
209
210
 
211
                  return "";
212
            };
213
         }
214
215
 
216
         {
217
            switch (type)
218
            {
219
               case json_integer:
220
                  return u.integer;
221
222
 
223
                  return (json_int_t) u.dbl;
224
225
 
226
                  return 0;
227
            };
228
         }
229
230
 
231
         {
232
            if (type != json_boolean)
233
               return false;
234
235
 
236
         }
237
238
 
239
         {
240
            switch (type)
241
            {
242
               case json_integer:
243
                  return (double) u.integer;
244
245
 
246
                  return u.dbl;
247
248
 
249
                  return 0;
250
            };
251
         }
252
253
 
254
255
 
256
257
 
258
                         size_t length);
259
260
 
261
json_value * json_parse_ex (json_settings * settings,
262
                            const json_char * json,
263
                            size_t length,
264
                            char * error);
265
266
 
267
268
 
269
 
270
 * use a custom mem_free.
271
 */
272
void json_value_free_ex (json_settings * settings,
273
                         json_value *);
274
275
 
276
 
277
   } /* extern "C" */
278
#endif
279
280
 
281