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,8 @@
1
+ /* Internal options symbols - forward declaration */
2
+ #ifndef ZSV_RUBY_OPTIONS_INTERNAL_H
3
+ #define ZSV_RUBY_OPTIONS_INTERNAL_H
4
+
5
+ /* Initialize option symbols (called from Init_zsv) */
6
+ void Init_zsv_options(void);
7
+
8
+ #endif /* ZSV_RUBY_OPTIONS_INTERNAL_H */
data/ext/zsv/parser.c ADDED
@@ -0,0 +1,300 @@
1
+ /* Parser wrapper implementation using zsv's callback API */
2
+ #include "parser.h"
3
+ #include <errno.h>
4
+ #include <string.h>
5
+
6
+ /* Forward declarations */
7
+ static void zsv_parser_init_common(zsv_ruby_parser_t *parser, VALUE opts_hash);
8
+ static void zsv_parser_finish_safe(zsv_ruby_parser_t *parser);
9
+
10
+ /* Row handler callback for zsv */
11
+ static void zsv_row_handler(void *ctx)
12
+ {
13
+ zsv_ruby_parser_t *parser = (zsv_ruby_parser_t *)ctx;
14
+
15
+ /* Don't allocate Ruby objects during cleanup/GC */
16
+ if (parser->in_cleanup) {
17
+ return;
18
+ }
19
+
20
+ /* Reset row builder for new row */
21
+ zsv_row_builder_reset(parser->row_builder);
22
+
23
+ /* Get all cells in this row */
24
+ size_t cell_count = zsv_cell_count(parser->zsv);
25
+ for (size_t i = 0; i < cell_count; i++) {
26
+ struct zsv_cell cell = zsv_get_cell(parser->zsv, i);
27
+ zsv_row_builder_add_cell(parser->row_builder, cell.str, cell.len);
28
+ }
29
+
30
+ /* Skip lines if configured */
31
+ if (parser->lines_skipped < (size_t)parser->options.skip_lines) {
32
+ parser->lines_skipped++;
33
+ return;
34
+ }
35
+
36
+ /* Process header row - only if headers:true and no custom headers provided */
37
+ if (parser->options.headers && NIL_P(parser->options.header_array) &&
38
+ !parser->header_row_processed) {
39
+ parser->headers = zsv_row_builder_to_array(parser->row_builder);
40
+ zsv_row_builder_set_headers(parser->row_builder, parser->headers);
41
+ parser->header_row_processed = true;
42
+ return; /* Don't store header row */
43
+ }
44
+
45
+ /* Build row as array or hash */
46
+ VALUE row;
47
+ if (!NIL_P(parser->headers)) {
48
+ row = zsv_row_builder_to_hash(parser->row_builder);
49
+ } else {
50
+ row = zsv_row_builder_to_array(parser->row_builder);
51
+ }
52
+
53
+ /* Add row to buffer */
54
+ rb_ary_push(parser->row_buffer, row);
55
+ parser->row_count++;
56
+ }
57
+
58
+ /* Initialize common parser setup */
59
+ static void zsv_parser_init_common(zsv_ruby_parser_t *parser, VALUE opts_hash)
60
+ {
61
+ /* Parse options */
62
+ zsv_options_parse(opts_hash, &parser->options);
63
+
64
+ /* Create row builder */
65
+ parser->row_builder = zsv_row_builder_new(parser->options.encoding);
66
+
67
+ /* Initialize zsv parser with callback */
68
+ struct zsv_opts zopts = {0};
69
+ zopts.delimiter = parser->options.delimiter;
70
+ zopts.row_handler = zsv_row_handler;
71
+ zopts.ctx = parser;
72
+
73
+ if (parser->file) {
74
+ zopts.stream = parser->file;
75
+ parser->zsv = zsv_new(&zopts);
76
+ } else {
77
+ /* IO object handling would require custom read callback */
78
+ rb_raise(rb_eNotImpError, "IO object parsing not yet implemented");
79
+ }
80
+
81
+ /* Set headers: use custom headers if provided, otherwise will be read from first row */
82
+ if (!NIL_P(parser->options.header_array)) {
83
+ parser->headers = parser->options.header_array;
84
+ zsv_row_builder_set_headers(parser->row_builder, parser->headers);
85
+ parser->header_row_processed = true; /* Skip reading headers from file */
86
+ } else {
87
+ parser->headers = Qnil;
88
+ }
89
+
90
+ parser->row_buffer = rb_ary_new();
91
+ parser->closed = false;
92
+ parser->eof_reached = false;
93
+ parser->in_cleanup = false;
94
+ parser->current_row = Qnil;
95
+ }
96
+
97
+ /* Create parser from file path */
98
+ zsv_ruby_parser_t *zsv_parser_new_from_path(const char *path, VALUE opts_hash)
99
+ {
100
+ zsv_ruby_parser_t *parser = ZSV_ALLOC(zsv_ruby_parser_t);
101
+ memset(parser, 0, sizeof(zsv_ruby_parser_t));
102
+
103
+ /* Open file */
104
+ parser->file = fopen(path, "rb");
105
+ if (!parser->file) {
106
+ xfree(parser);
107
+ rb_sys_fail(path);
108
+ }
109
+
110
+ zsv_parser_init_common(parser, opts_hash);
111
+ return parser;
112
+ }
113
+
114
+ /* Create parser from Ruby IO */
115
+ zsv_ruby_parser_t *zsv_parser_new_from_io(VALUE io, VALUE opts_hash)
116
+ {
117
+ zsv_ruby_parser_t *parser = ZSV_ALLOC(zsv_ruby_parser_t);
118
+ memset(parser, 0, sizeof(zsv_ruby_parser_t));
119
+
120
+ parser->io = io;
121
+ zsv_parser_init_common(parser, opts_hash);
122
+
123
+ return parser;
124
+ }
125
+
126
+ /* Create parser from string */
127
+ zsv_ruby_parser_t *zsv_parser_new_from_string(VALUE string, VALUE opts_hash)
128
+ {
129
+ Check_Type(string, T_STRING);
130
+
131
+ zsv_ruby_parser_t *parser = ZSV_ALLOC(zsv_ruby_parser_t);
132
+ memset(parser, 0, sizeof(zsv_ruby_parser_t));
133
+
134
+ /* Create memory-backed file */
135
+ const char *str_ptr = RSTRING_PTR(string);
136
+ size_t str_len = RSTRING_LEN(string);
137
+
138
+ parser->file = fmemopen((void *)str_ptr, str_len, "rb");
139
+ if (!parser->file) {
140
+ xfree(parser);
141
+ rb_raise(rb_eRuntimeError, "Failed to create memory stream");
142
+ }
143
+
144
+ zsv_parser_init_common(parser, opts_hash);
145
+ return parser;
146
+ }
147
+
148
+ /* Free parser */
149
+ void zsv_parser_free(zsv_ruby_parser_t *parser)
150
+ {
151
+ if (!parser)
152
+ return;
153
+
154
+ zsv_parser_close(parser);
155
+
156
+ if (parser->row_builder) {
157
+ zsv_row_builder_free(parser->row_builder);
158
+ }
159
+
160
+ if (parser->error_message) {
161
+ xfree(parser->error_message);
162
+ }
163
+
164
+ zsv_options_free(&parser->options);
165
+ xfree(parser);
166
+ }
167
+
168
+ /* Parse next row - pull-based interface */
169
+ VALUE zsv_parser_shift(zsv_ruby_parser_t *parser)
170
+ {
171
+ if (parser->closed) {
172
+ return Qnil;
173
+ }
174
+
175
+ /* If we have buffered rows, return the first one */
176
+ if (RARRAY_LEN(parser->row_buffer) > 0) {
177
+ return rb_ary_shift(parser->row_buffer);
178
+ }
179
+
180
+ /* If we've reached EOF, no more rows */
181
+ if (parser->eof_reached) {
182
+ return Qnil;
183
+ }
184
+
185
+ /* Parse more data */
186
+ enum zsv_status status = zsv_parse_more(parser->zsv);
187
+
188
+ /* Check for errors */
189
+ if (status != zsv_status_ok && status != zsv_status_no_more_input) {
190
+ RAISE_MALFORMED_CSV("CSV parsing error");
191
+ }
192
+
193
+ /* If EOF reached, finish to flush final row */
194
+ if (status == zsv_status_no_more_input && !parser->eof_reached) {
195
+ /* Call finish() BEFORE marking EOF to flush any pending row */
196
+ zsv_parser_finish_safe(parser);
197
+ parser->eof_reached = true;
198
+ }
199
+
200
+ /* Return first buffered row, or nil if buffer is empty */
201
+ if (RARRAY_LEN(parser->row_buffer) > 0) {
202
+ return rb_ary_shift(parser->row_buffer);
203
+ }
204
+
205
+ return Qnil; /* EOF or no rows yet */
206
+ }
207
+
208
+ /* Parse all rows with block */
209
+ void zsv_parser_each(zsv_ruby_parser_t *parser)
210
+ {
211
+ VALUE row;
212
+ while (!NIL_P(row = zsv_parser_shift(parser))) {
213
+ rb_yield(row);
214
+ }
215
+ }
216
+
217
+ /* Rewind parser */
218
+ void zsv_parser_rewind(zsv_ruby_parser_t *parser)
219
+ {
220
+ if (!parser->file) {
221
+ rb_raise(rb_eIOError, "Cannot rewind non-file parser");
222
+ }
223
+
224
+ rewind(parser->file);
225
+ zsv_finish(parser->zsv);
226
+ zsv_delete(parser->zsv);
227
+
228
+ /* Reinitialize parser */
229
+ struct zsv_opts zopts = {0};
230
+ zopts.delimiter = parser->options.delimiter;
231
+ zopts.row_handler = zsv_row_handler;
232
+ zopts.ctx = parser;
233
+ zopts.stream = parser->file;
234
+
235
+ parser->zsv = zsv_new(&zopts);
236
+
237
+ parser->row_count = 0;
238
+ parser->lines_skipped = 0;
239
+ parser->header_row_processed = false;
240
+ parser->eof_reached = false;
241
+ parser->in_cleanup = false;
242
+ parser->row_buffer = rb_ary_new();
243
+ parser->current_row = Qnil;
244
+ }
245
+
246
+ /* Finish parsing safely (flush final row if needed) */
247
+ static void zsv_parser_finish_safe(zsv_ruby_parser_t *parser)
248
+ {
249
+ if (!parser->zsv) {
250
+ return; /* No parser */
251
+ }
252
+
253
+ /* Only finish if we can allocate (not in GC) */
254
+ if (!parser->in_cleanup) {
255
+ zsv_finish(parser->zsv);
256
+ }
257
+ }
258
+
259
+ /* Close parser */
260
+ void zsv_parser_close(zsv_ruby_parser_t *parser)
261
+ {
262
+ if (!parser || parser->closed)
263
+ return;
264
+
265
+ /* Mark as closed and in_cleanup FIRST to prevent Ruby allocations
266
+ * during GC phase. This is critical because dfree may be called
267
+ * during GC, and zsv_finish/zsv_delete can trigger row callbacks. */
268
+ parser->closed = true;
269
+ parser->in_cleanup = true;
270
+
271
+ if (parser->zsv) {
272
+ /* Delete parser - this calls zsv_finish internally and frees buffers.
273
+ * Row callbacks may fire but in_cleanup flag prevents allocations. */
274
+ zsv_delete(parser->zsv);
275
+ parser->zsv = NULL;
276
+ }
277
+
278
+ if (parser->file) {
279
+ fclose(parser->file);
280
+ parser->file = NULL;
281
+ }
282
+ }
283
+
284
+ /* Get headers */
285
+ VALUE zsv_parser_headers(zsv_ruby_parser_t *parser)
286
+ {
287
+ return parser->headers;
288
+ }
289
+
290
+ /* Check if closed */
291
+ bool zsv_parser_closed(zsv_ruby_parser_t *parser)
292
+ {
293
+ return parser->closed;
294
+ }
295
+
296
+ /* Get row count */
297
+ size_t zsv_parser_row_count(zsv_ruby_parser_t *parser)
298
+ {
299
+ return parser->row_count;
300
+ }
data/ext/zsv/parser.h ADDED
@@ -0,0 +1,62 @@
1
+ /* Parser wrapper around zsv */
2
+ #ifndef ZSV_RUBY_PARSER_H
3
+ #define ZSV_RUBY_PARSER_H
4
+
5
+ #include "common.h"
6
+ #include "options.h"
7
+ #include "row.h"
8
+
9
+ /* Parser state structure */
10
+ typedef struct {
11
+ zsv_parser zsv; /* zsv parser instance */
12
+ FILE *file; /* File handle (if parsing file) */
13
+ VALUE io; /* Ruby IO object (if parsing IO) */
14
+ zsv_ruby_options_t options; /* Parser options */
15
+ zsv_row_builder_t *row_builder; /* Row builder */
16
+ VALUE current_row; /* Current row being built */
17
+ VALUE row_buffer; /* Buffer of parsed rows (Ruby array) */
18
+ VALUE headers; /* Parsed headers (if header mode) */
19
+ size_t row_count; /* Number of rows parsed */
20
+ size_t lines_skipped; /* Number of lines skipped */
21
+ bool header_row_processed; /* Whether header row was processed */
22
+ bool closed; /* Whether parser is closed */
23
+ bool eof_reached; /* Whether EOF was reached */
24
+ bool in_cleanup; /* True during zsv_finish cleanup */
25
+ int error_code; /* Last error code */
26
+ char *error_message; /* Last error message */
27
+ } zsv_ruby_parser_t;
28
+
29
+ /* Create new parser from file path */
30
+ zsv_ruby_parser_t *zsv_parser_new_from_path(const char *path, VALUE opts_hash);
31
+
32
+ /* Create new parser from Ruby IO object */
33
+ zsv_ruby_parser_t *zsv_parser_new_from_io(VALUE io, VALUE opts_hash);
34
+
35
+ /* Create new parser from string */
36
+ zsv_ruby_parser_t *zsv_parser_new_from_string(VALUE string, VALUE opts_hash);
37
+
38
+ /* Free parser and associated resources */
39
+ void zsv_parser_free(zsv_ruby_parser_t *parser);
40
+
41
+ /* Parse next row, returns Ruby array or hash */
42
+ VALUE zsv_parser_shift(zsv_ruby_parser_t *parser);
43
+
44
+ /* Parse all rows, yielding to block */
45
+ void zsv_parser_each(zsv_ruby_parser_t *parser);
46
+
47
+ /* Rewind parser to beginning */
48
+ void zsv_parser_rewind(zsv_ruby_parser_t *parser);
49
+
50
+ /* Close parser */
51
+ void zsv_parser_close(zsv_ruby_parser_t *parser);
52
+
53
+ /* Get headers */
54
+ VALUE zsv_parser_headers(zsv_ruby_parser_t *parser);
55
+
56
+ /* Check if parser is closed */
57
+ bool zsv_parser_closed(zsv_ruby_parser_t *parser);
58
+
59
+ /* Get row count */
60
+ size_t zsv_parser_row_count(zsv_ruby_parser_t *parser);
61
+
62
+ #endif /* ZSV_RUBY_PARSER_H */
data/ext/zsv/row.c ADDED
@@ -0,0 +1,122 @@
1
+ /* Row handling and conversion implementation */
2
+ #include "row.h"
3
+
4
+ #define INITIAL_ROW_CAPACITY 32
5
+
6
+ zsv_row_builder_t *zsv_row_builder_new(rb_encoding *encoding)
7
+ {
8
+ zsv_row_builder_t *builder = ZSV_ALLOC(zsv_row_builder_t);
9
+
10
+ builder->capacity = INITIAL_ROW_CAPACITY;
11
+ builder->cells = ZSV_ALLOC_N(VALUE, builder->capacity);
12
+ builder->count = 0;
13
+ builder->headers = Qnil;
14
+ builder->header_cache = NULL;
15
+ builder->header_count = 0;
16
+ builder->encoding = encoding;
17
+
18
+ return builder;
19
+ }
20
+
21
+ void zsv_row_builder_free(zsv_row_builder_t *builder)
22
+ {
23
+ if (builder) {
24
+ xfree(builder->cells);
25
+ if (builder->header_cache) {
26
+ xfree(builder->header_cache);
27
+ }
28
+ xfree(builder);
29
+ }
30
+ }
31
+
32
+ void zsv_row_builder_reset(zsv_row_builder_t *builder)
33
+ {
34
+ builder->count = 0;
35
+ }
36
+
37
+ static void zsv_row_builder_ensure_capacity(zsv_row_builder_t *builder, size_t needed)
38
+ {
39
+ if (needed <= builder->capacity) {
40
+ return;
41
+ }
42
+
43
+ /* Double capacity until we have enough */
44
+ size_t new_capacity = builder->capacity;
45
+ while (new_capacity < needed) {
46
+ new_capacity *= 2;
47
+ }
48
+
49
+ ZSV_REALLOC_N(builder->cells, VALUE, new_capacity);
50
+ builder->capacity = new_capacity;
51
+ }
52
+
53
+ void zsv_row_builder_add_cell(zsv_row_builder_t *builder, const unsigned char *data, size_t length)
54
+ {
55
+ zsv_row_builder_ensure_capacity(builder, builder->count + 1);
56
+
57
+ /* Create Ruby string with proper encoding */
58
+ VALUE str = rb_enc_str_new((const char *)data, length, builder->encoding);
59
+
60
+ /* Freeze string for memory efficiency (shared strings) */
61
+ rb_str_freeze(str);
62
+
63
+ builder->cells[builder->count++] = str;
64
+ }
65
+
66
+ VALUE zsv_row_builder_to_array(zsv_row_builder_t *builder)
67
+ {
68
+ VALUE row = rb_ary_new_from_values(builder->count, builder->cells);
69
+ return row;
70
+ }
71
+
72
+ VALUE zsv_row_builder_to_hash(zsv_row_builder_t *builder)
73
+ {
74
+ if (NIL_P(builder->headers)) {
75
+ rb_raise(rb_eRuntimeError, "Headers not set for hash conversion");
76
+ }
77
+
78
+ /* Use cached header count for efficiency */
79
+ size_t header_count = builder->header_count;
80
+ size_t cell_count = builder->count;
81
+
82
+ /* Pre-allocate hash with expected size (Ruby 3.2+) */
83
+ #ifdef HAVE_RB_HASH_NEW_CAPA
84
+ VALUE hash = rb_hash_new_capa(cell_count);
85
+ #else
86
+ VALUE hash = rb_hash_new();
87
+ #endif
88
+
89
+ /* Fast path: use cached header pointers (no rb_ary_entry calls) */
90
+ size_t matched = (cell_count < header_count) ? cell_count : header_count;
91
+ for (size_t i = 0; i < matched; i++) {
92
+ rb_hash_aset(hash, builder->header_cache[i], builder->cells[i]);
93
+ }
94
+
95
+ /* Rare case: more cells than headers, add with numeric keys */
96
+ for (size_t i = header_count; i < cell_count; i++) {
97
+ rb_hash_aset(hash, SIZET2NUM(i), builder->cells[i]);
98
+ }
99
+
100
+ return hash;
101
+ }
102
+
103
+ void zsv_row_builder_set_headers(zsv_row_builder_t *builder, VALUE headers)
104
+ {
105
+ Check_Type(headers, T_ARRAY);
106
+ builder->headers = headers;
107
+
108
+ /* Cache header count and pointers for fast access in to_hash */
109
+ builder->header_count = RARRAY_LEN(headers);
110
+
111
+ /* Free old cache if exists */
112
+ if (builder->header_cache) {
113
+ xfree(builder->header_cache);
114
+ }
115
+
116
+ /* Allocate and populate header cache */
117
+ builder->header_cache = ZSV_ALLOC_N(VALUE, builder->header_count);
118
+ const VALUE *header_ptr = RARRAY_CONST_PTR(headers);
119
+ for (size_t i = 0; i < builder->header_count; i++) {
120
+ builder->header_cache[i] = header_ptr[i];
121
+ }
122
+ }
data/ext/zsv/row.h ADDED
@@ -0,0 +1,39 @@
1
+ /* Row handling and conversion */
2
+ #ifndef ZSV_RUBY_ROW_H
3
+ #define ZSV_RUBY_ROW_H
4
+
5
+ #include "common.h"
6
+
7
+ /* Row builder for efficient conversion from zsv cells to Ruby arrays/hashes */
8
+ typedef struct {
9
+ VALUE *cells; /* Array of Ruby string cells */
10
+ size_t count; /* Number of cells in current row */
11
+ size_t capacity; /* Allocated capacity */
12
+ VALUE headers; /* Header array (for hash mode) */
13
+ VALUE *header_cache; /* Cached header VALUE pointers for fast access */
14
+ size_t header_count; /* Number of headers (cached) */
15
+ rb_encoding *encoding; /* String encoding */
16
+ } zsv_row_builder_t;
17
+
18
+ /* Initialize row builder */
19
+ zsv_row_builder_t *zsv_row_builder_new(rb_encoding *encoding);
20
+
21
+ /* Free row builder */
22
+ void zsv_row_builder_free(zsv_row_builder_t *builder);
23
+
24
+ /* Reset row builder for next row */
25
+ void zsv_row_builder_reset(zsv_row_builder_t *builder);
26
+
27
+ /* Add cell to current row */
28
+ void zsv_row_builder_add_cell(zsv_row_builder_t *builder, const unsigned char *data, size_t length);
29
+
30
+ /* Build Ruby array from current row */
31
+ VALUE zsv_row_builder_to_array(zsv_row_builder_t *builder);
32
+
33
+ /* Build Ruby hash from current row (requires headers) */
34
+ VALUE zsv_row_builder_to_hash(zsv_row_builder_t *builder);
35
+
36
+ /* Set headers for hash mode */
37
+ void zsv_row_builder_set_headers(zsv_row_builder_t *builder, VALUE headers);
38
+
39
+ #endif /* ZSV_RUBY_ROW_H */