fizx-ordered_json 0.3.1 → 0.3.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (89) hide show
  1. data/.gitignore +29 -0
  2. data/CHANGELOG +22 -0
  3. data/README +4 -0
  4. data/Rakefile +35 -0
  5. data/ext/Makefile +149 -0
  6. data/ext/json-c-0.8/AUTHORS +2 -0
  7. data/ext/json-c-0.8/COPYING +19 -0
  8. data/ext/json-c-0.8/ChangeLog +73 -0
  9. data/ext/json-c-0.8/INSTALL +229 -0
  10. data/ext/json-c-0.8/Makefile.am +43 -0
  11. data/ext/json-c-0.8/Makefile.in +734 -0
  12. data/ext/json-c-0.8/NEWS +1 -0
  13. data/ext/json-c-0.8/README +20 -0
  14. data/ext/json-c-0.8/aclocal.m4 +8794 -0
  15. data/ext/json-c-0.8/arraylist.c +93 -0
  16. data/ext/json-c-0.8/arraylist.h +45 -0
  17. data/ext/json-c-0.8/bits.h +27 -0
  18. data/ext/json-c-0.8/config.guess +1526 -0
  19. data/ext/json-c-0.8/config.h.in +121 -0
  20. data/ext/json-c-0.8/config.sub +1658 -0
  21. data/ext/json-c-0.8/configure +14243 -0
  22. data/ext/json-c-0.8/configure.in +33 -0
  23. data/ext/json-c-0.8/debug.c +98 -0
  24. data/ext/json-c-0.8/debug.h +42 -0
  25. data/ext/json-c-0.8/depcomp +530 -0
  26. data/ext/json-c-0.8/doc/html/annotated.html +40 -0
  27. data/ext/json-c-0.8/doc/html/arraylist_8h.html +234 -0
  28. data/ext/json-c-0.8/doc/html/bits_8h.html +144 -0
  29. data/ext/json-c-0.8/doc/html/config_8h.html +606 -0
  30. data/ext/json-c-0.8/doc/html/debug_8h.html +386 -0
  31. data/ext/json-c-0.8/doc/html/doxygen.css +473 -0
  32. data/ext/json-c-0.8/doc/html/doxygen.png +0 -0
  33. data/ext/json-c-0.8/doc/html/files.html +42 -0
  34. data/ext/json-c-0.8/doc/html/functions.html +206 -0
  35. data/ext/json-c-0.8/doc/html/functions_vars.html +206 -0
  36. data/ext/json-c-0.8/doc/html/globals.html +445 -0
  37. data/ext/json-c-0.8/doc/html/globals_defs.html +200 -0
  38. data/ext/json-c-0.8/doc/html/globals_enum.html +50 -0
  39. data/ext/json-c-0.8/doc/html/globals_eval.html +135 -0
  40. data/ext/json-c-0.8/doc/html/globals_func.html +194 -0
  41. data/ext/json-c-0.8/doc/html/globals_type.html +58 -0
  42. data/ext/json-c-0.8/doc/html/globals_vars.html +50 -0
  43. data/ext/json-c-0.8/doc/html/index.html +25 -0
  44. data/ext/json-c-0.8/doc/html/json_8h.html +26 -0
  45. data/ext/json-c-0.8/doc/html/json__object_8h.html +1042 -0
  46. data/ext/json-c-0.8/doc/html/json__object__private_8h.html +69 -0
  47. data/ext/json-c-0.8/doc/html/json__tokener_8h.html +360 -0
  48. data/ext/json-c-0.8/doc/html/json__util_8h.html +100 -0
  49. data/ext/json-c-0.8/doc/html/linkhash_8h.html +734 -0
  50. data/ext/json-c-0.8/doc/html/printbuf_8h.html +171 -0
  51. data/ext/json-c-0.8/doc/html/structarray__list.html +104 -0
  52. data/ext/json-c-0.8/doc/html/structjson__object.html +141 -0
  53. data/ext/json-c-0.8/doc/html/structjson__object__iter.html +87 -0
  54. data/ext/json-c-0.8/doc/html/structjson__tokener.html +206 -0
  55. data/ext/json-c-0.8/doc/html/structjson__tokener__srec.html +104 -0
  56. data/ext/json-c-0.8/doc/html/structlh__entry.html +105 -0
  57. data/ext/json-c-0.8/doc/html/structlh__table.html +275 -0
  58. data/ext/json-c-0.8/doc/html/structprintbuf.html +87 -0
  59. data/ext/json-c-0.8/doc/html/tab_b.gif +0 -0
  60. data/ext/json-c-0.8/doc/html/tab_l.gif +0 -0
  61. data/ext/json-c-0.8/doc/html/tab_r.gif +0 -0
  62. data/ext/json-c-0.8/doc/html/tabs.css +102 -0
  63. data/ext/json-c-0.8/doc/html/unionjson__object_1_1data.html +140 -0
  64. data/ext/json-c-0.8/install-sh +519 -0
  65. data/ext/json-c-0.8/json.h +31 -0
  66. data/ext/json-c-0.8/json.pc.in +11 -0
  67. data/ext/json-c-0.8/json_object.c +511 -0
  68. data/ext/json-c-0.8/json_object.h +310 -0
  69. data/ext/json-c-0.8/json_object_private.h +44 -0
  70. data/ext/json-c-0.8/json_tokener.c +517 -0
  71. data/ext/json-c-0.8/json_tokener.h +90 -0
  72. data/ext/json-c-0.8/json_util.c +122 -0
  73. data/ext/json-c-0.8/json_util.h +23 -0
  74. data/ext/json-c-0.8/linkhash.c +218 -0
  75. data/ext/json-c-0.8/linkhash.h +264 -0
  76. data/ext/json-c-0.8/ltmain.sh +7880 -0
  77. data/ext/json-c-0.8/missing +360 -0
  78. data/ext/json-c-0.8/printbuf.c +145 -0
  79. data/ext/json-c-0.8/printbuf.h +38 -0
  80. data/ext/json-c-0.8/test1.c +164 -0
  81. data/ext/json-c-0.8/test2.c +20 -0
  82. data/ext/json-c-0.8/test3.c +22 -0
  83. data/ext/ordered_json_c.c +199 -0
  84. data/lib/ordered_json.rb +26 -0
  85. data/ordered_json.gemspec +102 -0
  86. data/test/crashing_example.rb +1 -0
  87. data/test/ordered_json_test.rb +86 -0
  88. data/test/pretty.json +11 -0
  89. metadata +91 -50
