zsv 1.3.1 → 1.4.4

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 (259) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +153 -2
  3. data/README.md +132 -240
  4. data/ext/zsv/ZSV_UPSTREAM +7 -0
  5. data/ext/zsv/common.h +0 -12
  6. data/ext/zsv/extconf.rb +70 -122
  7. data/ext/zsv/options.c +63 -62
  8. data/ext/zsv/options.h +8 -11
  9. data/ext/zsv/parser.c +390 -201
  10. data/ext/zsv/parser.h +35 -22
  11. data/ext/zsv/row.c +75 -28
  12. data/ext/zsv/row.h +15 -9
  13. data/ext/zsv/upstream.rb +55 -0
  14. data/ext/zsv/vendor/zsv/LICENSE +21 -0
  15. data/ext/zsv/vendor/zsv/VENDORED_FROM +2 -0
  16. data/ext/zsv/vendor/zsv/configure +1212 -0
  17. data/ext/zsv/vendor/{zsv-1.3.0 → zsv}/include/zsv/api.h +39 -0
  18. data/ext/zsv/vendor/{zsv-1.3.0 → zsv}/include/zsv/common.h +36 -0
  19. data/ext/zsv/vendor/{zsv-1.3.0 → zsv}/include/zsv/ext/sheet.h +8 -1
  20. data/ext/zsv/vendor/{zsv-1.3.0 → zsv}/include/zsv/ext.h +6 -2
  21. data/ext/zsv/vendor/zsv/include/zsv/utils/appname.h +51 -0
  22. data/ext/zsv/vendor/{zsv-1.3.0 → zsv}/include/zsv/utils/arg.h +50 -1
  23. data/ext/zsv/vendor/{zsv-1.3.0 → zsv}/include/zsv/utils/compiler.h +19 -8
  24. data/ext/zsv/vendor/{zsv-1.3.0 → zsv}/include/zsv/utils/dirs.h +2 -0
  25. data/ext/zsv/vendor/{zsv-1.3.0 → zsv}/include/zsv/utils/file-mem.h +1 -0
  26. data/ext/zsv/vendor/{zsv-1.3.0 → zsv}/include/zsv/utils/file.h +28 -2
  27. data/ext/zsv/vendor/zsv/include/zsv/utils/os.h +145 -0
  28. data/ext/zsv/vendor/zsv/include/zsv/utils/output.h +34 -0
  29. data/ext/zsv/vendor/{zsv-1.3.0 → zsv}/include/zsv/utils/overwrite_writer.h +1 -1
  30. data/ext/zsv/vendor/{zsv-1.3.0 → zsv}/include/zsv/utils/prop.h +16 -4
  31. data/ext/zsv/vendor/zsv/include/zsv/utils/rng.h +35 -0
  32. data/ext/zsv/vendor/{zsv-1.3.0 → zsv}/include/zsv/utils/signal.h +7 -0
  33. data/ext/zsv/vendor/zsv/include/zsv/utils/sql.h +13 -0
  34. data/ext/zsv/vendor/{zsv-1.3.0 → zsv}/include/zsv/utils/string.h +25 -0
  35. data/ext/zsv/vendor/{zsv-1.3.0 → zsv}/include/zsv/utils/writer.h +9 -1
  36. data/ext/zsv/vendor/{zsv-1.3.0 → zsv}/include/zsv/zsv_export.h +1 -1
  37. data/ext/zsv/vendor/{zsv-1.3.0/include/zsv.h → zsv/include/zsv.h.in} +1 -3
  38. data/ext/zsv/vendor/zsv/src/Makefile +238 -0
  39. data/ext/zsv/vendor/{zsv-1.3.0 → zsv}/src/zsv.c +152 -14
  40. data/ext/zsv/vendor/{zsv-1.3.0 → zsv}/src/zsv_internal.c +108 -50
  41. data/ext/zsv/vendor/zsv/src/zsv_scan_delim_fast.c +741 -0
  42. data/ext/zsv/vendor/zsv/src/zsv_scan_simd_avx2.h +89 -0
  43. data/ext/zsv/vendor/zsv/src/zsv_scan_simd_neon.h +80 -0
  44. data/ext/zsv/vendor/zsv/src/zsv_scan_simd_sse2.h +93 -0
  45. data/ext/zsv/vendor/zsv/src/zsv_scan_simd_wasm.h +79 -0
  46. data/ext/zsv/vendor/zsv/src/zsv_strencode.c +84 -0
  47. data/ext/zsv/zsv_ext.c +176 -105
  48. data/lib/zsv/errors.rb +32 -0
  49. data/lib/zsv/input.rb +88 -0
  50. data/lib/zsv/options.rb +132 -0
  51. data/lib/zsv/strict_validator.rb +124 -0
  52. data/lib/zsv/version.rb +1 -1
  53. data/lib/zsv.rb +137 -35
  54. metadata +81 -230
  55. data/ext/zsv/vendor/zsv-1.3.0/app/2db.c +0 -756
  56. data/ext/zsv/vendor/zsv-1.3.0/app/2json.c +0 -381
  57. data/ext/zsv/vendor/zsv-1.3.0/app/2tsv.c +0 -228
  58. data/ext/zsv/vendor/zsv-1.3.0/app/builtin/help.c +0 -123
  59. data/ext/zsv/vendor/zsv-1.3.0/app/builtin/license.c +0 -39
  60. data/ext/zsv/vendor/zsv-1.3.0/app/builtin/register.c +0 -104
  61. data/ext/zsv/vendor/zsv-1.3.0/app/builtin/thirdparty.c +0 -41
  62. data/ext/zsv/vendor/zsv-1.3.0/app/builtin/unregister.c +0 -1
  63. data/ext/zsv/vendor/zsv-1.3.0/app/builtin/version.c +0 -14
  64. data/ext/zsv/vendor/zsv-1.3.0/app/check/simdutf_wrapper.h +0 -19
  65. data/ext/zsv/vendor/zsv-1.3.0/app/check/utf8.c +0 -116
  66. data/ext/zsv/vendor/zsv-1.3.0/app/check.c +0 -194
  67. data/ext/zsv/vendor/zsv-1.3.0/app/cli.c +0 -796
  68. data/ext/zsv/vendor/zsv-1.3.0/app/cli_const.h +0 -41
  69. data/ext/zsv/vendor/zsv-1.3.0/app/cli_export.h +0 -16
  70. data/ext/zsv/vendor/zsv-1.3.0/app/cli_ini.c +0 -280
  71. data/ext/zsv/vendor/zsv-1.3.0/app/cli_internal.h +0 -36
  72. data/ext/zsv/vendor/zsv-1.3.0/app/compare.c +0 -913
  73. data/ext/zsv/vendor/zsv-1.3.0/app/compare.h +0 -23
  74. data/ext/zsv/vendor/zsv-1.3.0/app/compare_added_column.c +0 -20
  75. data/ext/zsv/vendor/zsv-1.3.0/app/compare_internal.h +0 -140
  76. data/ext/zsv/vendor/zsv-1.3.0/app/compare_sort.c +0 -91
  77. data/ext/zsv/vendor/zsv-1.3.0/app/compare_unique_colname.c +0 -81
  78. data/ext/zsv/vendor/zsv-1.3.0/app/count-pull.c +0 -82
  79. data/ext/zsv/vendor/zsv-1.3.0/app/count.c +0 -404
  80. data/ext/zsv/vendor/zsv-1.3.0/app/desc.c +0 -569
  81. data/ext/zsv/vendor/zsv-1.3.0/app/echo.c +0 -365
  82. data/ext/zsv/vendor/zsv-1.3.0/app/ext_example/my_extension.c +0 -366
  83. data/ext/zsv/vendor/zsv-1.3.0/app/ext_example/mysheet_extension.c +0 -341
  84. data/ext/zsv/vendor/zsv-1.3.0/app/ext_template/YOUR_EXTENSION_zsvext.c +0 -263
  85. data/ext/zsv/vendor/zsv-1.3.0/app/external/inih/ini.c +0 -298
  86. data/ext/zsv/vendor/zsv-1.3.0/app/external/inih/ini.h +0 -157
  87. data/ext/zsv/vendor/zsv-1.3.0/app/external/json_writer-1.01/json_numeric.c +0 -177
  88. data/ext/zsv/vendor/zsv-1.3.0/app/external/json_writer-1.01/jsonwriter.c +0 -444
  89. data/ext/zsv/vendor/zsv-1.3.0/app/external/json_writer-1.01/jsonwriter.h +0 -145
  90. data/ext/zsv/vendor/zsv-1.3.0/app/external/json_writer-1.01/utils.c +0 -110
  91. data/ext/zsv/vendor/zsv-1.3.0/app/external/memfile-1.0/include/memfile.h +0 -15
  92. data/ext/zsv/vendor/zsv-1.3.0/app/external/memfile-1.0/src/memfile.c +0 -64
  93. data/ext/zsv/vendor/zsv-1.3.0/app/external/sglib/sglib.h +0 -1955
  94. data/ext/zsv/vendor/zsv-1.3.0/app/external/simdutf/simdutf.h +0 -6802
  95. data/ext/zsv/vendor/zsv-1.3.0/app/external/sqlite3/sqlite3.c +0 -230517
  96. data/ext/zsv/vendor/zsv-1.3.0/app/external/sqlite3/sqlite3.h +0 -12174
  97. data/ext/zsv/vendor/zsv-1.3.0/app/external/sqlite3/sqlite3_and_csv_vtab.c +0 -2
  98. data/ext/zsv/vendor/zsv-1.3.0/app/external/sqlite3/sqlite3_csv_vtab-mem.c +0 -142
  99. data/ext/zsv/vendor/zsv-1.3.0/app/external/sqlite3/sqlite3_csv_vtab-mem.h +0 -49
  100. data/ext/zsv/vendor/zsv-1.3.0/app/external/sqlite3/sqlite3_csv_vtab-zsv.c +0 -485
  101. data/ext/zsv/vendor/zsv-1.3.0/app/external/sqlite3/sqlite3_csv_vtab.c +0 -1015
  102. data/ext/zsv/vendor/zsv-1.3.0/app/external/sqlite3/sqlite3ext.h +0 -663
  103. data/ext/zsv/vendor/zsv-1.3.0/app/external/sqlite3/vtab_helper.c +0 -85
  104. data/ext/zsv/vendor/zsv-1.3.0/app/external/yajl/build/yajl-2.1.1/include/yajl/yajl_common.h +0 -75
  105. data/ext/zsv/vendor/zsv-1.3.0/app/external/yajl/build/yajl-2.1.1/include/yajl/yajl_gen.h +0 -167
  106. data/ext/zsv/vendor/zsv-1.3.0/app/external/yajl/build/yajl-2.1.1/include/yajl/yajl_parse.h +0 -228
  107. data/ext/zsv/vendor/zsv-1.3.0/app/external/yajl/build/yajl-2.1.1/include/yajl/yajl_tree.h +0 -186
  108. data/ext/zsv/vendor/zsv-1.3.0/app/external/yajl/build/yajl-2.1.1/include/yajl/yajl_version.h +0 -23
  109. data/ext/zsv/vendor/zsv-1.3.0/app/external/yajl/src/api/yajl_common.h +0 -76
  110. data/ext/zsv/vendor/zsv-1.3.0/app/external/yajl/src/api/yajl_gen.h +0 -167
  111. data/ext/zsv/vendor/zsv-1.3.0/app/external/yajl/src/api/yajl_parse.h +0 -238
  112. data/ext/zsv/vendor/zsv-1.3.0/app/external/yajl/src/api/yajl_tree.h +0 -186
  113. data/ext/zsv/vendor/zsv-1.3.0/app/external/yajl/src/yajl.c +0 -184
  114. data/ext/zsv/vendor/zsv-1.3.0/app/external/yajl/src/yajl_alloc.c +0 -52
  115. data/ext/zsv/vendor/zsv-1.3.0/app/external/yajl/src/yajl_alloc.h +0 -34
  116. data/ext/zsv/vendor/zsv-1.3.0/app/external/yajl/src/yajl_buf.c +0 -103
  117. data/ext/zsv/vendor/zsv-1.3.0/app/external/yajl/src/yajl_buf.h +0 -57
  118. data/ext/zsv/vendor/zsv-1.3.0/app/external/yajl/src/yajl_bytestack.h +0 -69
  119. data/ext/zsv/vendor/zsv-1.3.0/app/external/yajl/src/yajl_encode.c +0 -220
  120. data/ext/zsv/vendor/zsv-1.3.0/app/external/yajl/src/yajl_encode.h +0 -34
  121. data/ext/zsv/vendor/zsv-1.3.0/app/external/yajl/src/yajl_gen.c +0 -362
  122. data/ext/zsv/vendor/zsv-1.3.0/app/external/yajl/src/yajl_lex.c +0 -764
  123. data/ext/zsv/vendor/zsv-1.3.0/app/external/yajl/src/yajl_lex.h +0 -117
  124. data/ext/zsv/vendor/zsv-1.3.0/app/external/yajl/src/yajl_parser.c +0 -508
  125. data/ext/zsv/vendor/zsv-1.3.0/app/external/yajl/src/yajl_parser.h +0 -78
  126. data/ext/zsv/vendor/zsv-1.3.0/app/external/yajl/src/yajl_tree.c +0 -505
  127. data/ext/zsv/vendor/zsv-1.3.0/app/external/yajl/src/yajl_version.c +0 -7
  128. data/ext/zsv/vendor/zsv-1.3.0/app/external/yajl_helper/yajl_helper/json_value.h +0 -59
  129. data/ext/zsv/vendor/zsv-1.3.0/app/external/yajl_helper/yajl_helper/yajl_helper.h +0 -208
  130. data/ext/zsv/vendor/zsv-1.3.0/app/external/yajl_helper/yajl_helper.c +0 -795
  131. data/ext/zsv/vendor/zsv-1.3.0/app/external/yajl_helper/yajl_helper_internal.h +0 -28
  132. data/ext/zsv/vendor/zsv-1.3.0/app/flatten.c +0 -851
  133. data/ext/zsv/vendor/zsv-1.3.0/app/jq.c +0 -106
  134. data/ext/zsv/vendor/zsv-1.3.0/app/jq.h +0 -6
  135. data/ext/zsv/vendor/zsv-1.3.0/app/mv.c +0 -113
  136. data/ext/zsv/vendor/zsv-1.3.0/app/noop.c +0 -90
  137. data/ext/zsv/vendor/zsv-1.3.0/app/overwrite.c +0 -295
  138. data/ext/zsv/vendor/zsv-1.3.0/app/paste.c +0 -175
  139. data/ext/zsv/vendor/zsv-1.3.0/app/pretty.c +0 -693
  140. data/ext/zsv/vendor/zsv-1.3.0/app/prop.c +0 -980
  141. data/ext/zsv/vendor/zsv-1.3.0/app/rm.c +0 -131
  142. data/ext/zsv/vendor/zsv-1.3.0/app/select/fixed.c +0 -130
  143. data/ext/zsv/vendor/zsv-1.3.0/app/select/internal.h +0 -118
  144. data/ext/zsv/vendor/zsv-1.3.0/app/select/parallel.c +0 -45
  145. data/ext/zsv/vendor/zsv-1.3.0/app/select/parallel.h +0 -41
  146. data/ext/zsv/vendor/zsv-1.3.0/app/select/processing.c +0 -107
  147. data/ext/zsv/vendor/zsv-1.3.0/app/select/rand.c +0 -20
  148. data/ext/zsv/vendor/zsv-1.3.0/app/select/regex.c +0 -61
  149. data/ext/zsv/vendor/zsv-1.3.0/app/select/search.c +0 -14
  150. data/ext/zsv/vendor/zsv-1.3.0/app/select/selection.c +0 -192
  151. data/ext/zsv/vendor/zsv-1.3.0/app/select/usage.c +0 -72
  152. data/ext/zsv/vendor/zsv-1.3.0/app/select-pull.c +0 -812
  153. data/ext/zsv/vendor/zsv-1.3.0/app/select.c +0 -753
  154. data/ext/zsv/vendor/zsv-1.3.0/app/serialize.c +0 -372
  155. data/ext/zsv/vendor/zsv-1.3.0/app/sheet/curses.h +0 -15
  156. data/ext/zsv/vendor/zsv-1.3.0/app/sheet/cursor.c +0 -119
  157. data/ext/zsv/vendor/zsv-1.3.0/app/sheet/errors.c +0 -45
  158. data/ext/zsv/vendor/zsv-1.3.0/app/sheet/file.c +0 -63
  159. data/ext/zsv/vendor/zsv-1.3.0/app/sheet/file.h +0 -12
  160. data/ext/zsv/vendor/zsv-1.3.0/app/sheet/filter.c +0 -166
  161. data/ext/zsv/vendor/zsv-1.3.0/app/sheet/handlers.c +0 -214
  162. data/ext/zsv/vendor/zsv-1.3.0/app/sheet/handlers_internal.h +0 -128
  163. data/ext/zsv/vendor/zsv-1.3.0/app/sheet/help.c +0 -43
  164. data/ext/zsv/vendor/zsv-1.3.0/app/sheet/index.c +0 -81
  165. data/ext/zsv/vendor/zsv-1.3.0/app/sheet/index.h +0 -25
  166. data/ext/zsv/vendor/zsv-1.3.0/app/sheet/key-bindings.c +0 -325
  167. data/ext/zsv/vendor/zsv-1.3.0/app/sheet/key-bindings.h +0 -73
  168. data/ext/zsv/vendor/zsv-1.3.0/app/sheet/lexer.c +0 -203
  169. data/ext/zsv/vendor/zsv-1.3.0/app/sheet/newline_handler.c +0 -7
  170. data/ext/zsv/vendor/zsv-1.3.0/app/sheet/pivot.c +0 -318
  171. data/ext/zsv/vendor/zsv-1.3.0/app/sheet/procedure.c +0 -134
  172. data/ext/zsv/vendor/zsv-1.3.0/app/sheet/procedure.h +0 -119
  173. data/ext/zsv/vendor/zsv-1.3.0/app/sheet/read-data.c +0 -322
  174. data/ext/zsv/vendor/zsv-1.3.0/app/sheet/screen_buffer.c +0 -203
  175. data/ext/zsv/vendor/zsv-1.3.0/app/sheet/screen_buffer.h +0 -36
  176. data/ext/zsv/vendor/zsv-1.3.0/app/sheet/sheet-sql.c +0 -167
  177. data/ext/zsv/vendor/zsv-1.3.0/app/sheet/sheet_internal.h +0 -36
  178. data/ext/zsv/vendor/zsv-1.3.0/app/sheet/sqlfilter.c +0 -153
  179. data/ext/zsv/vendor/zsv-1.3.0/app/sheet/terminfo.c +0 -32
  180. data/ext/zsv/vendor/zsv-1.3.0/app/sheet/transformation.c +0 -312
  181. data/ext/zsv/vendor/zsv-1.3.0/app/sheet/transformation.h +0 -29
  182. data/ext/zsv/vendor/zsv-1.3.0/app/sheet/ui_buffer.c +0 -266
  183. data/ext/zsv/vendor/zsv-1.3.0/app/sheet/usage.c +0 -9
  184. data/ext/zsv/vendor/zsv-1.3.0/app/sheet/utf8-width.c +0 -60
  185. data/ext/zsv/vendor/zsv-1.3.0/app/sheet.c +0 -1007
  186. data/ext/zsv/vendor/zsv-1.3.0/app/sql.c +0 -453
  187. data/ext/zsv/vendor/zsv-1.3.0/app/sql_internal.c +0 -101
  188. data/ext/zsv/vendor/zsv-1.3.0/app/sql_internal.h +0 -49
  189. data/ext/zsv/vendor/zsv-1.3.0/app/stack.c +0 -393
  190. data/ext/zsv/vendor/zsv-1.3.0/app/utils/arg.c +0 -322
  191. data/ext/zsv/vendor/zsv-1.3.0/app/utils/cache.c +0 -228
  192. data/ext/zsv/vendor/zsv-1.3.0/app/utils/cat.c +0 -91
  193. data/ext/zsv/vendor/zsv-1.3.0/app/utils/chunk.c +0 -240
  194. data/ext/zsv/vendor/zsv-1.3.0/app/utils/chunk.h +0 -63
  195. data/ext/zsv/vendor/zsv-1.3.0/app/utils/clock.c +0 -57
  196. data/ext/zsv/vendor/zsv-1.3.0/app/utils/db.c +0 -148
  197. data/ext/zsv/vendor/zsv-1.3.0/app/utils/dirs-no-jq.c +0 -2
  198. data/ext/zsv/vendor/zsv-1.3.0/app/utils/dirs.c +0 -427
  199. data/ext/zsv/vendor/zsv-1.3.0/app/utils/dirs_from_json.c +0 -253
  200. data/ext/zsv/vendor/zsv-1.3.0/app/utils/dirs_to_json.c +0 -121
  201. data/ext/zsv/vendor/zsv-1.3.0/app/utils/dl.c +0 -20
  202. data/ext/zsv/vendor/zsv-1.3.0/app/utils/emcc/fs_api.c +0 -159
  203. data/ext/zsv/vendor/zsv-1.3.0/app/utils/err.c +0 -24
  204. data/ext/zsv/vendor/zsv-1.3.0/app/utils/file-mem.c +0 -180
  205. data/ext/zsv/vendor/zsv-1.3.0/app/utils/file.c +0 -256
  206. data/ext/zsv/vendor/zsv-1.3.0/app/utils/index.c +0 -197
  207. data/ext/zsv/vendor/zsv-1.3.0/app/utils/index.h +0 -49
  208. data/ext/zsv/vendor/zsv-1.3.0/app/utils/jq.c +0 -400
  209. data/ext/zsv/vendor/zsv-1.3.0/app/utils/json.c +0 -120
  210. data/ext/zsv/vendor/zsv-1.3.0/app/utils/mem.c +0 -18
  211. data/ext/zsv/vendor/zsv-1.3.0/app/utils/memmem.c +0 -132
  212. data/ext/zsv/vendor/zsv-1.3.0/app/utils/os.c +0 -178
  213. data/ext/zsv/vendor/zsv-1.3.0/app/utils/overwrite.c +0 -258
  214. data/ext/zsv/vendor/zsv-1.3.0/app/utils/overwrite_writer.c +0 -246
  215. data/ext/zsv/vendor/zsv-1.3.0/app/utils/pcre2-8/pcre2-8-test.c +0 -123
  216. data/ext/zsv/vendor/zsv-1.3.0/app/utils/pcre2-8/pcre2-8.c +0 -153
  217. data/ext/zsv/vendor/zsv-1.3.0/app/utils/pcre2-8/pcre2-8.h +0 -54
  218. data/ext/zsv/vendor/zsv-1.3.0/app/utils/prop.c +0 -267
  219. data/ext/zsv/vendor/zsv-1.3.0/app/utils/signal.c +0 -53
  220. data/ext/zsv/vendor/zsv-1.3.0/app/utils/string.c +0 -357
  221. data/ext/zsv/vendor/zsv-1.3.0/app/utils/win/dir_exists_longpath.c +0 -83
  222. data/ext/zsv/vendor/zsv-1.3.0/app/utils/win/dl.c +0 -33
  223. data/ext/zsv/vendor/zsv-1.3.0/app/utils/win/fopen_longpath.c +0 -184
  224. data/ext/zsv/vendor/zsv-1.3.0/app/utils/win/foreach_dirent_longpath.c +0 -292
  225. data/ext/zsv/vendor/zsv-1.3.0/app/utils/win/io.c +0 -259
  226. data/ext/zsv/vendor/zsv-1.3.0/app/utils/win/io.h +0 -13
  227. data/ext/zsv/vendor/zsv-1.3.0/app/utils/win/mkdir_longpath.c +0 -255
  228. data/ext/zsv/vendor/zsv-1.3.0/app/utils/win/remove_longpath.c +0 -96
  229. data/ext/zsv/vendor/zsv-1.3.0/app/utils/writer.c +0 -361
  230. data/ext/zsv/vendor/zsv-1.3.0/app/zsv_command.h +0 -40
  231. data/ext/zsv/vendor/zsv-1.3.0/app/zsv_command_standalone.c +0 -16
  232. data/ext/zsv/vendor/zsv-1.3.0/app/zsv_main.h +0 -44
  233. data/ext/zsv/vendor/zsv-1.3.0/examples/js/zsv_parser_api_dummy.c +0 -3
  234. data/ext/zsv/vendor/zsv-1.3.0/examples/lib/parse_by_chunk.c +0 -100
  235. data/ext/zsv/vendor/zsv-1.3.0/examples/lib/print_my_column.c +0 -143
  236. data/ext/zsv/vendor/zsv-1.3.0/examples/lib/pull.c +0 -89
  237. data/ext/zsv/vendor/zsv-1.3.0/examples/lib/simple.c +0 -123
  238. data/ext/zsv/vendor/zsv-1.3.0/fuzz/fuzz.c +0 -16
  239. data/ext/zsv/vendor/zsv-1.3.0/include/zsv/utils/os.h +0 -54
  240. data/ext/zsv/vendor/zsv-1.3.0/include/zsv/utils/sql.h +0 -11
  241. data/ext/zsv/vendor/zsv-1.3.0/src/zsv_strencode.c +0 -51
  242. /data/ext/zsv/vendor/{zsv-1.3.0 → zsv}/include/zsv/ext/implementation.h +0 -0
  243. /data/ext/zsv/vendor/{zsv-1.3.0 → zsv}/include/zsv/ext/implementation_private.h +0 -0
  244. /data/ext/zsv/vendor/{zsv-1.3.0 → zsv}/include/zsv/utils/cache.h +0 -0
  245. /data/ext/zsv/vendor/{zsv-1.3.0 → zsv}/include/zsv/utils/clock.h +0 -0
  246. /data/ext/zsv/vendor/{zsv-1.3.0 → zsv}/include/zsv/utils/db.h +0 -0
  247. /data/ext/zsv/vendor/{zsv-1.3.0 → zsv}/include/zsv/utils/dl.h +0 -0
  248. /data/ext/zsv/vendor/{zsv-1.3.0 → zsv}/include/zsv/utils/emcc/fs_api.h +0 -0
  249. /data/ext/zsv/vendor/{zsv-1.3.0 → zsv}/include/zsv/utils/err.h +0 -0
  250. /data/ext/zsv/vendor/{zsv-1.3.0 → zsv}/include/zsv/utils/jq.h +0 -0
  251. /data/ext/zsv/vendor/{zsv-1.3.0 → zsv}/include/zsv/utils/json.h +0 -0
  252. /data/ext/zsv/vendor/{zsv-1.3.0 → zsv}/include/zsv/utils/mem.h +0 -0
  253. /data/ext/zsv/vendor/{zsv-1.3.0 → zsv}/include/zsv/utils/memmem.h +0 -0
  254. /data/ext/zsv/vendor/{zsv-1.3.0 → zsv}/include/zsv/utils/overwrite.h +0 -0
  255. /data/ext/zsv/vendor/{zsv-1.3.0 → zsv}/include/zsv/utils/utf8.h +0 -0
  256. /data/ext/zsv/vendor/{zsv-1.3.0 → zsv}/include/zsv/utils/win/dl.h +0 -0
  257. /data/ext/zsv/vendor/{zsv-1.3.0 → zsv}/src/vector_delim.c +0 -0
  258. /data/ext/zsv/vendor/{zsv-1.3.0 → zsv}/src/zsv_scan_delim.c +0 -0
  259. /data/ext/zsv/vendor/{zsv-1.3.0 → zsv}/src/zsv_scan_fixed.c +0 -0
