zsv 1.4.4-aarch64-linux-gnu

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 (77) hide show
  1. checksums.yaml +7 -0
  2. data/CHANGELOG.md +187 -0
  3. data/LICENSE +21 -0
  4. data/README.md +203 -0
  5. data/ext/zsv/ZSV_UPSTREAM +7 -0
  6. data/ext/zsv/common.h +22 -0
  7. data/ext/zsv/extconf.rb +102 -0
  8. data/ext/zsv/options.c +126 -0
  9. data/ext/zsv/options.h +28 -0
  10. data/ext/zsv/options_internal.h +8 -0
  11. data/ext/zsv/parser.c +503 -0
  12. data/ext/zsv/parser.h +75 -0
  13. data/ext/zsv/row.c +169 -0
  14. data/ext/zsv/row.h +45 -0
  15. data/ext/zsv/upstream.rb +55 -0
  16. data/ext/zsv/vendor/zsv/LICENSE +21 -0
  17. data/ext/zsv/vendor/zsv/VENDORED_FROM +2 -0
  18. data/ext/zsv/vendor/zsv/configure +1212 -0
  19. data/ext/zsv/vendor/zsv/include/zsv/api.h +375 -0
  20. data/ext/zsv/vendor/zsv/include/zsv/common.h +397 -0
  21. data/ext/zsv/vendor/zsv/include/zsv/ext/implementation.h +62 -0
  22. data/ext/zsv/vendor/zsv/include/zsv/ext/implementation_private.h +113 -0
  23. data/ext/zsv/vendor/zsv/include/zsv/ext/sheet.h +80 -0
  24. data/ext/zsv/vendor/zsv/include/zsv/ext.h +333 -0
  25. data/ext/zsv/vendor/zsv/include/zsv/utils/appname.h +51 -0
  26. data/ext/zsv/vendor/zsv/include/zsv/utils/arg.h +139 -0
  27. data/ext/zsv/vendor/zsv/include/zsv/utils/cache.h +49 -0
  28. data/ext/zsv/vendor/zsv/include/zsv/utils/clock.h +36 -0
  29. data/ext/zsv/vendor/zsv/include/zsv/utils/compiler.h +69 -0
  30. data/ext/zsv/vendor/zsv/include/zsv/utils/db.h +19 -0
  31. data/ext/zsv/vendor/zsv/include/zsv/utils/dirs.h +149 -0
  32. data/ext/zsv/vendor/zsv/include/zsv/utils/dl.h +22 -0
  33. data/ext/zsv/vendor/zsv/include/zsv/utils/emcc/fs_api.h +28 -0
  34. data/ext/zsv/vendor/zsv/include/zsv/utils/err.h +22 -0
  35. data/ext/zsv/vendor/zsv/include/zsv/utils/file-mem.h +18 -0
  36. data/ext/zsv/vendor/zsv/include/zsv/utils/file.h +125 -0
  37. data/ext/zsv/vendor/zsv/include/zsv/utils/jq.h +65 -0
  38. data/ext/zsv/vendor/zsv/include/zsv/utils/json.h +19 -0
  39. data/ext/zsv/vendor/zsv/include/zsv/utils/mem.h +19 -0
  40. data/ext/zsv/vendor/zsv/include/zsv/utils/memmem.h +13 -0
  41. data/ext/zsv/vendor/zsv/include/zsv/utils/os.h +145 -0
  42. data/ext/zsv/vendor/zsv/include/zsv/utils/output.h +34 -0
  43. data/ext/zsv/vendor/zsv/include/zsv/utils/overwrite.h +71 -0
  44. data/ext/zsv/vendor/zsv/include/zsv/utils/overwrite_writer.h +53 -0
  45. data/ext/zsv/vendor/zsv/include/zsv/utils/prop.h +119 -0
  46. data/ext/zsv/vendor/zsv/include/zsv/utils/rng.h +35 -0
  47. data/ext/zsv/vendor/zsv/include/zsv/utils/signal.h +25 -0
  48. data/ext/zsv/vendor/zsv/include/zsv/utils/sql.h +13 -0
  49. data/ext/zsv/vendor/zsv/include/zsv/utils/string.h +173 -0
  50. data/ext/zsv/vendor/zsv/include/zsv/utils/utf8.h +41 -0
  51. data/ext/zsv/vendor/zsv/include/zsv/utils/win/dl.h +25 -0
  52. data/ext/zsv/vendor/zsv/include/zsv/utils/writer.h +109 -0
  53. data/ext/zsv/vendor/zsv/include/zsv/zsv_export.h +33 -0
  54. data/ext/zsv/vendor/zsv/include/zsv.h.in +18 -0
  55. data/ext/zsv/vendor/zsv/src/Makefile +238 -0
  56. data/ext/zsv/vendor/zsv/src/vector_delim.c +60 -0
  57. data/ext/zsv/vendor/zsv/src/zsv.c +622 -0
  58. data/ext/zsv/vendor/zsv/src/zsv_internal.c +789 -0
  59. data/ext/zsv/vendor/zsv/src/zsv_scan_delim.c +285 -0
  60. data/ext/zsv/vendor/zsv/src/zsv_scan_delim_fast.c +741 -0
  61. data/ext/zsv/vendor/zsv/src/zsv_scan_fixed.c +88 -0
  62. data/ext/zsv/vendor/zsv/src/zsv_scan_simd_avx2.h +89 -0
  63. data/ext/zsv/vendor/zsv/src/zsv_scan_simd_neon.h +80 -0
  64. data/ext/zsv/vendor/zsv/src/zsv_scan_simd_sse2.h +93 -0
  65. data/ext/zsv/vendor/zsv/src/zsv_scan_simd_wasm.h +79 -0
  66. data/ext/zsv/vendor/zsv/src/zsv_strencode.c +84 -0
  67. data/ext/zsv/zsv_ext.c +417 -0
  68. data/lib/zsv/3.3/zsv.so +0 -0
  69. data/lib/zsv/3.4/zsv.so +0 -0
  70. data/lib/zsv/4.0/zsv.so +0 -0
  71. data/lib/zsv/errors.rb +32 -0
  72. data/lib/zsv/input.rb +88 -0
  73. data/lib/zsv/options.rb +132 -0
  74. data/lib/zsv/strict_validator.rb +124 -0
  75. data/lib/zsv/version.rb +5 -0
  76. data/lib/zsv.rb +183 -0
  77. metadata +196 -0