@@ -0,0 +1,310 @@
1
+ /*
2
+ * $Id: json_object.h,v 1.12 2006/01/30 23:07:57 mclark Exp $
3
+ *
4
+ * Copyright (c) 2004, 2005 Metaparadigm Pte. Ltd.
5
+ * Michael Clark <michael@metaparadigm.com>
6
+ *
7
+ * This library is free software; you can redistribute it and/or modify
8
+ * it under the terms of the MIT license. See COPYING for details.
9
+ *
10
+ */
11
+
12
+ #ifndef _json_object_h_
13
+ #define _json_object_h_
14
+
15
+ #define JSON_OBJECT_DEF_HASH_ENTIRES 16
16
+
17
+ #undef FALSE
18
+ #define FALSE ((boolean)0)
19
+
20
+ #undef TRUE
21
+ #define TRUE ((boolean)1)
22
+
23
+ extern char *json_number_chars;
24
+ extern char *json_hex_chars;
25
+
26
+ /* forward structure definitions */
27
+
28
+ typedef int boolean;
29
+ struct printbuf;
30
+ struct lh_table;
31
+ struct array_list;
32
+ struct json_object;
33
+ struct json_object_iter;
34
+
35
+ /* supported object types */
36
+
37
+ enum json_type {
38
+ json_type_null,
39
+ json_type_boolean,
40
+ json_type_double,
41
+ json_type_int,
42
+ json_type_object,
43
+ json_type_array,
44
+ json_type_string
45
+ };
46
+
47
+ /* reference counting functions */
48
+
49
+ /**
50
+ * Increment the reference count of json_object
51
+ * @param obj the json_object instance
52
+ */
53
+ extern struct json_object* json_object_get(struct json_object *obj);
54
+
55
+ /**
56
+ * Decrement the reference count of json_object and free if it reaches zero
57
+ * @param obj the json_object instance
58
+ */
59
+ extern void json_object_put(struct json_object *obj);
60
+
61
+
62
+ /**
63
+ * Check if the json_object is of a given type
64
+ * @param obj the json_object instance
65
+ * @param type one of:
66
+ json_type_boolean,
67
+ json_type_double,
68
+ json_type_int,
69
+ json_type_object,
70
+ json_type_array,
71
+ json_type_string,
72
+ */
73
+ extern int json_object_is_type(struct json_object *obj, enum json_type type);
74
+
75
+ /**
76
+ * Get the type of the json_object
77
+ * @param obj the json_object instance
78
+ * @returns type being one of:
79
+ json_type_boolean,
80
+ json_type_double,
81
+ json_type_int,
82
+ json_type_object,
83
+ json_type_array,
84
+ json_type_string,
85
+ */
86
+ extern enum json_type json_object_get_type(struct json_object *obj);
87
+
88
+
89
+ /** Stringify object to json format
90
+ * @param obj the json_object instance
91
+ * @returns a string in JSON format
92
+ */
93
+ extern char* json_object_to_json_string(struct json_object *obj);
94
+
95
+
96
+ /* object type methods */
97
+
98
+ /** Create a new empty object
99
+ * @returns a json_object of type json_type_object
100
+ */
101
+ extern struct json_object* json_object_new_object(void);
102
+
103
+ /** Get the hashtable of a json_object of type json_type_object
104
+ * @param obj the json_object instance
105
+ * @returns a linkhash
106
+ */
107
+ extern struct lh_table* json_object_get_object(struct json_object *obj);
108
+
109
+ /** Add an object field to a json_object of type json_type_object
110
+ *
111
+ * The reference count will *not* be incremented. This is to make adding
112
+ * fields to objects in code more compact. If you want to retain a reference
113
+ * to an added object you must wrap the passed object with json_object_get
114
+ *
115
+ * @param obj the json_object instance
116
+ * @param key the object field name (a private copy will be duplicated)
117
+ * @param val a json_object or NULL member to associate with the given field
118
+ */
119
+ extern void json_object_object_add(struct json_object* obj, char *key,
120
+ struct json_object *val);
121
+
122
+ /** Get the json_object associate with a given object field
123
+ * @param obj the json_object instance
124
+ * @param key the object field name
125
+ * @returns the json_object associated with the given field name
126
+ */
127
+ extern struct json_object* json_object_object_get(struct json_object* obj,
128
+ char *key);
129
+
130
+ /** Delete the given json_object field
131
+ *
132
+ * The reference count will be decremented for the deleted object
133
+ *
134
+ * @param obj the json_object instance
135
+ * @param key the object field name
136
+ */
137
+ extern void json_object_object_del(struct json_object* obj, char *key);
138
+
139
+ /** Iterate through all keys and values of an object
140
+ * @param obj the json_object instance
141
+ * @param key the local name for the char* key variable defined in the body
142
+ * @param val the local name for the json_object* object variable defined in the body
143
+ */
144
+ #if defined(__GNUC__) && !defined(__STRICT_ANSI__)
145
+
146
+ # define json_object_object_foreach(obj,key,val) \
147
+ char *key; struct json_object *val; \
148
+ for(struct lh_entry *entry = json_object_get_object(obj)->head; ({ if(entry) { key = (char*)entry->k; val = (struct json_object*)entry->v; } ; entry; }); entry = entry->next )
149
+
150
+ #else /* ANSI C or MSC */
151
+
152
+ # define json_object_object_foreach(obj,key,val) \
153
+ char *key; struct json_object *val; struct lh_entry *entry; \
154
+ for(entry = json_object_get_object(obj)->head; (entry ? (key = (char*)entry->k, val = (struct json_object*)entry->v, entry) : 0); entry = entry->next)
155
+
156
+ #endif /* defined(__GNUC__) && !defined(__STRICT_ANSI__) */
157
+
158
+ /** Iterate through all keys and values of an object (ANSI C Safe)
159
+ * @param obj the json_object instance
160
+ * @param iter the object iterator
161
+ */
162
+ #define json_object_object_foreachC(obj,iter) \
163
+ for(iter.entry = json_object_get_object(obj)->head; (iter.entry ? (iter.key = (char*)iter.entry->k, iter.val = (struct json_object*)iter.entry->v, iter.entry) : 0); iter.entry = iter.entry->next)
164
+
165
+ /* Array type methods */
166
+
167
+ /** Create a new empty json_object of type json_type_array
168
+ * @returns a json_object of type json_type_array
169
+ */
170
+ extern struct json_object* json_object_new_array(void);
171
+
172
+ /** Get the arraylist of a json_object of type json_type_array
173
+ * @param obj the json_object instance
174
+ * @returns an arraylist
175
+ */
176
+ extern struct array_list* json_object_get_array(struct json_object *obj);
177
+
178
+ /** Get the length of a json_object of type json_type_array
179
+ * @param obj the json_object instance
180
+ * @returns an int
181
+ */
182
+ extern int json_object_array_length(struct json_object *obj);
183
+
184
+ /** Add an element to the end of a json_object of type json_type_array
185
+ *
186
+ * The reference count will *not* be incremented. This is to make adding
187
+ * fields to objects in code more compact. If you want to retain a reference
188
+ * to an added object you must wrap the passed object with json_object_get
189
+ *
190
+ * @param obj the json_object instance
191
+ * @param val the json_object to be added
192
+ */
193
+ extern int json_object_array_add(struct json_object *obj,
194
+ struct json_object *val);
195
+
196
+ /** Insert or replace an element at a specified index in an array (a json_object of type json_type_array)
197
+ *
198
+ * The reference count will *not* be incremented. This is to make adding
199
+ * fields to objects in code more compact. If you want to retain a reference
200
+ * to an added object you must wrap the passed object with json_object_get
201
+ *
202
+ * The reference count of a replaced object will be decremented.
203
+ *
204
+ * The array size will be automatically be expanded to the size of the
205
+ * index if the index is larger than the current size.
206
+ *
207
+ * @param obj the json_object instance
208
+ * @param idx the index to insert the element at
209
+ * @param val the json_object to be added
210
+ */
211
+ extern int json_object_array_put_idx(struct json_object *obj, int idx,
212
+ struct json_object *val);
213
+
214
+ /** Get the element at specificed index of the array (a json_object of type json_type_array)
215
+ * @param obj the json_object instance
216
+ * @param idx the index to get the element at
217
+ * @returns the json_object at the specified index (or NULL)
218
+ */
219
+ extern struct json_object* json_object_array_get_idx(struct json_object *obj,
220
+ int idx);
221
+
222
+ /* boolean type methods */
223
+
224
+ /** Create a new empty json_object of type json_type_boolean
225
+ * @param b a boolean TRUE or FALSE (0 or 1)
226
+ * @returns a json_object of type json_type_boolean
227
+ */
228
+ extern struct json_object* json_object_new_boolean(boolean b);
229
+
230
+ /** Get the boolean value of a json_object
231
+ *
232
+ * The type is coerced to a boolean if the passed object is not a boolean.
233
+ * integer and double objects will return FALSE if there value is zero
234
+ * or TRUE otherwise. If the passed object is a string it will return
235
+ * TRUE if it has a non zero length. If any other object type is passed
236
+ * TRUE will be returned if the object is not NULL.
237
+ *
238
+ * @param obj the json_object instance
239
+ * @returns a boolean
240
+ */
241
+ extern boolean json_object_get_boolean(struct json_object *obj);
242
+
243
+
244
+ /* int type methods */
245
+
246
+ /** Create a new empty json_object of type json_type_int
247
+ * @param i the integer
248
+ * @returns a json_object of type json_type_int
249
+ */
250
+ extern struct json_object* json_object_new_int(int i);
251
+
252
+ /** Get the int value of a json_object
253
+ *
254
+ * The type is coerced to a int if the passed object is not a int.
255
+ * double objects will return their integer conversion. Strings will be
256
+ * parsed as an integer. If no conversion exists then 0 is returned.
257
+ *
258
+ * @param obj the json_object instance
259
+ * @returns an int
260
+ */
261
+ extern int json_object_get_int(struct json_object *obj);
262
+
263
+
264
+ /* double type methods */
265
+
266
+ /** Create a new empty json_object of type json_type_double
267
+ * @param d the double
268
+ * @returns a json_object of type json_type_double
269
+ */
270
+ extern struct json_object* json_object_new_double(double d);
271
+
272
+ /** Get the double value of a json_object
273
+ *
274
+ * The type is coerced to a double if the passed object is not a double.
275
+ * integer objects will return their dboule conversion. Strings will be
276
+ * parsed as a double. If no conversion exists then 0.0 is returned.
277
+ *
278
+ * @param obj the json_object instance
279
+ * @returns an double
280
+ */
281
+ extern double json_object_get_double(struct json_object *obj);
282
+
283
+
284
+ /* string type methods */
285
+
286
+ /** Create a new empty json_object of type json_type_string
287
+ *
288
+ * A copy of the string is made and the memory is managed by the json_object
289
+ *
290
+ * @param s the string
291
+ * @returns a json_object of type json_type_string
292
+ */
293
+ extern struct json_object* json_object_new_string(char *s);
294
+
295
+ extern struct json_object* json_object_new_string_len(char *s, int len);
296
+
297
+ /** Get the string value of a json_object
298
+ *
299
+ * If the passed object is not of type json_type_string then the JSON
300
+ * representation of the object is returned.
301
+ *
302
+ * The returned string memory is managed by the json_object and will
303
+ * be freed when the reference count of the json_object drops to zero.
304
+ *
305
+ * @param obj the json_object instance
306
+ * @returns a string
307
+ */
308
+ extern char* json_object_get_string(struct json_object *obj);
309
+
310
+ #endif
@@ -0,0 +1,44 @@
1
+ /*
2
+ * $Id: json_object_private.h,v 1.4 2006/01/26 02:16:28 mclark Exp $
3
+ *
4
+ * Copyright (c) 2004, 2005 Metaparadigm Pte. Ltd.
5
+ * Michael Clark <michael@metaparadigm.com>
6
+ *
7
+ * This library is free software; you can redistribute it and/or modify
8
+ * it under the terms of the MIT license. See COPYING for details.
9
+ *
10
+ */
11
+
12
+ #ifndef _json_object_private_h_
13
+ #define _json_object_private_h_
14
+
15
+ typedef void (json_object_delete_fn)(struct json_object *o);
16
+ typedef int (json_object_to_json_string_fn)(struct json_object *o,
17
+ struct printbuf *pb);
18
+
19
+ struct json_object
20
+ {
21
+ enum json_type o_type;
22
+ json_object_delete_fn *_delete;
23
+ json_object_to_json_string_fn *_to_json_string;
24
+ int _ref_count;
25
+ struct printbuf *_pb;
26
+ union data {
27
+ boolean c_boolean;
28
+ double c_double;
29
+ int c_int;
30
+ struct lh_table *c_object;
31
+ struct array_list *c_array;
32
+ char *c_string;
33
+ } o;
34
+ };
35
+
36
+ /* CAW: added for ANSI C iteration correctness */
37
+ struct json_object_iter
38
+ {
39
+ char *key;
40
+ struct json_object *val;
41
+ struct lh_entry *entry;
42
+ };
43
+
44
+ #endif