@@ -0,0 +1,35 @@
1
+ /*
2
+ * Copyright (C) 2025 Liquidaty and the zsv/lib contributors
3
+ * All rights reserved
4
+ *
5
+ * This file is part of zsv/lib, distributed under the license defined at
6
+ * https://opensource.org/licenses/MIT
7
+ */
8
+
9
+ #ifndef ZSV_RNG_H
10
+ #define ZSV_RNG_H
11
+
12
+ #include <stdint.h>
13
+
14
+ /**
15
+ * Small, self-contained, platform-independent PRNG (xoshiro256**, seeded via
16
+ * splitmix64). Not cryptographic. A given seed yields the same sequence on
17
+ * every compiler and OS, so seeded output is reproducible across platforms.
18
+ */
19
+ struct zsv_rng {
20
+ uint64_t s[4];
21
+ };
22
+
23
+ /** Initialize from a 64-bit seed; any seed (including 0) is valid */
24
+ void zsv_rng_seed(struct zsv_rng *r, uint64_t seed);
25
+
26
+ /** 64 bits from the best OS entropy source available; never fails */
27
+ uint64_t zsv_rng_entropy(void);
28
+
29
+ /** Next 64-bit value */
30
+ uint64_t zsv_rng_next(struct zsv_rng *r);
31
+
32
+ /** Unbiased value in [0, n). n == 0 returns 0 */
33
+ uint64_t zsv_rng_below(struct zsv_rng *r, uint64_t n);
34
+
35
+ #endif
@@ -9,6 +9,13 @@
9
9
  #ifndef ZSV_SIGNAL_H
