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.
- checksums.yaml +7 -0
- data/CHANGELOG.md +36 -0
- data/LICENSE +21 -0
- data/README.md +311 -0
- data/ext/zsv/common.h +34 -0
- data/ext/zsv/extconf.rb +137 -0
- data/ext/zsv/options.c +126 -0
- data/ext/zsv/options.h +31 -0
- data/ext/zsv/options_internal.h +8 -0
- data/ext/zsv/parser.c +300 -0
- data/ext/zsv/parser.h +62 -0
- data/ext/zsv/row.c +122 -0
- data/ext/zsv/row.h +39 -0
- data/ext/zsv/vendor/zsv-1.3.0/app/2db.c +756 -0
- data/ext/zsv/vendor/zsv-1.3.0/app/2json.c +381 -0
- data/ext/zsv/vendor/zsv-1.3.0/app/2tsv.c +228 -0
- data/ext/zsv/vendor/zsv-1.3.0/app/builtin/help.c +123 -0
- data/ext/zsv/vendor/zsv-1.3.0/app/builtin/license.c +39 -0
- data/ext/zsv/vendor/zsv-1.3.0/app/builtin/register.c +104 -0
- data/ext/zsv/vendor/zsv-1.3.0/app/builtin/thirdparty.c +41 -0
- data/ext/zsv/vendor/zsv-1.3.0/app/builtin/unregister.c +1 -0
- data/ext/zsv/vendor/zsv-1.3.0/app/builtin/version.c +14 -0
- data/ext/zsv/vendor/zsv-1.3.0/app/check/simdutf_wrapper.h +19 -0
- data/ext/zsv/vendor/zsv-1.3.0/app/check/utf8.c +116 -0
- data/ext/zsv/vendor/zsv-1.3.0/app/check.c +194 -0
- data/ext/zsv/vendor/zsv-1.3.0/app/cli.c +796 -0
- data/ext/zsv/vendor/zsv-1.3.0/app/cli_const.h +41 -0
- data/ext/zsv/vendor/zsv-1.3.0/app/cli_export.h +16 -0
- data/ext/zsv/vendor/zsv-1.3.0/app/cli_ini.c +280 -0
- data/ext/zsv/vendor/zsv-1.3.0/app/cli_internal.h +36 -0
- data/ext/zsv/vendor/zsv-1.3.0/app/compare.c +913 -0
- data/ext/zsv/vendor/zsv-1.3.0/app/compare.h +23 -0
- data/ext/zsv/vendor/zsv-1.3.0/app/compare_added_column.c +20 -0
- data/ext/zsv/vendor/zsv-1.3.0/app/compare_internal.h +140 -0
- data/ext/zsv/vendor/zsv-1.3.0/app/compare_sort.c +91 -0
- data/ext/zsv/vendor/zsv-1.3.0/app/compare_unique_colname.c +81 -0
- data/ext/zsv/vendor/zsv-1.3.0/app/count-pull.c +82 -0
- data/ext/zsv/vendor/zsv-1.3.0/app/count.c +404 -0
- data/ext/zsv/vendor/zsv-1.3.0/app/desc.c +569 -0
- data/ext/zsv/vendor/zsv-1.3.0/app/echo.c +365 -0
- data/ext/zsv/vendor/zsv-1.3.0/app/ext_example/my_extension.c +366 -0
- data/ext/zsv/vendor/zsv-1.3.0/app/ext_example/mysheet_extension.c +341 -0
- data/ext/zsv/vendor/zsv-1.3.0/app/ext_template/YOUR_EXTENSION_zsvext.c +263 -0
- data/ext/zsv/vendor/zsv-1.3.0/app/external/inih/ini.c +298 -0
- data/ext/zsv/vendor/zsv-1.3.0/app/external/inih/ini.h +157 -0
- data/ext/zsv/vendor/zsv-1.3.0/app/external/json_writer-1.01/json_numeric.c +177 -0
- data/ext/zsv/vendor/zsv-1.3.0/app/external/json_writer-1.01/jsonwriter.c +444 -0
- data/ext/zsv/vendor/zsv-1.3.0/app/external/json_writer-1.01/jsonwriter.h +145 -0
- data/ext/zsv/vendor/zsv-1.3.0/app/external/json_writer-1.01/utils.c +110 -0
- data/ext/zsv/vendor/zsv-1.3.0/app/external/memfile-1.0/include/memfile.h +15 -0
- data/ext/zsv/vendor/zsv-1.3.0/app/external/memfile-1.0/src/memfile.c +64 -0
- data/ext/zsv/vendor/zsv-1.3.0/app/external/sglib/sglib.h +1955 -0
- data/ext/zsv/vendor/zsv-1.3.0/app/external/simdutf/simdutf.h +6802 -0
- data/ext/zsv/vendor/zsv-1.3.0/app/external/sqlite3/sqlite3.c +230517 -0
- data/ext/zsv/vendor/zsv-1.3.0/app/external/sqlite3/sqlite3.h +12174 -0
- data/ext/zsv/vendor/zsv-1.3.0/app/external/sqlite3/sqlite3_and_csv_vtab.c +2 -0
- data/ext/zsv/vendor/zsv-1.3.0/app/external/sqlite3/sqlite3_csv_vtab-mem.c +142 -0
- data/ext/zsv/vendor/zsv-1.3.0/app/external/sqlite3/sqlite3_csv_vtab-mem.h +49 -0
- data/ext/zsv/vendor/zsv-1.3.0/app/external/sqlite3/sqlite3_csv_vtab-zsv.c +485 -0
- data/ext/zsv/vendor/zsv-1.3.0/app/external/sqlite3/sqlite3_csv_vtab.c +1015 -0
- data/ext/zsv/vendor/zsv-1.3.0/app/external/sqlite3/sqlite3ext.h +663 -0
- data/ext/zsv/vendor/zsv-1.3.0/app/external/sqlite3/vtab_helper.c +85 -0
- data/ext/zsv/vendor/zsv-1.3.0/app/external/yajl/build/yajl-2.1.1/include/yajl/yajl_common.h +75 -0
- data/ext/zsv/vendor/zsv-1.3.0/app/external/yajl/build/yajl-2.1.1/include/yajl/yajl_gen.h +167 -0
- data/ext/zsv/vendor/zsv-1.3.0/app/external/yajl/build/yajl-2.1.1/include/yajl/yajl_parse.h +228 -0
- data/ext/zsv/vendor/zsv-1.3.0/app/external/yajl/build/yajl-2.1.1/include/yajl/yajl_tree.h +186 -0
- data/ext/zsv/vendor/zsv-1.3.0/app/external/yajl/build/yajl-2.1.1/include/yajl/yajl_version.h +23 -0
- data/ext/zsv/vendor/zsv-1.3.0/app/external/yajl/src/api/yajl_common.h +76 -0
- data/ext/zsv/vendor/zsv-1.3.0/app/external/yajl/src/api/yajl_gen.h +167 -0
- data/ext/zsv/vendor/zsv-1.3.0/app/external/yajl/src/api/yajl_parse.h +238 -0
- data/ext/zsv/vendor/zsv-1.3.0/app/external/yajl/src/api/yajl_tree.h +186 -0
- data/ext/zsv/vendor/zsv-1.3.0/app/external/yajl/src/yajl.c +184 -0
- data/ext/zsv/vendor/zsv-1.3.0/app/external/yajl/src/yajl_alloc.c +52 -0
- data/ext/zsv/vendor/zsv-1.3.0/app/external/yajl/src/yajl_alloc.h +34 -0
- data/ext/zsv/vendor/zsv-1.3.0/app/external/yajl/src/yajl_buf.c +103 -0
- data/ext/zsv/vendor/zsv-1.3.0/app/external/yajl/src/yajl_buf.h +57 -0
- data/ext/zsv/vendor/zsv-1.3.0/app/external/yajl/src/yajl_bytestack.h +69 -0
- data/ext/zsv/vendor/zsv-1.3.0/app/external/yajl/src/yajl_encode.c +220 -0
- data/ext/zsv/vendor/zsv-1.3.0/app/external/yajl/src/yajl_encode.h +34 -0
- data/ext/zsv/vendor/zsv-1.3.0/app/external/yajl/src/yajl_gen.c +362 -0
- data/ext/zsv/vendor/zsv-1.3.0/app/external/yajl/src/yajl_lex.c +764 -0
- data/ext/zsv/vendor/zsv-1.3.0/app/external/yajl/src/yajl_lex.h +117 -0
- data/ext/zsv/vendor/zsv-1.3.0/app/external/yajl/src/yajl_parser.c +508 -0
- data/ext/zsv/vendor/zsv-1.3.0/app/external/yajl/src/yajl_parser.h +78 -0
- data/ext/zsv/vendor/zsv-1.3.0/app/external/yajl/src/yajl_tree.c +505 -0
- data/ext/zsv/vendor/zsv-1.3.0/app/external/yajl/src/yajl_version.c +7 -0
- data/ext/zsv/vendor/zsv-1.3.0/app/external/yajl_helper/yajl_helper/json_value.h +59 -0
- data/ext/zsv/vendor/zsv-1.3.0/app/external/yajl_helper/yajl_helper/yajl_helper.h +208 -0
- data/ext/zsv/vendor/zsv-1.3.0/app/external/yajl_helper/yajl_helper.c +795 -0
- data/ext/zsv/vendor/zsv-1.3.0/app/external/yajl_helper/yajl_helper_internal.h +28 -0
- data/ext/zsv/vendor/zsv-1.3.0/app/flatten.c +851 -0
- data/ext/zsv/vendor/zsv-1.3.0/app/jq.c +106 -0
- data/ext/zsv/vendor/zsv-1.3.0/app/jq.h +6 -0
- data/ext/zsv/vendor/zsv-1.3.0/app/mv.c +113 -0
- data/ext/zsv/vendor/zsv-1.3.0/app/noop.c +90 -0
- data/ext/zsv/vendor/zsv-1.3.0/app/overwrite.c +295 -0
- data/ext/zsv/vendor/zsv-1.3.0/app/paste.c +175 -0
- data/ext/zsv/vendor/zsv-1.3.0/app/pretty.c +693 -0
- data/ext/zsv/vendor/zsv-1.3.0/app/prop.c +980 -0
- data/ext/zsv/vendor/zsv-1.3.0/app/rm.c +131 -0
- data/ext/zsv/vendor/zsv-1.3.0/app/select/fixed.c +130 -0
- data/ext/zsv/vendor/zsv-1.3.0/app/select/internal.h +118 -0
- data/ext/zsv/vendor/zsv-1.3.0/app/select/parallel.c +45 -0
- data/ext/zsv/vendor/zsv-1.3.0/app/select/parallel.h +41 -0
- data/ext/zsv/vendor/zsv-1.3.0/app/select/processing.c +107 -0
- data/ext/zsv/vendor/zsv-1.3.0/app/select/rand.c +20 -0
- data/ext/zsv/vendor/zsv-1.3.0/app/select/regex.c +61 -0
- data/ext/zsv/vendor/zsv-1.3.0/app/select/search.c +14 -0
- data/ext/zsv/vendor/zsv-1.3.0/app/select/selection.c +192 -0
- data/ext/zsv/vendor/zsv-1.3.0/app/select/usage.c +72 -0
- data/ext/zsv/vendor/zsv-1.3.0/app/select-pull.c +812 -0
- data/ext/zsv/vendor/zsv-1.3.0/app/select.c +753 -0
- data/ext/zsv/vendor/zsv-1.3.0/app/serialize.c +372 -0
- data/ext/zsv/vendor/zsv-1.3.0/app/sheet/curses.h +15 -0
- data/ext/zsv/vendor/zsv-1.3.0/app/sheet/cursor.c +119 -0
- data/ext/zsv/vendor/zsv-1.3.0/app/sheet/errors.c +45 -0
- data/ext/zsv/vendor/zsv-1.3.0/app/sheet/file.c +63 -0
- data/ext/zsv/vendor/zsv-1.3.0/app/sheet/file.h +12 -0
- data/ext/zsv/vendor/zsv-1.3.0/app/sheet/filter.c +166 -0
- data/ext/zsv/vendor/zsv-1.3.0/app/sheet/handlers.c +214 -0
- data/ext/zsv/vendor/zsv-1.3.0/app/sheet/handlers_internal.h +128 -0
- data/ext/zsv/vendor/zsv-1.3.0/app/sheet/help.c +43 -0
- data/ext/zsv/vendor/zsv-1.3.0/app/sheet/index.c +81 -0
- data/ext/zsv/vendor/zsv-1.3.0/app/sheet/index.h +25 -0
- data/ext/zsv/vendor/zsv-1.3.0/app/sheet/key-bindings.c +325 -0
- data/ext/zsv/vendor/zsv-1.3.0/app/sheet/key-bindings.h +73 -0
- data/ext/zsv/vendor/zsv-1.3.0/app/sheet/lexer.c +203 -0
- data/ext/zsv/vendor/zsv-1.3.0/app/sheet/newline_handler.c +7 -0
- data/ext/zsv/vendor/zsv-1.3.0/app/sheet/pivot.c +318 -0
- data/ext/zsv/vendor/zsv-1.3.0/app/sheet/procedure.c +134 -0
- data/ext/zsv/vendor/zsv-1.3.0/app/sheet/procedure.h +119 -0
- data/ext/zsv/vendor/zsv-1.3.0/app/sheet/read-data.c +322 -0
- data/ext/zsv/vendor/zsv-1.3.0/app/sheet/screen_buffer.c +203 -0
- data/ext/zsv/vendor/zsv-1.3.0/app/sheet/screen_buffer.h +36 -0
- data/ext/zsv/vendor/zsv-1.3.0/app/sheet/sheet-sql.c +167 -0
- data/ext/zsv/vendor/zsv-1.3.0/app/sheet/sheet_internal.h +36 -0
- data/ext/zsv/vendor/zsv-1.3.0/app/sheet/sqlfilter.c +153 -0
- data/ext/zsv/vendor/zsv-1.3.0/app/sheet/terminfo.c +32 -0
- data/ext/zsv/vendor/zsv-1.3.0/app/sheet/transformation.c +312 -0
- data/ext/zsv/vendor/zsv-1.3.0/app/sheet/transformation.h +29 -0
- data/ext/zsv/vendor/zsv-1.3.0/app/sheet/ui_buffer.c +266 -0
- data/ext/zsv/vendor/zsv-1.3.0/app/sheet/usage.c +9 -0
- data/ext/zsv/vendor/zsv-1.3.0/app/sheet/utf8-width.c +60 -0
- data/ext/zsv/vendor/zsv-1.3.0/app/sheet.c +1007 -0
- data/ext/zsv/vendor/zsv-1.3.0/app/sql.c +453 -0
- data/ext/zsv/vendor/zsv-1.3.0/app/sql_internal.c +101 -0
- data/ext/zsv/vendor/zsv-1.3.0/app/sql_internal.h +49 -0
- data/ext/zsv/vendor/zsv-1.3.0/app/stack.c +393 -0
- data/ext/zsv/vendor/zsv-1.3.0/app/utils/arg.c +322 -0
- data/ext/zsv/vendor/zsv-1.3.0/app/utils/cache.c +228 -0
- data/ext/zsv/vendor/zsv-1.3.0/app/utils/cat.c +91 -0
- data/ext/zsv/vendor/zsv-1.3.0/app/utils/chunk.c +240 -0
- data/ext/zsv/vendor/zsv-1.3.0/app/utils/chunk.h +63 -0
- data/ext/zsv/vendor/zsv-1.3.0/app/utils/clock.c +57 -0
- data/ext/zsv/vendor/zsv-1.3.0/app/utils/db.c +148 -0
- data/ext/zsv/vendor/zsv-1.3.0/app/utils/dirs-no-jq.c +2 -0
- data/ext/zsv/vendor/zsv-1.3.0/app/utils/dirs.c +427 -0
- data/ext/zsv/vendor/zsv-1.3.0/app/utils/dirs_from_json.c +253 -0
- data/ext/zsv/vendor/zsv-1.3.0/app/utils/dirs_to_json.c +121 -0
- data/ext/zsv/vendor/zsv-1.3.0/app/utils/dl.c +20 -0
- data/ext/zsv/vendor/zsv-1.3.0/app/utils/emcc/fs_api.c +159 -0
- data/ext/zsv/vendor/zsv-1.3.0/app/utils/err.c +24 -0
- data/ext/zsv/vendor/zsv-1.3.0/app/utils/file-mem.c +180 -0
- data/ext/zsv/vendor/zsv-1.3.0/app/utils/file.c +256 -0
- data/ext/zsv/vendor/zsv-1.3.0/app/utils/index.c +197 -0
- data/ext/zsv/vendor/zsv-1.3.0/app/utils/index.h +49 -0
- data/ext/zsv/vendor/zsv-1.3.0/app/utils/jq.c +400 -0
- data/ext/zsv/vendor/zsv-1.3.0/app/utils/json.c +120 -0
- data/ext/zsv/vendor/zsv-1.3.0/app/utils/mem.c +18 -0
- data/ext/zsv/vendor/zsv-1.3.0/app/utils/memmem.c +132 -0
- data/ext/zsv/vendor/zsv-1.3.0/app/utils/os.c +178 -0
- data/ext/zsv/vendor/zsv-1.3.0/app/utils/overwrite.c +258 -0
- data/ext/zsv/vendor/zsv-1.3.0/app/utils/overwrite_writer.c +246 -0
- data/ext/zsv/vendor/zsv-1.3.0/app/utils/pcre2-8/pcre2-8-test.c +123 -0
- data/ext/zsv/vendor/zsv-1.3.0/app/utils/pcre2-8/pcre2-8.c +153 -0
- data/ext/zsv/vendor/zsv-1.3.0/app/utils/pcre2-8/pcre2-8.h +54 -0
- data/ext/zsv/vendor/zsv-1.3.0/app/utils/prop.c +267 -0
- data/ext/zsv/vendor/zsv-1.3.0/app/utils/signal.c +53 -0
- data/ext/zsv/vendor/zsv-1.3.0/app/utils/string.c +357 -0
- data/ext/zsv/vendor/zsv-1.3.0/app/utils/win/dir_exists_longpath.c +83 -0
- data/ext/zsv/vendor/zsv-1.3.0/app/utils/win/dl.c +33 -0
- data/ext/zsv/vendor/zsv-1.3.0/app/utils/win/fopen_longpath.c +184 -0
- data/ext/zsv/vendor/zsv-1.3.0/app/utils/win/foreach_dirent_longpath.c +292 -0
- data/ext/zsv/vendor/zsv-1.3.0/app/utils/win/io.c +259 -0
- data/ext/zsv/vendor/zsv-1.3.0/app/utils/win/io.h +13 -0
- data/ext/zsv/vendor/zsv-1.3.0/app/utils/win/mkdir_longpath.c +255 -0
- data/ext/zsv/vendor/zsv-1.3.0/app/utils/win/remove_longpath.c +96 -0
- data/ext/zsv/vendor/zsv-1.3.0/app/utils/writer.c +361 -0
- data/ext/zsv/vendor/zsv-1.3.0/app/zsv_command.h +40 -0
- data/ext/zsv/vendor/zsv-1.3.0/app/zsv_command_standalone.c +16 -0
- data/ext/zsv/vendor/zsv-1.3.0/app/zsv_main.h +44 -0
- data/ext/zsv/vendor/zsv-1.3.0/examples/js/zsv_parser_api_dummy.c +3 -0
- data/ext/zsv/vendor/zsv-1.3.0/examples/lib/parse_by_chunk.c +100 -0
- data/ext/zsv/vendor/zsv-1.3.0/examples/lib/print_my_column.c +143 -0
- data/ext/zsv/vendor/zsv-1.3.0/examples/lib/pull.c +89 -0
- data/ext/zsv/vendor/zsv-1.3.0/examples/lib/simple.c +123 -0
- data/ext/zsv/vendor/zsv-1.3.0/fuzz/fuzz.c +16 -0
- data/ext/zsv/vendor/zsv-1.3.0/include/zsv/api.h +336 -0
- data/ext/zsv/vendor/zsv-1.3.0/include/zsv/common.h +361 -0
- data/ext/zsv/vendor/zsv-1.3.0/include/zsv/ext/implementation.h +62 -0
- data/ext/zsv/vendor/zsv-1.3.0/include/zsv/ext/implementation_private.h +113 -0
- data/ext/zsv/vendor/zsv-1.3.0/include/zsv/ext/sheet.h +73 -0
- data/ext/zsv/vendor/zsv-1.3.0/include/zsv/ext.h +329 -0
- data/ext/zsv/vendor/zsv-1.3.0/include/zsv/utils/arg.h +90 -0
- data/ext/zsv/vendor/zsv-1.3.0/include/zsv/utils/cache.h +49 -0
- data/ext/zsv/vendor/zsv-1.3.0/include/zsv/utils/clock.h +36 -0
- data/ext/zsv/vendor/zsv-1.3.0/include/zsv/utils/compiler.h +58 -0
- data/ext/zsv/vendor/zsv-1.3.0/include/zsv/utils/db.h +19 -0
- data/ext/zsv/vendor/zsv-1.3.0/include/zsv/utils/dirs.h +147 -0
- data/ext/zsv/vendor/zsv-1.3.0/include/zsv/utils/dl.h +22 -0
- data/ext/zsv/vendor/zsv-1.3.0/include/zsv/utils/emcc/fs_api.h +28 -0
- data/ext/zsv/vendor/zsv-1.3.0/include/zsv/utils/err.h +22 -0
- data/ext/zsv/vendor/zsv-1.3.0/include/zsv/utils/file-mem.h +17 -0
- data/ext/zsv/vendor/zsv-1.3.0/include/zsv/utils/file.h +99 -0
- data/ext/zsv/vendor/zsv-1.3.0/include/zsv/utils/jq.h +65 -0
- data/ext/zsv/vendor/zsv-1.3.0/include/zsv/utils/json.h +19 -0
- data/ext/zsv/vendor/zsv-1.3.0/include/zsv/utils/mem.h +19 -0
- data/ext/zsv/vendor/zsv-1.3.0/include/zsv/utils/memmem.h +13 -0
- data/ext/zsv/vendor/zsv-1.3.0/include/zsv/utils/os.h +54 -0
- data/ext/zsv/vendor/zsv-1.3.0/include/zsv/utils/overwrite.h +71 -0
- data/ext/zsv/vendor/zsv-1.3.0/include/zsv/utils/overwrite_writer.h +53 -0
- data/ext/zsv/vendor/zsv-1.3.0/include/zsv/utils/prop.h +107 -0
- data/ext/zsv/vendor/zsv-1.3.0/include/zsv/utils/signal.h +18 -0
- data/ext/zsv/vendor/zsv-1.3.0/include/zsv/utils/sql.h +11 -0
- data/ext/zsv/vendor/zsv-1.3.0/include/zsv/utils/string.h +148 -0
- data/ext/zsv/vendor/zsv-1.3.0/include/zsv/utils/utf8.h +41 -0
- data/ext/zsv/vendor/zsv-1.3.0/include/zsv/utils/win/dl.h +25 -0
- data/ext/zsv/vendor/zsv-1.3.0/include/zsv/utils/writer.h +101 -0
- data/ext/zsv/vendor/zsv-1.3.0/include/zsv/zsv_export.h +33 -0
- data/ext/zsv/vendor/zsv-1.3.0/include/zsv.h +20 -0
- data/ext/zsv/vendor/zsv-1.3.0/src/vector_delim.c +60 -0
- data/ext/zsv/vendor/zsv-1.3.0/src/zsv.c +484 -0
- data/ext/zsv/vendor/zsv-1.3.0/src/zsv_internal.c +731 -0
- data/ext/zsv/vendor/zsv-1.3.0/src/zsv_scan_delim.c +285 -0
- data/ext/zsv/vendor/zsv-1.3.0/src/zsv_scan_fixed.c +88 -0
- data/ext/zsv/vendor/zsv-1.3.0/src/zsv_strencode.c +51 -0
- data/ext/zsv/zsv_ext.c +343 -0
- data/lib/zsv/version.rb +5 -0
- data/lib/zsv.rb +81 -0
- metadata +340 -0
|
@@ -0,0 +1,484 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright (C) 2021 Tai Chi Minh Ralph Eastwood (self), Matt Wong (Guarnerix Inc dba Liquidaty)
|
|
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_MIN_SCANNER_BUFFSIZE
|
|
10
|
+
#define ZSV_MIN_SCANNER_BUFFSIZE 4096
|
|
11
|
+
#endif
|
|
12
|
+
|
|
13
|
+
#include "zsv.h"
|
|
14
|
+
#include <zsv/utils/compiler.h>
|
|
15
|
+
#ifdef ZSV_EXTRAS
|
|
16
|
+
#include <zsv/utils/arg.h>
|
|
17
|
+
#endif
|
|
18
|
+
|
|
19
|
+
static struct zsv_cell zsv_get_cell_1(zsv_parser parser, size_t ix);
|
|
20
|
+
static struct zsv_cell zsv_get_cell_with_overwrite(zsv_parser parser, size_t col_ix);
|
|
21
|
+
#include "zsv_internal.c"
|
|
22
|
+
|
|
23
|
+
#ifndef ZSV_VERSION
|
|
24
|
+
#define ZSV_VERSION "unknown"
|
|
25
|
+
#endif
|
|
26
|
+
|
|
27
|
+
ZSV_EXPORT
|
|
28
|
+
const char *zsv_lib_version(void) {
|
|
29
|
+
return ZSV_VERSION;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
#include "zsv_strencode.c"
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* When we parse a chunk, if it was not the first parse call, we might have a partial
|
|
36
|
+
* row at the end of our buffer that must be moved. The reason we do this at the beginning
|
|
37
|
+
* of a parse and not at the end of the prior parse is so that between chunks, the input
|
|
38
|
+
* chunk remains available in a contiguous block of one or more rows
|
|
39
|
+
*/
|
|
40
|
+
// __attribute__((always_inline))
|
|
41
|
+
inline static size_t scanner_pre_parse(struct zsv_scanner *scanner) {
|
|
42
|
+
scanner->last = '\0';
|
|
43
|
+
if (VERY_LIKELY(scanner->old_bytes_read)) {
|
|
44
|
+
scanner->last = scanner->buff.buff[scanner->old_bytes_read - 1];
|
|
45
|
+
if (scanner->row_start < scanner->old_bytes_read) {
|
|
46
|
+
size_t len = scanner->old_bytes_read - scanner->row_start;
|
|
47
|
+
memmove(scanner->buff.buff, scanner->buff.buff + scanner->row_start, len);
|
|
48
|
+
scanner->partial_row_length = len;
|
|
49
|
+
} else {
|
|
50
|
+
scanner->cell_start = 0;
|
|
51
|
+
scanner->row_start = 0;
|
|
52
|
+
zsv_clear_cell(scanner);
|
|
53
|
+
}
|
|
54
|
+
scanner->cell_start -= scanner->row_start;
|
|
55
|
+
for (size_t i2 = 0; i2 < scanner->row.used; i2++)
|
|
56
|
+
scanner->row.cells[i2].str -= scanner->row_start;
|
|
57
|
+
scanner->row_start = 0;
|
|
58
|
+
scanner->old_bytes_read = 0;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
scanner->cum_scanned_length += scanner->scanned_length - scanner->partial_row_length;
|
|
62
|
+
|
|
63
|
+
size_t capacity = scanner->buff.size - scanner->partial_row_length;
|
|
64
|
+
if (VERY_UNLIKELY(capacity == 0)) {
|
|
65
|
+
// our row size was too small to fit a single row of data
|
|
66
|
+
scanner->errprintf(scanner->errf, "Warning: row %zu truncated\n", scanner->data_row_count);
|
|
67
|
+
if (scanner->mode == ZSV_MODE_FIXED) {
|
|
68
|
+
if (VERY_UNLIKELY(row_fx(scanner, scanner->buff.buff, 0, scanner->buff.size)))
|
|
69
|
+
return zsv_status_cancelled;
|
|
70
|
+
} else if (VERY_UNLIKELY(row_dl(scanner)))
|
|
71
|
+
return zsv_status_cancelled;
|
|
72
|
+
|
|
73
|
+
// throw away the next row end
|
|
74
|
+
scanner->buffer_exceeded = 1;
|
|
75
|
+
scanner->opts.row_handler = zsv_throwaway_row;
|
|
76
|
+
scanner->opts.ctx = scanner;
|
|
77
|
+
|
|
78
|
+
scanner->partial_row_length = 0;
|
|
79
|
+
capacity = scanner->buff.size;
|
|
80
|
+
}
|
|
81
|
+
return capacity;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
/**
|
|
85
|
+
* apply --header-row option
|
|
86
|
+
*/
|
|
87
|
+
static enum zsv_status zsv_insert_string(struct zsv_scanner *scanner) {
|
|
88
|
+
// to do: replace below with
|
|
89
|
+
// return parse_bytes(scanner, bytes, len);
|
|
90
|
+
size_t len = strlen(scanner->insert_string);
|
|
91
|
+
if (len > scanner->buff.size - scanner->partial_row_length)
|
|
92
|
+
len = scanner->buff.size - 1; // to do: throw an error instead
|
|
93
|
+
memcpy(scanner->buff.buff + scanner->partial_row_length, scanner->insert_string, len);
|
|
94
|
+
if (scanner->buff.buff[len] != '\n')
|
|
95
|
+
scanner->buff.buff[len] = '\n';
|
|
96
|
+
enum zsv_status stat = zsv_scan(scanner, scanner->buff.buff, len + 1);
|
|
97
|
+
scanner->insert_string = NULL;
|
|
98
|
+
return stat;
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
/**
|
|
102
|
+
* Read the next chunk of data from our input stream and parse it, calling our
|
|
103
|
+
* custom handlers as each cell and row are parsed
|
|
104
|
+
*/
|
|
105
|
+
ZSV_EXPORT
|
|
106
|
+
enum zsv_status zsv_parse_more(struct zsv_scanner *scanner) {
|
|
107
|
+
if (VERY_UNLIKELY(scanner->insert_string != NULL))
|
|
108
|
+
zsv_insert_string(scanner);
|
|
109
|
+
|
|
110
|
+
size_t capacity = scanner_pre_parse(scanner);
|
|
111
|
+
size_t bytes_read;
|
|
112
|
+
if (VERY_UNLIKELY(scanner->checked_bom == 0)) {
|
|
113
|
+
#ifdef ZSV_EXTRAS
|
|
114
|
+
// initialize progress timer
|
|
115
|
+
if (scanner->opts.progress.seconds_interval)
|
|
116
|
+
scanner->progress.last_time = time(NULL);
|
|
117
|
+
#endif
|
|
118
|
+
size_t bom_len = strlen(ZSV_BOM);
|
|
119
|
+
scanner->checked_bom = 1;
|
|
120
|
+
if ((bytes_read = scanner->read(scanner->buff.buff, 1, bom_len, scanner->in)) == bom_len &&
|
|
121
|
+
!memcmp(scanner->buff.buff, ZSV_BOM, bom_len)) {
|
|
122
|
+
// have bom. disregard what we just read
|
|
123
|
+
bytes_read = scanner->read(scanner->buff.buff, 1, capacity, scanner->in);
|
|
124
|
+
scanner->had_bom = 1;
|
|
125
|
+
} else { // no BOM. keep the bytes we just read
|
|
126
|
+
// bytes_read = bom_len + scanner->read(scanner->buff.buff + bom_len, 1, capacity - bom_len, scanner->in);
|
|
127
|
+
if (bytes_read == bom_len) // maybe we only read < 3 bytes
|
|
128
|
+
bytes_read += scanner->read(scanner->buff.buff + bom_len, 1, capacity - bom_len, scanner->in);
|
|
129
|
+
}
|
|
130
|
+
} else // already checked bom. read as usual
|
|
131
|
+
bytes_read = scanner->read(scanner->buff.buff + scanner->partial_row_length, 1, capacity, scanner->in);
|
|
132
|
+
scanner->started = 1;
|
|
133
|
+
if (VERY_UNLIKELY(scanner->filter != NULL))
|
|
134
|
+
bytes_read = scanner->filter(scanner->filter_ctx, scanner->buff.buff + scanner->partial_row_length, bytes_read);
|
|
135
|
+
if (VERY_LIKELY(bytes_read))
|
|
136
|
+
return zsv_scan(scanner, scanner->buff.buff, bytes_read);
|
|
137
|
+
|
|
138
|
+
scanner->scanned_length = scanner->partial_row_length;
|
|
139
|
+
return zsv_status_no_more_input;
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
ZSV_EXPORT
|
|
143
|
+
void zsv_abort(zsv_parser parser) {
|
|
144
|
+
parser->abort = 1;
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
ZSV_EXPORT
|
|
148
|
+
char zsv_row_is_blank(zsv_parser parser) {
|
|
149
|
+
return zsv_internal_row_is_blank(parser);
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
static void zsv_pull_row(void *ctx) {
|
|
153
|
+
zsv_parser parser = ctx;
|
|
154
|
+
parser->pull.now = 1;
|
|
155
|
+
parser->pull.row_used = parser->row.used;
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
/**
|
|
159
|
+
* For pull parsing, use zsv_next_row(). Not quite as fast as push parsing, but pretty close
|
|
160
|
+
* @return zsv_status_row on success
|
|
161
|
+
*/
|
|
162
|
+
ZSV_EXPORT
|
|
163
|
+
enum zsv_status zsv_next_row(zsv_parser parser) {
|
|
164
|
+
if (VERY_UNLIKELY(!parser->pull.regs)) {
|
|
165
|
+
if (parser->started)
|
|
166
|
+
return zsv_status_error; // error: already started a push parser
|
|
167
|
+
if (!(parser->pull.regs = calloc(1, sizeof(*parser->pull.regs))))
|
|
168
|
+
return zsv_status_memory;
|
|
169
|
+
parser->mode = ZSV_MODE_DELIM_PULL;
|
|
170
|
+
zsv_set_row_handler(parser, zsv_pull_row);
|
|
171
|
+
zsv_set_context(parser, parser);
|
|
172
|
+
if (parser->insert_string != NULL)
|
|
173
|
+
parser->pull.stat = zsv_insert_string(parser);
|
|
174
|
+
if (parser->pull.stat == zsv_status_row)
|
|
175
|
+
return parser->pull.stat;
|
|
176
|
+
}
|
|
177
|
+
if (VERY_LIKELY(parser->pull.stat == zsv_status_row))
|
|
178
|
+
parser->pull.stat = zsv_scan_delim_pull(parser, parser->pull.buff, parser->pull.bytes_read);
|
|
179
|
+
if (VERY_UNLIKELY(parser->pull.stat == zsv_status_ok)) {
|
|
180
|
+
do {
|
|
181
|
+
parser->pull.stat = zsv_parse_more(parser); // should return zsv_status_row or zsv_status_no_more_input
|
|
182
|
+
} while (parser->pull.stat == zsv_status_ok);
|
|
183
|
+
if (VERY_LIKELY(parser->pull.stat == zsv_status_row))
|
|
184
|
+
return parser->pull.stat;
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
if (VERY_UNLIKELY(parser->pull.stat == zsv_status_no_more_input)) {
|
|
188
|
+
parser->pull.now = 0;
|
|
189
|
+
zsv_finish(parser);
|
|
190
|
+
|
|
191
|
+
parser->pull.stat = zsv_status_done;
|
|
192
|
+
if (parser->pull.now) {
|
|
193
|
+
parser->pull.now = 0;
|
|
194
|
+
parser->row.used = parser->pull.row_used;
|
|
195
|
+
return zsv_status_row;
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
return parser->pull.stat;
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
// to do: rename to zsv_column_count(). rename all other zsv_hand to just zsv_
|
|
202
|
+
ZSV_EXPORT
|
|
203
|
+
size_t zsv_cell_count(zsv_parser parser) {
|
|
204
|
+
return parser->row.used;
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
ZSV_EXPORT
|
|
208
|
+
void zsv_set_row_handler(zsv_parser parser, void (*row_handler)(void *ctx)) {
|
|
209
|
+
if (parser->opts.row_handler == parser->opts_orig.row_handler)
|
|
210
|
+
parser->opts.row_handler = row_handler;
|
|
211
|
+
parser->opts_orig.row_handler = row_handler;
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
ZSV_EXPORT
|
|
215
|
+
void zsv_set_context(zsv_parser parser, void *ctx) {
|
|
216
|
+
if (parser->opts.ctx == parser->opts_orig.ctx)
|
|
217
|
+
parser->opts.ctx = ctx;
|
|
218
|
+
parser->opts_orig.ctx = ctx;
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
ZSV_EXPORT
|
|
222
|
+
void zsv_set_read(zsv_parser parser, size_t (*read_func)(void *restrict, size_t n, size_t size, void *restrict)) {
|
|
223
|
+
parser->read = read_func;
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
ZSV_EXPORT
|
|
227
|
+
void zsv_set_input(zsv_parser parser, void *in) {
|
|
228
|
+
parser->in = in;
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
ZSV_EXPORT
|
|
232
|
+
char zsv_quoted(zsv_parser parser) {
|
|
233
|
+
return parser->quoted || parser->opts.no_quotes;
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
static struct zsv_cell zsv_get_cell_1(zsv_parser parser, size_t ix) {
|
|
237
|
+
if (VERY_LIKELY(ix < parser->row.used))
|
|
238
|
+
return parser->row.cells[ix];
|
|
239
|
+
|
|
240
|
+
struct zsv_cell c = {0, 0, 0, 0};
|
|
241
|
+
return c;
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
// to do: benchmark returning zsv_cell struct vs just a zsv_cell pointer
|
|
245
|
+
ZSV_EXPORT
|
|
246
|
+
struct zsv_cell zsv_get_cell(zsv_parser parser, size_t ix) {
|
|
247
|
+
return parser->get_cell(parser, ix);
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
/**
|
|
251
|
+
* `zsv_get_cell_len()` is not needed in most cases, but may be useful in
|
|
252
|
+
* restrictive cases such as when calling from Javascript into wasm
|
|
253
|
+
*/
|
|
254
|
+
ZSV_EXPORT
|
|
255
|
+
size_t zsv_get_cell_len(zsv_parser parser, size_t ix) {
|
|
256
|
+
if (ix < parser->row.used)
|
|
257
|
+
return parser->row.cells[ix].len;
|
|
258
|
+
return 0;
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
ZSV_EXPORT
|
|
262
|
+
unsigned char *zsv_get_cell_str(zsv_parser parser, size_t ix) {
|
|
263
|
+
struct zsv_cell c = zsv_get_cell_1(parser, ix);
|
|
264
|
+
return c.len ? c.str : NULL;
|
|
265
|
+
}
|
|
266
|
+
|
|
267
|
+
ZSV_EXPORT enum zsv_status zsv_set_fixed_offsets(zsv_parser parser, size_t count, size_t *offsets) {
|
|
268
|
+
if (!count) {
|
|
269
|
+
parser->errprintf(parser->errf, "Fixed offset count must be greater than zero\n");
|
|
270
|
+
return zsv_status_invalid_option;
|
|
271
|
+
}
|
|
272
|
+
if (offsets[0] == 0)
|
|
273
|
+
parser->errprintf(parser->errf, "Warning: first cell width is zero\n");
|
|
274
|
+
for (size_t i = 1; i < count; i++) {
|
|
275
|
+
if (offsets[i - 1] > offsets[i]) {
|
|
276
|
+
parser->errprintf(parser->errf, "Invalid offset %zu may not exceed prior offset %zu\n", offsets[i],
|
|
277
|
+
offsets[i - 1]);
|
|
278
|
+
return zsv_status_invalid_option;
|
|
279
|
+
} else if (offsets[i - 1] == offsets[i])
|
|
280
|
+
parser->errprintf(parser->errf, "Warning: offset %zu repeated, will always yield empty cell\n", offsets[i - 1]);
|
|
281
|
+
}
|
|
282
|
+
|
|
283
|
+
if (offsets[count - 1] > parser->buff.size) {
|
|
284
|
+
parser->errprintf(parser->errf, "Offset %zu exceeds total buffer size %zu\n", offsets[count - 1],
|
|
285
|
+
parser->buff.size);
|
|
286
|
+
return zsv_status_invalid_option;
|
|
287
|
+
}
|
|
288
|
+
if (parser->cum_scanned_length) {
|
|
289
|
+
parser->errprintf(parser->errf, "Scanner mode cannot be changed after parsing has begun\n");
|
|
290
|
+
return zsv_status_invalid_option;
|
|
291
|
+
}
|
|
292
|
+
|
|
293
|
+
free(parser->fixed.offsets);
|
|
294
|
+
parser->fixed.offsets = calloc(count, sizeof(*parser->fixed.offsets));
|
|
295
|
+
if (parser->fixed.offsets == NULL) {
|
|
296
|
+
parser->errprintf(parser->errf, "Out of memory!\n");
|
|
297
|
+
return zsv_status_memory;
|
|
298
|
+
}
|
|
299
|
+
parser->fixed.count = count;
|
|
300
|
+
for (unsigned i = 0; i < count; i++)
|
|
301
|
+
parser->fixed.offsets[i] = offsets[i];
|
|
302
|
+
|
|
303
|
+
parser->mode = ZSV_MODE_FIXED;
|
|
304
|
+
parser->checked_bom = 1;
|
|
305
|
+
|
|
306
|
+
set_callbacks(parser);
|
|
307
|
+
|
|
308
|
+
return zsv_status_ok;
|
|
309
|
+
}
|
|
310
|
+
|
|
311
|
+
ZSV_EXPORT
|
|
312
|
+
int zsv_peek(zsv_parser z) {
|
|
313
|
+
if (z->scanned_length + 1 < z->buff.size)
|
|
314
|
+
return z->buff.buff[z->scanned_length + 1];
|
|
315
|
+
return -1;
|
|
316
|
+
}
|
|
317
|
+
|
|
318
|
+
/**
|
|
319
|
+
* Create a zsv parser
|
|
320
|
+
* @param opts
|
|
321
|
+
* @returns parser handle
|
|
322
|
+
*/
|
|
323
|
+
ZSV_EXPORT
|
|
324
|
+
zsv_parser zsv_new(struct zsv_opts *opts) {
|
|
325
|
+
struct zsv_opts tmp;
|
|
326
|
+
if (!opts) {
|
|
327
|
+
opts = &tmp;
|
|
328
|
+
memset(opts, 0, sizeof(*opts));
|
|
329
|
+
}
|
|
330
|
+
|
|
331
|
+
if (!opts->max_row_size)
|
|
332
|
+
opts->max_row_size = ZSV_ROW_MAX_SIZE_DEFAULT;
|
|
333
|
+
if (!opts->max_columns)
|
|
334
|
+
opts->max_columns = ZSV_MAX_COLS_DEFAULT;
|
|
335
|
+
if (opts->delimiter == '\n' || opts->delimiter == '\r' || opts->delimiter == '"') {
|
|
336
|
+
int (*errprintf)(void *, const char *fmt, ...) = opts->errprintf ? opts->errprintf : zsv_generic_fprintf;
|
|
337
|
+
errprintf(opts->errf ? opts->errf : stderr, "Invalid delimiter\n");
|
|
338
|
+
return NULL;
|
|
339
|
+
}
|
|
340
|
+
struct zsv_scanner *scanner = calloc(1, sizeof(*scanner));
|
|
341
|
+
if (scanner) {
|
|
342
|
+
if (zsv_scanner_init(scanner, opts)) {
|
|
343
|
+
zsv_delete(scanner);
|
|
344
|
+
scanner = NULL;
|
|
345
|
+
}
|
|
346
|
+
}
|
|
347
|
+
return scanner;
|
|
348
|
+
}
|
|
349
|
+
|
|
350
|
+
ZSV_EXPORT
|
|
351
|
+
enum zsv_status zsv_finish(struct zsv_scanner *scanner) {
|
|
352
|
+
enum zsv_status stat = zsv_status_ok;
|
|
353
|
+
if (!scanner)
|
|
354
|
+
return zsv_status_error;
|
|
355
|
+
if (!scanner->abort) {
|
|
356
|
+
if (scanner->mode == ZSV_MODE_FIXED) {
|
|
357
|
+
if (scanner->partial_row_length && memchr("\n\r", scanner->buff.buff[scanner->partial_row_length - 1], 2))
|
|
358
|
+
scanner->partial_row_length--;
|
|
359
|
+
if (scanner->partial_row_length)
|
|
360
|
+
return row_fx(scanner, scanner->buff.buff, 0, scanner->partial_row_length);
|
|
361
|
+
return zsv_status_ok;
|
|
362
|
+
}
|
|
363
|
+
|
|
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++;
|
|
373
|
+
}
|
|
374
|
+
}
|
|
375
|
+
}
|
|
376
|
+
|
|
377
|
+
if (!scanner->finished) {
|
|
378
|
+
scanner->finished = 1;
|
|
379
|
+
if (!scanner->abort) {
|
|
380
|
+
if (scanner->scanned_length > 0 && scanner->scanned_length >= scanner->cell_start)
|
|
381
|
+
cell_dl(scanner, scanner->buff.buff + scanner->cell_start, scanner->scanned_length - scanner->cell_start);
|
|
382
|
+
if (scanner->have_cell) {
|
|
383
|
+
if (row_dl(scanner))
|
|
384
|
+
stat = zsv_status_cancelled;
|
|
385
|
+
}
|
|
386
|
+
} else
|
|
387
|
+
stat = zsv_status_cancelled;
|
|
388
|
+
#ifdef ZSV_EXTRAS
|
|
389
|
+
if (scanner->opts.completed.callback)
|
|
390
|
+
scanner->opts.completed.callback(scanner->opts.completed.ctx, stat);
|
|
391
|
+
#endif
|
|
392
|
+
}
|
|
393
|
+
return stat;
|
|
394
|
+
}
|
|
395
|
+
|
|
396
|
+
ZSV_EXPORT
|
|
397
|
+
enum zsv_status zsv_delete(zsv_parser parser) {
|
|
398
|
+
if (parser) {
|
|
399
|
+
if (parser->free_buff && parser->buff.buff)
|
|
400
|
+
free(parser->buff.buff);
|
|
401
|
+
|
|
402
|
+
free(parser->row.cells);
|
|
403
|
+
free(parser->fixed.offsets);
|
|
404
|
+
collate_header_destroy(&parser->collate_header);
|
|
405
|
+
free(parser->pull.regs);
|
|
406
|
+
|
|
407
|
+
#ifdef ZSV_EXTRAS
|
|
408
|
+
if (parser->overwrite.close)
|
|
409
|
+
parser->overwrite.close(parser->overwrite.ctx);
|
|
410
|
+
#endif
|
|
411
|
+
|
|
412
|
+
if (parser->errclose)
|
|
413
|
+
parser->errclose(parser->errf);
|
|
414
|
+
free(parser);
|
|
415
|
+
}
|
|
416
|
+
return zsv_status_ok;
|
|
417
|
+
}
|
|
418
|
+
|
|
419
|
+
ZSV_EXPORT
|
|
420
|
+
const unsigned char *zsv_parse_status_desc(enum zsv_status status) {
|
|
421
|
+
switch (status) {
|
|
422
|
+
case zsv_status_ok:
|
|
423
|
+
return (unsigned char *)"OK";
|
|
424
|
+
case zsv_status_cancelled:
|
|
425
|
+
return (unsigned char *)"User cancelled";
|
|
426
|
+
case zsv_status_no_more_input:
|
|
427
|
+
return (unsigned char *)"No more input";
|
|
428
|
+
case zsv_status_invalid_option:
|
|
429
|
+
return (unsigned char *)"Invalid option";
|
|
430
|
+
case zsv_status_memory:
|
|
431
|
+
return (unsigned char *)"Out of memory";
|
|
432
|
+
case zsv_status_done:
|
|
433
|
+
return (unsigned char *)"No more rows to pull";
|
|
434
|
+
case zsv_status_row:
|
|
435
|
+
return (unsigned char *)"Row successfully pulled";
|
|
436
|
+
case zsv_status_error:
|
|
437
|
+
return (unsigned char *)"Unexpected error";
|
|
438
|
+
#ifdef ZSV_EXTRAS
|
|
439
|
+
case zsv_status_max_rows_read:
|
|
440
|
+
return (unsigned char *)"Maximum specified rows have been parsed";
|
|
441
|
+
#endif
|
|
442
|
+
}
|
|
443
|
+
return (unsigned char *)"Unknown";
|
|
444
|
+
}
|
|
445
|
+
|
|
446
|
+
ZSV_EXPORT
|
|
447
|
+
size_t zsv_scanned_length(zsv_parser parser) {
|
|
448
|
+
return parser->scanned_length;
|
|
449
|
+
}
|
|
450
|
+
|
|
451
|
+
ZSV_EXPORT
|
|
452
|
+
size_t zsv_cum_scanned_length(zsv_parser parser) {
|
|
453
|
+
return parser->cum_scanned_length + (parser->finished ? 0 : parser->scanned_length) +
|
|
454
|
+
(parser->had_bom ? strlen(ZSV_BOM) : 0);
|
|
455
|
+
}
|
|
456
|
+
|
|
457
|
+
ZSV_EXPORT
|
|
458
|
+
size_t zsv_row_length_raw_bytes(zsv_parser parser) {
|
|
459
|
+
return parser->scanned_length - parser->row_start;
|
|
460
|
+
}
|
|
461
|
+
|
|
462
|
+
/**
|
|
463
|
+
* @param parser parser handle
|
|
464
|
+
* @param buff the input buffer. Note: this buffer may not overlap with
|
|
465
|
+
* the parser buffer!
|
|
466
|
+
* @param len length of the input to parse
|
|
467
|
+
*/
|
|
468
|
+
enum zsv_status zsv_parse_bytes(struct zsv_scanner *scanner, const unsigned char *bytes, size_t len) {
|
|
469
|
+
enum zsv_status stat = zsv_status_ok;
|
|
470
|
+
const unsigned char *cursor = bytes;
|
|
471
|
+
while (len && stat == zsv_status_ok) {
|
|
472
|
+
size_t capacity = scanner_pre_parse(scanner);
|
|
473
|
+
size_t this_chunk_size = len > capacity ? capacity : len;
|
|
474
|
+
memcpy(scanner->buff.buff + scanner->partial_row_length, cursor, this_chunk_size);
|
|
475
|
+
cursor += this_chunk_size;
|
|
476
|
+
len -= this_chunk_size;
|
|
477
|
+
if (scanner->filter)
|
|
478
|
+
this_chunk_size =
|
|
479
|
+
scanner->filter(scanner->filter_ctx, scanner->buff.buff + scanner->partial_row_length, this_chunk_size);
|
|
480
|
+
if (this_chunk_size)
|
|
481
|
+
stat = zsv_scan(scanner, scanner->buff.buff, this_chunk_size);
|
|
482
|
+
}
|
|
483
|
+
return stat;
|
|
484
|
+
}
|