ffi-yajl 0.0.4-universal-java → 0.1.0-universal-java

Sign up to get free protection for your applications and to get access to all the features.
Files changed (180) hide show
  1. checksums.yaml +4 -4
  2. data/Rakefile +114 -30
  3. data/ext/ffi_yajl/ext/encoder/extconf.rb +5 -5
  4. data/ext/ffi_yajl/ext/parser/extconf.rb +5 -5
  5. data/lib/ffi_yajl/ffi.rb +2 -1
  6. data/lib/ffi_yajl/version.rb +1 -1
  7. data/spec/ffi_yajl/encoder_spec.rb +6 -6
  8. data/spec/ffi_yajl/json_gem_spec.rb +13 -13
  9. data/spec/ffi_yajl/parser_spec.rb +9 -9
  10. metadata +17 -175
  11. data/ext/libyajl2/extconf.rb +0 -60
  12. data/ext/libyajl2/vendored/.gitignore +0 -3
  13. data/ext/libyajl2/vendored/BUILDING +0 -23
  14. data/ext/libyajl2/vendored/BUILDING.win32 +0 -27
  15. data/ext/libyajl2/vendored/CMakeLists.txt +0 -79
  16. data/ext/libyajl2/vendored/COPYING +0 -13
  17. data/ext/libyajl2/vendored/ChangeLog +0 -175
  18. data/ext/libyajl2/vendored/README +0 -74
  19. data/ext/libyajl2/vendored/TODO +0 -9
  20. data/ext/libyajl2/vendored/YAJLDoc.cmake +0 -26
  21. data/ext/libyajl2/vendored/configure +0 -79
  22. data/ext/libyajl2/vendored/example/CMakeLists.txt +0 -23
  23. data/ext/libyajl2/vendored/example/README.md +0 -7
  24. data/ext/libyajl2/vendored/example/parse_config.c +0 -69
  25. data/ext/libyajl2/vendored/example/sample.config +0 -101
  26. data/ext/libyajl2/vendored/perf/CMakeLists.txt +0 -23
  27. data/ext/libyajl2/vendored/perf/documents.c +0 -1418
  28. data/ext/libyajl2/vendored/perf/documents.h +0 -28
  29. data/ext/libyajl2/vendored/perf/perftest.c +0 -134
  30. data/ext/libyajl2/vendored/reformatter/CMakeLists.txt +0 -39
  31. data/ext/libyajl2/vendored/reformatter/json_reformat.c +0 -194
  32. data/ext/libyajl2/vendored/src/CMakeLists.txt +0 -86
  33. data/ext/libyajl2/vendored/src/YAJL.dxy +0 -1258
  34. data/ext/libyajl2/vendored/src/api/yajl_common.h +0 -75
  35. data/ext/libyajl2/vendored/src/api/yajl_gen.h +0 -157
  36. data/ext/libyajl2/vendored/src/api/yajl_parse.h +0 -226
  37. data/ext/libyajl2/vendored/src/api/yajl_tree.h +0 -185
  38. data/ext/libyajl2/vendored/src/api/yajl_version.h.cmake +0 -23
  39. data/ext/libyajl2/vendored/src/yajl +0 -33
  40. data/ext/libyajl2/vendored/src/yajl.c +0 -175
  41. data/ext/libyajl2/vendored/src/yajl.pc.cmake +0 -9
  42. data/ext/libyajl2/vendored/src/yajl_alloc.c +0 -52
  43. data/ext/libyajl2/vendored/src/yajl_alloc.h +0 -34
  44. data/ext/libyajl2/vendored/src/yajl_buf.c +0 -103
  45. data/ext/libyajl2/vendored/src/yajl_buf.h +0 -57
  46. data/ext/libyajl2/vendored/src/yajl_bytestack.h +0 -69
  47. data/ext/libyajl2/vendored/src/yajl_encode.c +0 -220
  48. data/ext/libyajl2/vendored/src/yajl_encode.h +0 -34
  49. data/ext/libyajl2/vendored/src/yajl_gen.c +0 -354
  50. data/ext/libyajl2/vendored/src/yajl_lex.c +0 -763
  51. data/ext/libyajl2/vendored/src/yajl_lex.h +0 -117
  52. data/ext/libyajl2/vendored/src/yajl_parser.c +0 -498
  53. data/ext/libyajl2/vendored/src/yajl_parser.h +0 -78
  54. data/ext/libyajl2/vendored/src/yajl_tree.c +0 -503
  55. data/ext/libyajl2/vendored/src/yajl_version.c +0 -7
  56. data/ext/libyajl2/vendored/test/CMakeLists.txt +0 -23
  57. data/ext/libyajl2/vendored/test/cases/ac_difficult_json_c_test_case_with_comments.json +0 -1
  58. data/ext/libyajl2/vendored/test/cases/ac_difficult_json_c_test_case_with_comments.json.gold +0 -36
  59. data/ext/libyajl2/vendored/test/cases/ac_simple_with_comments.json +0 -11
  60. data/ext/libyajl2/vendored/test/cases/ac_simple_with_comments.json.gold +0 -9
  61. data/ext/libyajl2/vendored/test/cases/ag_false_then_garbage.json +0 -1
  62. data/ext/libyajl2/vendored/test/cases/ag_false_then_garbage.json.gold +0 -2
  63. data/ext/libyajl2/vendored/test/cases/ag_null_then_garbage.json +0 -1
  64. data/ext/libyajl2/vendored/test/cases/ag_null_then_garbage.json.gold +0 -2
  65. data/ext/libyajl2/vendored/test/cases/ag_true_then_garbage.json +0 -1
  66. data/ext/libyajl2/vendored/test/cases/ag_true_then_garbage.json.gold +0 -2
  67. data/ext/libyajl2/vendored/test/cases/am_eof.json +0 -1
  68. data/ext/libyajl2/vendored/test/cases/am_eof.json.gold +0 -4
  69. data/ext/libyajl2/vendored/test/cases/am_integers.json +0 -1
  70. data/ext/libyajl2/vendored/test/cases/am_integers.json.gold +0 -3
  71. data/ext/libyajl2/vendored/test/cases/am_multiple.json +0 -3
  72. data/ext/libyajl2/vendored/test/cases/am_multiple.json.gold +0 -5
  73. data/ext/libyajl2/vendored/test/cases/am_stuff.json +0 -7
  74. data/ext/libyajl2/vendored/test/cases/am_stuff.json.gold +0 -14
  75. data/ext/libyajl2/vendored/test/cases/ap_array_open.json +0 -1
  76. data/ext/libyajl2/vendored/test/cases/ap_array_open.json.gold +0 -2
  77. data/ext/libyajl2/vendored/test/cases/ap_eof_str.json +0 -1
  78. data/ext/libyajl2/vendored/test/cases/ap_eof_str.json.gold +0 -1
  79. data/ext/libyajl2/vendored/test/cases/ap_map_open.json +0 -1
  80. data/ext/libyajl2/vendored/test/cases/ap_map_open.json.gold +0 -2
  81. data/ext/libyajl2/vendored/test/cases/ap_partial_ok.json +0 -1
  82. data/ext/libyajl2/vendored/test/cases/ap_partial_ok.json.gold +0 -4
  83. data/ext/libyajl2/vendored/test/cases/array.json +0 -6
  84. data/ext/libyajl2/vendored/test/cases/array.json.gold +0 -22
  85. data/ext/libyajl2/vendored/test/cases/array_close.json +0 -1
  86. data/ext/libyajl2/vendored/test/cases/array_close.json.gold +0 -2
  87. data/ext/libyajl2/vendored/test/cases/bignums.json +0 -1
  88. data/ext/libyajl2/vendored/test/cases/bignums.json.gold +0 -5
  89. data/ext/libyajl2/vendored/test/cases/bogus_char.json +0 -4
  90. data/ext/libyajl2/vendored/test/cases/bogus_char.json.gold +0 -10
  91. data/ext/libyajl2/vendored/test/cases/codepoints_from_unicode_org.json +0 -1
  92. data/ext/libyajl2/vendored/test/cases/codepoints_from_unicode_org.json.gold +0 -2
  93. data/ext/libyajl2/vendored/test/cases/deep_arrays.json +0 -1
  94. data/ext/libyajl2/vendored/test/cases/deep_arrays.json.gold +0 -2049
  95. data/ext/libyajl2/vendored/test/cases/difficult_json_c_test_case.json +0 -1
  96. data/ext/libyajl2/vendored/test/cases/difficult_json_c_test_case.json.gold +0 -36
  97. data/ext/libyajl2/vendored/test/cases/doubles.json +0 -1
  98. data/ext/libyajl2/vendored/test/cases/doubles.json.gold +0 -7
  99. data/ext/libyajl2/vendored/test/cases/doubles_in_array.json +0 -1
  100. data/ext/libyajl2/vendored/test/cases/doubles_in_array.json.gold +0 -8
  101. data/ext/libyajl2/vendored/test/cases/empty_array.json +0 -1
  102. data/ext/libyajl2/vendored/test/cases/empty_array.json.gold +0 -3
  103. data/ext/libyajl2/vendored/test/cases/empty_string.json +0 -1
  104. data/ext/libyajl2/vendored/test/cases/empty_string.json.gold +0 -2
  105. data/ext/libyajl2/vendored/test/cases/escaped_bulgarian.json +0 -4
  106. data/ext/libyajl2/vendored/test/cases/escaped_bulgarian.json.gold +0 -7
  107. data/ext/libyajl2/vendored/test/cases/escaped_foobar.json +0 -1
  108. data/ext/libyajl2/vendored/test/cases/escaped_foobar.json.gold +0 -2
  109. data/ext/libyajl2/vendored/test/cases/false.json +0 -1
  110. data/ext/libyajl2/vendored/test/cases/false.json.gold +0 -2
  111. data/ext/libyajl2/vendored/test/cases/fg_false_then_garbage.json +0 -1
  112. data/ext/libyajl2/vendored/test/cases/fg_false_then_garbage.json.gold +0 -3
  113. data/ext/libyajl2/vendored/test/cases/fg_issue_7.json +0 -1
  114. data/ext/libyajl2/vendored/test/cases/fg_issue_7.json.gold +0 -3
  115. data/ext/libyajl2/vendored/test/cases/fg_null_then_garbage.json +0 -1
  116. data/ext/libyajl2/vendored/test/cases/fg_null_then_garbage.json.gold +0 -3
  117. data/ext/libyajl2/vendored/test/cases/fg_true_then_garbage.json +0 -1
  118. data/ext/libyajl2/vendored/test/cases/fg_true_then_garbage.json.gold +0 -3
  119. data/ext/libyajl2/vendored/test/cases/four_byte_utf8.json +0 -2
  120. data/ext/libyajl2/vendored/test/cases/four_byte_utf8.json.gold +0 -5
  121. data/ext/libyajl2/vendored/test/cases/high_overflow.json +0 -1
  122. data/ext/libyajl2/vendored/test/cases/high_overflow.json.gold +0 -2
  123. data/ext/libyajl2/vendored/test/cases/integers.json +0 -3
  124. data/ext/libyajl2/vendored/test/cases/integers.json.gold +0 -14
  125. data/ext/libyajl2/vendored/test/cases/invalid_utf8.json +0 -1
  126. data/ext/libyajl2/vendored/test/cases/invalid_utf8.json.gold +0 -3
  127. data/ext/libyajl2/vendored/test/cases/isolated_surrogate_marker.json +0 -1
  128. data/ext/libyajl2/vendored/test/cases/isolated_surrogate_marker.json.gold +0 -2
  129. data/ext/libyajl2/vendored/test/cases/leading_zero_in_number.json +0 -1
  130. data/ext/libyajl2/vendored/test/cases/leading_zero_in_number.json.gold +0 -5
  131. data/ext/libyajl2/vendored/test/cases/lonely_minus_sign.json +0 -7
  132. data/ext/libyajl2/vendored/test/cases/lonely_minus_sign.json.gold +0 -9
  133. data/ext/libyajl2/vendored/test/cases/lonely_number.json +0 -1
  134. data/ext/libyajl2/vendored/test/cases/lonely_number.json.gold +0 -2
  135. data/ext/libyajl2/vendored/test/cases/low_overflow.json +0 -1
  136. data/ext/libyajl2/vendored/test/cases/low_overflow.json.gold +0 -2
  137. data/ext/libyajl2/vendored/test/cases/map_close.json +0 -1
  138. data/ext/libyajl2/vendored/test/cases/map_close.json.gold +0 -2
  139. data/ext/libyajl2/vendored/test/cases/missing_integer_after_decimal_point.json +0 -1
  140. data/ext/libyajl2/vendored/test/cases/missing_integer_after_decimal_point.json.gold +0 -2
  141. data/ext/libyajl2/vendored/test/cases/missing_integer_after_exponent.json +0 -1
  142. data/ext/libyajl2/vendored/test/cases/missing_integer_after_exponent.json.gold +0 -2
  143. data/ext/libyajl2/vendored/test/cases/multiple.json +0 -3
  144. data/ext/libyajl2/vendored/test/cases/multiple.json.gold +0 -4
  145. data/ext/libyajl2/vendored/test/cases/non_utf8_char_in_string.json +0 -1
  146. data/ext/libyajl2/vendored/test/cases/non_utf8_char_in_string.json.gold +0 -8
  147. data/ext/libyajl2/vendored/test/cases/np_partial_bad.json +0 -1
  148. data/ext/libyajl2/vendored/test/cases/np_partial_bad.json.gold +0 -5
  149. data/ext/libyajl2/vendored/test/cases/null.json +0 -1
  150. data/ext/libyajl2/vendored/test/cases/null.json.gold +0 -2
  151. data/ext/libyajl2/vendored/test/cases/nulls_and_bools.json +0 -5
  152. data/ext/libyajl2/vendored/test/cases/nulls_and_bools.json.gold +0 -9
  153. data/ext/libyajl2/vendored/test/cases/simple.json +0 -5
  154. data/ext/libyajl2/vendored/test/cases/simple.json.gold +0 -9
  155. data/ext/libyajl2/vendored/test/cases/simple_with_comments.json +0 -11
  156. data/ext/libyajl2/vendored/test/cases/simple_with_comments.json.gold +0 -5
  157. data/ext/libyajl2/vendored/test/cases/string_invalid_escape.json +0 -1
  158. data/ext/libyajl2/vendored/test/cases/string_invalid_escape.json.gold +0 -3
  159. data/ext/libyajl2/vendored/test/cases/string_invalid_hex_char.json +0 -1
  160. data/ext/libyajl2/vendored/test/cases/string_invalid_hex_char.json.gold +0 -2
  161. data/ext/libyajl2/vendored/test/cases/string_with_escapes.json +0 -3
  162. data/ext/libyajl2/vendored/test/cases/string_with_escapes.json.gold +0 -7
  163. data/ext/libyajl2/vendored/test/cases/string_with_invalid_newline.json +0 -2
  164. data/ext/libyajl2/vendored/test/cases/string_with_invalid_newline.json.gold +0 -2
  165. data/ext/libyajl2/vendored/test/cases/three_byte_utf8.json +0 -1
  166. data/ext/libyajl2/vendored/test/cases/three_byte_utf8.json.gold +0 -7
  167. data/ext/libyajl2/vendored/test/cases/true.json +0 -1
  168. data/ext/libyajl2/vendored/test/cases/true.json.gold +0 -2
  169. data/ext/libyajl2/vendored/test/cases/unescaped_bulgarian.json +0 -1
  170. data/ext/libyajl2/vendored/test/cases/unescaped_bulgarian.json.gold +0 -4
  171. data/ext/libyajl2/vendored/test/cases/zerobyte.json +0 -1
  172. data/ext/libyajl2/vendored/test/cases/zerobyte.json.gold +0 -0
  173. data/ext/libyajl2/vendored/test/run_tests.sh +0 -94
  174. data/ext/libyajl2/vendored/test/yajl_test.c +0 -281
  175. data/ext/libyajl2/vendored/verify/CMakeLists.txt +0 -39
  176. data/ext/libyajl2/vendored/verify/json_verify.c +0 -116
  177. data/lib/libyajl.so +0 -0
  178. data/lib/libyajl.so.2 +0 -0
  179. data/lib/libyajl.so.2.0.5 +0 -0
  180. data/lib/libyajl_s.a +0 -0