10
10
  #define ZSV_SIGNAL_H
11
11
 
12
+ // wasm has no signals: wasi-libc's <signal.h> is a hard #error unless this is
13
+ // defined. Set it here so this installed header can be included on wasi without
14
+ // the consumer having to know; linking still requires -lwasi-emulated-signal.
15
+ #if defined(__wasi__) && !defined(_WASI_EMULATED_SIGNAL)
16
+ #define _WASI_EMULATED_SIGNAL
17
+ #endif
18
+
12
19
  #include <signal.h>
13
20
 
14
21
  extern volatile sig_atomic_t zsv_signal_interrupted;
@@ -0,0 +1,13 @@
1
+ #ifndef ZSV_UTILS_SQL_H
2
+ #define ZSV_UTILS_SQL_H
3
+
4
+ typedef struct zsv_sqlite3_db *zsv_sqlite3_db_t;
5
+
6
+ struct zsv_sqlite3_dbopts {
7
+ unsigned char in_memory : 1;
8
+ unsigned char dedupe_cols : 1; // auto-rename duplicate input column names (a, a_2, ...)
9
+ unsigned char warn_dupe_rename : 1; // note each such rename on stderr (off for curses UIs)
10
+ unsigned char _ : 5;
11
+ };
12
+
13
+ #endif
@@ -48,6 +48,31 @@ int zsv_stricmp(const unsigned char *s1, const unsigned char *s2);
48
48
  int zsv_strincmp(const unsigned char *s1, size_t len1, const unsigned char *s2, size_t len2);
