zsv 1.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (240) hide show
  1. checksums.yaml +7 -0
  2. data/CHANGELOG.md +36 -0
  3. data/LICENSE +21 -0
  4. data/README.md +311 -0
  5. data/ext/zsv/common.h +34 -0
  6. data/ext/zsv/extconf.rb +137 -0
  7. data/ext/zsv/options.c +126 -0
  8. data/ext/zsv/options.h +31 -0
  9. data/ext/zsv/options_internal.h +8 -0
  10. data/ext/zsv/parser.c +300 -0
  11. data/ext/zsv/parser.h +62 -0
  12. data/ext/zsv/row.c +122 -0
  13. data/ext/zsv/row.h +39 -0
  14. data/ext/zsv/vendor/zsv-1.3.0/app/2db.c +756 -0
  15. data/ext/zsv/vendor/zsv-1.3.0/app/2json.c +381 -0
  16. data/ext/zsv/vendor/zsv-1.3.0/app/2tsv.c +228 -0
  17. data/ext/zsv/vendor/zsv-1.3.0/app/builtin/help.c +123 -0
  18. data/ext/zsv/vendor/zsv-1.3.0/app/builtin/license.c +39 -0
  19. data/ext/zsv/vendor/zsv-1.3.0/app/builtin/register.c +104 -0
  20. data/ext/zsv/vendor/zsv-1.3.0/app/builtin/thirdparty.c +41 -0
  21. data/ext/zsv/vendor/zsv-1.3.0/app/builtin/unregister.c +1 -0
  22. data/ext/zsv/vendor/zsv-1.3.0/app/builtin/version.c +14 -0
  23. data/ext/zsv/vendor/zsv-1.3.0/app/check/simdutf_wrapper.h +19 -0
  24. data/ext/zsv/vendor/zsv-1.3.0/app/check/utf8.c +116 -0
  25. data/ext/zsv/vendor/zsv-1.3.0/app/check.c +194 -0
  26. data/ext/zsv/vendor/zsv-1.3.0/app/cli.c +796 -0
  27. data/ext/zsv/vendor/zsv-1.3.0/app/cli_const.h +41 -0
  28. data/ext/zsv/vendor/zsv-1.3.0/app/cli_export.h +16 -0
  29. data/ext/zsv/vendor/zsv-1.3.0/app/cli_ini.c +280 -0
  30. data/ext/zsv/vendor/zsv-1.3.0/app/cli_internal.h +36 -0
  31. data/ext/zsv/vendor/zsv-1.3.0/app/compare.c +913 -0
  32. data/ext/zsv/vendor/zsv-1.3.0/app/compare.h +23 -0
  33. data/ext/zsv/vendor/zsv-1.3.0/app/compare_added_column.c +20 -0
  34. data/ext/zsv/vendor/zsv-1.3.0/app/compare_internal.h +140 -0
  35. data/ext/zsv/vendor/zsv-1.3.0/app/compare_sort.c +91 -0
  36. data/ext/zsv/vendor/zsv-1.3.0/app/compare_unique_colname.c +81 -0
  37. data/ext/zsv/vendor/zsv-1.3.0/app/count-pull.c +82 -0
  38. data/ext/zsv/vendor/zsv-1.3.0/app/count.c +404 -0
  39. data/ext/zsv/vendor/zsv-1.3.0/app/desc.c +569 -0
  40. data/ext/zsv/vendor/zsv-1.3.0/app/echo.c +365 -0
  41. data/ext/zsv/vendor/zsv-1.3.0/app/ext_example/my_extension.c +366 -0
  42. data/ext/zsv/vendor/zsv-1.3.0/app/ext_example/mysheet_extension.c +341 -0
  43. data/ext/zsv/vendor/zsv-1.3.0/app/ext_template/YOUR_EXTENSION_zsvext.c +263 -0
  44. data/ext/zsv/vendor/zsv-1.3.0/app/external/inih/ini.c +298 -0
  45. data/ext/zsv/vendor/zsv-1.3.0/app/external/inih/ini.h +157 -0
  46. data/ext/zsv/vendor/zsv-1.3.0/app/external/json_writer-1.01/json_numeric.c +177 -0
  47. data/ext/zsv/vendor/zsv-1.3.0/app/external/json_writer-1.01/jsonwriter.c +444 -0
  48. data/ext/zsv/vendor/zsv-1.3.0/app/external/json_writer-1.01/jsonwriter.h +145 -0
  49. data/ext/zsv/vendor/zsv-1.3.0/app/external/json_writer-1.01/utils.c +110 -0
  50. data/ext/zsv/vendor/zsv-1.3.0/app/external/memfile-1.0/include/memfile.h +15 -0
  51. data/ext/zsv/vendor/zsv-1.3.0/app/external/memfile-1.0/src/memfile.c +64 -0
  52. data/ext/zsv/vendor/zsv-1.3.0/app/external/sglib/sglib.h +1955 -0
  53. data/ext/zsv/vendor/zsv-1.3.0/app/external/simdutf/simdutf.h +6802 -0
  54. data/ext/zsv/vendor/zsv-1.3.0/app/external/sqlite3/sqlite3.c +230517 -0
  55. data/ext/zsv/vendor/zsv-1.3.0/app/external/sqlite3/sqlite3.h +12174 -0
  56. data/ext/zsv/vendor/zsv-1.3.0/app/external/sqlite3/sqlite3_and_csv_vtab.c +2 -0
  57. data/ext/zsv/vendor/zsv-1.3.0/app/external/sqlite3/sqlite3_csv_vtab-mem.c +142 -0
  58. data/ext/zsv/vendor/zsv-1.3.0/app/external/sqlite3/sqlite3_csv_vtab-mem.h +49 -0
  59. data/ext/zsv/vendor/zsv-1.3.0/app/external/sqlite3/sqlite3_csv_vtab-zsv.c +485 -0
  60. data/ext/zsv/vendor/zsv-1.3.0/app/external/sqlite3/sqlite3_csv_vtab.c +1015 -0
  61. data/ext/zsv/vendor/zsv-1.3.0/app/external/sqlite3/sqlite3ext.h +663 -0
  62. data/ext/zsv/vendor/zsv-1.3.0/app/external/sqlite3/vtab_helper.c +85 -0
  63. data/ext/zsv/vendor/zsv-1.3.0/app/external/yajl/build/yajl-2.1.1/include/yajl/yajl_common.h +75 -0
  64. data/ext/zsv/vendor/zsv-1.3.0/app/external/yajl/build/yajl-2.1.1/include/yajl/yajl_gen.h +167 -0
  65. data/ext/zsv/vendor/zsv-1.3.0/app/external/yajl/build/yajl-2.1.1/include/yajl/yajl_parse.h +228 -0
  66. data/ext/zsv/vendor/zsv-1.3.0/app/external/yajl/build/yajl-2.1.1/include/yajl/yajl_tree.h +186 -0
  67. data/ext/zsv/vendor/zsv-1.3.0/app/external/yajl/build/yajl-2.1.1/include/yajl/yajl_version.h +23 -0
  68. data/ext/zsv/vendor/zsv-1.3.0/app/external/yajl/src/api/yajl_common.h +76 -0
  69. data/ext/zsv/vendor/zsv-1.3.0/app/external/yajl/src/api/yajl_gen.h +167 -0
  70. data/ext/zsv/vendor/zsv-1.3.0/app/external/yajl/src/api/yajl_parse.h +238 -0
  71. data/ext/zsv/vendor/zsv-1.3.0/app/external/yajl/src/api/yajl_tree.h +186 -0
  72. data/ext/zsv/vendor/zsv-1.3.0/app/external/yajl/src/yajl.c +184 -0
  73. data/ext/zsv/vendor/zsv-1.3.0/app/external/yajl/src/yajl_alloc.c +52 -0
  74. data/ext/zsv/vendor/zsv-1.3.0/app/external/yajl/src/yajl_alloc.h +34 -0
  75. data/ext/zsv/vendor/zsv-1.3.0/app/external/yajl/src/yajl_buf.c +103 -0
  76. data/ext/zsv/vendor/zsv-1.3.0/app/external/yajl/src/yajl_buf.h +57 -0
  77. data/ext/zsv/vendor/zsv-1.3.0/app/external/yajl/src/yajl_bytestack.h +69 -0
  78. data/ext/zsv/vendor/zsv-1.3.0/app/external/yajl/src/yajl_encode.c +220 -0
  79. data/ext/zsv/vendor/zsv-1.3.0/app/external/yajl/src/yajl_encode.h +34 -0
  80. data/ext/zsv/vendor/zsv-1.3.0/app/external/yajl/src/yajl_gen.c +362 -0
  81. data/ext/zsv/vendor/zsv-1.3.0/app/external/yajl/src/yajl_lex.c +764 -0
  82. data/ext/zsv/vendor/zsv-1.3.0/app/external/yajl/src/yajl_lex.h +117 -0
  83. data/ext/zsv/vendor/zsv-1.3.0/app/external/yajl/src/yajl_parser.c +508 -0
  84. data/ext/zsv/vendor/zsv-1.3.0/app/external/yajl/src/yajl_parser.h +78 -0
  85. data/ext/zsv/vendor/zsv-1.3.0/app/external/yajl/src/yajl_tree.c +505 -0
  86. data/ext/zsv/vendor/zsv-1.3.0/app/external/yajl/src/yajl_version.c +7 -0
  87. data/ext/zsv/vendor/zsv-1.3.0/app/external/yajl_helper/yajl_helper/json_value.h +59 -0
  88. data/ext/zsv/vendor/zsv-1.3.0/app/external/yajl_helper/yajl_helper/yajl_helper.h +208 -0
  89. data/ext/zsv/vendor/zsv-1.3.0/app/external/yajl_helper/yajl_helper.c +795 -0
  90. data/ext/zsv/vendor/zsv-1.3.0/app/external/yajl_helper/yajl_helper_internal.h +28 -0
  91. data/ext/zsv/vendor/zsv-1.3.0/app/flatten.c +851 -0
  92. data/ext/zsv/vendor/zsv-1.3.0/app/jq.c +106 -0
  93. data/ext/zsv/vendor/zsv-1.3.0/app/jq.h +6 -0
  94. data/ext/zsv/vendor/zsv-1.3.0/app/mv.c +113 -0
  95. data/ext/zsv/vendor/zsv-1.3.0/app/noop.c +90 -0
  96. data/ext/zsv/vendor/zsv-1.3.0/app/overwrite.c +295 -0
  97. data/ext/zsv/vendor/zsv-1.3.0/app/paste.c +175 -0
  98. data/ext/zsv/vendor/zsv-1.3.0/app/pretty.c +693 -0
  99. data/ext/zsv/vendor/zsv-1.3.0/app/prop.c +980 -0
  100. data/ext/zsv/vendor/zsv-1.3.0/app/rm.c +131 -0
  101. data/ext/zsv/vendor/zsv-1.3.0/app/select/fixed.c +130 -0
  102. data/ext/zsv/vendor/zsv-1.3.0/app/select/internal.h +118 -0
  103. data/ext/zsv/vendor/zsv-1.3.0/app/select/parallel.c +45 -0
  104. data/ext/zsv/vendor/zsv-1.3.0/app/select/parallel.h +41 -0
  105. data/ext/zsv/vendor/zsv-1.3.0/app/select/processing.c +107 -0
  106. data/ext/zsv/vendor/zsv-1.3.0/app/select/rand.c +20 -0
  107. data/ext/zsv/vendor/zsv-1.3.0/app/select/regex.c +61 -0
  108. data/ext/zsv/vendor/zsv-1.3.0/app/select/search.c +14 -0
  109. data/ext/zsv/vendor/zsv-1.3.0/app/select/selection.c +192 -0
  110. data/ext/zsv/vendor/zsv-1.3.0/app/select/usage.c +72 -0
  111. data/ext/zsv/vendor/zsv-1.3.0/app/select-pull.c +812 -0
  112. data/ext/zsv/vendor/zsv-1.3.0/app/select.c +753 -0
  113. data/ext/zsv/vendor/zsv-1.3.0/app/serialize.c +372 -0
  114. data/ext/zsv/vendor/zsv-1.3.0/app/sheet/curses.h +15 -0
  115. data/ext/zsv/vendor/zsv-1.3.0/app/sheet/cursor.c +119 -0
  116. data/ext/zsv/vendor/zsv-1.3.0/app/sheet/errors.c +45 -0
  117. data/ext/zsv/vendor/zsv-1.3.0/app/sheet/file.c +63 -0
  118. data/ext/zsv/vendor/zsv-1.3.0/app/sheet/file.h +12 -0
  119. data/ext/zsv/vendor/zsv-1.3.0/app/sheet/filter.c +166 -0
  120. data/ext/zsv/vendor/zsv-1.3.0/app/sheet/handlers.c +214 -0
  121. data/ext/zsv/vendor/zsv-1.3.0/app/sheet/handlers_internal.h +128 -0
  122. data/ext/zsv/vendor/zsv-1.3.0/app/sheet/help.c +43 -0
  123. data/ext/zsv/vendor/zsv-1.3.0/app/sheet/index.c +81 -0
  124. data/ext/zsv/vendor/zsv-1.3.0/app/sheet/index.h +25 -0
  125. data/ext/zsv/vendor/zsv-1.3.0/app/sheet/key-bindings.c +325 -0
  126. data/ext/zsv/vendor/zsv-1.3.0/app/sheet/key-bindings.h +73 -0
  127. data/ext/zsv/vendor/zsv-1.3.0/app/sheet/lexer.c +203 -0
  128. data/ext/zsv/vendor/zsv-1.3.0/app/sheet/newline_handler.c +7 -0
  129. data/ext/zsv/vendor/zsv-1.3.0/app/sheet/pivot.c +318 -0
  130. data/ext/zsv/vendor/zsv-1.3.0/app/sheet/procedure.c +134 -0
  131. data/ext/zsv/vendor/zsv-1.3.0/app/sheet/procedure.h +119 -0
  132. data/ext/zsv/vendor/zsv-1.3.0/app/sheet/read-data.c +322 -0
  133. data/ext/zsv/vendor/zsv-1.3.0/app/sheet/screen_buffer.c +203 -0
  134. data/ext/zsv/vendor/zsv-1.3.0/app/sheet/screen_buffer.h +36 -0
  135. data/ext/zsv/vendor/zsv-1.3.0/app/sheet/sheet-sql.c +167 -0
  136. data/ext/zsv/vendor/zsv-1.3.0/app/sheet/sheet_internal.h +36 -0
  137. data/ext/zsv/vendor/zsv-1.3.0/app/sheet/sqlfilter.c +153 -0
  138. data/ext/zsv/vendor/zsv-1.3.0/app/sheet/terminfo.c +32 -0
  139. data/ext/zsv/vendor/zsv-1.3.0/app/sheet/transformation.c +312 -0
  140. data/ext/zsv/vendor/zsv-1.3.0/app/sheet/transformation.h +29 -0
  141. data/ext/zsv/vendor/zsv-1.3.0/app/sheet/ui_buffer.c +266 -0
  142. data/ext/zsv/vendor/zsv-1.3.0/app/sheet/usage.c +9 -0
  143. data/ext/zsv/vendor/zsv-1.3.0/app/sheet/utf8-width.c +60 -0
  144. data/ext/zsv/vendor/zsv-1.3.0/app/sheet.c +1007 -0
  145. data/ext/zsv/vendor/zsv-1.3.0/app/sql.c +453 -0
  146. data/ext/zsv/vendor/zsv-1.3.0/app/sql_internal.c +101 -0
  147. data/ext/zsv/vendor/zsv-1.3.0/app/sql_internal.h +49 -0
  148. data/ext/zsv/vendor/zsv-1.3.0/app/stack.c +393 -0
  149. data/ext/zsv/vendor/zsv-1.3.0/app/utils/arg.c +322 -0
  150. data/ext/zsv/vendor/zsv-1.3.0/app/utils/cache.c +228 -0
  151. data/ext/zsv/vendor/zsv-1.3.0/app/utils/cat.c +91 -0
  152. data/ext/zsv/vendor/zsv-1.3.0/app/utils/chunk.c +240 -0
  153. data/ext/zsv/vendor/zsv-1.3.0/app/utils/chunk.h +63 -0
  154. data/ext/zsv/vendor/zsv-1.3.0/app/utils/clock.c +57 -0
  155. data/ext/zsv/vendor/zsv-1.3.0/app/utils/db.c +148 -0
  156. data/ext/zsv/vendor/zsv-1.3.0/app/utils/dirs-no-jq.c +2 -0
  157. data/ext/zsv/vendor/zsv-1.3.0/app/utils/dirs.c +427 -0
  158. data/ext/zsv/vendor/zsv-1.3.0/app/utils/dirs_from_json.c +253 -0
  159. data/ext/zsv/vendor/zsv-1.3.0/app/utils/dirs_to_json.c +121 -0
  160. data/ext/zsv/vendor/zsv-1.3.0/app/utils/dl.c +20 -0
  161. data/ext/zsv/vendor/zsv-1.3.0/app/utils/emcc/fs_api.c +159 -0
  162. data/ext/zsv/vendor/zsv-1.3.0/app/utils/err.c +24 -0
  163. data/ext/zsv/vendor/zsv-1.3.0/app/utils/file-mem.c +180 -0
  164. data/ext/zsv/vendor/zsv-1.3.0/app/utils/file.c +256 -0
  165. data/ext/zsv/vendor/zsv-1.3.0/app/utils/index.c +197 -0
  166. data/ext/zsv/vendor/zsv-1.3.0/app/utils/index.h +49 -0
  167. data/ext/zsv/vendor/zsv-1.3.0/app/utils/jq.c +400 -0
  168. data/ext/zsv/vendor/zsv-1.3.0/app/utils/json.c +120 -0
  169. data/ext/zsv/vendor/zsv-1.3.0/app/utils/mem.c +18 -0
  170. data/ext/zsv/vendor/zsv-1.3.0/app/utils/memmem.c +132 -0
  171. data/ext/zsv/vendor/zsv-1.3.0/app/utils/os.c +178 -0
  172. data/ext/zsv/vendor/zsv-1.3.0/app/utils/overwrite.c +258 -0
  173. data/ext/zsv/vendor/zsv-1.3.0/app/utils/overwrite_writer.c +246 -0
  174. data/ext/zsv/vendor/zsv-1.3.0/app/utils/pcre2-8/pcre2-8-test.c +123 -0
  175. data/ext/zsv/vendor/zsv-1.3.0/app/utils/pcre2-8/pcre2-8.c +153 -0
  176. data/ext/zsv/vendor/zsv-1.3.0/app/utils/pcre2-8/pcre2-8.h +54 -0
  177. data/ext/zsv/vendor/zsv-1.3.0/app/utils/prop.c +267 -0
  178. data/ext/zsv/vendor/zsv-1.3.0/app/utils/signal.c +53 -0
  179. data/ext/zsv/vendor/zsv-1.3.0/app/utils/string.c +357 -0
  180. data/ext/zsv/vendor/zsv-1.3.0/app/utils/win/dir_exists_longpath.c +83 -0
  181. data/ext/zsv/vendor/zsv-1.3.0/app/utils/win/dl.c +33 -0
  182. data/ext/zsv/vendor/zsv-1.3.0/app/utils/win/fopen_longpath.c +184 -0
  183. data/ext/zsv/vendor/zsv-1.3.0/app/utils/win/foreach_dirent_longpath.c +292 -0
  184. data/ext/zsv/vendor/zsv-1.3.0/app/utils/win/io.c +259 -0
  185. data/ext/zsv/vendor/zsv-1.3.0/app/utils/win/io.h +13 -0
  186. data/ext/zsv/vendor/zsv-1.3.0/app/utils/win/mkdir_longpath.c +255 -0
  187. data/ext/zsv/vendor/zsv-1.3.0/app/utils/win/remove_longpath.c +96 -0
  188. data/ext/zsv/vendor/zsv-1.3.0/app/utils/writer.c +361 -0
  189. data/ext/zsv/vendor/zsv-1.3.0/app/zsv_command.h +40 -0
  190. data/ext/zsv/vendor/zsv-1.3.0/app/zsv_command_standalone.c +16 -0
  191. data/ext/zsv/vendor/zsv-1.3.0/app/zsv_main.h +44 -0
  192. data/ext/zsv/vendor/zsv-1.3.0/examples/js/zsv_parser_api_dummy.c +3 -0
  193. data/ext/zsv/vendor/zsv-1.3.0/examples/lib/parse_by_chunk.c +100 -0
  194. data/ext/zsv/vendor/zsv-1.3.0/examples/lib/print_my_column.c +143 -0
  195. data/ext/zsv/vendor/zsv-1.3.0/examples/lib/pull.c +89 -0
  196. data/ext/zsv/vendor/zsv-1.3.0/examples/lib/simple.c +123 -0
  197. data/ext/zsv/vendor/zsv-1.3.0/fuzz/fuzz.c +16 -0
  198. data/ext/zsv/vendor/zsv-1.3.0/include/zsv/api.h +336 -0
  199. data/ext/zsv/vendor/zsv-1.3.0/include/zsv/common.h +361 -0
  200. data/ext/zsv/vendor/zsv-1.3.0/include/zsv/ext/implementation.h +62 -0
  201. data/ext/zsv/vendor/zsv-1.3.0/include/zsv/ext/implementation_private.h +113 -0
  202. data/ext/zsv/vendor/zsv-1.3.0/include/zsv/ext/sheet.h +73 -0
  203. data/ext/zsv/vendor/zsv-1.3.0/include/zsv/ext.h +329 -0
  204. data/ext/zsv/vendor/zsv-1.3.0/include/zsv/utils/arg.h +90 -0
  205. data/ext/zsv/vendor/zsv-1.3.0/include/zsv/utils/cache.h +49 -0
  206. data/ext/zsv/vendor/zsv-1.3.0/include/zsv/utils/clock.h +36 -0
  207. data/ext/zsv/vendor/zsv-1.3.0/include/zsv/utils/compiler.h +58 -0
  208. data/ext/zsv/vendor/zsv-1.3.0/include/zsv/utils/db.h +19 -0
  209. data/ext/zsv/vendor/zsv-1.3.0/include/zsv/utils/dirs.h +147 -0
  210. data/ext/zsv/vendor/zsv-1.3.0/include/zsv/utils/dl.h +22 -0
  211. data/ext/zsv/vendor/zsv-1.3.0/include/zsv/utils/emcc/fs_api.h +28 -0
  212. data/ext/zsv/vendor/zsv-1.3.0/include/zsv/utils/err.h +22 -0
  213. data/ext/zsv/vendor/zsv-1.3.0/include/zsv/utils/file-mem.h +17 -0
  214. data/ext/zsv/vendor/zsv-1.3.0/include/zsv/utils/file.h +99 -0
  215. data/ext/zsv/vendor/zsv-1.3.0/include/zsv/utils/jq.h +65 -0
  216. data/ext/zsv/vendor/zsv-1.3.0/include/zsv/utils/json.h +19 -0
  217. data/ext/zsv/vendor/zsv-1.3.0/include/zsv/utils/mem.h +19 -0
  218. data/ext/zsv/vendor/zsv-1.3.0/include/zsv/utils/memmem.h +13 -0
  219. data/ext/zsv/vendor/zsv-1.3.0/include/zsv/utils/os.h +54 -0
  220. data/ext/zsv/vendor/zsv-1.3.0/include/zsv/utils/overwrite.h +71 -0
  221. data/ext/zsv/vendor/zsv-1.3.0/include/zsv/utils/overwrite_writer.h +53 -0
  222. data/ext/zsv/vendor/zsv-1.3.0/include/zsv/utils/prop.h +107 -0
  223. data/ext/zsv/vendor/zsv-1.3.0/include/zsv/utils/signal.h +18 -0
  224. data/ext/zsv/vendor/zsv-1.3.0/include/zsv/utils/sql.h +11 -0
  225. data/ext/zsv/vendor/zsv-1.3.0/include/zsv/utils/string.h +148 -0
  226. data/ext/zsv/vendor/zsv-1.3.0/include/zsv/utils/utf8.h +41 -0
  227. data/ext/zsv/vendor/zsv-1.3.0/include/zsv/utils/win/dl.h +25 -0
  228. data/ext/zsv/vendor/zsv-1.3.0/include/zsv/utils/writer.h +101 -0
  229. data/ext/zsv/vendor/zsv-1.3.0/include/zsv/zsv_export.h +33 -0
  230. data/ext/zsv/vendor/zsv-1.3.0/include/zsv.h +20 -0
  231. data/ext/zsv/vendor/zsv-1.3.0/src/vector_delim.c +60 -0
  232. data/ext/zsv/vendor/zsv-1.3.0/src/zsv.c +484 -0
  233. data/ext/zsv/vendor/zsv-1.3.0/src/zsv_internal.c +731 -0
  234. data/ext/zsv/vendor/zsv-1.3.0/src/zsv_scan_delim.c +285 -0
  235. data/ext/zsv/vendor/zsv-1.3.0/src/zsv_scan_fixed.c +88 -0
  236. data/ext/zsv/vendor/zsv-1.3.0/src/zsv_strencode.c +51 -0
  237. data/ext/zsv/zsv_ext.c +343 -0
  238. data/lib/zsv/version.rb +5 -0
  239. data/lib/zsv.rb +81 -0
  240. metadata +340 -0