@@ -1,34 +0,0 @@
1
- /*
2
- * Copyright (c) 2007-2011, Lloyd Hilaiel <lloyd@hilaiel.com>
3
- *
4
- * Permission to use, copy, modify, and/or distribute this software for any
5
- * purpose with or without fee is hereby granted, provided that the above
6
- * copyright notice and this permission notice appear in all copies.
7
- *
8
- * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
9
- * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
10
- * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
11
- * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12
- * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
13
- * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
14
- * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
15
- */
16
-
17
- /**
18
- * \file yajl_alloc.h
19
- * default memory allocation routines for yajl which use malloc/realloc and
20
- * free
21
- */
22
-
23
- #ifndef __YAJL_ALLOC_H__
24
- #define __YAJL_ALLOC_H__
25
-
26
- #include "api/yajl_common.h"
27
-
28
- #define YA_MALLOC(afs, sz) (afs)->malloc((afs)->ctx, (sz))
29
- #define YA_FREE(afs, ptr) (afs)->free((afs)->ctx, (ptr))
30
- #define YA_REALLOC(afs, ptr, sz) (afs)->realloc((afs)->ctx, (ptr), (sz))
31
-
32
- void yajl_set_default_alloc_funcs(yajl_alloc_funcs * yaf);
33
-
34
- #endif
@@ -1,103 +0,0 @@
1
- /*
2
- * Copyright (c) 2007-2011, Lloyd Hilaiel <lloyd@hilaiel.com>
3
- *
4
- * Permission to use, copy, modify, and/or distribute this software for any
5
- * purpose with or without fee is hereby granted, provided that the above
6
- * copyright notice and this permission notice appear in all copies.
7
- *
8
- * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
9
- * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
10
- * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
11
- * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12
- * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
13
- * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
14
- * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
15
- */
16
-
17
- #include "yajl_buf.h"
18
-
19
- #include <assert.h>
20
- #include <stdlib.h>
21
- #include <string.h>
22
-
23
- #define YAJL_BUF_INIT_SIZE 2048
24
-
25
- struct yajl_buf_t {
26
- size_t len;
27
- size_t used;
28
- unsigned char * data;
29
- yajl_alloc_funcs * alloc;
30
- };
31
-
32
- static
33
- void yajl_buf_ensure_available(yajl_buf buf, size_t want)
34
- {
35
- size_t need;
36
-
37
- assert(buf != NULL);
38
-
39
- /* first call */
40
- if (buf->data == NULL) {
41
- buf->len = YAJL_BUF_INIT_SIZE;
42
- buf->data = (unsigned char *) YA_MALLOC(buf->alloc, buf->len);
43
- buf->data[0] = 0;
44
- }
45
-
46
- need = buf->len;
47
-
48
- while (want >= (need - buf->used)) need <<= 1;
49
-
50
- if (need != buf->len) {
51
- buf->data = (unsigned char *) YA_REALLOC(buf->alloc, buf->data, need);
52
- buf->len = need;
53
- }
54
- }
55
-
56
- yajl_buf yajl_buf_alloc(yajl_alloc_funcs * alloc)
57
- {
58
- yajl_buf b = YA_MALLOC(alloc, sizeof(struct yajl_buf_t));
59
- memset((void *) b, 0, sizeof(struct yajl_buf_t));
60
- b->alloc = alloc;
61
- return b;
62
- }
63
-
64
- void yajl_buf_free(yajl_buf buf)
65
- {
66
- assert(buf != NULL);
67
- if (buf->data) YA_FREE(buf->alloc, buf->data);
68
- YA_FREE(buf->alloc, buf);
69
- }
70
-
71
- void yajl_buf_append(yajl_buf buf, const void * data, size_t len)
72
- {
73
- yajl_buf_ensure_available(buf, len);
74
- if (len > 0) {
75
- assert(data != NULL);
76
- memcpy(buf->data + buf->used, data, len);
77
- buf->used += len;
78
- buf->data[buf->used] = 0;
79
- }
80
- }
81
-
82
- void yajl_buf_clear(yajl_buf buf)
83
- {
84
- buf->used = 0;
85
- if (buf->data) buf->data[buf->used] = 0;
86
- }
87
-
88
- const unsigned char * yajl_buf_data(yajl_buf buf)
89
- {
90
- return buf->data;
91
- }
92
-
93
- size_t yajl_buf_len(yajl_buf buf)
94
- {
95
- return buf->used;
96
- }
97
-
98
- void
99
- yajl_buf_truncate(yajl_buf buf, size_t len)
100
- {
101
- assert(len <= buf->used);
102
- buf->used = len;
103
- }
@@ -1,57 +0,0 @@
1
- /*
2
- * Copyright (c) 2007-2011, Lloyd Hilaiel <lloyd@hilaiel.com>
3
- *
4
- * Permission to use, copy, modify, and/or distribute this software for any
5
- * purpose with or without fee is hereby granted, provided that the above
6
- * copyright notice and this permission notice appear in all copies.
7
- *
8
- * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
9
- * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
10
- * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
11
- * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12
- * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
13
- * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
14
- * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
15
- */
16
-
17
- #ifndef __YAJL_BUF_H__
18
- #define __YAJL_BUF_H__
19
-
20
- #include "api/yajl_common.h"
21
- #include "yajl_alloc.h"
22
-
23
- /*
24
- * Implementation/performance notes. If this were moved to a header
25
- * only implementation using #define's where possible we might be
26
- * able to sqeeze a little performance out of the guy by killing function
27
- * call overhead. YMMV.
28
- */
29
-
30
- /**
31
- * yajl_buf is a buffer with exponential growth. the buffer ensures that
32
- * you are always null padded.
33
- */
34
- typedef struct yajl_buf_t * yajl_buf;
35
-
36
- /* allocate a new buffer */
37
- yajl_buf yajl_buf_alloc(yajl_alloc_funcs * alloc);
38
-
39
- /* free the buffer */
40
- void yajl_buf_free(yajl_buf buf);
41
-
42
- /* append a number of bytes to the buffer */
43
- void yajl_buf_append(yajl_buf buf, const void * data, size_t len);
44
-
45
- /* empty the buffer */
46
- void yajl_buf_clear(yajl_buf buf);
47
-
48
- /* get a pointer to the beginning of the buffer */
49
- const unsigned char * yajl_buf_data(yajl_buf buf);
50
-
51
- /* get the length of the buffer */
52
- size_t yajl_buf_len(yajl_buf buf);
53
-
54
- /* truncate the buffer */
55
- void yajl_buf_truncate(yajl_buf buf, size_t len);
56
-
57
- #endif
@@ -1,69 +0,0 @@
1
- /*
2
- * Copyright (c) 2007-2011, Lloyd Hilaiel <lloyd@hilaiel.com>
3
- *
4
- * Permission to use, copy, modify, and/or distribute this software for any
5
- * purpose with or without fee is hereby granted, provided that the above
6
- * copyright notice and this permission notice appear in all copies.
7
- *
8
- * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
9
- * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
10
- * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
11
- * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12
- * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
13
- * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
14
- * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
15
- */
16
-
17
- /*
18
- * A header only implementation of a simple stack of bytes, used in YAJL
19
- * to maintain parse state.
20
- */
21
-
22
- #ifndef __YAJL_BYTESTACK_H__
23
- #define __YAJL_BYTESTACK_H__
24
-
25
- #include "api/yajl_common.h"
26
-
27
- #define YAJL_BS_INC 128
28
-
29
- typedef struct yajl_bytestack_t
30
- {
31
- unsigned char * stack;
32
- size_t size;
33
- size_t used;
34
- yajl_alloc_funcs * yaf;
35
- } yajl_bytestack;
36
-
37
- /* initialize a bytestack */
38
- #define yajl_bs_init(obs, _yaf) { \
39
- (obs).stack = NULL; \
40
- (obs).size = 0; \
41
- (obs).used = 0; \
42
- (obs).yaf = (_yaf); \
43
- } \
44
-
45
-
46
- /* initialize a bytestack */
47
- #define yajl_bs_free(obs) \
48
- if ((obs).stack) (obs).yaf->free((obs).yaf->ctx, (obs).stack);
49
-
50
- #define yajl_bs_current(obs) \
51
- (assert((obs).used > 0), (obs).stack[(obs).used - 1])
52
-
53
- #define yajl_bs_push(obs, byte) { \
54
- if (((obs).size - (obs).used) == 0) { \
55
- (obs).size += YAJL_BS_INC; \
56
- (obs).stack = (obs).yaf->realloc((obs).yaf->ctx,\
57
- (void *) (obs).stack, (obs).size);\
58
- } \
59
- (obs).stack[((obs).used)++] = (byte); \
60
- }
61
-
62
- /* removes the top item of the stack, returns nothing */
63
- #define yajl_bs_pop(obs) { ((obs).used)--; }
64
-
65
- #define yajl_bs_set(obs, byte) \
66
- (obs).stack[((obs).used) - 1] = (byte);
67
-
68
-
69
- #endif
@@ -1,220 +0,0 @@
1
- /*
2
- * Copyright (c) 2007-2011, Lloyd Hilaiel <lloyd@hilaiel.com>
3
- *
4
- * Permission to use, copy, modify, and/or distribute this software for any
5
- * purpose with or without fee is hereby granted, provided that the above
6
- * copyright notice and this permission notice appear in all copies.
7
- *
8
- * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
9
- * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
10
- * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
11
- * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12
- * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
13
- * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
14
- * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
15
- */
16
-
17
- #include "yajl_encode.h"
18
-
19
- #include <assert.h>
20
- #include <stdlib.h>
21
- #include <string.h>
22
- #include <stdio.h>
23
-
24
- static void CharToHex(unsigned char c, char * hexBuf)
25
- {
26
- const char * hexchar = "0123456789ABCDEF";
27
- hexBuf[0] = hexchar[c >> 4];
28
- hexBuf[1] = hexchar[c & 0x0F];
29
- }
30
-
31
- void
32
- yajl_string_encode(const yajl_print_t print,
33
- void * ctx,
34
- const unsigned char * str,
35
- size_t len,
36
- int escape_solidus)
37
- {
38
- size_t beg = 0;
39
- size_t end = 0;
40
- char hexBuf[7];
41
- hexBuf[0] = '\\'; hexBuf[1] = 'u'; hexBuf[2] = '0'; hexBuf[3] = '0';
42
- hexBuf[6] = 0;
43
-
44
- while (end < len) {
45
- const char * escaped = NULL;
46
- switch (str[end]) {
47
- case '\r': escaped = "\\r"; break;
48
- case '\n': escaped = "\\n"; break;
49
- case '\\': escaped = "\\\\"; break;
50
- /* it is not required to escape a solidus in JSON:
51
- * read sec. 2.5: http://www.ietf.org/rfc/rfc4627.txt
52
- * specifically, this production from the grammar:
53
- * unescaped = %x20-21 / %x23-5B / %x5D-10FFFF
54
- */
55
- case '/': if (escape_solidus) escaped = "\\/"; break;
56
- case '"': escaped = "\\\""; break;
57
- case '\f': escaped = "\\f"; break;
58
- case '\b': escaped = "\\b"; break;
59
- case '\t': escaped = "\\t"; break;
60
- default:
61
- if ((unsigned char) str[end] < 32) {
62
- CharToHex(str[end], hexBuf + 4);
63
- escaped = hexBuf;
64
- }
65
- break;
66
- }
67
- if (escaped != NULL) {
68
- print(ctx, (const char *) (str + beg), end - beg);
69
- print(ctx, escaped, (unsigned int)strlen(escaped));
70
- beg = ++end;
71
- } else {
72
- ++end;
73
- }
74
- }
75
- print(ctx, (const char *) (str + beg), end - beg);
76
- }
77
-
78
- static void hexToDigit(unsigned int * val, const unsigned char * hex)
79
- {
80
- unsigned int i;
81
- for (i=0;i<4;i++) {
82
- unsigned char c = hex[i];
83
- if (c >= 'A') c = (c & ~0x20) - 7;
84
- c -= '0';
85
- assert(!(c & 0xF0));
86
- *val = (*val << 4) | c;
87
- }
88
- }
89
-
90
- static void Utf32toUtf8(unsigned int codepoint, char * utf8Buf)
91
- {
92
- if (codepoint < 0x80) {
93
- utf8Buf[0] = (char) codepoint;
94
- utf8Buf[1] = 0;
95
- } else if (codepoint < 0x0800) {
96
- utf8Buf[0] = (char) ((codepoint >> 6) | 0xC0);
97
- utf8Buf[1] = (char) ((codepoint & 0x3F) | 0x80);
98
- utf8Buf[2] = 0;
99
- } else if (codepoint < 0x10000) {
100
- utf8Buf[0] = (char) ((codepoint >> 12) | 0xE0);
101
- utf8Buf[1] = (char) (((codepoint >> 6) & 0x3F) | 0x80);
102
- utf8Buf[2] = (char) ((codepoint & 0x3F) | 0x80);
103
- utf8Buf[3] = 0;
104
- } else if (codepoint < 0x200000) {
105
- utf8Buf[0] =(char)((codepoint >> 18) | 0xF0);
106
- utf8Buf[1] =(char)(((codepoint >> 12) & 0x3F) | 0x80);
107
- utf8Buf[2] =(char)(((codepoint >> 6) & 0x3F) | 0x80);
108
- utf8Buf[3] =(char)((codepoint & 0x3F) | 0x80);
109
- utf8Buf[4] = 0;
110
- } else {
111
- utf8Buf[0] = '?';
112
- utf8Buf[1] = 0;
113
- }
114
- }
115
-
116
- void yajl_string_decode(yajl_buf buf, const unsigned char * str,
117
- size_t len)
118
- {
119
- size_t beg = 0;
120
- size_t end = 0;
121
-
122
- while (end < len) {
123
- if (str[end] == '\\') {
124
- char utf8Buf[5];
125
- const char * unescaped = "?";
126
- yajl_buf_append(buf, str + beg, end - beg);
127
- switch (str[++end]) {
128
- case 'r': unescaped = "\r"; break;
129
- case 'n': unescaped = "\n"; break;
130
- case '\\': unescaped = "\\"; break;
131
- case '/': unescaped = "/"; break;
132
- case '"': unescaped = "\""; break;
133
- case 'f': unescaped = "\f"; break;
134
- case 'b': unescaped = "\b"; break;
135
- case 't': unescaped = "\t"; break;
136
- case 'u': {
137
- unsigned int codepoint = 0;
138
- hexToDigit(&codepoint, str + ++end);
139
- end+=3;
140
- /* check if this is a surrogate */
141
- if ((codepoint & 0xFC00) == 0xD800) {
142
- end++;
143
- if (str[end] == '\\' && str[end + 1] == 'u') {
144
- unsigned int surrogate = 0;
145
- hexToDigit(&surrogate, str + end + 2);
146
- codepoint =
147
- (((codepoint & 0x3F) << 10) |
148
- ((((codepoint >> 6) & 0xF) + 1) << 16) |
149
- (surrogate & 0x3FF));
150
- end += 5;
151
- } else {
152
- unescaped = "?";
153
- break;
154
- }
155
- }
156
-
157
- Utf32toUtf8(codepoint, utf8Buf);
158
- unescaped = utf8Buf;
159
-
160
- if (codepoint == 0) {
161
- yajl_buf_append(buf, unescaped, 1);
162
- beg = ++end;
163
- continue;
164
- }
165
-
166
- break;
167
- }
168
- default:
169
- assert("this should never happen" == NULL);
170
- }
171
- yajl_buf_append(buf, unescaped, (unsigned int)strlen(unescaped));
172
- beg = ++end;
173
- } else {
174
- end++;
175
- }
176
- }
177
- yajl_buf_append(buf, str + beg, end - beg);
178
- }
179
-
180
- #define ADV_PTR s++; if (!(len--)) return 0;
181
-
182
- int yajl_string_validate_utf8(const unsigned char * s, size_t len)
183
- {
184
- if (!len) return 1;
185
- if (!s) return 0;
186
-
187
- while (len--) {
188
- /* single byte */
189
- if (*s <= 0x7f) {
190
- /* noop */
191
- }
192
- /* two byte */
193
- else if ((*s >> 5) == 0x6) {
194
- ADV_PTR;
195
- if (!((*s >> 6) == 0x2)) return 0;
196
- }
197
- /* three byte */
198
- else if ((*s >> 4) == 0x0e) {
199
- ADV_PTR;
200
- if (!((*s >> 6) == 0x2)) return 0;
201
- ADV_PTR;
202
- if (!((*s >> 6) == 0x2)) return 0;
203
- }
204
- /* four byte */
205
- else if ((*s >> 3) == 0x1e) {
206
- ADV_PTR;
207
- if (!((*s >> 6) == 0x2)) return 0;
208
- ADV_PTR;
209
- if (!((*s >> 6) == 0x2)) return 0;
210
- ADV_PTR;
211
- if (!((*s >> 6) == 0x2)) return 0;
212
- } else {
213
- return 0;
214
- }
215
-
216
- s++;
217
- }
218
-
219
- return 1;
220
- }