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.
- checksums.yaml +4 -4
- data/CHANGELOG.md +153 -2
- data/README.md +132 -240
- data/ext/zsv/ZSV_UPSTREAM +7 -0
- data/ext/zsv/common.h +0 -12
- data/ext/zsv/extconf.rb +70 -122
- data/ext/zsv/options.c +63 -62
- data/ext/zsv/options.h +8 -11
- data/ext/zsv/parser.c +390 -201
- data/ext/zsv/parser.h +35 -22
- data/ext/zsv/row.c +75 -28
- data/ext/zsv/row.h +15 -9
- data/ext/zsv/upstream.rb +55 -0
- data/ext/zsv/vendor/zsv/LICENSE +21 -0
- data/ext/zsv/vendor/zsv/VENDORED_FROM +2 -0
- data/ext/zsv/vendor/zsv/configure +1212 -0
- data/ext/zsv/vendor/{zsv-1.3.0 → zsv}/include/zsv/api.h +39 -0
- data/ext/zsv/vendor/{zsv-1.3.0 → zsv}/include/zsv/common.h +36 -0
- data/ext/zsv/vendor/{zsv-1.3.0 → zsv}/include/zsv/ext/sheet.h +8 -1
- data/ext/zsv/vendor/{zsv-1.3.0 → zsv}/include/zsv/ext.h +6 -2
- data/ext/zsv/vendor/zsv/include/zsv/utils/appname.h +51 -0
- data/ext/zsv/vendor/{zsv-1.3.0 → zsv}/include/zsv/utils/arg.h +50 -1
- data/ext/zsv/vendor/{zsv-1.3.0 → zsv}/include/zsv/utils/compiler.h +19 -8
- data/ext/zsv/vendor/{zsv-1.3.0 → zsv}/include/zsv/utils/dirs.h +2 -0
- data/ext/zsv/vendor/{zsv-1.3.0 → zsv}/include/zsv/utils/file-mem.h +1 -0
- data/ext/zsv/vendor/{zsv-1.3.0 → zsv}/include/zsv/utils/file.h +28 -2
- data/ext/zsv/vendor/zsv/include/zsv/utils/os.h +145 -0
- data/ext/zsv/vendor/zsv/include/zsv/utils/output.h +34 -0
- data/ext/zsv/vendor/{zsv-1.3.0 → zsv}/include/zsv/utils/overwrite_writer.h +1 -1
- data/ext/zsv/vendor/{zsv-1.3.0 → zsv}/include/zsv/utils/prop.h +16 -4
- data/ext/zsv/vendor/zsv/include/zsv/utils/rng.h +35 -0
- data/ext/zsv/vendor/{zsv-1.3.0 → zsv}/include/zsv/utils/signal.h +7 -0
- data/ext/zsv/vendor/zsv/include/zsv/utils/sql.h +13 -0
- data/ext/zsv/vendor/{zsv-1.3.0 → zsv}/include/zsv/utils/string.h +25 -0
- data/ext/zsv/vendor/{zsv-1.3.0 → zsv}/include/zsv/utils/writer.h +9 -1
- data/ext/zsv/vendor/{zsv-1.3.0 → zsv}/include/zsv/zsv_export.h +1 -1
- data/ext/zsv/vendor/{zsv-1.3.0/include/zsv.h → zsv/include/zsv.h.in} +1 -3
- data/ext/zsv/vendor/zsv/src/Makefile +238 -0
- data/ext/zsv/vendor/{zsv-1.3.0 → zsv}/src/zsv.c +152 -14
- data/ext/zsv/vendor/{zsv-1.3.0 → zsv}/src/zsv_internal.c +108 -50
- data/ext/zsv/vendor/zsv/src/zsv_scan_delim_fast.c +741 -0
- data/ext/zsv/vendor/zsv/src/zsv_scan_simd_avx2.h +89 -0
- data/ext/zsv/vendor/zsv/src/zsv_scan_simd_neon.h +80 -0
- data/ext/zsv/vendor/zsv/src/zsv_scan_simd_sse2.h +93 -0
- data/ext/zsv/vendor/zsv/src/zsv_scan_simd_wasm.h +79 -0
- data/ext/zsv/vendor/zsv/src/zsv_strencode.c +84 -0
- data/ext/zsv/zsv_ext.c +176 -105
- data/lib/zsv/errors.rb +32 -0
- data/lib/zsv/input.rb +88 -0
- data/lib/zsv/options.rb +132 -0
- data/lib/zsv/strict_validator.rb +124 -0
- data/lib/zsv/version.rb +1 -1
- data/lib/zsv.rb +137 -35
- metadata +81 -230
- data/ext/zsv/vendor/zsv-1.3.0/app/2db.c +0 -756
- data/ext/zsv/vendor/zsv-1.3.0/app/2json.c +0 -381
- data/ext/zsv/vendor/zsv-1.3.0/app/2tsv.c +0 -228
- data/ext/zsv/vendor/zsv-1.3.0/app/builtin/help.c +0 -123
- data/ext/zsv/vendor/zsv-1.3.0/app/builtin/license.c +0 -39
- data/ext/zsv/vendor/zsv-1.3.0/app/builtin/register.c +0 -104
- data/ext/zsv/vendor/zsv-1.3.0/app/builtin/thirdparty.c +0 -41
- data/ext/zsv/vendor/zsv-1.3.0/app/builtin/unregister.c +0 -1
- data/ext/zsv/vendor/zsv-1.3.0/app/builtin/version.c +0 -14
- data/ext/zsv/vendor/zsv-1.3.0/app/check/simdutf_wrapper.h +0 -19
- data/ext/zsv/vendor/zsv-1.3.0/app/check/utf8.c +0 -116
- data/ext/zsv/vendor/zsv-1.3.0/app/check.c +0 -194
- data/ext/zsv/vendor/zsv-1.3.0/app/cli.c +0 -796
- data/ext/zsv/vendor/zsv-1.3.0/app/cli_const.h +0 -41
- data/ext/zsv/vendor/zsv-1.3.0/app/cli_export.h +0 -16
- data/ext/zsv/vendor/zsv-1.3.0/app/cli_ini.c +0 -280
- data/ext/zsv/vendor/zsv-1.3.0/app/cli_internal.h +0 -36
- data/ext/zsv/vendor/zsv-1.3.0/app/compare.c +0 -913
- data/ext/zsv/vendor/zsv-1.3.0/app/compare.h +0 -23
- data/ext/zsv/vendor/zsv-1.3.0/app/compare_added_column.c +0 -20
- data/ext/zsv/vendor/zsv-1.3.0/app/compare_internal.h +0 -140
- data/ext/zsv/vendor/zsv-1.3.0/app/compare_sort.c +0 -91
- data/ext/zsv/vendor/zsv-1.3.0/app/compare_unique_colname.c +0 -81
- data/ext/zsv/vendor/zsv-1.3.0/app/count-pull.c +0 -82
- data/ext/zsv/vendor/zsv-1.3.0/app/count.c +0 -404
- data/ext/zsv/vendor/zsv-1.3.0/app/desc.c +0 -569
- data/ext/zsv/vendor/zsv-1.3.0/app/echo.c +0 -365
- data/ext/zsv/vendor/zsv-1.3.0/app/ext_example/my_extension.c +0 -366
- data/ext/zsv/vendor/zsv-1.3.0/app/ext_example/mysheet_extension.c +0 -341
- data/ext/zsv/vendor/zsv-1.3.0/app/ext_template/YOUR_EXTENSION_zsvext.c +0 -263
- data/ext/zsv/vendor/zsv-1.3.0/app/external/inih/ini.c +0 -298
- data/ext/zsv/vendor/zsv-1.3.0/app/external/inih/ini.h +0 -157
- data/ext/zsv/vendor/zsv-1.3.0/app/external/json_writer-1.01/json_numeric.c +0 -177
- data/ext/zsv/vendor/zsv-1.3.0/app/external/json_writer-1.01/jsonwriter.c +0 -444
- data/ext/zsv/vendor/zsv-1.3.0/app/external/json_writer-1.01/jsonwriter.h +0 -145
- data/ext/zsv/vendor/zsv-1.3.0/app/external/json_writer-1.01/utils.c +0 -110
- data/ext/zsv/vendor/zsv-1.3.0/app/external/memfile-1.0/include/memfile.h +0 -15
- data/ext/zsv/vendor/zsv-1.3.0/app/external/memfile-1.0/src/memfile.c +0 -64
- data/ext/zsv/vendor/zsv-1.3.0/app/external/sglib/sglib.h +0 -1955
- data/ext/zsv/vendor/zsv-1.3.0/app/external/simdutf/simdutf.h +0 -6802
- data/ext/zsv/vendor/zsv-1.3.0/app/external/sqlite3/sqlite3.c +0 -230517
- data/ext/zsv/vendor/zsv-1.3.0/app/external/sqlite3/sqlite3.h +0 -12174
- data/ext/zsv/vendor/zsv-1.3.0/app/external/sqlite3/sqlite3_and_csv_vtab.c +0 -2
- data/ext/zsv/vendor/zsv-1.3.0/app/external/sqlite3/sqlite3_csv_vtab-mem.c +0 -142
- data/ext/zsv/vendor/zsv-1.3.0/app/external/sqlite3/sqlite3_csv_vtab-mem.h +0 -49
- data/ext/zsv/vendor/zsv-1.3.0/app/external/sqlite3/sqlite3_csv_vtab-zsv.c +0 -485
- data/ext/zsv/vendor/zsv-1.3.0/app/external/sqlite3/sqlite3_csv_vtab.c +0 -1015
- data/ext/zsv/vendor/zsv-1.3.0/app/external/sqlite3/sqlite3ext.h +0 -663
- data/ext/zsv/vendor/zsv-1.3.0/app/external/sqlite3/vtab_helper.c +0 -85
- data/ext/zsv/vendor/zsv-1.3.0/app/external/yajl/build/yajl-2.1.1/include/yajl/yajl_common.h +0 -75
- data/ext/zsv/vendor/zsv-1.3.0/app/external/yajl/build/yajl-2.1.1/include/yajl/yajl_gen.h +0 -167
- data/ext/zsv/vendor/zsv-1.3.0/app/external/yajl/build/yajl-2.1.1/include/yajl/yajl_parse.h +0 -228
- data/ext/zsv/vendor/zsv-1.3.0/app/external/yajl/build/yajl-2.1.1/include/yajl/yajl_tree.h +0 -186
- data/ext/zsv/vendor/zsv-1.3.0/app/external/yajl/build/yajl-2.1.1/include/yajl/yajl_version.h +0 -23
- data/ext/zsv/vendor/zsv-1.3.0/app/external/yajl/src/api/yajl_common.h +0 -76
- data/ext/zsv/vendor/zsv-1.3.0/app/external/yajl/src/api/yajl_gen.h +0 -167
- data/ext/zsv/vendor/zsv-1.3.0/app/external/yajl/src/api/yajl_parse.h +0 -238
- data/ext/zsv/vendor/zsv-1.3.0/app/external/yajl/src/api/yajl_tree.h +0 -186
- data/ext/zsv/vendor/zsv-1.3.0/app/external/yajl/src/yajl.c +0 -184
- data/ext/zsv/vendor/zsv-1.3.0/app/external/yajl/src/yajl_alloc.c +0 -52
- data/ext/zsv/vendor/zsv-1.3.0/app/external/yajl/src/yajl_alloc.h +0 -34
- data/ext/zsv/vendor/zsv-1.3.0/app/external/yajl/src/yajl_buf.c +0 -103
- data/ext/zsv/vendor/zsv-1.3.0/app/external/yajl/src/yajl_buf.h +0 -57
- data/ext/zsv/vendor/zsv-1.3.0/app/external/yajl/src/yajl_bytestack.h +0 -69
- data/ext/zsv/vendor/zsv-1.3.0/app/external/yajl/src/yajl_encode.c +0 -220
- data/ext/zsv/vendor/zsv-1.3.0/app/external/yajl/src/yajl_encode.h +0 -34
- data/ext/zsv/vendor/zsv-1.3.0/app/external/yajl/src/yajl_gen.c +0 -362
- data/ext/zsv/vendor/zsv-1.3.0/app/external/yajl/src/yajl_lex.c +0 -764
- data/ext/zsv/vendor/zsv-1.3.0/app/external/yajl/src/yajl_lex.h +0 -117
- data/ext/zsv/vendor/zsv-1.3.0/app/external/yajl/src/yajl_parser.c +0 -508
- data/ext/zsv/vendor/zsv-1.3.0/app/external/yajl/src/yajl_parser.h +0 -78
- data/ext/zsv/vendor/zsv-1.3.0/app/external/yajl/src/yajl_tree.c +0 -505
- data/ext/zsv/vendor/zsv-1.3.0/app/external/yajl/src/yajl_version.c +0 -7
- data/ext/zsv/vendor/zsv-1.3.0/app/external/yajl_helper/yajl_helper/json_value.h +0 -59
- data/ext/zsv/vendor/zsv-1.3.0/app/external/yajl_helper/yajl_helper/yajl_helper.h +0 -208
- data/ext/zsv/vendor/zsv-1.3.0/app/external/yajl_helper/yajl_helper.c +0 -795
- data/ext/zsv/vendor/zsv-1.3.0/app/external/yajl_helper/yajl_helper_internal.h +0 -28
- data/ext/zsv/vendor/zsv-1.3.0/app/flatten.c +0 -851
- data/ext/zsv/vendor/zsv-1.3.0/app/jq.c +0 -106
- data/ext/zsv/vendor/zsv-1.3.0/app/jq.h +0 -6
- data/ext/zsv/vendor/zsv-1.3.0/app/mv.c +0 -113
- data/ext/zsv/vendor/zsv-1.3.0/app/noop.c +0 -90
- data/ext/zsv/vendor/zsv-1.3.0/app/overwrite.c +0 -295
- data/ext/zsv/vendor/zsv-1.3.0/app/paste.c +0 -175
- data/ext/zsv/vendor/zsv-1.3.0/app/pretty.c +0 -693
- data/ext/zsv/vendor/zsv-1.3.0/app/prop.c +0 -980
- data/ext/zsv/vendor/zsv-1.3.0/app/rm.c +0 -131
- data/ext/zsv/vendor/zsv-1.3.0/app/select/fixed.c +0 -130
- data/ext/zsv/vendor/zsv-1.3.0/app/select/internal.h +0 -118
- data/ext/zsv/vendor/zsv-1.3.0/app/select/parallel.c +0 -45
- data/ext/zsv/vendor/zsv-1.3.0/app/select/parallel.h +0 -41
- data/ext/zsv/vendor/zsv-1.3.0/app/select/processing.c +0 -107
- data/ext/zsv/vendor/zsv-1.3.0/app/select/rand.c +0 -20
- data/ext/zsv/vendor/zsv-1.3.0/app/select/regex.c +0 -61
- data/ext/zsv/vendor/zsv-1.3.0/app/select/search.c +0 -14
- data/ext/zsv/vendor/zsv-1.3.0/app/select/selection.c +0 -192
- data/ext/zsv/vendor/zsv-1.3.0/app/select/usage.c +0 -72
- data/ext/zsv/vendor/zsv-1.3.0/app/select-pull.c +0 -812
- data/ext/zsv/vendor/zsv-1.3.0/app/select.c +0 -753
- data/ext/zsv/vendor/zsv-1.3.0/app/serialize.c +0 -372
- data/ext/zsv/vendor/zsv-1.3.0/app/sheet/curses.h +0 -15
- data/ext/zsv/vendor/zsv-1.3.0/app/sheet/cursor.c +0 -119
- data/ext/zsv/vendor/zsv-1.3.0/app/sheet/errors.c +0 -45
- data/ext/zsv/vendor/zsv-1.3.0/app/sheet/file.c +0 -63
- data/ext/zsv/vendor/zsv-1.3.0/app/sheet/file.h +0 -12
- data/ext/zsv/vendor/zsv-1.3.0/app/sheet/filter.c +0 -166
- data/ext/zsv/vendor/zsv-1.3.0/app/sheet/handlers.c +0 -214
- data/ext/zsv/vendor/zsv-1.3.0/app/sheet/handlers_internal.h +0 -128
- data/ext/zsv/vendor/zsv-1.3.0/app/sheet/help.c +0 -43
- data/ext/zsv/vendor/zsv-1.3.0/app/sheet/index.c +0 -81
- data/ext/zsv/vendor/zsv-1.3.0/app/sheet/index.h +0 -25
- data/ext/zsv/vendor/zsv-1.3.0/app/sheet/key-bindings.c +0 -325
- data/ext/zsv/vendor/zsv-1.3.0/app/sheet/key-bindings.h +0 -73
- data/ext/zsv/vendor/zsv-1.3.0/app/sheet/lexer.c +0 -203
- data/ext/zsv/vendor/zsv-1.3.0/app/sheet/newline_handler.c +0 -7
- data/ext/zsv/vendor/zsv-1.3.0/app/sheet/pivot.c +0 -318
- data/ext/zsv/vendor/zsv-1.3.0/app/sheet/procedure.c +0 -134
- data/ext/zsv/vendor/zsv-1.3.0/app/sheet/procedure.h +0 -119
- data/ext/zsv/vendor/zsv-1.3.0/app/sheet/read-data.c +0 -322
- data/ext/zsv/vendor/zsv-1.3.0/app/sheet/screen_buffer.c +0 -203
- data/ext/zsv/vendor/zsv-1.3.0/app/sheet/screen_buffer.h +0 -36
- data/ext/zsv/vendor/zsv-1.3.0/app/sheet/sheet-sql.c +0 -167
- data/ext/zsv/vendor/zsv-1.3.0/app/sheet/sheet_internal.h +0 -36
- data/ext/zsv/vendor/zsv-1.3.0/app/sheet/sqlfilter.c +0 -153
- data/ext/zsv/vendor/zsv-1.3.0/app/sheet/terminfo.c +0 -32
- data/ext/zsv/vendor/zsv-1.3.0/app/sheet/transformation.c +0 -312
- data/ext/zsv/vendor/zsv-1.3.0/app/sheet/transformation.h +0 -29
- data/ext/zsv/vendor/zsv-1.3.0/app/sheet/ui_buffer.c +0 -266
- data/ext/zsv/vendor/zsv-1.3.0/app/sheet/usage.c +0 -9
- data/ext/zsv/vendor/zsv-1.3.0/app/sheet/utf8-width.c +0 -60
- data/ext/zsv/vendor/zsv-1.3.0/app/sheet.c +0 -1007
- data/ext/zsv/vendor/zsv-1.3.0/app/sql.c +0 -453
- data/ext/zsv/vendor/zsv-1.3.0/app/sql_internal.c +0 -101
- data/ext/zsv/vendor/zsv-1.3.0/app/sql_internal.h +0 -49
- data/ext/zsv/vendor/zsv-1.3.0/app/stack.c +0 -393
- data/ext/zsv/vendor/zsv-1.3.0/app/utils/arg.c +0 -322
- data/ext/zsv/vendor/zsv-1.3.0/app/utils/cache.c +0 -228
- data/ext/zsv/vendor/zsv-1.3.0/app/utils/cat.c +0 -91
- data/ext/zsv/vendor/zsv-1.3.0/app/utils/chunk.c +0 -240
- data/ext/zsv/vendor/zsv-1.3.0/app/utils/chunk.h +0 -63
- data/ext/zsv/vendor/zsv-1.3.0/app/utils/clock.c +0 -57
- data/ext/zsv/vendor/zsv-1.3.0/app/utils/db.c +0 -148
- data/ext/zsv/vendor/zsv-1.3.0/app/utils/dirs-no-jq.c +0 -2
- data/ext/zsv/vendor/zsv-1.3.0/app/utils/dirs.c +0 -427
- data/ext/zsv/vendor/zsv-1.3.0/app/utils/dirs_from_json.c +0 -253
- data/ext/zsv/vendor/zsv-1.3.0/app/utils/dirs_to_json.c +0 -121
- data/ext/zsv/vendor/zsv-1.3.0/app/utils/dl.c +0 -20
- data/ext/zsv/vendor/zsv-1.3.0/app/utils/emcc/fs_api.c +0 -159
- data/ext/zsv/vendor/zsv-1.3.0/app/utils/err.c +0 -24
- data/ext/zsv/vendor/zsv-1.3.0/app/utils/file-mem.c +0 -180
- data/ext/zsv/vendor/zsv-1.3.0/app/utils/file.c +0 -256
- data/ext/zsv/vendor/zsv-1.3.0/app/utils/index.c +0 -197
- data/ext/zsv/vendor/zsv-1.3.0/app/utils/index.h +0 -49
- data/ext/zsv/vendor/zsv-1.3.0/app/utils/jq.c +0 -400
- data/ext/zsv/vendor/zsv-1.3.0/app/utils/json.c +0 -120
- data/ext/zsv/vendor/zsv-1.3.0/app/utils/mem.c +0 -18
- data/ext/zsv/vendor/zsv-1.3.0/app/utils/memmem.c +0 -132
- data/ext/zsv/vendor/zsv-1.3.0/app/utils/os.c +0 -178
- data/ext/zsv/vendor/zsv-1.3.0/app/utils/overwrite.c +0 -258
- data/ext/zsv/vendor/zsv-1.3.0/app/utils/overwrite_writer.c +0 -246
- data/ext/zsv/vendor/zsv-1.3.0/app/utils/pcre2-8/pcre2-8-test.c +0 -123
- data/ext/zsv/vendor/zsv-1.3.0/app/utils/pcre2-8/pcre2-8.c +0 -153
- data/ext/zsv/vendor/zsv-1.3.0/app/utils/pcre2-8/pcre2-8.h +0 -54
- data/ext/zsv/vendor/zsv-1.3.0/app/utils/prop.c +0 -267
- data/ext/zsv/vendor/zsv-1.3.0/app/utils/signal.c +0 -53
- data/ext/zsv/vendor/zsv-1.3.0/app/utils/string.c +0 -357
- data/ext/zsv/vendor/zsv-1.3.0/app/utils/win/dir_exists_longpath.c +0 -83
- data/ext/zsv/vendor/zsv-1.3.0/app/utils/win/dl.c +0 -33
- data/ext/zsv/vendor/zsv-1.3.0/app/utils/win/fopen_longpath.c +0 -184
- data/ext/zsv/vendor/zsv-1.3.0/app/utils/win/foreach_dirent_longpath.c +0 -292
- data/ext/zsv/vendor/zsv-1.3.0/app/utils/win/io.c +0 -259
- data/ext/zsv/vendor/zsv-1.3.0/app/utils/win/io.h +0 -13
- data/ext/zsv/vendor/zsv-1.3.0/app/utils/win/mkdir_longpath.c +0 -255
- data/ext/zsv/vendor/zsv-1.3.0/app/utils/win/remove_longpath.c +0 -96
- data/ext/zsv/vendor/zsv-1.3.0/app/utils/writer.c +0 -361
- data/ext/zsv/vendor/zsv-1.3.0/app/zsv_command.h +0 -40
- data/ext/zsv/vendor/zsv-1.3.0/app/zsv_command_standalone.c +0 -16
- data/ext/zsv/vendor/zsv-1.3.0/app/zsv_main.h +0 -44
- data/ext/zsv/vendor/zsv-1.3.0/examples/js/zsv_parser_api_dummy.c +0 -3
- data/ext/zsv/vendor/zsv-1.3.0/examples/lib/parse_by_chunk.c +0 -100
- data/ext/zsv/vendor/zsv-1.3.0/examples/lib/print_my_column.c +0 -143
- data/ext/zsv/vendor/zsv-1.3.0/examples/lib/pull.c +0 -89
- data/ext/zsv/vendor/zsv-1.3.0/examples/lib/simple.c +0 -123
- data/ext/zsv/vendor/zsv-1.3.0/fuzz/fuzz.c +0 -16
- data/ext/zsv/vendor/zsv-1.3.0/include/zsv/utils/os.h +0 -54
- data/ext/zsv/vendor/zsv-1.3.0/include/zsv/utils/sql.h +0 -11
- data/ext/zsv/vendor/zsv-1.3.0/src/zsv_strencode.c +0 -51
- /data/ext/zsv/vendor/{zsv-1.3.0 → zsv}/include/zsv/ext/implementation.h +0 -0
- /data/ext/zsv/vendor/{zsv-1.3.0 → zsv}/include/zsv/ext/implementation_private.h +0 -0
- /data/ext/zsv/vendor/{zsv-1.3.0 → zsv}/include/zsv/utils/cache.h +0 -0
- /data/ext/zsv/vendor/{zsv-1.3.0 → zsv}/include/zsv/utils/clock.h +0 -0
- /data/ext/zsv/vendor/{zsv-1.3.0 → zsv}/include/zsv/utils/db.h +0 -0
- /data/ext/zsv/vendor/{zsv-1.3.0 → zsv}/include/zsv/utils/dl.h +0 -0
- /data/ext/zsv/vendor/{zsv-1.3.0 → zsv}/include/zsv/utils/emcc/fs_api.h +0 -0
- /data/ext/zsv/vendor/{zsv-1.3.0 → zsv}/include/zsv/utils/err.h +0 -0
- /data/ext/zsv/vendor/{zsv-1.3.0 → zsv}/include/zsv/utils/jq.h +0 -0
- /data/ext/zsv/vendor/{zsv-1.3.0 → zsv}/include/zsv/utils/json.h +0 -0
- /data/ext/zsv/vendor/{zsv-1.3.0 → zsv}/include/zsv/utils/mem.h +0 -0
- /data/ext/zsv/vendor/{zsv-1.3.0 → zsv}/include/zsv/utils/memmem.h +0 -0
- /data/ext/zsv/vendor/{zsv-1.3.0 → zsv}/include/zsv/utils/overwrite.h +0 -0
- /data/ext/zsv/vendor/{zsv-1.3.0 → zsv}/include/zsv/utils/utf8.h +0 -0
- /data/ext/zsv/vendor/{zsv-1.3.0 → zsv}/include/zsv/utils/win/dl.h +0 -0
- /data/ext/zsv/vendor/{zsv-1.3.0 → zsv}/src/vector_delim.c +0 -0
- /data/ext/zsv/vendor/{zsv-1.3.0 → zsv}/src/zsv_scan_delim.c +0 -0
- /data/ext/zsv/vendor/{zsv-1.3.0 → zsv}/src/zsv_scan_fixed.c +0 -0
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require 'strscan'
|
|
4
|
+
|
|
5
|
+
module ZSV
|
|
6
|
+
# Checks that input is well-formed CSV the way Ruby's CSV does in its
|
|
7
|
+
# default (non-liberal) mode. zsv itself never rejects input, so this pass
|
|
8
|
+
# is what backs +liberal_parsing: false+.
|
|
9
|
+
#
|
|
10
|
+
# The input is read one physical line at a time. A line without a quote is
|
|
11
|
+
# accepted as is, and a line that is one well-formed record is accepted by a
|
|
12
|
+
# single regexp match; only the rest (fields spanning lines, errors) is
|
|
13
|
+
# scanned field by field.
|
|
14
|
+
#
|
|
15
|
+
# Errors carry the number CSV reports: the 1-based record, where a quoted
|
|
16
|
+
# field that spans several lines counts once. Records are told apart by
|
|
17
|
+
# "\n" (so "\r\n" works too); input using a lone "\r" is one record here.
|
|
18
|
+
class StrictValidator
|
|
19
|
+
QUOTE = '"'
|
|
20
|
+
BOM = "\xEF\xBB\xBF".b.freeze
|
|
21
|
+
ROW_END = /\r\n|\n|\r/
|
|
22
|
+
QUOTED_BODY = /(?:[^"]+|"")*/
|
|
23
|
+
|
|
24
|
+
# @param string [String] CSV data
|
|
25
|
+
# @param col_sep [String] single-character column separator
|
|
26
|
+
# @raise [MalformedCSVError, InvalidEncodingError]
|
|
27
|
+
def self.validate_string(string, col_sep:)
|
|
28
|
+
unless string.valid_encoding?
|
|
29
|
+
new(col_sep, string.encoding).validate(string.each_line("\n"))
|
|
30
|
+
return
|
|
31
|
+
end
|
|
32
|
+
return unless string.include?(QUOTE)
|
|
33
|
+
|
|
34
|
+
new(col_sep, nil).validate(string.each_line("\n"))
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
# @param path [String] file to check
|
|
38
|
+
# @param col_sep [String] single-character column separator
|
|
39
|
+
# @param encoding [Encoding] encoding the fields will be labelled with
|
|
40
|
+
# @raise [MalformedCSVError, InvalidEncodingError]
|
|
41
|
+
def self.validate_file(path, col_sep:, encoding:)
|
|
42
|
+
File.open(path, 'rb') do |file|
|
|
43
|
+
new(col_sep, encoding).validate(file.each_line("\n"))
|
|
44
|
+
end
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
# @param col_sep [String] single-character column separator
|
|
48
|
+
# @param encoding [Encoding, nil] encoding to verify each line against, nil to skip
|
|
49
|
+
def initialize(col_sep, encoding)
|
|
50
|
+
separator = Regexp.escape(col_sep)
|
|
51
|
+
field = /(?>"(?>[^"]+|"")*"|[^"#{separator}\r\n]*)/
|
|
52
|
+
@col_sep = col_sep
|
|
53
|
+
@unquoted = /[^"#{separator}\r\n]*/
|
|
54
|
+
@complete_record = /\A#{field}(?>#{separator}#{field})*\r?\n?\z/
|
|
55
|
+
@encoding = encoding
|
|
56
|
+
end
|
|
57
|
+
|
|
58
|
+
# @param lines [Enumerable<String>] physical lines, including their "\n"
|
|
59
|
+
# @raise [MalformedCSVError, InvalidEncodingError]
|
|
60
|
+
# @return [void]
|
|
61
|
+
def validate(lines)
|
|
62
|
+
record = 0
|
|
63
|
+
in_quotes = false
|
|
64
|
+
|
|
65
|
+
lines.each_with_index do |line, index|
|
|
66
|
+
record += 1 unless in_quotes
|
|
67
|
+
check_encoding(line, record, first_line: index.zero?)
|
|
68
|
+
next if !in_quotes && (!line.include?(QUOTE) || line.match?(@complete_record))
|
|
69
|
+
|
|
70
|
+
in_quotes = scan(line, in_quotes, record, first_line: index.zero?)
|
|
71
|
+
end
|
|
72
|
+
|
|
73
|
+
raise MalformedCSVError.new('Unclosed quoted field', record) if in_quotes
|
|
74
|
+
end
|
|
75
|
+
|
|
76
|
+
private
|
|
77
|
+
|
|
78
|
+
def check_encoding(line, record, first_line:)
|
|
79
|
+
return unless @encoding
|
|
80
|
+
|
|
81
|
+
line = line.byteslice(BOM.bytesize..) if first_line && line.b.start_with?(BOM)
|
|
82
|
+
return if line.force_encoding(@encoding).valid_encoding?
|
|
83
|
+
|
|
84
|
+
raise InvalidEncodingError.new("Invalid byte sequence in #{@encoding}", record)
|
|
85
|
+
end
|
|
86
|
+
|
|
87
|
+
# Scans one physical line. Returns true when it ends inside a quoted field.
|
|
88
|
+
def scan(line, in_quotes, record, first_line:)
|
|
89
|
+
scanner = StringScanner.new(line.b)
|
|
90
|
+
scanner.skip(BOM) if first_line
|
|
91
|
+
|
|
92
|
+
until scanner.eos?
|
|
93
|
+
if in_quotes
|
|
94
|
+
return true unless close_quoted_field(scanner, record)
|
|
95
|
+
|
|
96
|
+
in_quotes = false
|
|
97
|
+
elsif scanner.skip(QUOTE)
|
|
98
|
+
in_quotes = true
|
|
99
|
+
else
|
|
100
|
+
skip_unquoted_field(scanner, record)
|
|
101
|
+
end
|
|
102
|
+
end
|
|
103
|
+
in_quotes
|
|
104
|
+
end
|
|
105
|
+
|
|
106
|
+
# Returns false when the line ends before the closing quote.
|
|
107
|
+
def close_quoted_field(scanner, record)
|
|
108
|
+
scanner.skip(QUOTED_BODY)
|
|
109
|
+
return false if scanner.eos?
|
|
110
|
+
|
|
111
|
+
scanner.skip(QUOTE)
|
|
112
|
+
return true if scanner.eos? || scanner.skip(@col_sep) || scanner.skip(ROW_END)
|
|
113
|
+
|
|
114
|
+
raise MalformedCSVError.new("Any value after quoted field isn't allowed", record)
|
|
115
|
+
end
|
|
116
|
+
|
|
117
|
+
def skip_unquoted_field(scanner, record)
|
|
118
|
+
scanner.skip(@unquoted)
|
|
119
|
+
return if scanner.eos? || scanner.skip(@col_sep) || scanner.skip(ROW_END)
|
|
120
|
+
|
|
121
|
+
raise MalformedCSVError.new('Illegal quoting', record)
|
|
122
|
+
end
|
|
123
|
+
end
|
|
124
|
+
end
|
data/lib/zsv/version.rb
CHANGED
data/lib/zsv.rb
CHANGED
|
@@ -1,12 +1,24 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
3
|
require_relative 'zsv/version'
|
|
4
|
-
|
|
4
|
+
# Load the C extension: precompiled gems ship one per Ruby minor
|
|
5
|
+
# (lib/zsv/3.4/zsv.so); source installs build lib/zsv/zsv.so.
|
|
6
|
+
begin
|
|
7
|
+
require_relative "zsv/#{RUBY_VERSION[/\A\d+\.\d+/]}/zsv"
|
|
8
|
+
rescue LoadError
|
|
9
|
+
require_relative 'zsv/zsv'
|
|
10
|
+
end
|
|
11
|
+
require_relative 'zsv/errors'
|
|
12
|
+
require_relative 'zsv/options'
|
|
13
|
+
require_relative 'zsv/strict_validator'
|
|
14
|
+
require_relative 'zsv/input'
|
|
5
15
|
|
|
6
16
|
# ZSV - SIMD-accelerated CSV parser
|
|
7
17
|
#
|
|
8
|
-
# A
|
|
9
|
-
#
|
|
18
|
+
# A fast CSV reader built on the zsv C library, with an API modelled on the
|
|
19
|
+
# reading half of Ruby's CSV stdlib. Rows are plain Arrays (or Hashes with
|
|
20
|
+
# +headers:+) of frozen Strings. See docs/API_REFERENCE.md for the exact
|
|
21
|
+
# differences from CSV.
|
|
10
22
|
#
|
|
11
23
|
# @example Basic usage
|
|
12
24
|
# ZSV.foreach("data.csv") do |row|
|
|
@@ -22,37 +34,34 @@ require_relative 'zsv/zsv' # Load C extension
|
|
|
22
34
|
# rows = ZSV.parse("a,b,c\n1,2,3\n")
|
|
23
35
|
#
|
|
24
36
|
module ZSV
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
#
|
|
29
|
-
#
|
|
30
|
-
# @param io [String, IO] File path or IO object to parse
|
|
31
|
-
# @param options [Hash] Parser options
|
|
32
|
-
# @return [Parser] New parser instance
|
|
37
|
+
# Ruby front of the module functions defined by the C extension: validates
|
|
38
|
+
# options and input before handing over to C.
|
|
39
|
+
module ModuleMethods
|
|
40
|
+
# Parse a CSV String and return all rows.
|
|
33
41
|
#
|
|
34
|
-
# @
|
|
35
|
-
#
|
|
36
|
-
#
|
|
37
|
-
#
|
|
38
|
-
#
|
|
39
|
-
def
|
|
40
|
-
|
|
42
|
+
# @param string [String] CSV data
|
|
43
|
+
# @param options [Hash] parser options, see docs/API_REFERENCE.md
|
|
44
|
+
# @return [Array<Array<String>>, Array<Hash>] all rows
|
|
45
|
+
# @raise [ArgumentError] for unknown or unsupported options
|
|
46
|
+
# @raise [MalformedCSVError] for malformed input with +liberal_parsing: false+
|
|
47
|
+
def parse(string, **options)
|
|
48
|
+
super(*Input.data(string, options))
|
|
41
49
|
end
|
|
42
50
|
|
|
43
|
-
# Parse
|
|
44
|
-
#
|
|
45
|
-
# This method provides lazy enumeration over CSV rows without loading
|
|
46
|
-
# the entire file into memory.
|
|
51
|
+
# Parse a single CSV line.
|
|
47
52
|
#
|
|
48
|
-
# @param
|
|
49
|
-
# @param options [Hash]
|
|
50
|
-
# @return [
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
53
|
+
# @param line [String] one CSV record
|
|
54
|
+
# @param options [Hash] parser options
|
|
55
|
+
# @return [Array<String>, Hash, nil] the first row, nil for an empty line
|
|
56
|
+
def parse_line(line, **)
|
|
57
|
+
parse(line, **).first
|
|
58
|
+
end
|
|
59
|
+
|
|
60
|
+
# Lazily enumerate the rows of a CSV String, a path or an IO.
|
|
55
61
|
#
|
|
62
|
+
# @param source [String, #to_path, #read] CSV data, a path or an IO
|
|
63
|
+
# @param options [Hash] parser options
|
|
64
|
+
# @return [Enumerator] rows, parsed as they are consumed
|
|
56
65
|
def parse_enum(source, **)
|
|
57
66
|
parser = Parser.new(source, **)
|
|
58
67
|
|
|
@@ -62,20 +71,113 @@ module ZSV
|
|
|
62
71
|
parser.close
|
|
63
72
|
end
|
|
64
73
|
end
|
|
74
|
+
|
|
75
|
+
# Stream the rows of a CSV file.
|
|
76
|
+
#
|
|
77
|
+
# @param path [String, #to_path] file to read
|
|
78
|
+
# @param mode [String] read mode ("r", "rb", "r:bom|utf-8")
|
|
79
|
+
# @param options [Hash] parser options
|
|
80
|
+
# @yieldparam row [Array<String>, Hash]
|
|
81
|
+
# @return [nil, Enumerator] an Enumerator when no block is given
|
|
82
|
+
def foreach(path, mode = 'r', **options, &block)
|
|
83
|
+
unless block
|
|
84
|
+
Options.normalize(options) # report bad options now, not at the first row
|
|
85
|
+
return to_enum(__method__, path, mode, **options)
|
|
86
|
+
end
|
|
87
|
+
|
|
88
|
+
super(*Input.path(path, mode, options), &block)
|
|
89
|
+
end
|
|
90
|
+
|
|
91
|
+
# Read a whole CSV file.
|
|
92
|
+
#
|
|
93
|
+
# @param path [String, #to_path] file to read
|
|
94
|
+
# @param options [Hash] parser options
|
|
95
|
+
# @return [Array<Array<String>>, Array<Hash>] all rows
|
|
96
|
+
def read(path, **options)
|
|
97
|
+
super(*Input.path(path, 'r', options))
|
|
98
|
+
end
|
|
99
|
+
|
|
100
|
+
# Open a CSV file for reading.
|
|
101
|
+
#
|
|
102
|
+
# @param path [String, #to_path] file to read
|
|
103
|
+
# @param mode [String] read mode ("r", "rb", "r:bom|utf-8")
|
|
104
|
+
# @param options [Hash] parser options
|
|
105
|
+
# @yieldparam parser [Parser] closed when the block returns
|
|
106
|
+
# @return [Parser, Object] the parser, or the block's value
|
|
107
|
+
def open(path, mode = 'r', **options, &)
|
|
108
|
+
path, native = Input.path(path, mode, options)
|
|
109
|
+
super(path, native, &)
|
|
110
|
+
end
|
|
111
|
+
|
|
112
|
+
# Create a parser for CSV data, a path or an IO. See Parser.new.
|
|
113
|
+
#
|
|
114
|
+
# @return [Parser]
|
|
115
|
+
def new(source, **)
|
|
116
|
+
Parser.new(source, **)
|
|
117
|
+
end
|
|
65
118
|
end
|
|
119
|
+
singleton_class.prepend(ModuleMethods)
|
|
66
120
|
|
|
67
|
-
#
|
|
68
|
-
|
|
69
|
-
#
|
|
121
|
+
# Ruby front of Parser.new.
|
|
122
|
+
module ParserConstruction
|
|
123
|
+
# @param source [String, #read, #to_path] CSV data, a path or an IO.
|
|
124
|
+
# A String holding a line ending is data; otherwise it is a path when
|
|
125
|
+
# such a file exists, data when it contains the column separator, and
|
|
126
|
+
# a (missing) path in any other case. Use ZSV.parse or ZSV.open to
|
|
127
|
+
# avoid the guess. An IO is read as the rows are consumed.
|
|
128
|
+
# @param options [Hash] parser options, see docs/API_REFERENCE.md
|
|
129
|
+
# @return [Parser]
|
|
130
|
+
def new(source, **options)
|
|
131
|
+
if source.is_a?(String)
|
|
132
|
+
return from_path(source, **options) unless Input.data?(source, Options.col_sep(options))
|
|
133
|
+
|
|
134
|
+
from_string(source, **options)
|
|
135
|
+
elsif Input.path?(source)
|
|
136
|
+
from_path(source, **options)
|
|
137
|
+
elsif source.respond_to?(:read)
|
|
138
|
+
# Strict parsing has to see the whole input before the first row
|
|
139
|
+
return from_string(source.read.to_s, **options) if Options.strict?(options)
|
|
140
|
+
|
|
141
|
+
super(*Input.io(source, options))
|
|
142
|
+
else
|
|
143
|
+
raise TypeError, "expected CSV data, a path or an IO, got #{source.class}"
|
|
144
|
+
end
|
|
145
|
+
end
|
|
146
|
+
|
|
147
|
+
# Create a parser over CSV data held in a String, never a path.
|
|
70
148
|
#
|
|
71
|
-
# @
|
|
149
|
+
# @param string [String] CSV data
|
|
150
|
+
# @param options [Hash] parser options
|
|
151
|
+
# @return [Parser]
|
|
152
|
+
def from_string(string, **options)
|
|
153
|
+
super(*Input.data(string, options))
|
|
154
|
+
end
|
|
155
|
+
|
|
156
|
+
# Create a parser over a file.
|
|
157
|
+
#
|
|
158
|
+
# @param path [String, #to_path] file to read
|
|
159
|
+
# @param options [Hash] parser options
|
|
160
|
+
# @return [Parser]
|
|
161
|
+
def from_path(path, **options)
|
|
162
|
+
super(*Input.path(path, 'r', options))
|
|
163
|
+
end
|
|
164
|
+
end
|
|
165
|
+
|
|
166
|
+
# Ruby front of the Parser instance methods defined by the C extension.
|
|
167
|
+
module ParserMethods
|
|
168
|
+
# Read all remaining rows.
|
|
169
|
+
#
|
|
170
|
+
# @return [Array<Array<String>>, Array<Hash>] remaining rows
|
|
72
171
|
def read
|
|
73
172
|
rows = []
|
|
74
173
|
each { |row| rows << row }
|
|
75
174
|
rows
|
|
76
175
|
end
|
|
77
|
-
|
|
78
|
-
# Alias for compatibility
|
|
79
176
|
alias to_a read
|
|
80
177
|
end
|
|
178
|
+
|
|
179
|
+
class Parser
|
|
180
|
+
singleton_class.prepend(ParserConstruction)
|
|
181
|
+
prepend ParserMethods
|
|
182
|
+
end
|
|
81
183
|
end
|