| line |
true |
false |
branch |
|
62
|
2 |
176 |
: SEPARATED_FIELD_DEFAULT_CAP; |
|
72
|
178 |
21700894 |
if (ctx->buf_len + 1 > ctx->buf_cap) { |
|
73
|
15 |
163 |
size_t new_cap = ctx->buf_cap ? ctx->buf_cap * 2 : 64; |
|
76
|
2 |
176 |
if (new_cap > cap_max) new_cap = cap_max; |
|
77
|
1 |
177 |
if (new_cap <= ctx->buf_len) { |
|
81
|
0 |
177 |
if (!new_buf) return SEPARATED_ERR_NOMEM; |
|
106
|
10 |
1 |
while (start < len && (buf[start] == ' ' || buf[start] == '\t')) start++; |
|
|
5 |
5 |
while (start < len && (buf[start] == ' ' || buf[start] == '\t')) start++; |
|
|
1 |
4 |
while (start < len && (buf[start] == ' ' || buf[start] == '\t')) start++; |
|
108
|
7 |
1 |
while (end > start && (buf[end - 1] == ' ' || buf[end - 1] == '\t')) end--; |
|
|
2 |
5 |
while (end > start && (buf[end - 1] == ' ' || buf[end - 1] == '\t')) end--; |
|
|
1 |
4 |
while (end > start && (buf[end - 1] == ' ' || buf[end - 1] == '\t')) end--; |
|
109
|
3 |
2 |
if (start > 0) memmove(buf, buf + start, end - start); |
|
124
|
6 |
921383 |
if (ctx->opts.trim && !ctx->field_was_quoted) { |
|
|
5 |
1 |
if (ctx->opts.trim && !ctx->field_was_quoted) { |
|
128
|
6 |
921383 |
if (ctx->opts.empty_is_undef |
|
129
|
5 |
1 |
&& !ctx->field_was_quoted |
|
130
|
2 |
3 |
&& ctx->buf_len == 0) { |
|
135
|
921377 |
10 |
const char *p = ctx->buf_len ? ctx->buf : ""; |
|
138
|
3 |
921383 |
if (call_rc != 0) return SEPARATED_ERR_ABORTED; |
|
143
|
110611 |
810772 |
if (end_of_row) { |
|
160
|
328 |
173 |
if (ctx->bom_checked) return; |
|
163
|
3 |
170 |
if (ctx->opts.binary) return; |
|
165
|
162 |
8 |
if (*plen >= 3) { |
|
167
|
1 |
161 |
if (u[0] == 0xEF && u[1] == 0xBB && u[2] == 0xBF) { |
|
|
1 |
0 |
if (u[0] == 0xEF && u[1] == 0xBB && u[2] == 0xBF) { |
|
|
1 |
0 |
if (u[0] == 0xEF && u[1] == 0xBB && u[2] == 0xBF) { |
|
248
|
14 |
22622305 |
if (ctx->pending_cr) { |
|
249
|
12 |
2 |
if (is_lf(c)) { |
|
251
|
8 |
4 |
if (ctx->opts.eol_mode == SEPARATED_EOL_AUTO) { |
|
253
|
2 |
2 |
} else if (ctx->opts.eol_mode != SEPARATED_EOL_CRLF |
|
254
|
2 |
0 |
&& ctx->opts.strict) { |
|
265
|
1 |
1 |
if (ctx->opts.eol_mode == SEPARATED_EOL_AUTO) { |
|
267
|
0 |
1 |
} else if (ctx->opts.eol_mode != SEPARATED_EOL_CR |
|
268
|
0 |
0 |
&& ctx->opts.strict) { |
|
276
|
16 |
22622289 |
if (is_cr(c)) { |
|
280
|
110604 |
22511685 |
if (is_lf(c)) { |
|
281
|
110600 |
4 |
if (ctx->opts.eol_mode == SEPARATED_EOL_AUTO) { |
|
283
|
0 |
4 |
} else if (ctx->opts.eol_mode != SEPARATED_EOL_LF |
|
284
|
0 |
0 |
&& ctx->opts.strict) { |
|
298
|
0 |
501 |
if (ctx->sticky_err) return ctx->sticky_err; |
|
303
|
22622575 |
487 |
while (i < len) { |
|
308
|
256 |
22622319 |
if (ctx->state == ST_IN_QUOTED) { |
|
309
|
12 |
244 |
if (ctx->opts.escape >= 0 && c == ctx->opts.escape) { |
|
|
2 |
10 |
if (ctx->opts.escape >= 0 && c == ctx->opts.escape) { |
|
311
|
0 |
2 |
if (i + 1 >= len) { |
|
322
|
0 |
0 |
PUTC(c); /* fall back to literal escape char */ |
|
327
|
0 |
2 |
PUTC(buf[i + 1]); |
|
332
|
52 |
202 |
if (c == ctx->opts.quote) { |
|
338
|
0 |
202 |
PUTC(c); |
|
346
|
18 |
22622301 |
if (eol < 0 && ctx->sticky_err) return ctx->sticky_err; |
|
|
2 |
16 |
if (eol < 0 && ctx->sticky_err) return ctx->sticky_err; |
|
348
|
110614 |
22511703 |
if (eol == 1) { |
|
355
|
26 |
110588 |
if (ctx->any_field_in_row || ctx->buf_len > 0 |
|
|
6 |
20 |
if (ctx->any_field_in_row || ctx->buf_len > 0 |
|
356
|
0 |
6 |
|| ctx->state != ST_START_FIELD) { |
|
358
|
3 |
110602 |
if (e != SEPARATED_OK) FAIL(e); |
|
363
|
2 |
22511701 |
if (eol == 2) { |
|
371
|
0 |
2 |
if (ctx->any_field_in_row || ctx->buf_len > 0 |
|
|
0 |
0 |
if (ctx->any_field_in_row || ctx->buf_len > 0 |
|
372
|
0 |
0 |
|| ctx->state != ST_START_FIELD) { |
|
374
|
0 |
2 |
if (e != SEPARATED_OK) FAIL(e); |
|
380
|
16 |
22511685 |
if (eol == -1) { |
|
390
|
6 |
921388 |
if (c == ctx->opts.sep) { |
|
391
|
0 |
6 |
EMIT(0); /* empty field, more to come on this row */ |
|
392
|
921296 |
92 |
} else if (ctx->opts.quote >= 0 && c == ctx->opts.quote) { |
|
|
40 |
921256 |
} else if (ctx->opts.quote >= 0 && c == ctx->opts.quote) { |
|
396
|
0 |
921348 |
PUTC(c); |
|
402
|
810739 |
20779509 |
if (c == ctx->opts.sep) { |
|
403
|
0 |
810739 |
EMIT(0); |
|
405
|
20779458 |
51 |
} else if (ctx->opts.quote >= 0 && c == ctx->opts.quote) { |
|
|
6 |
20779452 |
} else if (ctx->opts.quote >= 0 && c == ctx->opts.quote) { |
|
406
|
3 |
3 |
if (ctx->opts.strict) FAIL(SEPARATED_ERR_BAD_QUOTE); |
|
408
|
0 |
3 |
PUTC(c); |
|
410
|
1 |
20779502 |
PUTC(c); |
|
415
|
12 |
31 |
if (c == ctx->opts.quote) { |
|
417
|
0 |
12 |
PUTC(c); |
|
419
|
27 |
4 |
} else if (c == ctx->opts.sep) { |
|
420
|
0 |
27 |
EMIT(0); |
|
423
|
2 |
2 |
if (ctx->opts.strict) FAIL(SEPARATED_ERR_BAD_QUOTE); |
|
426
|
0 |
2 |
PUTC(c); |
|
450
|
0 |
160 |
if (ctx->sticky_err) return ctx->sticky_err; |
|
453
|
2 |
158 |
if (ctx->pending_cr) { |
|
454
|
1 |
1 |
if (ctx->opts.eol_mode == SEPARATED_EOL_AUTO) { |
|
456
|
0 |
1 |
} else if (ctx->opts.eol_mode != SEPARATED_EOL_CR |
|
457
|
0 |
0 |
&& ctx->opts.strict) { |
|
461
|
0 |
2 |
if (ctx->any_field_in_row || ctx->buf_len > 0 |
|
|
0 |
0 |
if (ctx->any_field_in_row || ctx->buf_len > 0 |
|
462
|
0 |
0 |
|| ctx->state != ST_START_FIELD) { |
|
464
|
0 |
2 |
if (e != SEPARATED_OK) FAIL(e); |
|
471
|
0 |
158 |
if (ctx->state == ST_IN_QUOTED) { |
|
472
|
0 |
0 |
if (ctx->opts.strict) FAIL(SEPARATED_ERR_BAD_QUOTE); |
|
478
|
153 |
5 |
if (ctx->any_field_in_row || ctx->buf_len > 0 |
|
|
153 |
0 |
if (ctx->any_field_in_row || ctx->buf_len > 0 |
|
479
|
153 |
0 |
|| ctx->state == ST_IN_UNQUOTED |
|
480
|
153 |
0 |
|| ctx->state == ST_IN_QUOTED |
|
481
|
0 |
153 |
|| ctx->state == ST_MAYBE_END_QUOTE) { |
|
483
|
0 |
5 |
if (e != SEPARATED_OK) FAIL(e); |
|
518
|
0 |
175 |
if (!ctx) return NULL; |
|
529
|
0 |
172 |
if (!ctx) return; |
|
550
|
0 |
148 |
if (!ctx) { |
|
551
|
0 |
0 |
if (err_offset) *err_offset = 0; |
|
556
|
137 |
8 |
if (e == SEPARATED_OK) { |
|
560
|
8 |
137 |
if (e != SEPARATED_OK) { |
|
561
|
8 |
0 |
if (err_offset) *err_offset = ctx->err_offset; |
|
564
|
137 |
0 |
if (err_offset) *err_offset = len; |