@@ -0,0 +1,285 @@
1
+ #ifdef ZSV_SUPPORT_PULL_PARSER
2
+
3
+ #define zsv_internal_save_reg(x) scanner->pull.regs->delim.x = x
4
+ #define zsv_internal_save_regs(loc) \
5
+ do { \
6
+ scanner->pull.regs->delim.location = loc; \
7
+ scanner->pull.buff = buff; \
8
+ scanner->pull.bytes_read = bytes_read; \
9
+ zsv_internal_save_reg(i); \
10
+ zsv_internal_save_reg(bytes_chunk_end); \
11
+ zsv_internal_save_reg(bytes_read); \
12
+ zsv_internal_save_reg(delimiter); \
13
+ zsv_internal_save_reg(c); \
14
+ zsv_internal_save_reg(skip_next_delim); \
15
+ zsv_internal_save_reg(quote); \
16
+ zsv_internal_save_reg(mask_total_offset); \
17
+ zsv_internal_save_reg(mask); \
18
+ zsv_internal_save_reg(mask_last_start); \
19
+ } while (0)
20
+
21
+ #define zsv_internal_restore_reg(x) x = scanner->pull.regs->delim.x
22
+ #define zsv_internal_restore_regs() \
23
+ do { \
24
+ buff = scanner->pull.buff; \
25
+ bytes_read = scanner->pull.bytes_read; \
26
+ zsv_internal_restore_reg(i); \
27
+ zsv_internal_restore_reg(bytes_chunk_end); \
28
+ zsv_internal_restore_reg(bytes_read); \
29
+ zsv_internal_restore_reg(delimiter); \
30
+ zsv_internal_restore_reg(c); \
31
+ zsv_internal_restore_reg(skip_next_delim); \
32
+ zsv_internal_restore_reg(quote); \
33
+ zsv_internal_restore_reg(mask_total_offset); \
34
+ zsv_internal_restore_reg(mask); \
35
+ zsv_internal_restore_reg(mask_last_start); \
36
+ memset(&v.dl, scanner->opts.delimiter, sizeof(zsv_uc_vector)); \
37
+ memset(&v.nl, '\n', sizeof(zsv_uc_vector)); \
38
+ memset(&v.cr, '\r', sizeof(zsv_uc_vector)); \
39
+ memset(&v.qt, scanner->opts.no_quotes > 0 ? 0 : '"', sizeof(v.qt)); \
40
+ } while (0)
41
+ #endif
42
+
43
+ static enum zsv_status ZSV_SCAN_DELIM(struct zsv_scanner *scanner, unsigned char *buff, size_t bytes_read) {
44
+ struct {
45
+ zsv_uc_vector dl;
46
+ zsv_uc_vector nl;
47
+ zsv_uc_vector cr;
48
+ zsv_uc_vector qt;
49
+ } v;
50
+
51
+ size_t i;
52
+ size_t bytes_chunk_end;
53
+ char delimiter;
54
+ unsigned char c;
55
+ char skip_next_delim;
56
+ int quote;
57
+ size_t mask_total_offset;
58
+ zsv_mask_t mask;
59
+ int mask_last_start;
60
+
61
+ #ifdef ZSV_SUPPORT_PULL_PARSER
62
+ if (scanner->pull.regs->delim.location) {
63
+ zsv_internal_restore_regs();
64
+ if (scanner->pull.regs->delim.location == 1)
65
+ goto zsv_cell_and_row_dl_1;
66
+ goto zsv_cell_and_row_dl_2;
67
+ }
68
+ #endif
69
+ bytes_read += scanner->partial_row_length;
70
+ i = scanner->partial_row_length;
71
+ skip_next_delim = 0;
72
+ bytes_chunk_end = bytes_read >= sizeof(zsv_uc_vector) ? bytes_read - sizeof(zsv_uc_vector) + 1 : 0;
73
+ delimiter = scanner->opts.delimiter;
74
+ scanner->partial_row_length = 0;
75
+
76
+ // to do: move into one-time execution code?
77
+ // (but, will also locate away from function stack)
78
+ quote = scanner->opts.no_quotes > 0 ? -1 : '"'; // ascii code 34
79
+ memset(&v.dl, delimiter, sizeof(zsv_uc_vector)); // ascii code 44
80
+ memset(&v.nl, '\n', sizeof(zsv_uc_vector)); // ascii code 10
81
+ memset(&v.cr, '\r', sizeof(zsv_uc_vector)); // ascii code 13
82
+ memset(&v.qt, scanner->opts.no_quotes > 0 ? 0 : '"', sizeof(v.qt));
83
+
84
+ if (scanner->quoted & ZSV_PARSER_QUOTE_PENDING) {
85
+ // if we're here, then the last chunk we read ended with a lone quote char inside
86
+ // a quoted cell, and we are waiting to find out whether it is followed by
87
+ // another dbl-quote e.g. if the end of the last chunk is |, we had:
88
+ // ...,"hel"|"o"
89
+ // ...,"hel"|,...
90
+ // ...,"hel"|p,...
91
+ scanner->quoted -= ZSV_PARSER_QUOTE_PENDING;
92
+ if (buff[i] != quote) {
93
+ scanner->quoted |= ZSV_PARSER_QUOTE_CLOSED;
94
+ scanner->quoted &= ~ZSV_PARSER_QUOTE_UNCLOSED; // scanner->quoted -= ZSV_PARSER_QUOTE_UNCLOSED;
95
+ scanner->quote_close_position = i - scanner->cell_start - 1;
96
+ } else {
97
+ scanner->quoted |= ZSV_PARSER_QUOTE_NEEDED;
98
+ scanner->quoted |= ZSV_PARSER_QUOTE_EMBEDDED;
99
+ i++;
100
+ }
101
+ }
102
+
103
+ #define scanner_last (i ? buff[i - 1] : scanner->last)
104
+
105
+ mask_total_offset = 0;
106
+ mask = 0;
107
+ scanner->buffer_end = bytes_read;
108
+ for (; i < bytes_read; i++) {
109
+ if (UNLIKELY(mask == 0)) {
110
+ mask_last_start = i;
111
+ if (VERY_LIKELY(i < bytes_chunk_end)) {
112
+ // keep going until we get a delim or we are at the eof
113
+ mask_total_offset = vec_delims(buff + i, bytes_read - i, &v.dl, &v.nl, &v.cr, &v.qt, &mask);
114
+ if (LIKELY(mask_total_offset != 0)) {
115
+ i += mask_total_offset;
116
+ if (VERY_UNLIKELY(mask == 0 && i == bytes_read))
117
+ break; // vector processing ended on exactly our buffer end
118
+ }
119
+ } else if (skip_next_delim) {
120
+ skip_next_delim = 0;
121
+ continue;
122
+ }
123
+ }
124
+ if (VERY_LIKELY(mask)) {
125
+ size_t next_offset = NEXT_BIT(mask);
126
+ i = mask_last_start + next_offset - 1;
127
+ mask = clear_lowest_bit(mask);
128
+ if (VERY_UNLIKELY(skip_next_delim)) {
129
+ skip_next_delim = 0;
130
+ continue;
131
+ }
132
+ }
133
+
134
+ // to do: consolidate csv and tsv/scanner->delimiter parsers
135
+ c = buff[i];
136
+ if (LIKELY(c == delimiter)) { // case ',':
137
+ if ((scanner->quoted & ZSV_PARSER_QUOTE_UNCLOSED) == 0) {
138
+ scanner->scanned_length = i;
139
+ cell_dl(scanner, buff + scanner->cell_start, i - scanner->cell_start);
140
+ scanner->cell_start = i + 1;
141
+ c = 0;
142
+ continue; // this char is not part of the cell content
143
+ } else
144
+ // we are inside an open quote, which is needed to escape this char
145
+ scanner->quoted |= ZSV_PARSER_QUOTE_NEEDED;
146
+ } else if (UNLIKELY(c == '\r')) {
147
+ #ifndef ZSV_NO_ONLY_CRLF
148
+ if (VERY_UNLIKELY(scanner->opts.only_crlf_rowend)) {
149
+ if (scanner->quoted & ZSV_PARSER_QUOTE_PENDING_LF)
150
+ // if we already had a lone \r in this cell,
151
+ // flip the flag to ZSV_PARSER_QUOTE_NEEDED
152
+ scanner->quoted |= ZSV_PARSER_QUOTE_NEEDED;
153
+ else
154
+ // otherwise this is the first \r in this cell,
155
+ // so set ZSV_PARSER_QUOTE_PENDING_LF, which
156
+ // will be removed if the next char is LF
157
+ scanner->quoted |= ZSV_PARSER_QUOTE_PENDING_LF;
158
+ continue;
159
+ }
160
+ #endif
161
+ if ((scanner->quoted & ZSV_PARSER_QUOTE_UNCLOSED) == 0) {
162
+ scanner->scanned_length = i;
163
+ enum zsv_status stat = cell_and_row_dl(scanner, buff + scanner->cell_start, i - scanner->cell_start);
164
+ if (VERY_UNLIKELY(stat))
165
+ return stat;
166
+ #ifdef ZSV_SUPPORT_PULL_PARSER
167
+ if (scanner->pull.now) {
168
+ scanner->pull.now = 0;
169
+ scanner->row.used = scanner->pull.row_used;
170
+ zsv_internal_save_regs(1);
171
+ return zsv_status_row;
172
+ }
173
+ zsv_cell_and_row_dl_1:
174
+ scanner->row.used = 0;
175
+ scanner->pull.regs->delim.location = 0;
176
+ #endif
177
+ scanner->cell_start = i + 1;
178
+ scanner->row_start = i + 1;
179
+ scanner->data_row_count++;
180
+ continue; // this char is not part of the cell content
181
+ } else
182
+ // we are inside an open quote, which is needed to escape this char
183
+ scanner->quoted |= ZSV_PARSER_QUOTE_NEEDED;
184
+ } else if (UNLIKELY(c == '\n')) {
185
+ if ((scanner->quoted & ZSV_PARSER_QUOTE_UNCLOSED) == 0) {
186
+ int is_crlf = (scanner_last == '\r');
187
+
188
+ // Handle logic for when we should SKIP this char (not a row end)
189
+ #ifndef ZSV_NO_ONLY_CRLF
190
+ if (VERY_UNLIKELY(scanner->opts.only_crlf_rowend)) {
191
+ if (!is_crlf) {
192
+ scanner->quoted |= ZSV_PARSER_QUOTE_NEEDED;
193
+ continue; // only-crlf mode: ignore lone \n
194
+ } else
195
+ // remove ZSV_PARSER_QUOTE_PENDING_LF if we have it
196
+ scanner->quoted &= ~ZSV_PARSER_QUOTE_PENDING_LF;
197
+ } else
198
+ #endif
199
+ {
200
+ if (is_crlf) {
201
+ // Standard mode: ignore \n because \r already handled the row end
202
+ scanner->cell_start = i + 1;
203
+ scanner->row_start = i + 1;
204
+ continue;
205
+ }
206
+ }
207
+
208
+ // If we reached here, this is a row end
209
+ scanner->scanned_length = i;
210
+
211
+ // Calculate cell length. In only-crlf mode, we must exclude the preceding \r
212
+ size_t cell_len = i - scanner->cell_start;
213
+ #ifndef ZSV_NO_ONLY_CRLF
214
+ if (VERY_UNLIKELY(scanner->opts.only_crlf_rowend))
215
+ cell_len--;
216
+ #endif
217
+ enum zsv_status stat = cell_and_row_dl(scanner, buff + scanner->cell_start, cell_len);
218
+ if (VERY_UNLIKELY(stat))
219
+ return stat;
220
+ #ifdef ZSV_SUPPORT_PULL_PARSER
221
+ if (scanner->pull.now) {
222
+ scanner->pull.now = 0;
223
+ scanner->row.used = scanner->pull.row_used;
224
+ zsv_internal_save_regs(2);
225
+ return zsv_status_row;
226
+ }
227
+ zsv_cell_and_row_dl_2:
228
+ scanner->row.used = 0;
229
+ scanner->pull.regs->delim.location = 0;
230
+ #endif
231
+ scanner->cell_start = i + 1;
232
+ scanner->row_start = i + 1;
233
+ scanner->data_row_count++;
234
+ continue; // this char is not part of the cell content
235
+ } else
236
+ // we are inside an open quote, which is needed to escape this char
237
+ scanner->quoted |= ZSV_PARSER_QUOTE_NEEDED;
238
+ } else if (LIKELY(c == quote)) {
239
+ if (i == scanner->cell_start && !scanner->buffer_exceeded) {
240
+ scanner->quoted = ZSV_PARSER_QUOTE_UNCLOSED;
241
+ scanner->quote_close_position = 0;
242
+ c = 0;
243
+ } else if (scanner->quoted & ZSV_PARSER_QUOTE_UNCLOSED) {
244
+ // the cell started with a quote that is not yet closed
245
+ if (VERY_LIKELY(i + 1 < bytes_read)) {
246
+ if (LIKELY(buff[i + 1] != quote)) {
247
+ // buff[i] is the closing quote (not an escaped quote)
248
+ scanner->quoted |= ZSV_PARSER_QUOTE_CLOSED;
249
+ scanner->quoted -= ZSV_PARSER_QUOTE_UNCLOSED;
250
+
251
+ // keep track of closing quote position to handle the edge case
252
+ // where content follows the closing quote e.g. cell content is:
253
+ // "this-cell"-did-not-need-quotes
254
+ if (LIKELY(scanner->quote_close_position == 0))
255
+ scanner->quote_close_position = i - scanner->cell_start;
256
+ } else {
257
+ // next char is also '"'
258
+ // e.g. cell content is: "this "" is a dbl quote"
259
+ // cursor is here => ^
260
+ // include in cell content and don't further process
261
+ scanner->quoted |= ZSV_PARSER_QUOTE_NEEDED;
262
+ scanner->quoted |= ZSV_PARSER_QUOTE_EMBEDDED;
263
+ skip_next_delim = 1;
264
+ }
265
+ } else // we are at the end of this input chunk
266
+ scanner->quoted |= ZSV_PARSER_QUOTE_PENDING;
267
+ } else {
268
+ // cell_length > 0 and cell did not start w quote, so
269
+ // we have a quote in middle of an unquoted cell
270
+ // process as a normal char
271
+ scanner->quoted |= ZSV_PARSER_QUOTE_EMBEDDED;
272
+ scanner->quote_close_position = scanner->quoted & ZSV_PARSER_QUOTE_CLOSED ? scanner->quote_close_position : 0;
273
+ }
274
+ }
275
+ }
276
+ scanner->scanned_length = i;
277
+
278
+ // save bytes_read-- we will need to shift any remaining partial row
279
+ // before we read next from our input. however, we intentionally refrain
280
+ // from doing this until the next parse_more() call, so that the entirety
281
+ // of all rows parsed thus far are still available until that next call
282
+ scanner->old_bytes_read = bytes_read;
283
+
284
+ return zsv_status_ok;
285
+ }