@@ -0,0 +1,186 @@
1
+ /*
2
+ * Copyright (c) 2010-2011 Florian Forster <ff at octo.it>
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_tree.h
19
+ *
20
+ * Parses JSON data and returns the data in tree form.
21
+ *
22
+ * \author Florian Forster
23
+ * \date August 2010
24
+ *
25
+ * This interface makes quick parsing and extraction of
26
+ * smallish JSON docs trivial:
27
+ *
28
+ * \include example/parse_config.c
29
+ */
30
+
31
+ #ifndef YAJL_TREE_H
32
+ #define YAJL_TREE_H 1
33
+
34
+ #include <yajl/yajl_common.h>
35
+
36
+ #ifdef __cplusplus
37
+ extern "C" {
38
+ #endif
39
+
40
+ /** possible data types that a yajl_val_s can hold */
41
+ typedef enum {
42
+ yajl_t_string = 1,
43
+ yajl_t_number = 2,
44
+ yajl_t_object = 3,
45
+ yajl_t_array = 4,
46
+ yajl_t_true = 5,
47
+ yajl_t_false = 6,
48
+ yajl_t_null = 7,
49
+ /** The any type isn't valid for yajl_val_s.type, but can be
50
+ * used as an argument to routines like yajl_tree_get().
51
+ */
52
+ yajl_t_any = 8
53
+ } yajl_type;
54
+
55
+ #define YAJL_NUMBER_INT_VALID 0x01
56
+ #define YAJL_NUMBER_DOUBLE_VALID 0x02
57
+
58
+ /** A pointer to a node in the parse tree */
59
+ typedef struct yajl_val_s * yajl_val;
60
+
61
+ /**
62
+ * A JSON value representation capable of holding one of the seven
63
+ * types above. For "string", "number", "object", and "array"
64
+ * additional data is available in the union. The "YAJL_IS_*"
65
+ * and "YAJL_GET_*" macros below allow type checking and convenient
66
+ * value extraction.
67
+ */
68
+ struct yajl_val_s
69
+ {
70
+ /** Type of the value contained. Use the "YAJL_IS_*" macros to check for a
71
+ * specific type. */
72
+ yajl_type type;
73
+ /** Type-specific data. You may use the "YAJL_GET_*" macros to access these
74
+ * members. */
75
+ union
76
+ {
77
+ char * string;
78
+ struct {
79
+ long long i; /*< integer value, if representable. */
80
+ double d; /*< double value, if representable. */
81
+ char *r; /*< unparsed number in string form. */
82
+ /** Signals whether the \em i and \em d members are
83
+ * valid. See \c YAJL_NUMBER_INT_VALID and
84
+ * \c YAJL_NUMBER_DOUBLE_VALID. */
85
+ unsigned int flags;
86
+ } number;
87
+ struct {
88
+ const char **keys; /*< Array of keys */
89
+ yajl_val *values; /*< Array of values. */
90
+ size_t len; /*< Number of key-value-pairs. */
91
+ } object;
92
+ struct {
93
+ yajl_val *values; /*< Array of elements. */
94
+ size_t len; /*< Number of elements. */
95
+ } array;
96
+ } u;
97
+ };
98
+
99
+ /**
100
+ * Parse a string.
101
+ *
102
+ * Parses an null-terminated string containing JSON data and returns a pointer
103
+ * to the top-level value (root of the parse tree).
104
+ *
105
+ * \param input Pointer to a null-terminated utf8 string containing
106
+ * JSON data.
107
+ * \param error_buffer Pointer to a buffer in which an error message will
108
+ * be stored if \em yajl_tree_parse fails, or
109
+ * \c NULL. The buffer will be initialized before
110
+ * parsing, so its content will be destroyed even if
111
+ * \em yajl_tree_parse succeeds.
112
+ * \param error_buffer_size Size of the memory area pointed to by
113
+ * \em error_buffer_size. If \em error_buffer_size is
114
+ * \c NULL, this argument is ignored.
115
+ *
116
+ * \returns Pointer to the top-level value or \c NULL on error. The memory
117
+ * pointed to must be freed using \em yajl_tree_free. In case of an error, a
118
+ * null terminated message describing the error in more detail is stored in
119
+ * \em error_buffer if it is not \c NULL.
120
+ */
121
+ YAJL_API yajl_val yajl_tree_parse (const char *input,
122
+ char *error_buffer, size_t error_buffer_size);
123
+
124
+
125
+ /**
126
+ * Free a parse tree returned by "yajl_tree_parse".
127
+ *
128
+ * \param v Pointer to a JSON value returned by "yajl_tree_parse". Passing NULL
129
+ * is valid and results in a no-op.
130
+ */
131
+ YAJL_API void yajl_tree_free (yajl_val v);
132
+
133
+ /**
134
+ * Access a nested value inside a tree.
135
+ *
136
+ * \param parent the node under which you'd like to extract values.
137
+ * \param path A null terminated array of strings, each the name of an object key
138
+ * \param type the yajl_type of the object you seek, or yajl_t_any if any will do.
139
+ *
140
+ * \returns a pointer to the found value, or NULL if we came up empty.
141
+ *
142
+ * Future Ideas: it'd be nice to move path to a string and implement support for
143
+ * a teeny tiny micro language here, so you can extract array elements, do things
144
+ * like .first and .last, even .length. Inspiration from JSONPath and css selectors?
145
+ * No it wouldn't be fast, but that's not what this API is about.
146
+ */
147
+ YAJL_API yajl_val yajl_tree_get(yajl_val parent, const char ** path, yajl_type type);
148
+
149
+ /* Various convenience macros to check the type of a `yajl_val` */
150
+ #define YAJL_IS_STRING(v) (((v) != NULL) && ((v)->type == yajl_t_string))
151
+ #define YAJL_IS_NUMBER(v) (((v) != NULL) && ((v)->type == yajl_t_number))
152
+ #define YAJL_IS_INTEGER(v) (YAJL_IS_NUMBER(v) && ((v)->u.number.flags & YAJL_NUMBER_INT_VALID))
153
+ #define YAJL_IS_DOUBLE(v) (YAJL_IS_NUMBER(v) && ((v)->u.number.flags & YAJL_NUMBER_DOUBLE_VALID))
154
+ #define YAJL_IS_OBJECT(v) (((v) != NULL) && ((v)->type == yajl_t_object))
155
+ #define YAJL_IS_ARRAY(v) (((v) != NULL) && ((v)->type == yajl_t_array ))
156
+ #define YAJL_IS_TRUE(v) (((v) != NULL) && ((v)->type == yajl_t_true ))
157
+ #define YAJL_IS_FALSE(v) (((v) != NULL) && ((v)->type == yajl_t_false ))
158
+ #define YAJL_IS_NULL(v) (((v) != NULL) && ((v)->type == yajl_t_null ))
159
+
160
+ /** Given a yajl_val_string return a ptr to the bare string it contains,
161
+ * or NULL if the value is not a string. */
162
+ #define YAJL_GET_STRING(v) (YAJL_IS_STRING(v) ? (v)->u.string : NULL)
163
+
164
+ /** Get the string representation of a number. You should check type first,
165
+ * perhaps using YAJL_IS_NUMBER */
166
+ #define YAJL_GET_NUMBER(v) ((v)->u.number.r)
167
+
168
+ /** Get the double representation of a number. You should check type first,
169
+ * perhaps using YAJL_IS_DOUBLE */
170
+ #define YAJL_GET_DOUBLE(v) ((v)->u.number.d)
171
+
172
+ /** Get the 64bit (long long) integer representation of a number. You should
173
+ * check type first, perhaps using YAJL_IS_INTEGER */
174
+ #define YAJL_GET_INTEGER(v) ((v)->u.number.i)
175
+
176
+ /** Get a pointer to a yajl_val_object or NULL if the value is not an object. */
177
+ #define YAJL_GET_OBJECT(v) (YAJL_IS_OBJECT(v) ? &(v)->u.object : NULL)
178
+
179
+ /** Get a pointer to a yajl_val_array or NULL if the value is not an object. */
180
+ #define YAJL_GET_ARRAY(v) (YAJL_IS_ARRAY(v) ? &(v)->u.array : NULL)
181
+
182
+ #ifdef __cplusplus
183
+ }
184
+ #endif
185
+
186
+ #endif /* YAJL_TREE_H */
@@ -0,0 +1,184 @@
1
+ /*
2
+ * Copyright (c) 2007-2014, Lloyd Hilaiel <me@lloyd.io>
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 "api/yajl_parse.h"
18
+ #include "yajl_lex.h"
19
+ #include "yajl_parser.h"
20
+ #include "yajl_alloc.h"
21
+
22
+ #include <stdlib.h>
23
+ #include <string.h>
24
+ #include <stdarg.h>
25
+ #include <assert.h>
26
+
27
+ const char *
28
+ yajl_status_to_string(yajl_status stat)
29
+ {
30
+ const char * statStr = "unknown";
31
+ switch (stat) {
32
+ case yajl_status_ok:
33
+ statStr = "ok, no error";
34
+ break;
35
+ case yajl_status_client_canceled:
36
+ statStr = "client canceled parse";
37
+ break;
38
+ case yajl_status_error:
39
+ statStr = "parse error";
40
+ break;
41
+ }
42
+ return statStr;
43
+ }
44
+
45
+
46
+ yajl_handle
47
+ yajl_alloc(const yajl_callbacks * callbacks,
48
+ yajl_alloc_funcs * afs,
49
+ void * ctx)
50
+ {
51
+ yajl_handle hand = NULL;
52
+ yajl_alloc_funcs afsBuffer;
53
+
54
+ /* first order of business is to set up memory allocation routines */
55
+ if (afs != NULL) {
56
+ if (afs->malloc == NULL || afs->realloc == NULL || afs->free == NULL)
57
+ {
58
+ return NULL;
59
+ }
60
+ } else {
61
+ yajl_set_default_alloc_funcs(&afsBuffer);
62
+ afs = &afsBuffer;
63
+ }
64
+
65
+ hand = (yajl_handle) YA_MALLOC(afs, sizeof(struct yajl_handle_t));
66
+
67
+ /* copy in pointers to allocation routines */
68
+ memcpy((void *) &(hand->alloc), (void *) afs, sizeof(yajl_alloc_funcs));
69
+
70
+ hand->callbacks = callbacks;
71
+ hand->ctx = ctx;
72
+ hand->lexer = NULL;
73
+ hand->bytesConsumed = 0;
74
+ hand->decodeBuf = yajl_buf_alloc(&(hand->alloc));
75
+ hand->flags = 0;
76
+ yajl_bs_init(hand->stateStack, &(hand->alloc));
77
+ yajl_bs_push(hand->stateStack, yajl_state_start);
78
+
79
+ return hand;
80
+ }
81
+
82
+ const yajl_callbacks *
83
+ yajl_swap_callbacks(yajl_handle h, const yajl_callbacks * callbacks, void *new_ctx) {
84
+ const yajl_callbacks *old_callbacks = h->callbacks;
85
+ h->callbacks = callbacks;
86
+ h->ctx = new_ctx;
87
+ return old_callbacks;
88
+ }
89
+
90
+ int
91
+ yajl_config(yajl_handle h, yajl_option opt, ...)
92
+ {
93
+ int rv = 1;
94
+ va_list ap;
95
+ va_start(ap, opt);
96
+
97
+ switch(opt) {
98
+ case yajl_allow_comments:
99
+ case yajl_dont_validate_strings:
100
+ case yajl_allow_trailing_garbage:
101
+ case yajl_allow_multiple_values:
102
+ case yajl_allow_partial_values:
103
+ if (va_arg(ap, int)) h->flags |= opt;
104
+ else h->flags &= ~opt;
105
+ break;
106
+ default:
107
+ rv = 0;
108
+ }
109
+ va_end(ap);
110
+
111
+ return rv;
112
+ }
113
+
114
+ void
115
+ yajl_free(yajl_handle handle)
116
+ {
117
+ yajl_bs_free(handle->stateStack);
118
+ yajl_buf_free(handle->decodeBuf);
119
+ if (handle->lexer) {
120
+ yajl_lex_free(handle->lexer);
121
+ handle->lexer = NULL;
122
+ }
123
+ YA_FREE(&(handle->alloc), handle);
124
+ }
125
+
126
+ yajl_status
127
+ yajl_parse(yajl_handle hand, const unsigned char * jsonText,
128
+ size_t jsonTextLen)
129
+ {
130
+ yajl_status status;
131
+
132
+ /* lazy allocation of the lexer */
133
+ if (hand->lexer == NULL) {
134
+ hand->lexer = yajl_lex_alloc(&(hand->alloc),
135
+ hand->flags & yajl_allow_comments,
136
+ !(hand->flags & yajl_dont_validate_strings));
137
+ }
138
+
139
+ status = yajl_do_parse(hand, jsonText, jsonTextLen);
140
+ return status;
141
+ }
142
+
143
+
144
+ yajl_status
145
+ yajl_complete_parse(yajl_handle hand)
146
+ {
147
+ /* The lexer is lazy allocated in the first call to parse. if parse is
148
+ * never called, then no data was provided to parse at all. This is a
149
+ * "premature EOF" error unless yajl_allow_partial_values is specified.
150
+ * allocating the lexer now is the simplest possible way to handle this
151
+ * case while preserving all the other semantics of the parser
152
+ * (multiple values, partial values, etc). */
153
+ if (hand->lexer == NULL) {
154
+ hand->lexer = yajl_lex_alloc(&(hand->alloc),
155
+ hand->flags & yajl_allow_comments,
156
+ !(hand->flags & yajl_dont_validate_strings));
157
+ }
158
+
159
+ return yajl_do_finish(hand);
160
+ }
161
+
162
+ unsigned char *
163
+ yajl_get_error(yajl_handle hand, int verbose,
164
+ const unsigned char * jsonText, size_t jsonTextLen)
165
+ {
166
+ return yajl_render_error_string(hand, jsonText, jsonTextLen, verbose);
167
+ }
168
+
169
+ size_t
170
+ yajl_get_bytes_consumed(yajl_handle hand)
171
+ {
172
+ if (!hand) return 0;
173
+ else return hand->bytesConsumed;
174
+ }
175
+
176
+
177
+ void
178
+ yajl_free_error(yajl_handle hand, unsigned char * str)
179
+ {
180
+ /* use memory allocation functions if set */
181
+ YA_FREE(&(hand->alloc), str);
182
+ }
183
+
184
+ /* XXX: add utility routines to parse from file */
@@ -0,0 +1,52 @@
1
+ /*
2
+ * Copyright (c) 2007-2014, Lloyd Hilaiel <me@lloyd.io>
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
+ #include "yajl_alloc.h"
24
+ #include <stdlib.h>
25
+
26
+ static void * yajl_internal_malloc(void *ctx, size_t sz)
27
+ {
28
+ (void)ctx;
29
+ return malloc(sz);
30
+ }
31
+
32
+ static void * yajl_internal_realloc(void *ctx, void * previous,
33
+ size_t sz)
34
+ {
35
+ (void)ctx;
36
+ return realloc(previous, sz);
37
+ }
38
+
39
+ static void yajl_internal_free(void *ctx, void * ptr)
40
+ {
41
+ (void)ctx;
42
+ free(ptr);
43
+ }
44
+
45
+ void yajl_set_default_alloc_funcs(yajl_alloc_funcs * yaf)
46
+ {
47
+ yaf->malloc = yajl_internal_malloc;
48
+ yaf->free = yajl_internal_free;
49
+ yaf->realloc = yajl_internal_realloc;
50
+ yaf->ctx = NULL;
51
+ }
52
+
@@ -0,0 +1,34 @@
1
+ /*
2
+ * Copyright (c) 2007-2014, Lloyd Hilaiel <me@lloyd.io>
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
@@ -0,0 +1,103 @@
1
+ /*
2
+ * Copyright (c) 2007-2014, Lloyd Hilaiel <me@lloyd.io>
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
+ }
@@ -0,0 +1,57 @@
1
+ /*
2
+ * Copyright (c) 2007-2014, Lloyd Hilaiel <me@lloyd.io>
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
@@ -0,0 +1,69 @@
1
+ /*
2
+ * Copyright (c) 2007-2014, Lloyd Hilaiel <me@lloyd.io>
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