49
49
  int zsv_strincmp_ascii(const unsigned char *s1, size_t len1, const unsigned char *s2, size_t len2);
50
50
 
51
+ #define ZSV_STRFOLD_ASCII 1 // every folded code point is ASCII: zsv_strcasestr_folded() may byte-scan
52
+ #define ZSV_STRFOLD_EXACT 2 // no code point has a case variant: a byte-exact search gives the same answer
53
+ #define ZSV_STRFOLD_MALFORMED 4 // some byte was not valid UTF-8 and is matched byte-wise
54
+ /**
55
+ * zsv_strfold(): lowercase s[0, len) into code points for zsv_strcasestr_folded()
56
+ * (Unicode simple case mapping via utf8proc; ASCII-only without it). A byte b that
57
+ * is not valid UTF-8 is stored as -1 - b, so it matches only that same byte where
58
+ * it is likewise not valid UTF-8.
59
+ *
60
+ * @param outlen receives the number of code points (0 on failure)
61
+ * @param flags receives ZSV_STRFOLD_* bits (0 on failure)
62
+ * @returns newly-allocated array; caller must free(). NULL on allocation failure
63
+ */
64
+ int32_t *zsv_strfold(const unsigned char *s, size_t len, size_t *outlen, unsigned *flags);
65
+
66
+ /**
67
+ * zsv_strcasestr_folded(): case-insensitive substring test against a needle from zsv_strfold().
68
+ * The haystack is folded on the fly by the same mapping; nothing is allocated.
69
+ *
70
+ * @param ascii non-zero iff zsv_strfold() reported ZSV_STRFOLD_ASCII; selects the byte-scanning kernel
71
+ * @returns non-zero if hay[0, len) contains the needle (an empty needle is found everywhere).
72
+ * Cost is O(len * fold_len) in the worst case and O(len) for a typical short needle
73
+ */
74
+ int zsv_strcasestr_folded(const unsigned char *hay, size_t len, const int32_t *fold, size_t fold_len, char ascii);
75
+
51
76
  #define ZSV_STRWHITE_FLAG_NO_EMBEDDED_NEWLINE 1
52
77
  /**
53
78
  * zsv_strwhite(): convert consecutive white to single space
@@ -10,7 +10,8 @@
10
10
  #define ZSV_WRITER_H
11
11
 
12
12
  #include <stdio.h>
13
- #include <stdint.h> // uint64_t
13
+ #include <stdint.h> // uint64_t
14
+ #include <zsv/common.h> // struct zsv_cell
14
15
 
15
16
  #define ZSV_WRITER_NEW_ROW 1
16
17
  #define ZSV_WRITER_SAME_ROW 0
@@ -63,6 +64,13 @@ enum zsv_writer_status zsv_writer_cell(zsv_csv_writer,
63
64
  char new_row, // ZSV_WRITER_NEW_ROW or ZSV_WRITER_SAME_ROW
64
65
  const unsigned char *s, size_t len, char check_if_needs_quoting);
65
66
 
67
+ /**
68
+ * Write an entire row of raw (pre-formatted) cells in one call.
69
+ * Skips per-cell quoting scans. Only valid when cells are already
70
+ * properly formatted (e.g., raw passthrough from the fast parser).
71
+ */
72
+ enum zsv_writer_status zsv_writer_row_raw(zsv_csv_writer, const struct zsv_cell *cells, unsigned int count);
73
+
66
74
  /*
67
75
  * Get total bytes that have been written (to disk and buffer)
68
76
  */
@@ -15,7 +15,7 @@
15
15
  # endif
16
16
  # else
17
17
  # ifdef __GNUC__
18
- # define ZSV_EXPORT __attribute__((dllimport))
18
+ # define ZSV_EXPORT __attribute__((visibility("default")))
19
19
  # else
20
20
  # define ZSV_EXPORT __declspec(dllimport)
21
21
  # endif
@@ -9,9 +9,7 @@
9
9
  #ifndef ZSV_H
10
10
  #define ZSV_H
11
11
 
12
- #ifndef ZSV_EXTRAS
13
- #define ZSV_EXTRAS
14
- #endif
12
+ __ZSV_EXTRAS__DEFINE__
15
13
 
16
14
  #include <stddef.h>
17
15
  #include "zsv/common.h"
@@ -0,0 +1,238 @@
1
+ # Makefile for use with GNU make
2
+
3
+ THIS_MAKEFILE_DIR:=$(shell dirname $(realpath $(lastword $(MAKEFILE_LIST))))
4
+ THIS_DIR:=$(shell basename "${THIS_MAKEFILE_DIR}")
5
+ THIS_MAKEFILE:=$(lastword $(MAKEFILE_LIST))
6
+
7
+ .POSIX:
8
+ .SUFFIXES:
9
+ .SUFFIXES: .o .c .a
10
+
11
+ CONFIGFILE ?=../config.mk
12
+ $(info Using config file ${CONFIGFILE})
13
+
14
+ CONFIGFILEPATH:=$(shell ls ${CONFIGFILE} >/dev/null 2>/dev/null && realpath ${CONFIGFILE})
15
+ ifeq ($(CONFIGFILEPATH),)
16
+ ifeq ($(shell dirname ${CONFIGFILE}),.)
17
+ CONFIGFILEPATH:=$(shell ls ../${CONFIGFILE} >/dev/null 2>/dev/null && realpath ../${CONFIGFILE})
18
+ ifneq ($(CONFIGFILEPATH),)
19
+ $(info Config file ${CONFIGFILE} not found; using ../${CONFIGFILE})
20
+ endif
21
+ endif
22
+ endif
23
+
24
+ ifeq ($(CONFIGFILEPATH),)
25
+ $(error Config file ${CONFIGFILE} not found)
26
+ else
27
+ include ${CONFIGFILEPATH}
28
+ endif
29
+
30
+ CC ?= cc
31
+ AWK ?= awk
32
+ AR ?= ar
33
+ RANLIB ?= ranlib
34
+ SED ?= sed
35
+
36
+ WIN=
37
+ DEBUG=0
38
+ ifeq ($(WIN),)
39
+ # MINGW = 1 in config.mk (configure's host check; not the environment, and a CC given
40
+ # on the command line does not undo it), or a w64 compiler
41
+ WIN=$(if $(and $(filter file,$(origin MINGW)),$(filter 1,$(MINGW))),1,$(if $(findstring w64,$(CC)),1,0))
42
+ endif
43
+
44
+ VERSION= $(shell (git describe --always --dirty --tags 2>/dev/null || echo "v0.0.0-zsv") | sed 's/^v//')
45
+
46
+ ifeq ($(BUILD_SHAREDLIB),1)
47
+ include ${THIS_MAKEFILE_DIR}/../make/sharedlib.mk # sets SHAREDLIB_EXT
48
+ endif
49
+
50
+ CFLAGS+= ${CFLAG_O} ${CFLAGS_OPT}
51
+ CFLAGS+= ${CFLAGS_AUTO}
52
+
53
+ CFLAGS+=-fsigned-char
54
+
55
+ ifeq ($(VERBOSE),1)
56
+ CFLAGS+= ${CFLAGS_VECTORIZE_OPTIMIZED} ${CFLAGS_VECTORIZE_MISSED} ${CFLAGS_VECTORIZE_ALL}
57
+ endif
58
+
59
+ ZSV_EXTRAS ?=
60
+ ifneq ($(findstring emcc,$(CC)),) # emcc
61
+ ZSV_EXTRAS=1
62
+ NO_THREADING=1
63
+ else # not emcc
64
+ CFLAGS+= ${CFLAGS_AVX} ${CFLAGS_SSE}
65
+ endif
66
+
67
+ ifeq ($(NO_THREADING),1)
68
+ CFLAGS+= -DNO_THREADING
69
+ endif
70
+
71
+ ifeq ($(HAVE_NEON),1)
72
+ CFLAGS+= -DZSV_HAVE_NEON
73
+ endif
74
+
75
+ ifeq ($(DEFAULT_PARSER_FAST),1)
76
+ CFLAGS+= -DZSV_DEFAULT_PARSER_FAST
77
+ endif
78
+
79
+ ifeq ($(ZSV_NO_ONLY_CRLF),1)
80
+ CFLAGS+= -DZSV_NO_ONLY_CRLF
81
+ endif
82
+
83
+ ifeq ($(ZSV_EXTRAS),1)
84
+ CFLAGS+= -DZSV_EXTRAS
85
+ endif
86
+
87
+ ifeq ($(DEBUG),0)
88
+ CFLAGS+= -DNDEBUG -O3 ${CFLAGS_LTO}
89
+
90
+ ifeq ($(PGO),1)
91
+ CFLAGS+= -fprofile-generate -fprofile-dir=/tmp/p4
92
+ else
93
+ ifeq ($(PGO),2)
94
+ CFLAGS+= -fprofile-use=/tmp/p4
95
+ else
96
+ $(info No profiling set. To use PGO, compile with PGO=1, then run with data, then compile again with PGO=2)
97
+ endif
98
+ endif
99
+ else
100
+ CFLAGS += ${CFLAGS_DEBUG}
101
+ endif
102
+
103
+ ifeq ($(DEBUG),1)
104
+ DBG_SUBDIR+=dbg
105
+ else
106
+ DBG_SUBDIR+=rel
107
+ endif
108
+
109
+ ifeq ($(WIN),0)
110
+ BUILD_SUBDIR=$(shell uname)/${DBG_SUBDIR}
111
+ WHICH=which
112
+ EXE=
113
+ CFLAGS+= -fPIC
114
+ else
115
+ BUILD_SUBDIR=win/${DBG_SUBDIR}
116
+ WHICH=where
117
+ EXE=.exe
118
+ CFLAGS+= -fpie
119
+ CFLAGS+= -D__USE_MINGW_ANSI_STDIO -D_ISOC99_SOURCE -Wl,--strip-all
120
+ endif
121
+
122
+ CCBN=$(shell basename ${CC})
123
+
124
+ CFLAGS+= -std=gnu11 -Wshadow -Wall -Wextra -Wno-missing-braces -pedantic -D_GNU_SOURCE
125
+
126
+ ifeq (${CCBN},clang)
127
+ CFLAGS+= -Wno-gnu-statement-expression
128
+ endif
129
+
130
+ CFLAGS+= ${ZSV_OPTIONAL_CFLAGS}
131
+
132
+ THIS_LIB_BASE=$(shell cd .. && pwd)
133
+ INCLUDE_DIR=${THIS_LIB_BASE}/include
134
+ BUILD_DIR=${THIS_LIB_BASE}/build/${BUILD_SUBDIR}/${CCBN}
135
+
136
+ NO_UTF8_CHECK=1
137
+
138
+ LIB_SUFFIX?=
139
+ ZSV_OBJ=${BUILD_DIR}/objs/zsv.o
140
+ LIBZSV_STATIC=libzsv${LIB_SUFFIX}.a
141
+ LIBZSV_STATIC_BUILD=${BUILD_DIR}/lib/${LIBZSV_STATIC}
142
+ LIBZSV_BUILD=${LIBZSV_STATIC_BUILD}
143
+ LIBZSV_INSTALL=${LIBDIR}/${LIBZSV_STATIC}
144
+
145
+ ifeq ($(BUILD_SHAREDLIB),1)
146
+ LIBZSV_SHARED=libzsv.${SHAREDLIB_EXT}
147
+ LIBZSV_SHARED_BUILD+=${BUILD_DIR}/lib/${LIBZSV_SHARED}
148
+ LIBZSV_BUILD+=${LIBZSV_SHARED_BUILD}
149
+ LIBZSV_INSTALL+=${LIBDIR}/${LIBZSV_SHARED}
150
+ ifeq ($(UNAME_S),Linux)
151
+ LDFLAGS += -Wl,-soname,libzsv.$(SHAREDLIB_EXT_SO_NAME)
152
+ endif
153
+ ifeq ($(WIN),)
154
+ CFLAGS+= ${CFLAGS_OPENMP}
155
+ endif
156
+ else
157
+ CFLAGS+= ${CFLAGS_OPENMP}
158
+ endif
159
+
160
+ ZSV_OBJ_OPTS=
161
+ ifeq ($(NO_UTF8_CHECK),1)
162
+ ZSV_OBJ_OPTS+= -DNO_UTF8_CHECK
163
+ endif
164
+
165
+ help:
166
+ @echo "Make options:"
167
+ @echo " `basename ${MAKE}` build|install|uninstall|clean"
168
+ @echo
169
+ @echo "Optional ake variables:"
170
+ @echo " [CONFIGFILE=config.mk] [NO_UTF8_CHECK=1] [VERBOSE=1] [LIBDIR=${LIBDIR}] [INCLUDEDIR=${INCLUDEDIR}] [LIB_SUFFIX=]"
171
+ @echo
172
+
173
+ build: ../include/zsv.h ${LIBZSV_BUILD}
174
+
175
+ ${LIBZSV_STATIC_BUILD}: ${ZSV_OBJ}
176
+ @mkdir -p `dirname "$@"`
177
+ @rm -f $@
178
+ $(AR) rcv $@ $?
179
+ $(RANLIB) $@
180
+ $(AR) -t $@
181
+ @echo Built $@
182
+
183
+ ${LIBZSV_SHARED_BUILD}: zsv.c zsv_internal.c
184
+ @mkdir -p `dirname "$@"`
185
+ ${CC} ${CFLAGS} ${CFLAGS_VISIBILITY_HIDDEN} -DZSV_BUILD_SHARED -DZSV_VERSION=\"${VERSION}\" -I${INCLUDE_DIR} ${ZSV_OBJ_OPTS} -shared -fPIC ${LDFLAGS} -o $@ $< -I../app/external/sqlite3
186
+ @echo Built $@
187
+
188
+ ../include/zsv.h: ../include/zsv.h.in
189
+ ifeq ($(ZSV_EXTRAS),1)
190
+ @sed 's/__ZSV_EXTRAS__DEFINE__/#ifndef ZSV_EXTRAS\n#define ZSV_EXTRAS\n#endif/' < ../include/zsv.h.in > $@
191
+ else
192
+ @sed 's/__ZSV_EXTRAS__DEFINE__//' < ../include/zsv.h.in > $@
193
+ endif
194
+
195
+ DESTDIR ?=
196
+
197
+ install: ../include/zsv.h ${LIBZSV_INSTALL}
198
+ mkdir -p $(INCLUDEDIR)
199
+ cp -p ../include/*.h $(INCLUDEDIR)
200
+ cp -pR ../include/zsv $(INCLUDEDIR)/
201
+ @echo "Header files copied to $(INCLUDEDIR)"
202
+ ifeq ($(BUILD_SHAREDLIB),1)
203
+ ifeq ($(UNAME_S),Linux)
204
+ @echo "Creating shared library symlinks:"
205
+ ln -srf $(LIBDIR)/libzsv.$(SHAREDLIB_EXT) $(LIBDIR)/libzsv.$(SHAREDLIB_EXT_SO_NAME)
206
+ ln -srf $(LIBDIR)/libzsv.$(SHAREDLIB_EXT_SO_NAME) $(LIBDIR)/libzsv.$(SHAREDLIB_EXT_LINK_NAME)
207
+ endif
208
+ endif
209
+ ifneq ($(DESTDIR),)
210
+ mkdir -p $(DESTDIR)/include $(DESTDIR)/lib
211
+ cp -pR $(INCLUDEDIR)/* $(DESTDIR)/include
212
+ cp -p $(LIBDIR)/* $(DESTDIR)/lib
213
+ @echo "Headers and library files installed to DESTDIR=${DESTDIR}"
214
+ endif
215
+
216
+ ${LIBZSV_INSTALL}: ${LIBDIR}/% : ${BUILD_DIR}/lib/%
217
+ mkdir -p `dirname "$@"`
218
+ cp -p "$<" "$@"
219
+ @echo "$* installed to $@"
220
+
221
+ uninstall:
222
+ ifneq ($(DESTDIR),)
223
+ rm -rf $(DESTDIR)/include/zsv*
224
+ rm -rf $(DESTDIR)/lib/libzsv*
225
+ else
226
+ @rm -rf ${INCLUDEDIR}/zsv*
227
+ rm -f ${LIBDIR}/libzsv*
228
+ endif
229
+
230
+ clean:
231
+ rm -rf ${BUILD_DIR}/objs ${LIBZSV_BUILD}
232
+ rm -f ../include/zsv.h
233
+
234
+ .PHONY: build install uninstall clean ${LIBZSV_INSTALL}
235
+
236
+ ${BUILD_DIR}/objs/zsv.o: zsv.c zsv_internal.c
237
+ @mkdir -p `dirname "$@"`
238
+ ${CC} ${CFLAGS} -DZSV_VERSION=\"${VERSION}\" -I${INCLUDE_DIR} ${ZSV_OBJ_OPTS} -o $@ -c $< -I../app/external/sqlite3
@@ -38,7 +38,7 @@ const char *zsv_lib_version(void) {
38
38
  * chunk remains available in a contiguous block of one or more rows
39
39
  */
40
40
  // __attribute__((always_inline))
41
- inline static size_t scanner_pre_parse(struct zsv_scanner *scanner) {
41
+ inline static enum zsv_status scanner_pre_parse(struct zsv_scanner *scanner, size_t *capacityp) {
42
42
  scanner->last = '\0';
43
43
  if (VERY_LIKELY(scanner->old_bytes_read)) {
44
44
  scanner->last = scanner->buff.buff[scanner->old_bytes_read - 1];
@@ -78,7 +78,9 @@ inline static size_t scanner_pre_parse(struct zsv_scanner *scanner) {
78
78
  scanner->partial_row_length = 0;
79
79
  capacity = scanner->buff.size;
80
80
  }
81
- return capacity;
81
+ if (capacityp)
82
+ *capacityp = capacity;
83
+ return zsv_status_ok;
82
84
  }
83
85
 
84
86
  /**
@@ -107,7 +109,10 @@ enum zsv_status zsv_parse_more(struct zsv_scanner *scanner) {
107
109
  if (VERY_UNLIKELY(scanner->insert_string != NULL))
108
110
  zsv_insert_string(scanner);
109
111
 
110
- size_t capacity = scanner_pre_parse(scanner);
112
+ size_t capacity;
113
+ enum zsv_status stat = scanner_pre_parse(scanner, &capacity);
114
+ if (stat != zsv_status_ok)
115
+ return stat;
111
116
  size_t bytes_read;
112
117
  if (VERY_UNLIKELY(scanner->checked_bom == 0)) {
113
118
  #ifdef ZSV_EXTRAS
@@ -139,6 +144,33 @@ enum zsv_status zsv_parse_more(struct zsv_scanner *scanner) {
139
144
  return zsv_status_no_more_input;
140
145
  }
141
146
 
147
+ ZSV_EXPORT
148
+ enum zsv_status zsv_set_column_filter(zsv_parser parser, const unsigned int *col_indices, unsigned int count) {
149
+ if (parser->needed_cols) {
150
+ free(parser->needed_cols);
151
+ parser->needed_cols = NULL;
152
+ parser->needed_cols_count = 0;
153
+ }
154
+ if (!col_indices || !count)
155
+ return zsv_status_ok;
156
+
157
+ unsigned int max_col = parser->row.allocated;
158
+ parser->needed_cols = calloc(max_col, 1);
159
+ if (!parser->needed_cols)
160
+ return zsv_status_memory;
161
+ parser->needed_cols_count = max_col;
162
+ for (unsigned int i = 0; i < count; i++) {
163
+ if (col_indices[i] < max_col)
164
+ parser->needed_cols[col_indices[i]] = 1;
165
+ }
166
+ return zsv_status_ok;
167
+ }
168
+
169
+ ZSV_EXPORT
170
+ void zsv_set_skip_cells(zsv_parser parser, int skip) {
171
+ parser->skip_cells = skip ? 1 : 0;
172
+ }
173
+
142
174
  ZSV_EXPORT
143
175
  void zsv_abort(zsv_parser parser) {
144
176
  parser->abort = 1;
@@ -195,6 +227,14 @@ enum zsv_status zsv_next_row(zsv_parser parser) {
195
227
  return zsv_status_row;
196
228
  }
197
229
  }
230
+ #ifdef ZSV_EXTRAS
231
+ if (VERY_UNLIKELY(parser->pull.stat == zsv_status_max_rows_read)) {
232
+ parser->pull.now = 0;
233
+ parser->row.used = parser->pull.row_used;
234
+ parser->pull.stat = zsv_status_done;
235
+ return zsv_status_row;
236
+ }
237
+ #endif
198
238
  return parser->pull.stat;
199
239
  }
200
240
 
@@ -269,6 +309,10 @@ ZSV_EXPORT enum zsv_status zsv_set_fixed_offsets(zsv_parser parser, size_t count
269
309
  parser->errprintf(parser->errf, "Fixed offset count must be greater than zero\n");
270
310
  return zsv_status_invalid_option;
271
311
  }
312
+ if (!offsets) {
313
+ parser->errprintf(parser->errf, "zsv_set_fixed_offsets: invalid NULL offsets argument\n");
314
+ return zsv_status_invalid_option;
315
+ }
272
316
  if (offsets[0] == 0)
273
317
  parser->errprintf(parser->errf, "Warning: first cell width is zero\n");
274
318
  for (size_t i = 1; i < count; i++) {
@@ -361,17 +405,101 @@ enum zsv_status zsv_finish(struct zsv_scanner *scanner) {
361
405
  return zsv_status_ok;
362
406
  }
363
407
 
364
- if ((scanner->quoted & ZSV_PARSER_QUOTE_UNCLOSED) && scanner->partial_row_length > scanner->cell_start) {
365
- int quote = '"';
366
- scanner->quoted |= ZSV_PARSER_QUOTE_CLOSED;
367
- scanner->quoted -= ZSV_PARSER_QUOTE_UNCLOSED;
368
- if (scanner->last == quote)
369
- scanner->quote_close_position = scanner->partial_row_length - scanner->cell_start;
370
- else {
371
- scanner->quote_close_position = scanner->partial_row_length - scanner->cell_start;
372
- scanner->scanned_length++;
408
+ /* EOF fix-up: if we ran out of input while still inside an unclosed
409
+ * quoted cell, virtually close it so cell_dl sees a consistent state.
410
+ * `pending` is the cell length signaled by whichever counter is set:
411
+ * partial_row_length (multi-chunk parses carrying data forward) or
412
+ * scanned_length (single-chunk parses where partial_row_length is 0).
413
+ *
414
+ * For a stray single `"` (pending < 2) the input is malformed; drop
415
+ * the quoted flag so the byte is emitted as plain content.
416
+ *
417
+ * Otherwise we synthesize a virtual closing quote and let cell_dl
418
+ * strip the surrounding quotes via its easy fast-path. cell_dl's
419
+ * easy path only adjusts pointer/length (no reads past the cell),
420
+ * so the synthesized closing quote at offset `pending` is never
421
+ * actually accessed.
422
+ *
423
+ * For the EMBEDDED case, however, cell_dl's `""`-collapse loop
424
+ * reads up to s[n-1] — i.e. one byte past the original valid input
425
+ * — which causes a heap-buffer-overflow on a tightly-sized scanner
426
+ * buffer. To produce the same cell content the easy path would
427
+ * produce when the over-read happened to land on a zero byte (no
428
+ * spurious extra `""` match), we do the de-escape ourselves in
429
+ * place, then have cell_dl run the easy fast-path on a synthetic
430
+ * envelope sized to the de-escaped content. The cell's quoted flags
431
+ * are preserved (CLOSED|NEEDED) so downstream writers re-quote on
432
+ * output. */
433
+ if (scanner->quoted & ZSV_PARSER_QUOTE_UNCLOSED) {
434
+ size_t pending = scanner->partial_row_length > scanner->cell_start
435
+ ? scanner->partial_row_length - scanner->cell_start
436
+ : scanner->scanned_length > scanner->cell_start ? scanner->scanned_length - scanner->cell_start
437
+ : 0;
438
+ if (pending > 0) {
439
+ if (pending < 2) {
440
+ scanner->quoted = 0;
441
+ } else if (scanner->quoted & ZSV_PARSER_QUOTE_EMBEDDED) {
442
+ /* In-place de-escape of `""` pairs in the cell interior
443
+ * (everything after the leading `"`). After this, cell_dl's
444
+ * easy fast-path sees a `"<de-escaped>"`-shaped envelope of
445
+ * length 2+out and strips both surrounding quotes via
446
+ * `s++; n -= 2`, yielding a cell view of exactly <de-escaped>
447
+ * bytes. The synthetic trailing `"` is never read. */
448
+ unsigned char *inner = scanner->buff.buff + scanner->cell_start + 1;
449
+ size_t inner_len = pending - 1;
450
+ size_t out = 0;
451
+ for (size_t i = 0; i < inner_len; i++) {
452
+ inner[out++] = inner[i];
453
+ if (i + 1 < inner_len && inner[i] == '"' && inner[i + 1] == '"')
454
+ i++;
455
+ }
456
+ scanner->scanned_length = scanner->cell_start + 2 + out;
457
+ scanner->quote_close_position = 1 + out;
458
+ /* Drop EMBEDDED so cell_dl picks the easy path; keep CLOSED
459
+ * and NEEDED so writers see the cell as needing re-quoting. */
460
+ scanner->quoted = (scanner->quoted | ZSV_PARSER_QUOTE_CLOSED | ZSV_PARSER_QUOTE_NEEDED) &
461
+ ~(ZSV_PARSER_QUOTE_UNCLOSED | ZSV_PARSER_QUOTE_PENDING | ZSV_PARSER_QUOTE_EMBEDDED);
462
+ } else {
463
+ int quote = '"';
464
+ scanner->quoted |= ZSV_PARSER_QUOTE_CLOSED;
465
+ scanner->quoted &= ~ZSV_PARSER_QUOTE_UNCLOSED;
466
+ scanner->quote_close_position = pending;
467
+ if (scanner->last != quote)
468
+ scanner->scanned_length++;
469
+ }
373
470
  }
374
471
  }
472
+ if (scanner->quoted != 0 && scanner->quote_close_position > 0 &&
473
+ scanner->cell_start + scanner->quote_close_position >= scanner->buff.size) {
474
+ // the below does not work if !scanner->free_buff
475
+ // use scanner_pre_parse() instead to shift the row over
476
+ // then append '"' to the end
477
+ size_t new_end = scanner->buff.size - scanner->row_start;
478
+ if (new_end >= scanner->buff.size) {
479
+ // row_start == 0: buffer entirely full, nothing to shift; truncate in place
480
+ scanner->errprintf(scanner->errf, "Warning: row %zu truncated\n", scanner->data_row_count);
481
+ new_end = scanner->buff.size - 1;
482
+ } else {
483
+ stat = scanner_pre_parse(scanner, NULL);
484
+ if (stat != zsv_status_ok)
485
+ return stat;
486
+ }
487
+ // qcp is relative to cell_start; scanned_length must not exceed new_end+1
488
+ // so that cell_dl's easy path (qcp+1 == n) is taken and no read past buffer
489
+ if (scanner->scanned_length > new_end + 1)
490
+ scanner->scanned_length = new_end + 1;
491
+ scanner->quote_close_position = new_end - scanner->cell_start;
492
+ scanner->buff.buff[new_end] = '"';
493
+ /*
494
+ size_t new_size = scanner->cell_start + scanner->quote_close_position + 1;
495
+
496
+ void *mem = realloc(scanner->buff.buff, new_size);
497
+ if (!mem)
498
+ return zsv_status_memory;
499
+ scanner->buff.buff = mem;
500
+ scanner->buff.size = new_size;
501
+ */
502
+ }
375
503
  }
376
504
 
377
505
  if (!scanner->finished) {
@@ -401,12 +529,15 @@ enum zsv_status zsv_delete(zsv_parser parser) {
401
529
 
402
530
  free(parser->row.cells);
403
531
  free(parser->fixed.offsets);
532
+ free(parser->needed_cols);
404
533
  collate_header_destroy(&parser->collate_header);
405
534
  free(parser->pull.regs);
406
535
 
407
536
  #ifdef ZSV_EXTRAS
408
- if (parser->overwrite.close)
537
+ if (parser->overwrite.close) {
409
538
  parser->overwrite.close(parser->overwrite.ctx);
539
+ parser->overwrite.ctx = NULL;
540
+ }
410
541
  #endif
411
542
 
412
543
  if (parser->errclose)
@@ -435,6 +566,8 @@ const unsigned char *zsv_parse_status_desc(enum zsv_status status) {
435
566
  return (unsigned char *)"Row successfully pulled";
436
567
  case zsv_status_error:
437
568
  return (unsigned char *)"Unexpected error";
569
+ case zsv_status_nonstandard_csv:
570
+ return (unsigned char *)"Non-standard CSV detected by fast SIMD engine; retry with ZSV_MODE_COMPAT";
438
571
  #ifdef ZSV_EXTRAS
439
572
  case zsv_status_max_rows_read:
440
573
  return (unsigned char *)"Maximum specified rows have been parsed";
@@ -466,10 +599,15 @@ size_t zsv_row_length_raw_bytes(zsv_parser parser) {
466
599
  * @param len length of the input to parse
467
600
  */
468
601
  enum zsv_status zsv_parse_bytes(struct zsv_scanner *scanner, const unsigned char *bytes, size_t len) {
602
+ if (VERY_UNLIKELY(scanner->abort || scanner->finished))
603
+ // e.g. from nonstandard-CSV detection, etc
604
+ return zsv_status_cancelled;
469
605
  enum zsv_status stat = zsv_status_ok;
470
606
  const unsigned char *cursor = bytes;
471
607
  while (len && stat == zsv_status_ok) {
472
- size_t capacity = scanner_pre_parse(scanner);
608
+ size_t capacity;
609
+ if ((stat = scanner_pre_parse(scanner, &capacity)) != zsv_status_ok)
610
+ break;
473
611
  size_t this_chunk_size = len > capacity ? capacity : len;
474
612
  memcpy(scanner->buff.buff + scanner->partial_row_length, cursor, this_chunk_size);
475
613
  cursor += this_chunk_size;