CSV_XS.xs

filter: Statementstmt 96.9% 1128 / 1163 Branchbran 55.9% 1586 / 2836 Conditioncond n/a MC/DCmcdc n/a Subroutinesub n/a Podpod n/a totaltotal 67.8% 2714 / 3999 CC 0 SCAR 0
CC
0
Cov
0%
CRAP 0
« blib/lib/Text/CSV_XS.pm ↑ Summary
1 /* Copyright (c) 2007-2026 H.Merijn Brand. All rights reserved.
2 * Copyright (c) 1998-2001 Jochen Wiedmann. All rights reserved.
3 * This program is free software; you can redistribute it and/or
4 * modify it under the same terms as Perl itself.
5 */
6 #define PERL_NO_GET_CONTEXT
7 #include <EXTERN.h>
8 #include <perl.h>
9 #include <XSUB.h>
10 #define DPPP_PL_parser_NO_DUMMY
11 #define NEED_utf8_to_uvchr_buf
12 #define NEED_my_snprintf
13 #define NEED_pv_escape
14 #define NEED_pv_pretty
15 #ifndef PERLIO_F_UTF8
16 # define PERLIO_F_UTF8 0x00008000
17 # endif
18 #ifndef MAXINT
19 # define MAXINT ((int)(~(unsigned)0 >> 1))
20 # endif
21 #include "ppport.h"
22 #define is_utf8_sv(s) is_utf8_string ((U8 *)SvPV_nolen (s), SvCUR (s))
23  
24 #define MAINT_DEBUG 0
25 #define MAINT_DEBUG_EOL 0
26  
27 #define BUFFER_SIZE 1024
28  
29 #define CSV_XS_TYPE_WARN 1
30 #define CSV_XS_TYPE_PV 0
31 #define CSV_XS_TYPE_IV 1
32 #define CSV_XS_TYPE_NV 2
33  
34 /* maximum length for EOL, SEP, and QUOTE - keep in sync with .pm */
35 #define MAX_ATTR_LEN 16
36  
37 #define CSV_FLAGS_QUO 0x0001
38 #define CSV_FLAGS_BIN 0x0002
39 #define CSV_FLAGS_EIF 0x0004
40 #define CSV_FLAGS_MIS 0x0010
41  
42 #define HOOK_ERROR 0x0001
43 #define HOOK_AFTER_PARSE 0x0002
44 #define HOOK_BEFORE_PRINT 0x0004
45  
46 #ifdef __THW_370__
47 /* EBCDIC on os390 z/OS: IS_EBCDIC reads better than __THW_370__ */
48 #define IS_EBCDIC
49 #endif
50  
51 #define CH_TAB '\t'
52 #define CH_NL '\n'
53 #define CH_CR '\r'
54 #define CH_SPACE ' '
55 #define CH_QUO '"'
56  
57 #ifdef IS_EBCDIC
58 #define CH_DEL '\007'
59 static unsigned char ec, ebcdic2ascii[256] = {
60 0x00, 0x01, 0x02, 0x03, 0x9c, 0x09, 0x86, 0x7f,
61 0x97, 0x8d, 0x8e, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f,
62 0x10, 0x11, 0x12, 0x13, 0x9d, 0x0a, 0x08, 0x87,
63 0x18, 0x19, 0x92, 0x8f, 0x1c, 0x1d, 0x1e, 0x1f,
64 0x80, 0x81, 0x82, 0x83, 0x84, 0x85, 0x17, 0x1b,
65 0x88, 0x89, 0x8a, 0x8b, 0x8c, 0x05, 0x06, 0x07,
66 0x90, 0x91, 0x16, 0x93, 0x94, 0x95, 0x96, 0x04,
67 0x98, 0x99, 0x9a, 0x9b, 0x14, 0x15, 0x9e, 0x1a,
68 0x20, 0xa0, 0xe2, 0xe4, 0xe0, 0xe1, 0xe3, 0xe5,
69 0xe7, 0xf1, 0xa2, 0x2e, 0x3c, 0x28, 0x2b, 0x7c,
70 0x26, 0xe9, 0xea, 0xeb, 0xe8, 0xed, 0xee, 0xef,
71 0xec, 0xdf, 0x21, 0x24, 0x2a, 0x29, 0x3b, 0x5e,
72 0x2d, 0x2f, 0xc2, 0xc4, 0xc0, 0xc1, 0xc3, 0xc5,
73 0xc7, 0xd1, 0xa6, 0x2c, 0x25, 0x5f, 0x3e, 0x3f,
74 0xf8, 0xc9, 0xca, 0xcb, 0xc8, 0xcd, 0xce, 0xcf,
75 0xcc, 0x60, 0x3a, 0x23, 0x40, 0x27, 0x3d, 0x22,
76 0xd8, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67,
77 0x68, 0x69, 0xab, 0xbb, 0xf0, 0xfd, 0xfe, 0xb1,
78 0xb0, 0x6a, 0x6b, 0x6c, 0x6d, 0x6e, 0x6f, 0x70,
79 0x71, 0x72, 0xaa, 0xba, 0xe6, 0xb8, 0xc6, 0xa4,
80 0xb5, 0x7e, 0x73, 0x74, 0x75, 0x76, 0x77, 0x78,
81 0x79, 0x7a, 0xa1, 0xbf, 0xd0, 0x5b, 0xde, 0xae,
82 0xac, 0xa3, 0xa5, 0xb7, 0xa9, 0xa7, 0xb6, 0xbc,
83 0xbd, 0xbe, 0xdd, 0xa8, 0xaf, 0x5d, 0xb4, 0xd7,
84 0x7b, 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47,
85 /* v this 0xa0 really should be 0xad. Needed for UTF = binary */
86 0x48, 0x49, 0xa0, 0xf4, 0xf6, 0xf2, 0xf3, 0xf5,
87 0x7d, 0x4a, 0x4b, 0x4c, 0x4d, 0x4e, 0x4f, 0x50,
88 0x51, 0x52, 0xb9, 0xfb, 0xfc, 0xf9, 0xfa, 0xff,
89 0x5c, 0xf7, 0x53, 0x54, 0x55, 0x56, 0x57, 0x58,
90 0x59, 0x5a, 0xb2, 0xd4, 0xd6, 0xd2, 0xd3, 0xd5,
91 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37,
92 0x38, 0x39, 0xb3, 0xdb, 0xdc, 0xd9, 0xda, 0x9f
93 };
94 #define is_csv_binary(ch) ((((ec = ebcdic2ascii[ch]) < 0x20 || ec >= 0x7f) && ch != CH_TAB) || ch == EOF)
95 #else
96 #define CH_DEL '\177'
97 #define is_csv_binary(ch) ((ch < CH_SPACE || ch >= CH_DEL) && ch != CH_TAB)
98 #endif
99 #define CH_EOLX 1215
100 #define CH_EOL *csv->eol
101 #define CH_SEPX 8888
102 #define CH_SEP *csv->sep
103 #define CH_QUOTEX 8889
104 #define CH_QUOTE *csv->quo
105  
106 #define useIO_EOF 0x10
107  
108 #define unless(expr) if (!(expr))
109  
110 #define _is_reftype(f,x) \
111 (f && ((SvGMAGICAL (f) && mg_get (f)) || 1) && SvROK (f) && SvTYPE (SvRV (f)) == x)
112 #define _is_arrayref(f) _is_reftype (f, SVt_PVAV)
113 #define _is_hashref(f) _is_reftype (f, SVt_PVHV)
114 #define _is_coderef(f) _is_reftype (f, SVt_PVCV)
115  
116 #define SvSetUndef(sv) sv_setpvn (sv, NULL, 0)
117 #define SvSetEmpty(sv) sv_setpvn_mg (sv, "", 0)
118  
119 #define CSV_XS_SELF \
120 if (!self || !SvOK (self) || !SvROK (self) || \
121 SvTYPE (SvRV (self)) != SVt_PVHV) \
122 croak ("self is not a hash ref"); \
123 hv = (HV *)SvRV (self)
124  
125 #define undef &PL_sv_undef
126 #define PUT_RETURN(x) \
127 SPAGAIN; \
128 ST (0) = x; \
129 XSRETURN (1)
130  
131 /* Keep in sync with .pm! */
132 #define CACHE_ID_quote_char 0
133 #define CACHE_ID_escape_char 1
134 #define CACHE_ID_sep_char 2
135 #define CACHE_ID_always_quote 4
136 #define CACHE_ID_quote_empty 5
137 #define CACHE_ID_quote_space 6
138 #define CACHE_ID_quote_binary 7
139 #define CACHE_ID_allow_loose_quotes 8
140 #define CACHE_ID_allow_loose_escapes 9
141 #define CACHE_ID_allow_unquoted_escape 10
142 #define CACHE_ID_allow_whitespace 11
143 #define CACHE_ID_blank_is_undef 12
144 #define CACHE_ID_empty_is_undef 13
145 #define CACHE_ID_auto_diag 14
146 #define CACHE_ID_diag_verbose 15
147 #define CACHE_ID_escape_null 16
148 #define CACHE_ID_formula 18
149 #define CACHE_ID_has_error_input 20
150 #define CACHE_ID_decode_utf8 21
151 #define CACHE_ID_verbatim 23
152 #define CACHE_ID_strict_eol 24
153 #define CACHE_ID_eol_is_cr 26
154 #define CACHE_ID_eol_type 27
155 #define CACHE_ID_strict 28
156 #define CACHE_ID_skip_empty_rows 29
157 #define CACHE_ID_binary 30
158 #define CACHE_ID_keep_meta_info 31
159 #define CACHE_ID__has_hooks 32
160 #define CACHE_ID__has_ahead 33
161 #define CACHE_ID_eol_len 36
162 #define CACHE_ID_sep_len 37
163 #define CACHE_ID_quo_len 38
164 #define CACHE_ID__is_bound 44
165 #define CACHE_ID_types 92
166 #define CACHE_ID_eol 100
167 #define CACHE_ID_sep 116
168 #define CACHE_ID_quo 132
169 #define CACHE_ID_undef_str 148
170 #define CACHE_ID_comment_str 156
171  
172 #define EOL_TYPE_UNDEF 0
173 #define EOL_TYPE_NL 1
174 #define EOL_TYPE_CR 2
175 #define EOL_TYPE_CRNL 3
176 #define EOL_TYPE_OTHER 4
177 #define EOL_TYPE(c) ((((char)c) == CH_NL) ? EOL_TYPE_NL : (((char)c) == CH_CR) ? EOL_TYPE_CR : EOL_TYPE_OTHER)
178 #define SET_EOL_TYPE(c,t) { \
179 unless (c->eol_type) { \
180 c->eol_type = t; \
181 c->cache[CACHE_ID_eol_type] = t;\
182 } \
183 }
184  
185 #define byte unsigned char
186 #define ulng unsigned long
187 typedef struct {
188 byte quote_char; /* 0 */
189 byte escape_char; /* 1 */
190 byte _sep_char; /* 2 : reserved for sep_char */
191 byte fld_idx; /* 3 */
192  
193 byte always_quote; /* 4 */
194 byte quote_empty; /* 5 */
195 byte quote_space; /* 6 */
196 byte quote_binary; /* 7 */
197  
198 byte allow_loose_quotes; /* 8 */
199 byte allow_loose_escapes; /* 9 */
200 byte allow_unquoted_escape; /* 10 */
201 byte allow_whitespace; /* 11 */
202  
203 byte blank_is_undef; /* 12 */
204 byte empty_is_undef; /* 13 */
205 byte auto_diag; /* 14 */
206 byte diag_verbose; /* 15 */
207  
208 byte escape_null; /* 16 */
209 byte first_safe_char; /* 17 */
210 byte formula; /* 18 */
211 byte utf8; /* 19 */
212  
213 byte has_error_input; /* 20 */
214 byte decode_utf8; /* 21 */
215 byte useIO; /* 22: Also used to indicate EOF */
216 byte verbatim; /* 23 */
217  
218 byte strict_eol; /* 24 */
219 byte eolx; /* 25 */
220 byte eol_is_cr; /* 26 */
221 byte eol_type; /* 27 */
222  
223 byte strict; /* 28 */
224 byte skip_empty_rows; /* 29 */
225 byte binary; /* 30 */
226 byte keep_meta_info; /* 31 */
227  
228 byte has_hooks; /* 32 */
229 byte has_ahead; /* 33 */
230 byte nyi_1; /* 34 : free */
231 byte nyi_2; /* 35 : free */
232  
233 byte eol_len; /* 36 */
234 byte sep_len; /* 37 */
235 byte quo_len; /* 38 */
236 byte types_len; /* 39 */
237  
238 short strict_n; /* 40.. */
239 long is_bound; /* 44.. */
240 ulng recno; /* 52.. */
241 byte * cache; /* 60.. */
242 SV * pself; /* 68.. PL_self, for error_diag */
243 HV * self; /* 76.. */
244 SV * bound; /* 84.. */
245 char * types; /* 92.. */
246  
247 byte eol[MAX_ATTR_LEN]; /* 100..115 */
248 byte sep[MAX_ATTR_LEN]; /* 116..131 */
249 byte quo[MAX_ATTR_LEN]; /* 132..147 */
250  
251 byte * undef_str; /* 148.. */
252 byte * comment_str; /* 156.. */
253  
254 char * bptr;
255 SV * tmp;
256 int eol_pos;
257 STRLEN size;
258 STRLEN used;
259 byte undef_flg;
260 char buffer[BUFFER_SIZE];
261 /* Likely 1240 bytes */
262 } csv_t;
263  
264 #define bool_opt_def(o,d) \
265 (((svp = hv_fetchs (self, o, FALSE)) && *svp) ? SvTRUE (*svp) : d)
266 #define bool_opt(o) bool_opt_def (o, 0)
267 #define num_opt_def(o,d) \
268 (((svp = hv_fetchs (self, o, FALSE)) && *svp) ? SvIV (*svp) : d)
269 #define num_opt(o) num_opt_def (o, 0)
270  
271 typedef struct {
272 int xs_errno;
273 const char *xs_errstr;
274 } xs_error_t;
275 static const xs_error_t xs_errors[] = {
276  
277 /* Generic errors */
278 { 1000, "INI - constructor failed" },
279 { 1001, "INI - sep_char is equal to quote_char or escape_char" },
280 { 1002, "INI - allow_whitespace with escape_char or quote_char SP or TAB" },
281 { 1003, "INI - \\r or \\n in main attr not allowed" },
282 { 1004, "INI - callbacks should be undef or a hashref" },
283 { 1005, "INI - EOL too long" },
284 { 1006, "INI - SEP too long" },
285 { 1007, "INI - QUOTE too long" },
286 { 1008, "INI - SEP undefined" },
287  
288 { 1010, "INI - the header is empty" },
289 { 1011, "INI - the header contains more than one valid separator" },
290 { 1012, "INI - the header contains an empty field" },
291 { 1013, "INI - the header contains non-unique fields" },
292 { 1014, "INI - header called on undefined stream" },
293  
294 /* Syntax errors */
295 { 1500, "PRM - Invalid/unsupported argument(s)" },
296 { 1501, "PRM - The key attribute is passed as an unsupported type" },
297 { 1502, "PRM - The value attribute is passed without the key attribute" },
298 { 1503, "PRM - The value attribute is passed as an unsupported type" },
299  
300 /* Parse errors */
301 { 2010, "ECR - QUO char inside quotes followed by CR not part of EOL" },
302 { 2011, "ECR - Characters after end of quoted field" },
303 { 2012, "EOF - End of data in parsing input stream" },
304 { 2013, "ESP - Specification error for fragments RFC7111" },
305 { 2014, "ENF - Inconsistent number of fields" },
306 { 2015, "ERW - Empty row" },
307 { 2016, "EOL - Inconsistent EOL" },
308  
309 /* EIQ - Error Inside Quotes */
310 { 2021, "EIQ - NL char inside quotes, binary off" },
311 { 2022, "EIQ - CR char inside quotes, binary off" },
312 { 2023, "EIQ - QUO character not allowed" },
313 { 2024, "EIQ - EOF cannot be escaped, not even inside quotes" },
314 { 2025, "EIQ - Loose unescaped escape" },
315 { 2026, "EIQ - Binary character inside quoted field, binary off" },
316 { 2027, "EIQ - Quoted field not terminated" },
317  
318 /* EIF - Error Inside Field */
319 { 2030, "EIF - NL char inside unquoted verbatim, binary off" },
320 { 2031, "EIF - CR char is first char of field, not part of EOL" },
321 { 2032, "EIF - CR char inside unquoted, not part of EOL" },
322 { 2034, "EIF - Loose unescaped quote" },
323 { 2035, "EIF - Escaped EOF in unquoted field" },
324 { 2036, "EIF - ESC error" },
325 { 2037, "EIF - Binary character in unquoted field, binary off" },
326  
327 /* Combine errors */
328 { 2110, "ECB - Binary character in Combine, binary off" },
329  
330 /* IO errors */
331 { 2200, "EIO - print to IO failed. See errno" },
332  
333 /* Hash-Ref errors */
334 { 3001, "EHR - Unsupported syntax for column_names ()" },
335 { 3002, "EHR - getline_hr () called before column_names ()" },
336 { 3003, "EHR - bind_columns () and column_names () fields count mismatch" },
337 { 3004, "EHR - bind_columns () only accepts refs to scalars" },
338 { 3006, "EHR - bind_columns () did not pass enough refs for parsed fields" },
339 { 3007, "EHR - bind_columns needs refs to writable scalars" },
340 { 3008, "EHR - unexpected error in bound fields" },
341 { 3009, "EHR - print_hr () called before column_names ()" },
342 { 3010, "EHR - print_hr () called with invalid arguments" },
343  
344 { 4001, "PRM - The key does not exist as field in the data" },
345  
346 { 5001, "PRM - The result does not match the output to append to" },
347 { 5002, "PRM - Unsupported output" },
348  
349 { 0, "" },
350 };
351  
352 static int last_error = 0;
353 static SV *m_getline, *m_print;
354  
355 #define is_EOL(c) (c == CH_EOLX)
356  
357 #define __is_SEPX(c) (c == CH_SEP && (csv->sep_len == 0 || (\
358 csv->size - csv->used >= (STRLEN)csv->sep_len - 1 &&\
359 !memcmp (csv->bptr + csv->used, csv->sep + 1, csv->sep_len - 1) &&\
360 (csv->used += csv->sep_len - 1) &&\
361 (c = CH_SEPX))))
362 #if MAINT_DEBUG > 1
363 static byte _is_SEPX (unsigned int c, csv_t *csv, int line) {
364 unsigned int b = __is_SEPX (c);
365 (void)fprintf (stderr, "# %4d - is_SEPX:\t%d (%d)\n", line, b, csv->sep_len);
366 if (csv->sep_len)
367 (void)fprintf (stderr,
368 "# len: %d, siz: %d, usd: %d, c: %03x, *sep: %03x\n",
369 csv->sep_len, csv->size, csv->used, c, CH_SEP);
370 return b;
371 } /* _is_SEPX */
372 #define is_SEP(c) _is_SEPX (c, csv, __LINE__)
373 #else
374 #define is_SEP(c) __is_SEPX (c)
375 #endif
376  
377 #define __is_QUOTEX(c) (CH_QUOTE && c == CH_QUOTE && (csv->quo_len == 0 || (\
378 csv->size - csv->used >= (STRLEN)csv->quo_len - 1 &&\
379 !memcmp (csv->bptr + csv->used, csv->quo + 1, csv->quo_len - 1) &&\
380 (csv->used += csv->quo_len - 1) &&\
381 (c = CH_QUOTEX))))
382 #if MAINT_DEBUG > 1
383 static byte _is_QUOTEX (unsigned int c, csv_t *csv, int line) {
384 unsigned int b = __is_QUOTEX (c);
385 (void)fprintf (stderr, "# %4d - is_QUOTEX:\t%d (%d)\n", line, b, csv->quo_len);
386  
387 if (csv->quo_len)
388 (void)fprintf (stderr,
389 "# len: %d, siz: %d, usd: %d, c: %03x, *quo: %03x\n",
390 csv->quo_len, csv->size, csv->used, c, CH_QUOTE);
391 return b;
392 } /* _is_QUOTEX */
393 #define is_QUOTE(c) _is_QUOTEX (c, csv, __LINE__)
394 #else
395 #define is_QUOTE(c) __is_QUOTEX (c)
396 #endif
397  
398 #define is_whitespace(ch) \
399 ( (ch) != CH_SEP && \
400 (ch) != CH_QUOTE && \
401 (ch) != csv->escape_char && \
402 ( (ch) == CH_SPACE || \
403 (ch) == CH_TAB \
404 ) \
405 )
406  
407 #define _pretty_strl(cp) cx_pretty_str (aTHX_ cp, strlen (cp))
408 #define _pretty_str(cp,xse) cx_pretty_str (aTHX_ cp, xse)
409 9 static char *cx_pretty_str (pTHX_ byte *s, STRLEN l) {
410 9 SV *dsv = newSVpvs_flags ("", SVs_TEMP);
411 9 return (pv_pretty (dsv, (char *)s, l, 0, NULL, NULL,
412 (PERL_PV_PRETTY_DUMP | PERL_PV_ESCAPE_UNI_DETECT)));
413 } /* _pretty_str */
414 #if MAINT_DEBUG > 4
415 #define _pretty_sv(cp) cx_pretty_sv (aTHX_ cp)
416 static char *cx_pretty_sv (pTHX_ SV *sv) {
417 if (SvOK (sv) && SvPOK (sv)) {
418 STRLEN l;
419 char *s = SvPV (sv, l);
420 return _pretty_str ((byte *)s, l);
421 }
422 return ("");
423 } /* _pretty_sv */
424 #endif
425  
426 #define SvDiag(xse) cx_SvDiag (aTHX_ xse)
427 3998 static SV *cx_SvDiag (pTHX_ int xse) {
428 3998 int i = 0;
429 SV *err;
430  
431 82917 ▶ while (xs_errors[i].xs_errno && xs_errors[i].xs_errno != xse) i++;
Branch: 2 branches
BranchTrueFalseTotal
while (xs_errors[i].xs_errno && xs_errors[i].xs_errno != xse) i++; 81880 1037 82917
while (xs_errors[i].xs_errno && xs_errors[i].xs_errno != xse) i++; 78919 2961 81880
432 3998 ▶ if ((err = newSVpv (xs_errors[i].xs_errstr, 0))) {
Branch: 1 branch
BranchTrueFalseTotal
if ((err = newSVpv (xs_errors[i].xs_errstr, 0))) { 3998 0 3998
433 3998 ▶ (void)SvUPGRADE (err, SVt_PVIV);
Branch: 1 branch
BranchTrueFalseTotal
(void)SvUPGRADE (err, SVt_PVIV); 3998 0 3998
434 3998 SvIV_set (err, xse);
435 3998 SvIOK_on (err);
436 }
437 3998 return (err);
438 } /* SvDiag */
439  
440 /* This function should be altered to deal with the optional extra argument
441 * that holds the replacement message */
442 #define SetDiag(csv,xse) cx_SetDiag (aTHX_ csv, xse, __LINE__)
443 #define SetDiagL(csv,xse,line) cx_SetDiag (aTHX_ csv, xse, line)
444 1882 static SV *cx_SetDiag (pTHX_ csv_t *csv, int xse, int line) {
445 1882 dSP;
446 1882 SV *err = SvDiag (xse);
447 1882 SV *pself = csv->pself;
448  
449 1882 last_error = xse;
450 1882 (void)hv_store (csv->self, "_ERROR_DIAG", 11, err, 0);
451 1882 ▶ if (xse == 0) {
Branch: 1 branch
BranchTrueFalseTotal
if (xse == 0) { 6 1876 1882
452 6 (void)hv_store (csv->self, "_ERROR_POS", 10, newSViv (0), 0);
453 6 (void)hv_store (csv->self, "_ERROR_FLD", 10, newSViv (0), 0);
454 6 (void)hv_store (csv->self, "_ERROR_INPUT", 12, &PL_sv_undef, 0);
455 6 csv->has_error_input = 0;
456 }
457 1882 ▶ if (line)
Branch: 1 branch
BranchTrueFalseTotal
if (line) 1882 0 1882
458 1882 (void)hv_store (csv->self, "_ERROR_SRC", 10, newSViv (line), 0);
459 1882 ▶ if (xse == 2012) /* EOF */
Branch: 1 branch
BranchTrueFalseTotal
if (xse == 2012) /* EOF */ 441 1441 1882
460 441 (void)hv_store (csv->self, "_EOF", 4, &PL_sv_yes, 0);
461 1882 ▶ if (csv->auto_diag) {
Branch: 1 branch
BranchTrueFalseTotal
if (csv->auto_diag) { 344 1538 1882
462 688 ▶ unless (_is_hashref (pself))
Branch: 5 branches
BranchTrueFalseTotal
unless (_is_hashref (pself)) 344 0 344
unless (_is_hashref (pself)) 0 344 344
unless (_is_hashref (pself)) 0 0 0
unless (_is_hashref (pself)) 182 162 344
unless (_is_hashref (pself)) 0 182 182
463 162 pself = newRV_inc ((SV *)csv->self);
464 344 ENTER;
465 344 ▶ PUSHMARK (SP);
Branch: 1 branch
BranchTrueFalseTotal
PUSHMARK (SP); 0 344 344
466 344 ▶ XPUSHs (pself);
Branch: 1 branch
BranchTrueFalseTotal
XPUSHs (pself); 0 344 344
467 344 PUTBACK;
468 344 call_pv ("Text::CSV_XS::error_diag", G_VOID | G_DISCARD);
469 341 LEAVE;
470 341 ▶ unless (pself == csv->pself)
Branch: 1 branch
BranchTrueFalseTotal
unless (pself == csv->pself) 161 180 341
471 161 sv_free (pself);
472 }
473 1879 return (err);
474 } /* SetDiag */
475  
476 #define xs_cache_get_eolt(hv) cx_xs_cache_get_eolt (aTHX_ hv)
477 32 static char *cx_xs_cache_get_eolt (pTHX_ HV *hv) {
478 SV **svp;
479 csv_t *csvs;
480  
481 32 ▶ unless ((svp = hv_fetchs (hv, "_CACHE", FALSE)) && *svp)
Branch: 2 branches
BranchTrueFalseTotal
unless ((svp = hv_fetchs (hv, "_CACHE", FALSE)) && *svp) 32 0 32
unless ((svp = hv_fetchs (hv, "_CACHE", FALSE)) && *svp) 0 32 32
482 0 return NULL;
483  
484 32 csvs = (csv_t *)SvPV_nolen (*svp);
485 32 ▶ if (csvs->eol_type == EOL_TYPE_NL) return "\n";
Branch: 1 branch
BranchTrueFalseTotal
if (csvs->eol_type == EOL_TYPE_NL) return "\n"; 0 32 32
486 32 ▶ if (csvs->eol_type == EOL_TYPE_CR) return "\r";
Branch: 1 branch
BranchTrueFalseTotal
if (csvs->eol_type == EOL_TYPE_CR) return "\r"; 0 32 32
487 32 ▶ if (csvs->eol_type == EOL_TYPE_CRNL) return "\r\n";
Branch: 1 branch
BranchTrueFalseTotal
if (csvs->eol_type == EOL_TYPE_CRNL) return "\r\n"; 21 11 32
488 11 ▶ if (csvs->eol_type == EOL_TYPE_OTHER) return (char *)(csvs->eol);
Branch: 1 branch
BranchTrueFalseTotal
if (csvs->eol_type == EOL_TYPE_OTHER) return (char *)(csvs->eol); 0 11 11
489 11 return NULL;
490 } /* cx_xs_cache_get_eolt */
491  
492 /* Hold an SV alive across cache memcpy ()s so the raw PV pointer we
493 * stash in csv->{undef_str,comment_str,types} stays valid even if
494 * the user mutates the public hash entry. The "_*_HELD" private
495 * hash key carries the refcount; the SV is freed automatically when
496 * csv->self is destroyed (or the key is overwritten/deleted). */
497 #define hold_sv(hv,key,val) cx_hold_sv (aTHX_ hv, key, sizeof (key) - 1, val)
498 1871 static void cx_hold_sv (pTHX_ HV *hv, const char *key, I32 klen, SV *val) {
499 1871 ▶ if (val == NULL) {
Branch: 1 branch
BranchTrueFalseTotal
if (val == NULL) { 1838 33 1871
500 1838 (void)hv_delete (hv, key, klen, G_DISCARD);
501 1838 return;
502 }
503 33 SvREFCNT_inc (val);
504 33 ▶ unless (hv_store (hv, key, klen, val, 0))
Branch: 1 branch
BranchTrueFalseTotal
unless (hv_store (hv, key, klen, val, 0)) 0 33 33
505 0 SvREFCNT_dec (val);
506 } /* cx_hold_sv */
507  
508 #define xs_cache_set(hv,idx,val) cx_xs_cache_set (aTHX_ hv, idx, val)
509 23365 static void cx_xs_cache_set (pTHX_ HV *hv, int idx, SV *val) {
510 SV **svp;
511 byte *cache;
512  
513 csv_t csvs;
514 23365 csv_t *csv = &csvs;
515  
516 IV iv;
517 byte bv;
518 23365 char *cp = "\0";
519 23365 STRLEN len = 0;
520  
521 23365 ▶ unless ((svp = hv_fetchs (hv, "_CACHE", FALSE)) && *svp)
Branch: 2 branches
BranchTrueFalseTotal
unless ((svp = hv_fetchs (hv, "_CACHE", FALSE)) && *svp) 22591 774 23365
unless ((svp = hv_fetchs (hv, "_CACHE", FALSE)) && *svp) 0 22591 22591
522 774 return;
523  
524 22591 cache = (byte *)SvPV_nolen (*svp);
525 22591 (void)memcpy (csv, cache, sizeof (csv_t));
526  
527 22591 ▶ if (SvPOK (val))
Branch: 1 branch
BranchTrueFalseTotal
if (SvPOK (val)) 16790 5801 22591
528 16790 cp = SvPV (val, len);
529 22591 ▶ if (SvIOK (val))
Branch: 1 branch
BranchTrueFalseTotal
if (SvIOK (val)) 5789 16802 22591
530 5789 iv = SvIV (val);
531 16802 ▶ else if (SvNOK (val)) /* Needed for 5.6.x but safe for 5.8.x+ */
Branch: 1 branch
BranchTrueFalseTotal
else if (SvNOK (val)) /* Needed for 5.6.x but safe for 5.8.x+ */ 0 16802 16802
532 0 iv = (IV)SvNV (val); /* uncoverable statement ancient perl required */
533 else
534 16802 iv = *cp;
535 22591 bv = (unsigned)iv & 0xff;
536  
537 22591 switch (idx) {
538  
539 /* single char/byte */
540 3122 case CACHE_ID_sep_char:
541 3122 CH_SEP = *cp;
542 3122 csv->sep_len = 0;
543 3122 break;
544  
545 3369 case CACHE_ID_quote_char:
546 3369 CH_QUOTE = *cp;
547 3369 csv->quo_len = 0;
548 3369 break;
549  
550 3478 case CACHE_ID_escape_char: csv->escape_char = *cp; break;
551  
552 /* boolean/numeric */
553 11 case CACHE_ID_binary: csv->binary = bv; break;
554 10 case CACHE_ID_keep_meta_info: csv->keep_meta_info = bv; break;
555 1798 case CACHE_ID_always_quote: csv->always_quote = bv; break;
556 3 case CACHE_ID_quote_empty: csv->quote_empty = bv; break;
557 6 case CACHE_ID_quote_space: csv->quote_space = bv; break;
558 10 case CACHE_ID_escape_null: csv->escape_null = bv; break;
559 6 case CACHE_ID_quote_binary: csv->quote_binary = bv; break;
560 1 case CACHE_ID_decode_utf8: csv->decode_utf8 = bv; break;
561 11 case CACHE_ID_allow_loose_escapes: csv->allow_loose_escapes = bv; break;
562 11 case CACHE_ID_allow_loose_quotes: csv->allow_loose_quotes = bv; break;
563 2 case CACHE_ID_allow_unquoted_escape: csv->allow_unquoted_escape = bv; break;
564 3719 case CACHE_ID_allow_whitespace: csv->allow_whitespace = bv; break;
565 1 case CACHE_ID_blank_is_undef: csv->blank_is_undef = bv; break;
566 1 case CACHE_ID_empty_is_undef: csv->empty_is_undef = bv; break;
567 1 case CACHE_ID_formula: csv->formula = bv; break;
568 1 case CACHE_ID_strict: csv->strict = bv; break;
569 6 case CACHE_ID_verbatim: csv->verbatim = bv; break;
570 1 case CACHE_ID_strict_eol: csv->strict_eol = bv; break;
571 0 case CACHE_ID_eol_type: csv->eol_type = bv; break;
572 4 case CACHE_ID_skip_empty_rows: csv->skip_empty_rows = bv; break;
573 9 case CACHE_ID_auto_diag: csv->auto_diag = bv; break;
574 8 case CACHE_ID_diag_verbose: csv->diag_verbose = bv; break;
575 143 case CACHE_ID__has_ahead: csv->has_ahead = bv; break;
576 12 case CACHE_ID__has_hooks: csv->has_hooks = bv; break;
577 0 case CACHE_ID_has_error_input: csv->has_error_input = bv; break;
578  
579 /* a 4-byte IV */
580 12 case CACHE_ID__is_bound: csv->is_bound = iv; break;
581  
582 /* string */
583 3223 case CACHE_ID_sep:
584 3223 ▶ if (len > MAX_ATTR_LEN) croak ("INI - SEP too long"); /* 1006 */
Branch: 1 branch
BranchTrueFalseTotal
if (len > MAX_ATTR_LEN) croak ("INI - SEP too long"); /* 1006 */ 0 3223 3223
585 3223 (void)memcpy (csv->sep, cp, len);
586 3223 ▶ csv->sep_len = len == 1 ? 0 : len;
Branch: 1 branch
BranchTrueFalseTotal
csv->sep_len = len == 1 ? 0 : len; 3223 0 3223
587 3223 break;
588  
589 3377 case CACHE_ID_quo:
590 3377 ▶ if (len > MAX_ATTR_LEN) croak ("INI - QUOTE too long"); /* 1007 */
Branch: 1 branch
BranchTrueFalseTotal
if (len > MAX_ATTR_LEN) croak ("INI - QUOTE too long"); /* 1007 */ 0 3377 3377
591 3377 (void)memcpy (csv->quo, cp, len);
592 3377 ▶ csv->quo_len = len == 1 ? 0 : len;
Branch: 1 branch
BranchTrueFalseTotal
csv->quo_len = len == 1 ? 0 : len; 3377 0 3377
593 3377 break;
594  
595 219 case CACHE_ID_eol:
596 219 ▶ if (len > MAX_ATTR_LEN) croak ("INI - EOL too long"); /* 1005 */
Branch: 1 branch
BranchTrueFalseTotal
if (len > MAX_ATTR_LEN) croak ("INI - EOL too long"); /* 1005 */ 0 219 219
597 219 (void)memcpy (csv->eol, cp, len);
598 219 csv->eol_len = len;
599 307 ▶ csv->eol_type = len == 0 ? EOL_TYPE_UNDEF
Branch: 1 branch
BranchTrueFalseTotal
csv->eol_type = len == 0 ? EOL_TYPE_UNDEF 88 131 219
600 88 ▶ : len == 1 && *cp == CH_NL ? EOL_TYPE_NL
Branch: 2 branches
BranchTrueFalseTotal
: len == 1 && *cp == CH_NL ? EOL_TYPE_NL 82 6 88
: len == 1 && *cp == CH_NL ? EOL_TYPE_NL 78 4 82
601 84 ▶ : len == 1 && *cp == CH_CR ? EOL_TYPE_CR
Branch: 2 branches
BranchTrueFalseTotal
: len == 1 && *cp == CH_CR ? EOL_TYPE_CR 78 6 84
: len == 1 && *cp == CH_CR ? EOL_TYPE_CR 2 76 78
602 8 ▶ : len == 2 && *cp == CH_CR
Branch: 2 branches
BranchTrueFalseTotal
: len == 2 && *cp == CH_CR 4 4 8
: len == 2 && *cp == CH_CR 4 0 4
603 4 ▶ && cp[1] == CH_NL ? EOL_TYPE_CRNL
Branch: 1 branch
BranchTrueFalseTotal
&& cp[1] == CH_NL ? EOL_TYPE_CRNL 4 0 4
604 : EOL_TYPE_OTHER;
605 219 csv->strict_eol &= 0x3F;
606 219 csv->eol_is_cr = csv->eol_type == EOL_TYPE_CR ? 1 : 0;
607 #if MAINT_DEBUG_EOL > 0
608 (void)fprintf (stderr, "# %04d cache set eol: '%s'\t(len: %d, is_cr: %d, tp: %02x)\n",
609 __LINE__, _pretty_str (cp, len), len, csv->eol_is_cr, csv->eol_type);
610 #endif
611 219 break;
612  
613 11 case CACHE_ID_undef_str:
614 11 ▶ if (*cp) {
Branch: 1 branch
BranchTrueFalseTotal
if (*cp) { 8 3 11
615 8 hold_sv (csv->self, "_UNDEF_STR_HELD", val);
616 8 csv->undef_str = (byte *)cp;
617 8 ▶ if (SvUTF8 (val))
Branch: 1 branch
BranchTrueFalseTotal
if (SvUTF8 (val)) 1 7 8
618 1 csv->undef_flg = 3;
619 }
620 else {
621 3 hold_sv (csv->self, "_UNDEF_STR_HELD", NULL);
622 3 csv->undef_str = NULL;
623 3 csv->undef_flg = 0;
624 }
625 11 break;
626  
627 2 case CACHE_ID_comment_str:
628 2 ▶ if (*cp) {
Branch: 1 branch
BranchTrueFalseTotal
if (*cp) { 1 1 2
629 1 hold_sv (csv->self, "_COMMENT_STR_HELD", val);
630 1 csv->comment_str = (byte *)cp;
631 }
632 else {
633 1 hold_sv (csv->self, "_COMMENT_STR_HELD", NULL);
634 1 csv->comment_str = NULL;
635 }
636 2 break;
637  
638 1 case CACHE_ID_types:
639 1 ▶ if (cp && len) {
Branch: 2 branches
BranchTrueFalseTotal
if (cp && len) { 1 0 1
if (cp && len) { 0 1 1
640 0 hold_sv (csv->self, "_TYPES_HELD", val);
641 0 csv->types = cp;
642 0 csv->types_len = len;
643 }
644 else {
645 1 hold_sv (csv->self, "_TYPES_HELD", NULL);
646 1 csv->types = NULL;
647 1 csv->types_len = 0;
648 }
649 1 break;
650  
651 2 default:
652 2 warn ("Unknown cache index %d ignored\n", idx);
653 }
654  
655 22591 csv->cache = cache;
656 22591 (void)memcpy (cache, csv, sizeof (csv_t));
657 } /* cache_set */
658  
659 #define _cache_show_byte(trim,c) \
660 warn (" %-21s %02x:%3d\n", trim, c, c)
661 #define _cache_show_char(trim,c) \
662 warn (" %-21s %02x:%s\n", trim, c, _pretty_str (&c, 1))
663 #define _cache_show_str(trim,l,str) \
664 warn (" %-21s %3d:%s\n", trim, l, _pretty_str (str, l))
665  
666 #define _csv_diag(csv) _xs_csv_diag (aTHX_ csv)
667 1 static void _xs_csv_diag (pTHX_ csv_t *csv) {
668 1 warn ("CACHE:\n");
669 1 _cache_show_char ("quote_char", CH_QUOTE);
670 1 _cache_show_char ("escape_char", csv->escape_char);
671 1 _cache_show_char ("sep_char", CH_SEP);
672 1 _cache_show_byte ("binary", csv->binary);
673 1 _cache_show_byte ("decode_utf8", csv->decode_utf8);
674  
675 1 _cache_show_byte ("allow_loose_escapes", csv->allow_loose_escapes);
676 1 _cache_show_byte ("allow_loose_quotes", csv->allow_loose_quotes);
677 1 _cache_show_byte ("allow_unquoted_escape", csv->allow_unquoted_escape);
678 1 _cache_show_byte ("allow_whitespace", csv->allow_whitespace);
679 1 _cache_show_byte ("always_quote", csv->always_quote);
680 1 _cache_show_byte ("quote_empty", csv->quote_empty);
681 1 _cache_show_byte ("quote_space", csv->quote_space);
682 1 _cache_show_byte ("escape_null", csv->escape_null);
683 1 _cache_show_byte ("quote_binary", csv->quote_binary);
684 1 _cache_show_byte ("auto_diag", csv->auto_diag);
685 1 _cache_show_byte ("diag_verbose", csv->diag_verbose);
686 1 _cache_show_byte ("formula", csv->formula);
687 1 _cache_show_byte ("strict", csv->strict);
688 1 _cache_show_byte ("strict_n", csv->strict_n);
689 1 _cache_show_byte ("strict_eol", csv->strict_eol);
690 1 _cache_show_byte ("eol_type", csv->eol_type);
691 1 _cache_show_byte ("skip_empty_rows", csv->skip_empty_rows);
692 1 _cache_show_byte ("has_error_input", csv->has_error_input);
693 1 _cache_show_byte ("blank_is_undef", csv->blank_is_undef);
694 1 _cache_show_byte ("empty_is_undef", csv->empty_is_undef);
695 1 _cache_show_byte ("has_ahead", csv->has_ahead);
696 1 _cache_show_byte ("keep_meta_info", csv->keep_meta_info);
697 1 _cache_show_byte ("verbatim", csv->verbatim);
698  
699 1 _cache_show_byte ("useIO", csv->useIO);
700 1 _cache_show_byte ("has_hooks", csv->has_hooks);
701 1 _cache_show_byte ("eol_is_cr", csv->eol_is_cr);
702 1 _cache_show_byte ("eol_len", csv->eol_len);
703 1 _cache_show_str ("eol", csv->eol_len, csv->eol);
704 1 _cache_show_byte ("sep_len", csv->sep_len);
705 1 ▶ if (csv->sep_len > 1)
Branch: 1 branch
BranchTrueFalseTotal
if (csv->sep_len > 1) 1 0 1
706 1 _cache_show_str ("sep", csv->sep_len, csv->sep);
707 1 _cache_show_byte ("quo_len", csv->quo_len);
708 1 ▶ if (csv->quo_len > 1)
Branch: 1 branch
BranchTrueFalseTotal
if (csv->quo_len > 1) 1 0 1
709 1 _cache_show_str ("quote", csv->quo_len, csv->quo);
710 1 ▶ if (csv->types_len)
Branch: 1 branch
BranchTrueFalseTotal
if (csv->types_len) 0 1 1
711 0 _cache_show_str ("types", csv->types_len, (byte *)csv->types);
712 else
713 1 _cache_show_str ("types", 0, (byte *)"");
714  
715 1 ▶ if (csv->bptr)
Branch: 1 branch
BranchTrueFalseTotal
if (csv->bptr) 1 0 1
716 1 _cache_show_str ("bptr", (int)strlen (csv->bptr), (byte *)csv->bptr);
717 1 ▶ if (csv->tmp && SvPOK (csv->tmp)) {
Branch: 2 branches
BranchTrueFalseTotal
if (csv->tmp && SvPOK (csv->tmp)) { 1 0 1
if (csv->tmp && SvPOK (csv->tmp)) { 1 0 1
718 1 char *s = SvPV_nolen (csv->tmp);
719 1 _cache_show_str ("tmp", (int)strlen (s), (byte *)s);
720 }
721 1 ▶ if (csv->cache)
Branch: 1 branch
BranchTrueFalseTotal
if (csv->cache) 1 0 1
722 1 warn (" %-20s %4d:0x%08lx\n", "cache", (int)sizeof (csv_t), (unsigned long)csv->cache);
723 else
724 0 warn (" %-22s --:no cache yet\n", "cache");
725 1 } /* _csv_diag */
726  
727 #define xs_cache_diag(hv) cx_xs_cache_diag (aTHX_ hv)
728 2 static void cx_xs_cache_diag (pTHX_ HV *hv) {
729 SV **svp;
730 byte *cache;
731 csv_t csvs;
732 2 csv_t *csv = &csvs;
733  
734 2 ▶ unless ((svp = hv_fetchs (hv, "_CACHE", FALSE)) && *svp) {
Branch: 2 branches
BranchTrueFalseTotal
unless ((svp = hv_fetchs (hv, "_CACHE", FALSE)) && *svp) { 1 1 2
unless ((svp = hv_fetchs (hv, "_CACHE", FALSE)) && *svp) { 0 1 1
735 1 warn ("CACHE: invalid\n");
736 1 return;
737 }
738  
739 1 cache = (byte *)SvPV_nolen (*svp);
740 1 (void)memcpy (csv, cache, sizeof (csv_t));
741 1 _csv_diag (csv);
742 } /* xs_cache_diag */
743  
744 #define set_eol_is_cr(csv) cx_set_eol_is_cr (aTHX_ csv)
745 45 static void cx_set_eol_is_cr (pTHX_ csv_t *csv) {
746 45 csv->eol_is_cr = 1;
747 45 csv->eol_len = 1;
748 45 csv->eol[0] = CH_CR;
749 45 csv->eol_type = EOL_TYPE_CR;
750 45 (void)memcpy (csv->cache, csv, sizeof (csv_t));
751  
752 45 (void)hv_store (csv->self, "eol", 3, newSVpvn ((char *)csv->eol, 1), 0);
753 #if MAINT_DEBUG_EOL > 0
754 (void)fprintf (stderr, "# %04d set eol is CR: '%s'\t(len: %d, is_cr: %d, tp: %02x)\n",
755 __LINE__, _pretty_str (csv->eol, csv->eol_len), csv->eol_len, csv->eol_is_cr, csv->eol_type);
756 #endif
757 45 } /* set_eol_is_cr */
758  
759 #define SetupCsv(csv,self,pself) cx_SetupCsv (aTHX_ csv, self, pself)
760 227957 static void cx_SetupCsv (pTHX_ csv_t *csv, HV *self, SV *pself) {
761 SV **svp;
762 STRLEN len;
763 char *ptr;
764  
765 227957 last_error = 0;
766  
767 227957 ▶ if ((svp = hv_fetchs (self, "_CACHE", FALSE)) && *svp) {
Branch: 2 branches
BranchTrueFalseTotal
if ((svp = hv_fetchs (self, "_CACHE", FALSE)) && *svp) { 227026 931 227957
if ((svp = hv_fetchs (self, "_CACHE", FALSE)) && *svp) { 227026 0 227026
768 227026 byte *cache = (byte *)SvPVX (*svp);
769 227026 (void)memcpy (csv, cache, sizeof (csv_t));
770 }
771 else {
772 SV *sv_cache;
773  
774 931 (void)memset (csv, 0, sizeof (csv_t)); /* Reset everything */
775  
776 931 csv->self = self;
777 931 csv->pself = pself;
778  
779 931 CH_SEP = ',';
780 931 ▶ if ((svp = hv_fetchs (self, "sep_char", FALSE)) && *svp && SvOK (*svp))
Branch: 3 branches
BranchTrueFalseTotal
if ((svp = hv_fetchs (self, "sep_char", FALSE)) && *svp && SvOK (*svp)) 931 0 931
if ((svp = hv_fetchs (self, "sep_char", FALSE)) && *svp && SvOK (*svp)) 931 0 931
if ((svp = hv_fetchs (self, "sep_char", FALSE)) && *svp && SvOK (*svp)) 931 0 931
781 1862 CH_SEP = *SvPV (*svp, len);
782 931 ▶ if ((svp = hv_fetchs (self, "sep", FALSE)) && *svp && SvOK (*svp)) {
Branch: 3 branches
BranchTrueFalseTotal
if ((svp = hv_fetchs (self, "sep", FALSE)) && *svp && SvOK (*svp)) { 226 705 931
if ((svp = hv_fetchs (self, "sep", FALSE)) && *svp && SvOK (*svp)) { 226 0 226
if ((svp = hv_fetchs (self, "sep", FALSE)) && *svp && SvOK (*svp)) { 226 0 226
783 226 ptr = SvPV (*svp, len);
784 226 ▶ if (len > MAX_ATTR_LEN) croak ("INI - SEP too long"); /* 1006 */
Branch: 1 branch
BranchTrueFalseTotal
if (len > MAX_ATTR_LEN) croak ("INI - SEP too long"); /* 1006 */ 1 225 226
785 225 (void)memcpy (csv->sep, ptr, len);
786 225 ▶ if (len > 1)
Branch: 1 branch
BranchTrueFalseTotal
if (len > 1) 5 220 225
787 5 csv->sep_len = len;
788 }
789  
790 930 CH_QUOTE = '"';
791 930 ▶ if ((svp = hv_fetchs (self, "quote_char", FALSE)) && *svp) {
Branch: 2 branches
BranchTrueFalseTotal
if ((svp = hv_fetchs (self, "quote_char", FALSE)) && *svp) { 930 0 930
if ((svp = hv_fetchs (self, "quote_char", FALSE)) && *svp) { 930 0 930
792 930 ▶ if (SvOK (*svp)) {
Branch: 1 branch
BranchTrueFalseTotal
if (SvOK (*svp)) { 927 3 930
793 927 ptr = SvPV (*svp, len);
794 927 ▶ CH_QUOTE = len ? *ptr : (char)0;
Branch: 1 branch
BranchTrueFalseTotal
CH_QUOTE = len ? *ptr : (char)0; 927 0 927
795 }
796 else
797 3 CH_QUOTE = (char)0;
798 }
799 930 ▶ if ((svp = hv_fetchs (self, "quote", FALSE)) && *svp && SvOK (*svp)) {
Branch: 3 branches
BranchTrueFalseTotal
if ((svp = hv_fetchs (self, "quote", FALSE)) && *svp && SvOK (*svp)) { 7 923 930
if ((svp = hv_fetchs (self, "quote", FALSE)) && *svp && SvOK (*svp)) { 7 0 7
if ((svp = hv_fetchs (self, "quote", FALSE)) && *svp && SvOK (*svp)) { 6 1 7
800 6 ptr = SvPV (*svp, len);
801 6 ▶ if (len > MAX_ATTR_LEN) croak ("INI - QUOTE too long"); /* 1007 */
Branch: 1 branch
BranchTrueFalseTotal
if (len > MAX_ATTR_LEN) croak ("INI - QUOTE too long"); /* 1007 */ 1 5 6
802 5 (void)memcpy (csv->quo, ptr, len);
803 5 ▶ if (len > 1)
Branch: 1 branch
BranchTrueFalseTotal
if (len > 1) 4 1 5
804 4 csv->quo_len = len;
805 }
806  
807 929 csv->escape_char = '"';
808 929 ▶ if ((svp = hv_fetchs (self, "escape_char", FALSE)) && *svp) {
Branch: 2 branches
BranchTrueFalseTotal
if ((svp = hv_fetchs (self, "escape_char", FALSE)) && *svp) { 929 0 929
if ((svp = hv_fetchs (self, "escape_char", FALSE)) && *svp) { 929 0 929
809 929 ▶ if (SvOK (*svp)) {
Branch: 1 branch
BranchTrueFalseTotal
if (SvOK (*svp)) { 923 6 929
810 923 ptr = SvPV (*svp, len);
811 923 ▶ csv->escape_char = len ? *ptr : (char)0;
Branch: 1 branch
BranchTrueFalseTotal
csv->escape_char = len ? *ptr : (char)0; 921 2 923
812 }
813 else
814 6 csv->escape_char = (char)0;
815 }
816  
817 929 ▶ if ((svp = hv_fetchs (self, "eol", FALSE)) && *svp && SvOK (*svp)) {
Branch: 3 branches
BranchTrueFalseTotal
if ((svp = hv_fetchs (self, "eol", FALSE)) && *svp && SvOK (*svp)) { 929 0 929
if ((svp = hv_fetchs (self, "eol", FALSE)) && *svp && SvOK (*svp)) { 929 0 929
if ((svp = hv_fetchs (self, "eol", FALSE)) && *svp && SvOK (*svp)) { 924 5 929
818 924 char *eol = SvPV (*svp, len);
819 924 ▶ if (len > MAX_ATTR_LEN) croak ("INI - EOL too long"); /* 1005 */
Branch: 1 branch
BranchTrueFalseTotal
if (len > MAX_ATTR_LEN) croak ("INI - EOL too long"); /* 1005 */ 1 923 924
820 923 (void)memcpy (csv->eol, eol, len);
821 923 csv->eol_len = len;
822 923 ▶ if (len == 1 && *eol == CH_CR) {
Branch: 2 branches
BranchTrueFalseTotal
if (len == 1 && *eol == CH_CR) { 104 819 923
if (len == 1 && *eol == CH_CR) { 42 62 104
823 42 csv->eol_is_cr = 1;
824 42 csv->eol_type = EOL_TYPE_CR;
825 }
826 881 ▶ else if (len == 1 && *eol == CH_NL)
Branch: 2 branches
BranchTrueFalseTotal
else if (len == 1 && *eol == CH_NL) 62 819 881
else if (len == 1 && *eol == CH_NL) 58 4 62
827 58 csv->eol_type = EOL_TYPE_NL;
828 823 ▶ else if (len == 2 && *eol == CH_CR && eol[1] == CH_NL)
Branch: 3 branches
BranchTrueFalseTotal
else if (len == 2 && *eol == CH_CR && eol[1] == CH_NL) 55 768 823
else if (len == 2 && *eol == CH_CR && eol[1] == CH_NL) 50 5 55
else if (len == 2 && *eol == CH_CR && eol[1] == CH_NL) 50 0 50
829 50 csv->eol_type = EOL_TYPE_CRNL;
830 }
831  
832 928 csv->undef_flg = 0;
833 928 ▶ if ((svp = hv_fetchs (self, "undef_str", FALSE)) && *svp && SvOK (*svp)) {
Branch: 3 branches
BranchTrueFalseTotal
if ((svp = hv_fetchs (self, "undef_str", FALSE)) && *svp && SvOK (*svp)) { 928 0 928
if ((svp = hv_fetchs (self, "undef_str", FALSE)) && *svp && SvOK (*svp)) { 928 0 928
if ((svp = hv_fetchs (self, "undef_str", FALSE)) && *svp && SvOK (*svp)) { 2 926 928
834 /*if (sv && (SvOK (sv) || (
835 (SvGMAGICAL (sv) && (mg_get (sv), 1) && SvOK (sv))))) {*/
836 2 hold_sv (self, "_UNDEF_STR_HELD", *svp);
837 2 csv->undef_str = (byte *)SvPV_nolen (*svp);
838 2 ▶ if (SvUTF8 (*svp))
Branch: 1 branch
BranchTrueFalseTotal
if (SvUTF8 (*svp)) 0 2 2
839 0 csv->undef_flg = 3;
840 }
841 else {
842 926 hold_sv (self, "_UNDEF_STR_HELD", NULL);
843 926 csv->undef_str = NULL;
844 }
845  
846 928 ▶ if ((svp = hv_fetchs (self, "comment_str", FALSE)) && *svp && SvOK (*svp)) {
Branch: 3 branches
BranchTrueFalseTotal
if ((svp = hv_fetchs (self, "comment_str", FALSE)) && *svp && SvOK (*svp)) { 928 0 928
if ((svp = hv_fetchs (self, "comment_str", FALSE)) && *svp && SvOK (*svp)) { 928 0 928
if ((svp = hv_fetchs (self, "comment_str", FALSE)) && *svp && SvOK (*svp)) { 21 907 928
847 21 hold_sv (self, "_COMMENT_STR_HELD", *svp);
848 42 csv->comment_str = (byte *)SvPV_nolen (*svp);
849 }
850 else {
851 907 hold_sv (self, "_COMMENT_STR_HELD", NULL);
852 907 csv->comment_str = NULL;
853 }
854  
855 928 ▶ if ((svp = hv_fetchs (self, "_types", FALSE)) && *svp && SvOK (*svp)) {
Branch: 3 branches
BranchTrueFalseTotal
if ((svp = hv_fetchs (self, "_types", FALSE)) && *svp && SvOK (*svp)) { 1 927 928
if ((svp = hv_fetchs (self, "_types", FALSE)) && *svp && SvOK (*svp)) { 1 0 1
if ((svp = hv_fetchs (self, "_types", FALSE)) && *svp && SvOK (*svp)) { 1 0 1
856 1 hold_sv (self, "_TYPES_HELD", *svp);
857 1 csv->types = SvPV (*svp, len);
858 1 csv->types_len = len;
859 }
860  
861 928 ▶ if ((svp = hv_fetchs (self, "_is_bound", FALSE)) && *svp && SvOK (*svp))
Branch: 3 branches
BranchTrueFalseTotal
if ((svp = hv_fetchs (self, "_is_bound", FALSE)) && *svp && SvOK (*svp)) 16 912 928
if ((svp = hv_fetchs (self, "_is_bound", FALSE)) && *svp && SvOK (*svp)) 16 0 16
if ((svp = hv_fetchs (self, "_is_bound", FALSE)) && *svp && SvOK (*svp)) 16 0 16
862 16 csv->is_bound = SvIV (*svp);
863 1856 ▶ if ((svp = hv_fetchs (self, "callbacks", FALSE)) && _is_hashref (*svp)) {
Branch: 6 branches
BranchTrueFalseTotal
if ((svp = hv_fetchs (self, "callbacks", FALSE)) && _is_hashref (*svp)) { 928 0 928
if ((svp = hv_fetchs (self, "callbacks", FALSE)) && _is_hashref (*svp)) { 928 0 928
if ((svp = hv_fetchs (self, "callbacks", FALSE)) && _is_hashref (*svp)) { 0 928 928
if ((svp = hv_fetchs (self, "callbacks", FALSE)) && _is_hashref (*svp)) { 0 0 0
if ((svp = hv_fetchs (self, "callbacks", FALSE)) && _is_hashref (*svp)) { 325 603 928
if ((svp = hv_fetchs (self, "callbacks", FALSE)) && _is_hashref (*svp)) { 325 0 325
864 325 HV *cb = (HV *)SvRV (*svp);
865 341 ▶ if ((svp = hv_fetchs (cb, "after_parse", FALSE)) && _is_coderef (*svp))
Branch: 6 branches
BranchTrueFalseTotal
if ((svp = hv_fetchs (cb, "after_parse", FALSE)) && _is_coderef (*svp)) 16 309 325
if ((svp = hv_fetchs (cb, "after_parse", FALSE)) && _is_coderef (*svp)) 16 0 16
if ((svp = hv_fetchs (cb, "after_parse", FALSE)) && _is_coderef (*svp)) 0 16 16
if ((svp = hv_fetchs (cb, "after_parse", FALSE)) && _is_coderef (*svp)) 0 0 0
if ((svp = hv_fetchs (cb, "after_parse", FALSE)) && _is_coderef (*svp)) 16 0 16
if ((svp = hv_fetchs (cb, "after_parse", FALSE)) && _is_coderef (*svp)) 16 0 16
866 16 csv->has_hooks |= HOOK_AFTER_PARSE;
867 328 ▶ if ((svp = hv_fetchs (cb, "before_print", FALSE)) && _is_coderef (*svp))
Branch: 6 branches
BranchTrueFalseTotal
if ((svp = hv_fetchs (cb, "before_print", FALSE)) && _is_coderef (*svp)) 3 322 325
if ((svp = hv_fetchs (cb, "before_print", FALSE)) && _is_coderef (*svp)) 3 0 3
if ((svp = hv_fetchs (cb, "before_print", FALSE)) && _is_coderef (*svp)) 0 3 3
if ((svp = hv_fetchs (cb, "before_print", FALSE)) && _is_coderef (*svp)) 0 0 0
if ((svp = hv_fetchs (cb, "before_print", FALSE)) && _is_coderef (*svp)) 3 0 3
if ((svp = hv_fetchs (cb, "before_print", FALSE)) && _is_coderef (*svp)) 3 0 3
868 3 csv->has_hooks |= HOOK_BEFORE_PRINT;
869 }
870  
871 928 ▶ csv->binary = bool_opt ("binary");
Branch: 2 branches
BranchTrueFalseTotal
csv->binary = bool_opt ("binary"); 928 0 928
csv->binary = bool_opt ("binary"); 928 0 928
872 928 ▶ csv->decode_utf8 = bool_opt ("decode_utf8");
Branch: 2 branches
BranchTrueFalseTotal
csv->decode_utf8 = bool_opt ("decode_utf8"); 928 0 928
csv->decode_utf8 = bool_opt ("decode_utf8"); 928 0 928
873 928 ▶ csv->always_quote = bool_opt ("always_quote");
Branch: 2 branches
BranchTrueFalseTotal
csv->always_quote = bool_opt ("always_quote"); 928 0 928
csv->always_quote = bool_opt ("always_quote"); 928 0 928
874 928 ▶ csv->strict = bool_opt ("strict");
Branch: 2 branches
BranchTrueFalseTotal
csv->strict = bool_opt ("strict"); 928 0 928
csv->strict = bool_opt ("strict"); 928 0 928
875 928 ▶ csv->strict_eol = num_opt ("strict_eol");
Branch: 2 branches
BranchTrueFalseTotal
csv->strict_eol = num_opt ("strict_eol"); 928 0 928
csv->strict_eol = num_opt ("strict_eol"); 928 0 928
876 928 ▶ csv->quote_empty = bool_opt ("quote_empty");
Branch: 2 branches
BranchTrueFalseTotal
csv->quote_empty = bool_opt ("quote_empty"); 928 0 928
csv->quote_empty = bool_opt ("quote_empty"); 928 0 928
877 928 ▶ csv->quote_space = bool_opt_def ("quote_space", 1);
Branch: 2 branches
BranchTrueFalseTotal
csv->quote_space = bool_opt_def ("quote_space", 1); 928 0 928
csv->quote_space = bool_opt_def ("quote_space", 1); 928 0 928
878 928 ▶ csv->escape_null = bool_opt_def ("escape_null", 1);
Branch: 2 branches
BranchTrueFalseTotal
csv->escape_null = bool_opt_def ("escape_null", 1); 928 0 928
csv->escape_null = bool_opt_def ("escape_null", 1); 928 0 928
879 928 ▶ csv->quote_binary = bool_opt_def ("quote_binary", 1);
Branch: 2 branches
BranchTrueFalseTotal
csv->quote_binary = bool_opt_def ("quote_binary", 1); 928 0 928
csv->quote_binary = bool_opt_def ("quote_binary", 1); 928 0 928
880 928 ▶ csv->allow_loose_quotes = bool_opt ("allow_loose_quotes");
Branch: 2 branches
BranchTrueFalseTotal
csv->allow_loose_quotes = bool_opt ("allow_loose_quotes"); 928 0 928
csv->allow_loose_quotes = bool_opt ("allow_loose_quotes"); 928 0 928
881 928 ▶ csv->allow_loose_escapes = bool_opt ("allow_loose_escapes");
Branch: 2 branches
BranchTrueFalseTotal
csv->allow_loose_escapes = bool_opt ("allow_loose_escapes"); 928 0 928
csv->allow_loose_escapes = bool_opt ("allow_loose_escapes"); 928 0 928
882 928 ▶ csv->allow_unquoted_escape = bool_opt ("allow_unquoted_escape");
Branch: 2 branches
BranchTrueFalseTotal
csv->allow_unquoted_escape = bool_opt ("allow_unquoted_escape"); 928 0 928
csv->allow_unquoted_escape = bool_opt ("allow_unquoted_escape"); 928 0 928
883 928 ▶ csv->allow_whitespace = bool_opt ("allow_whitespace");
Branch: 2 branches
BranchTrueFalseTotal
csv->allow_whitespace = bool_opt ("allow_whitespace"); 928 0 928
csv->allow_whitespace = bool_opt ("allow_whitespace"); 928 0 928
884 928 ▶ csv->blank_is_undef = bool_opt ("blank_is_undef");
Branch: 2 branches
BranchTrueFalseTotal
csv->blank_is_undef = bool_opt ("blank_is_undef"); 928 0 928
csv->blank_is_undef = bool_opt ("blank_is_undef"); 928 0 928
885 928 ▶ csv->empty_is_undef = bool_opt ("empty_is_undef");
Branch: 2 branches
BranchTrueFalseTotal
csv->empty_is_undef = bool_opt ("empty_is_undef"); 928 0 928
csv->empty_is_undef = bool_opt ("empty_is_undef"); 928 0 928
886 928 ▶ csv->verbatim = bool_opt ("verbatim");
Branch: 2 branches
BranchTrueFalseTotal
csv->verbatim = bool_opt ("verbatim"); 928 0 928
csv->verbatim = bool_opt ("verbatim"); 928 0 928
887  
888 928 ▶ csv->auto_diag = num_opt ("auto_diag");
Branch: 2 branches
BranchTrueFalseTotal
csv->auto_diag = num_opt ("auto_diag"); 928 0 928
csv->auto_diag = num_opt ("auto_diag"); 928 0 928
889 928 ▶ csv->diag_verbose = num_opt ("diag_verbose");
Branch: 2 branches
BranchTrueFalseTotal
csv->diag_verbose = num_opt ("diag_verbose"); 928 0 928
csv->diag_verbose = num_opt ("diag_verbose"); 928 0 928
890 928 ▶ csv->keep_meta_info = num_opt ("keep_meta_info");
Branch: 2 branches
BranchTrueFalseTotal
csv->keep_meta_info = num_opt ("keep_meta_info"); 928 0 928
csv->keep_meta_info = num_opt ("keep_meta_info"); 928 0 928
891 928 ▶ csv->skip_empty_rows = num_opt ("skip_empty_rows");
Branch: 2 branches
BranchTrueFalseTotal
csv->skip_empty_rows = num_opt ("skip_empty_rows"); 928 0 928
csv->skip_empty_rows = num_opt ("skip_empty_rows"); 928 0 928
892 928 ▶ csv->formula = num_opt ("formula");
Branch: 2 branches
BranchTrueFalseTotal
csv->formula = num_opt ("formula"); 928 0 928
csv->formula = num_opt ("formula"); 928 0 928
893  
894 928 ▶ unless (csv->escape_char) csv->escape_null = 0;
Branch: 1 branch
BranchTrueFalseTotal
unless (csv->escape_char) csv->escape_null = 0; 8 920 928
895  
896 928 sv_cache = newSVpvn ((char *)csv, sizeof (csv_t));
897 928 csv->cache = (byte *)SvPVX (sv_cache);
898 928 SvREADONLY_on (sv_cache);
899  
900 928 (void)memcpy (csv->cache, csv, sizeof (csv_t));
901  
902 928 (void)hv_store (self, "_CACHE", 6, sv_cache, 0);
903 }
904  
905 227954 csv->utf8 = 0;
906 227954 csv->size = 0;
907 227954 csv->used = 0;
908  
909 /* This is EBCDIC-safe, as it is used after translation */
910 227954 ▶ csv->first_safe_char = csv->quote_space ? 0x21 : 0x20;
Branch: 1 branch
BranchTrueFalseTotal
csv->first_safe_char = csv->quote_space ? 0x21 : 0x20; 227890 64 227954
911  
912 227954 ▶ if (csv->is_bound) {
Branch: 1 branch
BranchTrueFalseTotal
if (csv->is_bound) { 123 227831 227954
913 246 ▶ if ((svp = hv_fetchs (self, "_BOUND_COLUMNS", FALSE)) && _is_arrayref (*svp))
Branch: 6 branches
BranchTrueFalseTotal
if ((svp = hv_fetchs (self, "_BOUND_COLUMNS", FALSE)) && _is_arrayref (*svp)) 123 0 123
if ((svp = hv_fetchs (self, "_BOUND_COLUMNS", FALSE)) && _is_arrayref (*svp)) 123 0 123
if ((svp = hv_fetchs (self, "_BOUND_COLUMNS", FALSE)) && _is_arrayref (*svp)) 0 123 123
if ((svp = hv_fetchs (self, "_BOUND_COLUMNS", FALSE)) && _is_arrayref (*svp)) 0 0 0
if ((svp = hv_fetchs (self, "_BOUND_COLUMNS", FALSE)) && _is_arrayref (*svp)) 109 14 123
if ((svp = hv_fetchs (self, "_BOUND_COLUMNS", FALSE)) && _is_arrayref (*svp)) 109 0 109
914 109 csv->bound = *svp;
915 else
916 14 csv->is_bound = 0;
917 }
918  
919 227954 csv->eol_pos = -1;
920 455908 csv->eolx = csv->eol_len
921 1366 ▶ ? csv->verbatim || csv->eol_len >= 2
Branch: 1 branch
BranchTrueFalseTotal
? csv->verbatim || csv->eol_len >= 2 914 452 1366
922 ? 1
923 914 ▶ : csv->eol[0] == CH_CR || csv->eol[0] == CH_NL
Branch: 1 branch
BranchTrueFalseTotal
: csv->eol[0] == CH_CR || csv->eol[0] == CH_NL 370 544 914
924 ? 0
925 370 ▶ : 1
Branch: 1 branch
BranchTrueFalseTotal
: 1 52 318 370
926 229320 ▶ : 0;
Branch: 2 branches
BranchTrueFalseTotal
: 0; 1373 226581 227954
: 0; 1366 7 1373
927 227954 ▶ if (csv->eol_type > 0 && csv->strict_eol > 0 && !*csv->eol)
Branch: 3 branches
BranchTrueFalseTotal
if (csv->eol_type > 0 && csv->strict_eol > 0 && !*csv->eol) 203216 24738 227954
if (csv->eol_type > 0 && csv->strict_eol > 0 && !*csv->eol) 909 202307 203216
if (csv->eol_type > 0 && csv->strict_eol > 0 && !*csv->eol) 750 159 909
928 750 csv->eol_is_cr = 0;
929 #if MAINT_DEBUG_EOL > 0
930 (void)fprintf (stderr, "# %04d setup eol: '%s'\t(len: %d, is_cr: %d, x: %d, pos: %d, tp: %02x)\n",
931 __LINE__, _pretty_str (csv->eol, csv->eol_len), csv->eol_len, csv->eol_is_cr, csv->eolx, csv->eol_pos, csv->eol_type);
932 #endif
933 227954 ▶ if (csv->sep_len > 1 && is_utf8_string ((U8 *)(csv->sep), csv->sep_len))
Branch: 2 branches
BranchTrueFalseTotal
if (csv->sep_len > 1 && is_utf8_string ((U8 *)(csv->sep), csv->sep_len)) 51 227903 227954
if (csv->sep_len > 1 && is_utf8_string ((U8 *)(csv->sep), csv->sep_len)) 51 0 51
934 51 csv->utf8 = 1;
935 227954 ▶ if (csv->quo_len > 1 && is_utf8_string ((U8 *)(csv->quo), csv->quo_len))
Branch: 2 branches
BranchTrueFalseTotal
if (csv->quo_len > 1 && is_utf8_string ((U8 *)(csv->quo), csv->quo_len)) 27 227927 227954
if (csv->quo_len > 1 && is_utf8_string ((U8 *)(csv->quo), csv->quo_len)) 27 0 27
936 27 csv->utf8 = 1;
937  
938 227954 ▶ if (csv->strict
Branch: 1 branch
BranchTrueFalseTotal
if (csv->strict 67 227887 227954
939 67 ▶ && !csv->strict_n
Branch: 1 branch
BranchTrueFalseTotal
&& !csv->strict_n 27 40 67
940 27 ▶ && (svp = hv_fetchs (self, "_COLUMN_NAMES", FALSE))
Branch: 1 branch
BranchTrueFalseTotal
&& (svp = hv_fetchs (self, "_COLUMN_NAMES", FALSE)) 27 0 27
941 54 ▶ && _is_arrayref (*svp))
Branch: 5 branches
BranchTrueFalseTotal
&& _is_arrayref (*svp)) 27 0 27
&& _is_arrayref (*svp)) 0 27 27
&& _is_arrayref (*svp)) 0 0 0
&& _is_arrayref (*svp)) 2 25 27
&& _is_arrayref (*svp)) 2 0 2
942 2 csv->strict_n = av_len ((AV *)(SvRV (*svp)));
943 227954 } /* SetupCsv */
944  
945 #define Print(csv,dst) cx_Print (aTHX_ csv, dst)
946 941316 static int cx_Print (pTHX_ csv_t *csv, SV *dst) {
947 int result;
948 941316 int keep = 0;
949  
950 941316 ▶ if (csv->useIO) {
Branch: 1 branch
BranchTrueFalseTotal
if (csv->useIO) { 939913 1403 941316
951 939913 SV *tmp = newSVpvn_flags (csv->buffer, csv->used, SVs_TEMP);
952 939913 dSP;
953 939913 ▶ PUSHMARK (sp);
Branch: 1 branch
BranchTrueFalseTotal
PUSHMARK (sp); 0 939913 939913
954 939913 ▶ EXTEND (sp, 2);
Branch: 1 branch
BranchTrueFalseTotal
EXTEND (sp, 2); 0 939913 939913
955 939913 PUSHs ((dst));
956 939913 ▶ if (csv->utf8) {
Branch: 1 branch
BranchTrueFalseTotal
if (csv->utf8) { 939652 261 939913
957 STRLEN len;
958 char *ptr;
959 int j;
960  
961 939652 ptr = SvPV (tmp, len);
962 3381042 ▶ while (len > 0 && !is_utf8_sv (tmp) && keep < 16) {
Branch: 3 branches
BranchTrueFalseTotal
while (len > 0 && !is_utf8_sv (tmp) && keep < 16) { 1690521 0 1690521
while (len > 0 && !is_utf8_sv (tmp) && keep < 16) { 750869 939652 1690521
while (len > 0 && !is_utf8_sv (tmp) && keep < 16) { 750869 0 750869
963 750869 ptr[--len] = (char)0;
964 750869 SvCUR_set (tmp, len);
965 750869 keep++;
966 }
967 1690521 ▶ for (j = 0; j < keep; j++)
Branch: 1 branch
BranchTrueFalseTotal
for (j = 0; j < keep; j++) 750869 939652 1690521
968 750869 csv->buffer[j] = csv->buffer[csv->used - keep + j];
969 939652 SvUTF8_on (tmp);
970 }
971 939913 PUSHs (tmp);
972 939913 PUTBACK;
973 939913 result = call_sv (m_print, G_METHOD);
974 939913 SPAGAIN;
975 939913 ▶ if (result) {
Branch: 1 branch
BranchTrueFalseTotal
if (result) { 939913 0 939913
976 939913 result = POPi;
977 939913 ▶ unless (result)
Branch: 1 branch
BranchTrueFalseTotal
unless (result) 1 939912 939913
978 1 (void)SetDiag (csv, 2200);
979 }
980 939913 PUTBACK;
981 }
982 else {
983 1403 sv_catpvn (SvRV (dst), csv->buffer, csv->used);
984 1403 result = TRUE;
985 }
986 941316 ▶ if (csv->utf8 && !csv->useIO && csv->decode_utf8
Branch: 3 branches
BranchTrueFalseTotal
if (csv->utf8 && !csv->useIO && csv->decode_utf8 939677 1639 941316
if (csv->utf8 && !csv->useIO && csv->decode_utf8 25 939652 939677
if (csv->utf8 && !csv->useIO && csv->decode_utf8 25 0 25
987 50 ▶ && SvROK (dst) && is_utf8_sv (SvRV (dst)))
Branch: 2 branches
BranchTrueFalseTotal
&& SvROK (dst) && is_utf8_sv (SvRV (dst))) 25 0 25
&& SvROK (dst) && is_utf8_sv (SvRV (dst))) 24 1 25
988 24 SvUTF8_on (SvRV (dst));
989 941316 csv->used = keep;
990 941316 return result;
991 } /* Print */
992  
993 #define CSV_PUT(csv,dst,c) { \
994 if ((csv)->used == sizeof ((csv)->buffer) - 1) { \
995 unless (Print ((csv), (dst))) \
996 return FALSE; \
997 } \
998 (csv)->buffer[(csv)->used++] = (c); \
999 }
1000  
1001 #define bound_field(csv,i,keep) cx_bound_field (aTHX_ csv, i, keep)
1002 180 static SV *cx_bound_field (pTHX_ csv_t *csv, SSize_t i, int keep) {
1003 180 SV *sv = csv->bound;
1004 AV *av;
1005  
1006 /* fprintf (stderr, "# New bind %d/%d\n", i, csv->is_bound);\ */
1007 180 ▶ if (i >= csv->is_bound) {
Branch: 1 branch
BranchTrueFalseTotal
if (i >= csv->is_bound) { 3 177 180
1008 3 (void)SetDiag (csv, 3006);
1009 3 return (NULL);
1010 }
1011  
1012 177 ▶ if (sv && SvROK (sv)) {
Branch: 2 branches
BranchTrueFalseTotal
if (sv && SvROK (sv)) { 177 0 177
if (sv && SvROK (sv)) { 177 0 177
1013 177 av = (AV *)(SvRV (sv));
1014 /* fprintf (stderr, "# Bind %d/%d/%d\n", i, csv->is_bound, av_len (av)); */
1015 177 sv = *av_fetch (av, i, FALSE);
1016 177 ▶ if (sv && SvROK (sv)) {
Branch: 2 branches
BranchTrueFalseTotal
if (sv && SvROK (sv)) { 177 0 177
if (sv && SvROK (sv)) { 177 0 177
1017 177 sv = SvRV (sv);
1018 177 ▶ if (keep)
Branch: 1 branch
BranchTrueFalseTotal
if (keep) 14 163 177
1019 14 return (sv);
1020  
1021 163 ▶ unless (SvREADONLY (sv)) {
Branch: 1 branch
BranchTrueFalseTotal
unless (SvREADONLY (sv)) { 162 1 163
1022 162 SvSetEmpty (sv);
1023 162 return (sv);
1024 }
1025 }
1026 }
1027 1 (void)SetDiag (csv, 3008);
1028 1 return (NULL);
1029 } /* bound_field */
1030  
1031 #define was_quoted(mf,idx) cx_was_quoted (aTHX_ mf, idx)
1032 17 static int cx_was_quoted (pTHX_ AV *mf, int idx) {
1033 17 SV **x = av_fetch (mf, idx, FALSE);
1034 17 ▶ return (x && SvIOK (*x) && SvIV (*x) & CSV_FLAGS_QUO ? 1 : 0);
Branch: 3 branches
BranchTrueFalseTotal
return (x && SvIOK (*x) && SvIV (*x) & CSV_FLAGS_QUO ? 1 : 0); 17 0 17
return (x && SvIOK (*x) && SvIV (*x) & CSV_FLAGS_QUO ? 1 : 0); 17 0 17
return (x && SvIOK (*x) && SvIV (*x) & CSV_FLAGS_QUO ? 1 : 0); 7 10 17
1035 } /* was_quoted */
1036  
1037 #define _formula(csv,sv,len,f) cx_formula (aTHX_ csv, sv, len, f)
1038 37 static char *cx_formula (pTHX_ csv_t *csv, SV *sv, STRLEN *len, int f) {
1039  
1040 37 int fa = csv->formula;
1041  
1042 37 ▶ if (fa == 1) die ("Formulas are forbidden\n");
Branch: 1 branch
BranchTrueFalseTotal
if (fa == 1) die ("Formulas are forbidden\n"); 3 34 37
1043 34 ▶ if (fa == 2) croak ("Formulas are forbidden\n");
Branch: 1 branch
BranchTrueFalseTotal
if (fa == 2) croak ("Formulas are forbidden\n"); 3 31 34
1044  
1045 31 ▶ if (fa == 3) {
Branch: 1 branch
BranchTrueFalseTotal
if (fa == 3) { 6 25 31
1046 6 char *ptr = SvPV_nolen (sv);
1047 char rec[40];
1048 char field[128];
1049 SV **svp;
1050  
1051 6 ▶ if (csv->recno) (void)sprintf (rec, " in record %lu", csv->recno + 1);
Branch: 1 branch
BranchTrueFalseTotal
if (csv->recno) (void)sprintf (rec, " in record %lu", csv->recno + 1); 3 3 6
1052 3 else *rec = (char)0;
1053  
1054 6 *field = (char)0;
1055 12 ▶ if ((svp = hv_fetchs (csv->self, "_COLUMN_NAMES", FALSE)) && _is_arrayref (*svp)) {
Branch: 6 branches
BranchTrueFalseTotal
if ((svp = hv_fetchs (csv->self, "_COLUMN_NAMES", FALSE)) && _is_arrayref (*svp)) { 6 0 6
if ((svp = hv_fetchs (csv->self, "_COLUMN_NAMES", FALSE)) && _is_arrayref (*svp)) { 6 0 6
if ((svp = hv_fetchs (csv->self, "_COLUMN_NAMES", FALSE)) && _is_arrayref (*svp)) { 0 6 6
if ((svp = hv_fetchs (csv->self, "_COLUMN_NAMES", FALSE)) && _is_arrayref (*svp)) { 0 0 0
if ((svp = hv_fetchs (csv->self, "_COLUMN_NAMES", FALSE)) && _is_arrayref (*svp)) { 1 5 6
if ((svp = hv_fetchs (csv->self, "_COLUMN_NAMES", FALSE)) && _is_arrayref (*svp)) { 1 0 1
1056 1 AV *avp = (AV *)SvRV (*svp);
1057 1 ▶ if (avp && av_len (avp) >= (f - 1)) {
Branch: 2 branches
BranchTrueFalseTotal
if (avp && av_len (avp) >= (f - 1)) { 1 0 1
if (avp && av_len (avp) >= (f - 1)) { 1 0 1
1058 1 SV **fnm = av_fetch (avp, f - 1, FALSE);
1059 1 ▶ if (fnm && *fnm && SvOK (*fnm))
Branch: 3 branches
BranchTrueFalseTotal
if (fnm && *fnm && SvOK (*fnm)) 1 0 1
if (fnm && *fnm && SvOK (*fnm)) 1 0 1
if (fnm && *fnm && SvOK (*fnm)) 1 0 1
1060 2 (void)sprintf (field, " (column: '%.100s')", SvPV_nolen (*fnm));
1061 }
1062 }
1063  
1064 6 warn ("Field %d%s%s contains formula '%s'\n", f, field, rec, ptr);
1065 6 return ptr;
1066 }
1067  
1068 25 ▶ if (len) *len = 0;
Branch: 1 branch
BranchTrueFalseTotal
if (len) *len = 0; 4 21 25
1069  
1070 25 ▶ if (fa == 4) {
Branch: 1 branch
BranchTrueFalseTotal
if (fa == 4) { 5 20 25
1071 5 ▶ unless (SvREADONLY (sv)) SvSetEmpty (sv);
Branch: 1 branch
BranchTrueFalseTotal
unless (SvREADONLY (sv)) SvSetEmpty (sv); 3 2 5
1072 5 return "";
1073 }
1074  
1075 20 ▶ if (fa == 5) {
Branch: 1 branch
BranchTrueFalseTotal
if (fa == 5) { 5 15 20
1076 5 ▶ unless (SvREADONLY (sv)) SvSetUndef (sv);
Branch: 1 branch
BranchTrueFalseTotal
unless (SvREADONLY (sv)) SvSetUndef (sv); 3 2 5
1077 5 return NULL;
1078 }
1079  
1080 15 ▶ if (fa == 6) {
Branch: 1 branch
BranchTrueFalseTotal
if (fa == 6) { 15 0 15
1081 int result;
1082 15 SV **svp = hv_fetchs (csv->self, "_FORMULA_CB", FALSE);
1083 30 ▶ if (svp && _is_coderef (*svp)) {
Branch: 6 branches
BranchTrueFalseTotal
if (svp && _is_coderef (*svp)) { 15 0 15
if (svp && _is_coderef (*svp)) { 15 0 15
if (svp && _is_coderef (*svp)) { 0 15 15
if (svp && _is_coderef (*svp)) { 0 0 0
if (svp && _is_coderef (*svp)) { 15 0 15
if (svp && _is_coderef (*svp)) { 15 0 15
1084 15 dSP;
1085 15 ENTER;
1086 15 SAVE_DEFSV; /* local $_ */
1087 15 ▶ DEFSV = sv;
Branch: 1 branch
BranchTrueFalseTotal
DEFSV = sv; 15 0 15
1088 15 ▶ PUSHMARK (SP);
Branch: 1 branch
BranchTrueFalseTotal
PUSHMARK (SP); 0 15 15
1089 15 PUTBACK;
1090 15 result = call_sv (*svp, G_SCALAR);
1091 15 SPAGAIN;
1092 15 ▶ if (result)
Branch: 1 branch
BranchTrueFalseTotal
if (result) 15 0 15
1093 15 sv_setsv (sv, POPs);
1094 15 PUTBACK;
1095 15 LEAVE;
1096 }
1097 30 ▶ return len ? SvPV (sv, *len) : SvPV_nolen (sv);
Branch: 1 branch
BranchTrueFalseTotal
return len ? SvPV (sv, *len) : SvPV_nolen (sv); 0 15 15
1098 }
1099  
1100 /* So far undefined behavior */
1101 0 return NULL;
1102 } /* _formula */
1103  
1104 #define SkipEmptyRow {\
1105 int ser = csv->skip_empty_rows; \
1106 \
1107 if (ser == 3) { (void)SetDiag (csv, 2015); die ("Empty row"); } \
1108 if (ser == 4) { (void)SetDiag (csv, 2015); croak ("Empty row"); } \
1109 if (ser == 5) { (void)SetDiag (csv, 2015); return FALSE; } \
1110 \
1111 if (ser <= 2) { /* skip & eof */ \
1112 csv->fld_idx = 0; \
1113 c = CSV_GET; \
1114 if (c == EOF || ser == 2) { \
1115 unless (csv->is_bound) sv_free (sv); \
1116 sv = NULL; \
1117 seenSomething = FALSE; \
1118 if (ser == 2) return FALSE; \
1119 break; \
1120 } \
1121 } \
1122 \
1123 if (ser == 6) { \
1124 int result, n, i; \
1125 SV *rv, **svp = hv_fetchs (csv->self, "_EMPTROW_CB", FALSE); \
1126 AV *avp; \
1127 unless (svp && _is_coderef (*svp)) \
1128 return FALSE; /* A callback is wanted, but none found */ \
1129 \
1130 dSP; \
1131 ENTER; \
1132 SAVE_DEFSV; /* local $_ */ \
1133 DEFSV = sv; \
1134 PUSHMARK (SP); \
1135 PUTBACK; \
1136 result = call_sv (*svp, G_SCALAR); \
1137 SPAGAIN; \
1138 unless (result) { \
1139 /* A false return will stop the parsing */ \
1140 unless (csv->is_bound) sv_free (sv); \
1141 sv = NULL; \
1142 waitingForField = 0; \
1143 return FALSE; \
1144 } \
1145 \
1146 PUTBACK; \
1147 LEAVE; \
1148 \
1149 rv = POPs; \
1150 /* Result should be a ref to a list. */ \
1151 unless (_is_arrayref (rv)) \
1152 return FALSE; \
1153 \
1154 avp = (AV *)SvRV (rv); \
1155 \
1156 unless (avp) return FALSE; \
1157 n = av_len (avp); \
1158 if (n <= 0) return TRUE; \
1159 \
1160 if (csv->is_bound && csv->is_bound < n) \
1161 n = csv->is_bound - 1; \
1162 \
1163 for (i = 0; i <= n; i++) { \
1164 SV **svp = av_fetch (avp, i, FALSE); \
1165 sv = svp && *svp ? *svp : NULL; \
1166 if (sv) { \
1167 SvREFCNT_inc (sv); \
1168 /* upgrade IV to IVPV if needed */ \
1169 (void)SvPV_nolen (sv); \
1170 } \
1171 AV_PUSH; \
1172 } \
1173 return TRUE; \
1174 } \
1175 }
1176  
1177 #define Combine(csv,dst,fields) cx_Combine (aTHX_ csv, dst, fields)
1178 221687 static int cx_Combine (pTHX_ csv_t *csv, SV *dst, AV *fields) {
1179 SSize_t i, n;
1180 221687 int bound = 0;
1181 221687 int aq = (int)csv->always_quote;
1182 221687 int qe = (int)csv->quote_empty;
1183 221687 int kmi = (int)csv->keep_meta_info;
1184 221687 AV *qm = NULL;
1185  
1186 221687 n = (IV)av_len (fields);
1187 221687 ▶ if (n < 0 && csv->is_bound) {
Branch: 2 branches
BranchTrueFalseTotal
if (n < 0 && csv->is_bound) { 200006 21681 221687
if (n < 0 && csv->is_bound) { 5 200001 200006
1188 5 n = csv->is_bound - 1;
1189 5 bound = 1;
1190 }
1191  
1192 221687 ▶ if (kmi >= 10) {
Branch: 1 branch
BranchTrueFalseTotal
if (kmi >= 10) { 2 221685 221687
1193 SV **svp;
1194 4 ▶ if ((svp = hv_fetchs (csv->self, "_FFLAGS", FALSE)) && _is_arrayref (*svp)) {
Branch: 6 branches
BranchTrueFalseTotal
if ((svp = hv_fetchs (csv->self, "_FFLAGS", FALSE)) && _is_arrayref (*svp)) { 2 0 2
if ((svp = hv_fetchs (csv->self, "_FFLAGS", FALSE)) && _is_arrayref (*svp)) { 2 0 2
if ((svp = hv_fetchs (csv->self, "_FFLAGS", FALSE)) && _is_arrayref (*svp)) { 0 2 2
if ((svp = hv_fetchs (csv->self, "_FFLAGS", FALSE)) && _is_arrayref (*svp)) { 0 0 0
if ((svp = hv_fetchs (csv->self, "_FFLAGS", FALSE)) && _is_arrayref (*svp)) { 2 0 2
if ((svp = hv_fetchs (csv->self, "_FFLAGS", FALSE)) && _is_arrayref (*svp)) { 2 0 2
1195 2 AV *avp = (AV *)SvRV (*svp);
1196 2 ▶ if (avp && av_len (avp) >= n)
Branch: 2 branches
BranchTrueFalseTotal
if (avp && av_len (avp) >= n) 2 0 2
if (avp && av_len (avp) >= n) 2 0 2
1197 2 qm = avp;
1198 }
1199 }
1200  
1201 275657 ▶ for (i = 0; i <= n; i++) {
Branch: 1 branch
BranchTrueFalseTotal
for (i = 0; i <= n; i++) { 53981 221676 275657
1202 SV *sv;
1203 53981 STRLEN len = 0;
1204 53981 char *ptr = NULL;
1205  
1206 53981 ▶ if (i > 0) {
Branch: 1 branch
BranchTrueFalseTotal
if (i > 0) { 32295 21686 53981
1207 32302 ▶ CSV_PUT (csv, dst, CH_SEP);
Branch: 2 branches
BranchTrueFalseTotal
CSV_PUT (csv, dst, CH_SEP); 0 32295 32295
CSV_PUT (csv, dst, CH_SEP); 0 0 0
1208 32295 ▶ if (csv->sep_len) {
Branch: 1 branch
BranchTrueFalseTotal
if (csv->sep_len) { 10 32285 32295
1209 int x;
1210 30 ▶ for (x = 1; x < (int)csv->sep_len; x++)
Branch: 1 branch
BranchTrueFalseTotal
for (x = 1; x < (int)csv->sep_len; x++) 20 10 30
1211 20 ▶ CSV_PUT (csv, dst, csv->sep[x]);
Branch: 2 branches
BranchTrueFalseTotal
CSV_PUT (csv, dst, csv->sep[x]); 0 20 20
CSV_PUT (csv, dst, csv->sep[x]); 0 0 0
1212 }
1213 }
1214  
1215 53981 ▶ if (bound)
Branch: 1 branch
BranchTrueFalseTotal
if (bound) 14 53967 53981
1216 14 sv = bound_field (csv, i, 1);
1217 else {
1218 53967 SV **svp = av_fetch (fields, i, FALSE);
1219 53967 ▶ sv = svp && *svp ? *svp : NULL;
Branch: 2 branches
BranchTrueFalseTotal
sv = svp && *svp ? *svp : NULL; 53967 0 53967
sv = svp && *svp ? *svp : NULL; 53967 0 53967
1220 }
1221  
1222 53981 ▶ if (sv && (SvOK (sv) || (
Branch: 2 branches
BranchTrueFalseTotal
if (sv && (SvOK (sv) || ( 53981 0 53981
if (sv && (SvOK (sv) || ( 55 53926 53981
1223 53968 ▶ (SvGMAGICAL (sv) && (mg_get (sv), 1) && SvOK (sv))))) {
Branch: 2 branches
BranchTrueFalseTotal
(SvGMAGICAL (sv) && (mg_get (sv), 1) && SvOK (sv))))) { 0 55 55
(SvGMAGICAL (sv) && (mg_get (sv), 1) && SvOK (sv))))) { 0 0 0
1224  
1225 int quoteMe;
1226  
1227 53926 ptr = SvPV (sv, len);
1228  
1229 53926 ▶ if (*ptr == '=' && csv->formula) {
Branch: 2 branches
BranchTrueFalseTotal
if (*ptr == '=' && csv->formula) { 16 53910 53926
if (*ptr == '=' && csv->formula) { 10 6 16
1230 10 ▶ unless (ptr = _formula (csv, sv, &len, i))
Branch: 1 branch
BranchTrueFalseTotal
unless (ptr = _formula (csv, sv, &len, i)) 2 4 6
1231 2 continue;
1232 }
1233 53920 ▶ if (len == 0)
Branch: 1 branch
BranchTrueFalseTotal
if (len == 0) 1412 52508 53920
1234 1412 ▶ quoteMe = aq ? 1 : qe ? 1 : qm ? was_quoted (qm, i) : 0;
Branch: 3 branches
BranchTrueFalseTotal
quoteMe = aq ? 1 : qe ? 1 : qm ? was_quoted (qm, i) : 0; 763 649 1412
quoteMe = aq ? 1 : qe ? 1 : qm ? was_quoted (qm, i) : 0; 760 3 763
quoteMe = aq ? 1 : qe ? 1 : qm ? was_quoted (qm, i) : 0; 5 755 760
1235 else {
1236  
1237 52508 ▶ if (SvUTF8 (sv)) {
Branch: 1 branch
BranchTrueFalseTotal
if (SvUTF8 (sv)) { 20045 32463 52508
1238 20045 csv->utf8 = 1;
1239 20045 csv->binary = 1;
1240 }
1241  
1242 52508 ▶ quoteMe = aq ? 1 : qm ? was_quoted (qm, i) : 0;
Branch: 2 branches
BranchTrueFalseTotal
quoteMe = aq ? 1 : qm ? was_quoted (qm, i) : 0; 46885 5623 52508
quoteMe = aq ? 1 : qm ? was_quoted (qm, i) : 0; 12 46873 46885
1243  
1244 /* Do we need quoting? We do quote, if the user requested
1245 * (always_quote), if binary or blank characters are found
1246 * and if the string contains quote or escape characters.
1247 */
1248 52508 ▶ if (!quoteMe && (quoteMe = CH_QUOTE)) {
Branch: 2 branches
BranchTrueFalseTotal
if (!quoteMe && (quoteMe = CH_QUOTE)) { 46880 5628 52508
if (!quoteMe && (quoteMe = CH_QUOTE)) { 46877 3 46880
1249 char *ptr2;
1250 STRLEN l;
1251  
1252 #if MAINT_DEBUG > 6
1253 (void)fprintf (stderr, "# %04d Combine:\n", __LINE__);
1254 sv_dump (sv);
1255 #else
1256 #if MAINT_DEBUG > 4
1257 (void)fprintf (stderr, "# %04d Combine: '%s'\n", __LINE__, _pretty_sv (sv));
1258 #endif
1259 #endif
1260 130581 ▶ for (ptr2 = ptr, l = len; l; ++ptr2, --l) {
Branch: 1 branch
BranchTrueFalseTotal
for (ptr2 = ptr, l = len; l; ++ptr2, --l) { 106840 23741 130581
1261 106840 byte c = *ptr2;
1262 #ifdef IS_EBCDIC
1263 byte x = ebcdic2ascii[c];
1264 #if MAINT_DEBUG > 4
1265 (void)fprintf (stderr, " %02x", x);
1266 #endif
1267 #else
1268 106840 byte x = c;
1269 #endif
1270  
1271 106840 ▶ if ((CH_QUOTE && c == CH_QUOTE) ||
Branch: 2 branches
BranchTrueFalseTotal
if ((CH_QUOTE && c == CH_QUOTE) || 106840 0 106840
if ((CH_QUOTE && c == CH_QUOTE) || 106531 309 106840
1272 106531 ▶ (CH_SEP && c == CH_SEP) ||
Branch: 2 branches
BranchTrueFalseTotal
(CH_SEP && c == CH_SEP) || 104136 2395 106531
(CH_SEP && c == CH_SEP) || 103985 151 104136
1273 212536 ▶ (csv->escape_char && c == csv->escape_char) ||
Branch: 4 branches
BranchTrueFalseTotal
(csv->escape_char && c == csv->escape_char) || 106376 4 106380
(csv->escape_char && c == csv->escape_char) || 106152 224 106376
(csv->escape_char && c == csv->escape_char) || 83694 22450 106144
(csv->escape_char && c == csv->escape_char) || 10 2 12
1274 192279 ▶ (csv->quote_binary ? (x >= 0x7f && x <= 0xa0) ||
Branch: 3 branches
BranchTrueFalseTotal
(csv->quote_binary ? (x >= 0x7f && x <= 0xa0) || 106144 12 106156
(csv->quote_binary ? (x >= 0x7f && x <= 0xa0) || 40074 66070 106144
(csv->quote_binary ? (x >= 0x7f && x <= 0xa0) || 20053 20021 40074
1275 86123 ▶ x < csv->first_safe_char
Branch: 1 branch
BranchTrueFalseTotal
x < csv->first_safe_char 2429 83694 86123
1276 24 ▶ : c == CH_NL || c == CH_CR ||
Branch: 2 branches
BranchTrueFalseTotal
: c == CH_NL || c == CH_CR || 12 0 12
: c == CH_NL || c == CH_CR || 12 0 12
1277 12 ▶ (csv->quote_space && (
Branch: 2 branches
BranchTrueFalseTotal
(csv->quote_space && ( 6 6 12
(csv->quote_space && ( 4 2 6
1278 4 ▶ c == CH_SPACE || c == CH_TAB)))) {
Branch: 1 branch
BranchTrueFalseTotal
c == CH_SPACE || c == CH_TAB)))) { 0 4 4
1279 /* Binary character */
1280 break;
1281 }
1282 }
1283 #if defined(IS_EBCDIC) && MAINT_DEBUG > 4
1284 (void)fprintf (stderr, "\n");
1285 #endif
1286 46877 quoteMe = (l > 0);
1287 }
1288 }
1289 53920 ▶ if (quoteMe) {
Branch: 1 branch
BranchTrueFalseTotal
if (quoteMe) { 29418 24502 53920
1290 29418 ▶ CSV_PUT (csv, dst, CH_QUOTE);
Branch: 2 branches
BranchTrueFalseTotal
CSV_PUT (csv, dst, CH_QUOTE); 0 29418 29418
CSV_PUT (csv, dst, CH_QUOTE); 0 0 0
1291 29418 ▶ if (csv->quo_len) {
Branch: 1 branch
BranchTrueFalseTotal
if (csv->quo_len) { 17 29401 29418
1292 int x;
1293 51 ▶ for (x = 1; x < (int)csv->quo_len; x++)
Branch: 1 branch
BranchTrueFalseTotal
for (x = 1; x < (int)csv->quo_len; x++) 34 17 51
1294 34 ▶ CSV_PUT (csv, dst, csv->quo[x]);
Branch: 2 branches
BranchTrueFalseTotal
CSV_PUT (csv, dst, csv->quo[x]); 0 34 34
CSV_PUT (csv, dst, csv->quo[x]); 0 0 0
1295 }
1296 }
1297 950415637 ▶ while (len-- > 0) {
Branch: 1 branch
BranchTrueFalseTotal
while (len-- > 0) { 950361724 53913 950415637
1298 950361724 char c = *ptr++;
1299 950361724 int e = 0;
1300  
1301 950361724 ▶ if (!csv->binary && is_csv_binary (c)) {
Branch: 4 branches
BranchTrueFalseTotal
if (!csv->binary && is_csv_binary (c)) { 786 950360938 950361724
if (!csv->binary && is_csv_binary (c)) { 769 17 786
if (!csv->binary && is_csv_binary (c)) { 0 769 769
if (!csv->binary && is_csv_binary (c)) { 7 10 17
1302 7 SvREFCNT_inc (sv);
1303 7 csv->has_error_input = 1;
1304 7 ▶ unless (hv_store (csv->self, "_ERROR_INPUT", 12, sv, 0))
Branch: 1 branch
BranchTrueFalseTotal
unless (hv_store (csv->self, "_ERROR_INPUT", 12, sv, 0)) 0 7 7
1305 0 SvREFCNT_dec (sv); /* uncoverable statement memory fail */
1306 7 (void)SetDiag (csv, 2110);
1307 7 return FALSE;
1308 }
1309 950361717 ▶ if (CH_QUOTE && (byte)c == CH_QUOTE && (csv->quo_len == 0 ||
Branch: 3 branches
BranchTrueFalseTotal
if (CH_QUOTE && (byte)c == CH_QUOTE && (csv->quo_len == 0 || 950361708 9 950361717
if (CH_QUOTE && (byte)c == CH_QUOTE && (csv->quo_len == 0 || 3226 950358482 950361708
if (CH_QUOTE && (byte)c == CH_QUOTE && (csv->quo_len == 0 || 9 3217 3226
1310 9 ▶ memcmp (ptr, csv->quo +1, csv->quo_len - 1) == 0))
Branch: 1 branch
BranchTrueFalseTotal
memcmp (ptr, csv->quo +1, csv->quo_len - 1) == 0)) 1 8 9
1311 3218 e = 1;
1312 else
1313 950358499 ▶ if (c == csv->escape_char && csv->escape_char)
Branch: 2 branches
BranchTrueFalseTotal
if (c == csv->escape_char && csv->escape_char) 2165 950356334 950358499
if (c == csv->escape_char && csv->escape_char) 2163 2 2165
1314 2163 e = 1;
1315 else
1316 950356336 ▶ if (c == (char)0 && csv->escape_null) {
Branch: 2 branches
BranchTrueFalseTotal
if (c == (char)0 && csv->escape_null) { 56 950356280 950356336
if (c == (char)0 && csv->escape_null) { 29 27 56
1317 29 e = 1;
1318 29 c = '0';
1319 }
1320 950361717 ▶ if (e && csv->escape_char)
Branch: 2 branches
BranchTrueFalseTotal
if (e && csv->escape_char) 5410 950356307 950361717
if (e && csv->escape_char) 5410 0 5410
1321 5410 ▶ CSV_PUT (csv, dst, csv->escape_char);
Branch: 2 branches
BranchTrueFalseTotal
CSV_PUT (csv, dst, csv->escape_char); 0 5410 5410
CSV_PUT (csv, dst, csv->escape_char); 0 0 0
1322 950361717 ▶ CSV_PUT (csv, dst, c);
Branch: 2 branches
BranchTrueFalseTotal
CSV_PUT (csv, dst, c); 919632 949442085 950361717
CSV_PUT (csv, dst, c); 0 919632 919632
1323 }
1324 53913 ▶ if (quoteMe) {
Branch: 1 branch
BranchTrueFalseTotal
if (quoteMe) { 29411 24502 53913
1325 29411 ▶ CSV_PUT (csv, dst, CH_QUOTE);
Branch: 2 branches
BranchTrueFalseTotal
CSV_PUT (csv, dst, CH_QUOTE); 0 29411 29411
CSV_PUT (csv, dst, CH_QUOTE); 0 0 0
1326 29411 ▶ if (csv->quo_len) {
Branch: 1 branch
BranchTrueFalseTotal
if (csv->quo_len) { 17 29394 29411
1327 int x;
1328 51 ▶ for (x = 1; x < (int)csv->quo_len; x++)
Branch: 1 branch
BranchTrueFalseTotal
for (x = 1; x < (int)csv->quo_len; x++) 34 17 51
1329 34 ▶ CSV_PUT (csv, dst, csv->quo[x]);
Branch: 2 branches
BranchTrueFalseTotal
CSV_PUT (csv, dst, csv->quo[x]); 0 34 34
CSV_PUT (csv, dst, csv->quo[x]); 0 0 0
1330 }
1331 }
1332 }
1333 else {
1334 55 ▶ if (csv->undef_str) {
Branch: 1 branch
BranchTrueFalseTotal
if (csv->undef_str) { 10 45 55
1335 10 byte *ptr = csv->undef_str;
1336 10 STRLEN len = strlen ((char *)ptr);
1337  
1338 10 ▶ if (csv->undef_flg) {
Branch: 1 branch
BranchTrueFalseTotal
if (csv->undef_flg) { 3 7 10
1339 3 csv->utf8 = 1;
1340 3 csv->binary = 1;
1341 }
1342  
1343 8224 ▶ while (len--)
Branch: 1 branch
BranchTrueFalseTotal
while (len--) 8214 10 8224
1344 8214 ▶ CSV_PUT (csv, dst, *ptr++);
Branch: 2 branches
BranchTrueFalseTotal
CSV_PUT (csv, dst, *ptr++); 8 8206 8214
CSV_PUT (csv, dst, *ptr++); 0 8 8
1345 }
1346 }
1347 }
1348 221676 ▶ if (csv->eol_len) {
Branch: 1 branch
BranchTrueFalseTotal
if (csv->eol_len) { 249 221427 221676
1349 249 STRLEN len = csv->eol_len;
1350 249 byte *ptr = csv->eol;
1351  
1352 696 ▶ while (len--)
Branch: 1 branch
BranchTrueFalseTotal
while (len--) 447 249 696
1353 447 ▶ CSV_PUT (csv, dst, *ptr++);
Branch: 2 branches
BranchTrueFalseTotal
CSV_PUT (csv, dst, *ptr++); 0 447 447
CSV_PUT (csv, dst, *ptr++); 0 0 0
1354 }
1355 221676 ▶ if (csv->used) {
Branch: 1 branch
BranchTrueFalseTotal
if (csv->used) { 21674 200002 221676
1356 21674 ▶ unless (Print (csv, dst))
Branch: 1 branch
BranchTrueFalseTotal
unless (Print (csv, dst)) 1 21673 21674
1357 1 return FALSE;
1358 21673 ▶ if (csv->used) {
Branch: 1 branch
BranchTrueFalseTotal
if (csv->used) { 2 21671 21673
1359 /* Print () held back trailing bytes that are not valid UTF-8
1360 * to complete them on the next flush. This was the last flush
1361 * of the record, so write them now, as they are */
1362 2 int r, utf8 = csv->utf8;
1363 2 csv->utf8 = 0;
1364 2 r = Print (csv, dst);
1365 2 csv->utf8 = utf8;
1366 2 return r;
1367 }
1368 }
1369 221673 return TRUE;
1370 } /* Combine */
1371  
1372 #if MAINT_DEBUG > 6
1373 #define ErrorDiag(csv) cx_ErrorDiag (aTHX_ csv)
1374 static void cx_ErrorDiag (pTHX_ csv_t *csv) {
1375 SV **svp;
1376  
1377 if ((svp = hv_fetchs (csv->self, "_ERROR_DIAG", FALSE)) && *svp) {
1378 if (SvIOK (*svp)) (void)fprintf (stderr, "ERR: %d\n", SvIV (*svp));
1379 if (SvPOK (*svp)) (void)fprintf (stderr, "ERR: %s\n", SvPV_nolen (*svp));
1380 }
1381 if ((svp = hv_fetchs (csv->self, "_ERROR_POS", FALSE)) && *svp) {
1382 if (SvIOK (*svp)) (void)fprintf (stderr, "POS: %d\n", SvIV (*svp));
1383 }
1384 if ((svp = hv_fetchs (csv->self, "_ERROR_FLD", FALSE)) && *svp) {
1385 if (SvIOK (*svp)) (void)fprintf (stderr, "FLD: %d\n", SvIV (*svp));
1386 }
1387 if ((svp = hv_fetchs (csv->self, "_ERROR_SRC", FALSE)) && *svp) {
1388 if (SvIOK (*svp)) (void)fprintf (stderr, "SRC: XS#%d\n", SvIV (*svp));
1389 }
1390 } /* ErrorDiag */
1391 #endif
1392  
1393 #define ParseError(csv,xse,pos) cx_ParseError (aTHX_ csv, xse, pos, __LINE__)
1394 374 static void cx_ParseError (pTHX_ csv_t *csv, int xse, STRLEN pos, int line) {
1395 374 (void)hv_store (csv->self, "_ERROR_POS", 10, newSViv (pos), 0);
1396 374 (void)hv_store (csv->self, "_ERROR_FLD", 10, newSViv (csv->fld_idx), 0);
1397 374 ▶ if (csv->tmp) {
Branch: 1 branch
BranchTrueFalseTotal
if (csv->tmp) { 374 0 374
1398 374 csv->has_error_input = 1;
1399 374 ▶ if (hv_store (csv->self, "_ERROR_INPUT", 12, csv->tmp, 0))
Branch: 1 branch
BranchTrueFalseTotal
if (hv_store (csv->self, "_ERROR_INPUT", 12, csv->tmp, 0)) 374 0 374
1400 374 SvREFCNT_inc (csv->tmp);
1401 else
1402 0 SvREFCNT_dec (csv->tmp);
1403 }
1404 374 (void)SetDiagL (csv, xse, line);
1405 371 } /* ParseError */
1406  
1407 #define CsvGet(csv,src) cx_CsvGet (aTHX_ csv, src)
1408 5487 static int cx_CsvGet (pTHX_ csv_t *csv, SV *src) {
1409 5487 ▶ unless (csv->useIO)
Branch: 1 branch
BranchTrueFalseTotal
unless (csv->useIO) 1533 3954 5487
1410 1533 return EOF;
1411  
1412 3954 ▶ if (csv->tmp && csv->eol_pos >= 0) {
Branch: 2 branches
BranchTrueFalseTotal
if (csv->tmp && csv->eol_pos >= 0) { 954 3000 3954
if (csv->tmp && csv->eol_pos >= 0) { 348 606 954
1413 348 csv->eol_pos = -2;
1414 348 sv_setpvn (csv->tmp, (char *)csv->eol, csv->eol_len);
1415 348 csv->bptr = SvPV (csv->tmp, csv->size);
1416 348 csv->used = 0;
1417 348 return CH_EOLX;
1418 }
1419  
1420 { STRLEN result;
1421 3606 dSP;
1422  
1423 3606 ▶ PUSHMARK (sp);
Branch: 1 branch
BranchTrueFalseTotal
PUSHMARK (sp); 0 3606 3606
1424 3606 ▶ EXTEND (sp, 1);
Branch: 1 branch
BranchTrueFalseTotal
EXTEND (sp, 1); 0 3606 3606
1425 3606 PUSHs (src);
1426 3606 PUTBACK;
1427 3606 result = call_sv (m_getline, G_METHOD);
1428 3606 SPAGAIN;
1429 3606 csv->eol_pos = -1;
1430 3606 ▶ csv->tmp = result ? POPs : NULL;
Branch: 1 branch
BranchTrueFalseTotal
csv->tmp = result ? POPs : NULL; 3606 0 3606
1431 3606 PUTBACK;
1432  
1433 #if MAINT_DEBUG > 6
1434 (void)fprintf (stderr, "# %04d getline () returned:\n", __LINE__);
1435 sv_dump (csv->tmp);
1436 #else
1437 #if MAINT_DEBUG > 4
1438 (void)fprintf (stderr, "# %04d getline () returned: '%s'\n", __LINE__, _pretty_sv (csv->tmp));
1439 #endif
1440 #endif
1441 }
1442 3606 ▶ if (csv->tmp && SvOK (csv->tmp)) {
Branch: 2 branches
BranchTrueFalseTotal
if (csv->tmp && SvOK (csv->tmp)) { 3606 0 3606
if (csv->tmp && SvOK (csv->tmp)) { 2948 658 3606
1443 STRLEN tmp_len;
1444 2948 csv->bptr = SvPV (csv->tmp, tmp_len);
1445 2948 csv->used = 0;
1446 2948 csv->size = tmp_len;
1447 2948 ▶ if (csv->eolx && csv->size >= csv->eol_len) {
Branch: 2 branches
BranchTrueFalseTotal
if (csv->eolx && csv->size >= csv->eol_len) { 358 2590 2948
if (csv->eolx && csv->size >= csv->eol_len) { 358 0 358
1448 358 int i, match = 1;
1449 1817 ▶ for (i = 1; i <= (int)csv->eol_len; i++) {
Branch: 1 branch
BranchTrueFalseTotal
for (i = 1; i <= (int)csv->eol_len; i++) { 1463 354 1817
1450 1463 ▶ unless (csv->bptr[csv->size - i] == csv->eol[csv->eol_len - i]) {
Branch: 1 branch
BranchTrueFalseTotal
unless (csv->bptr[csv->size - i] == csv->eol[csv->eol_len - i]) { 4 1459 1463
1451 4 match = 0;
1452 4 break;
1453 }
1454 }
1455 358 ▶ if (match) {
Branch: 1 branch
BranchTrueFalseTotal
if (match) { 354 4 358
1456 #if MAINT_DEBUG > 4 || MAIN_DEBUG_EOL > 0
1457 (void)fprintf (stderr, "# %04d EOLX match, size: %d\n", __LINE__, csv->size);
1458 #endif
1459 354 csv->size -= csv->eol_len;
1460 354 ▶ unless (csv->verbatim)
Branch: 1 branch
BranchTrueFalseTotal
unless (csv->verbatim) 351 3 354
1461 351 csv->eol_pos = csv->size;
1462 354 csv->bptr[csv->size] = (char)0;
1463 354 SvCUR_set (csv->tmp, csv->size);
1464 354 ▶ unless (csv->verbatim || csv->size)
Branch: 2 branches
BranchTrueFalseTotal
unless (csv->verbatim || csv->size) 351 3 354
unless (csv->verbatim || csv->size) 6 345 351
1465 2948 return CH_EOLX;
1466 }
1467 }
1468 2942 ▶ if (SvUTF8 (csv->tmp)) csv->utf8 = 1;
Branch: 1 branch
BranchTrueFalseTotal
if (SvUTF8 (csv->tmp)) csv->utf8 = 1; 70 2872 2942
1469 2942 ▶ if (tmp_len)
Branch: 1 branch
BranchTrueFalseTotal
if (tmp_len) 2942 0 2942
1470 2942 return ((byte)csv->bptr[csv->used++]);
1471 }
1472 658 csv->useIO |= useIO_EOF;
1473 658 return EOF;
1474 } /* CsvGet */
1475  
1476 #define ERROR_INSIDE_QUOTES(diag_code) { \
1477 unless (csv->is_bound) SvREFCNT_dec (sv); \
1478 ParseError (csv, diag_code, csv->used - 1); \
1479 return FALSE; \
1480 }
1481 #define ERROR_INSIDE_FIELD(diag_code) { \
1482 unless (csv->is_bound) SvREFCNT_dec (sv); \
1483 ParseError (csv, diag_code, csv->used - 1); \
1484 return FALSE; \
1485 }
1486 #define ERROR_EOL { \
1487 unless (csv->strict_eol & 0x40) \
1488 ParseError (csv, 2016, csv->used - 1); \
1489 if (csv->strict_eol & 0x0e) { \
1490 if (!csv->is_bound) SvREFCNT_dec (sv); \
1491 return FALSE; \
1492 } \
1493 csv->strict_eol |= 0x40; \
1494 }
1495  
1496 #if MAINT_DEBUG > 4
1497 #define PUT_RPT (void)fprintf (stderr, "# %04d CSV_PUT: 0x%02x '%c'\n", __LINE__, c, isprint (c) ? c : '?')
1498 #define PUT_SEPX_RPT1 (void)fprintf (stderr, "# %04d PUT SEPX\n", __LINE__)
1499 #define PUT_SEPX_RPT2 (void)fprintf (stderr, "# %04d Done putting SEPX\n")
1500 #define PUT_QUOX_RPT1 (void)fprintf (stderr, "# %04d PUT QUOX\n", __LINE__)
1501 #define PUT_QUOX_RPT2 (void)fprintf (stderr, "# %04d Done putting QUOX\n")
1502 #define PUT_EOLX_RPT1 (void)fprintf (stderr, "# %04d PUT EOLX\n", __LINE__)
1503 #define PUT_EOLX_RPT2 (void)fprintf (stderr, "# %04d Done putting EOLX\n")
1504 #if MAINT_DEBUG > 6
1505 #define PUSH_RPT (void)fprintf (stderr, "# %04d AV_PUSHd\n", __LINE__); sv_dump (sv)
1506 #else
1507 #define PUSH_RPT (void)fprintf (stderr, "# %04d AV_PUSHd '%s'\n", __LINE__, _pretty_sv (sv))
1508 #endif
1509 #else
1510 #define PUT_RPT
1511 #define PUT_SEPX_RPT1
1512 #define PUT_SEPX_RPT2
1513 #define PUT_QUOX_RPT1
1514 #define PUT_QUOX_RPT2
1515 #define PUT_EOLX_RPT1
1516 #define PUT_EOLX_RPT2
1517 #define PUSH_RPT
1518 #endif
1519 #define CSV_PUT_SV1(c) { \
1520 len = SvCUR ((sv)); \
1521 SvGROW ((sv), len + 2); \
1522 *SvEND ((sv)) = c; \
1523 PUT_RPT; \
1524 SvCUR_set ((sv), len + 1); \
1525 }
1526 #define CSV_PUT_SV(c) { \
1527 if (c == CH_EOLX) { \
1528 int x; PUT_EOLX_RPT1; \
1529 if (csv->eol_pos == -2) \
1530 csv->size = 0; \
1531 for (x = 0; x < (int)csv->eol_len; x++) \
1532 CSV_PUT_SV1 (csv->eol[x]); \
1533 csv->eol_pos = -1; \
1534 PUT_EOLX_RPT2; \
1535 } \
1536 else if (c == CH_SEPX) { \
1537 int x; PUT_SEPX_RPT1; \
1538 for (x = 0; x < (int)csv->sep_len; x++) \
1539 CSV_PUT_SV1 (csv->sep[x]); \
1540 PUT_SEPX_RPT2; \
1541 } \
1542 else if (c == CH_QUOTEX) { \
1543 int x; PUT_QUOX_RPT1; \
1544 for (x = 0; x < (int)csv->quo_len; x++) \
1545 CSV_PUT_SV1 (csv->quo[x]); \
1546 PUT_QUOX_RPT2; \
1547 } \
1548 else \
1549 CSV_PUT_SV1 (c); \
1550 }
1551  
1552 #define CSV_GET1 \
1553 (csv->used < csv->size ? (byte)csv->bptr[csv->used++] : CsvGet (csv, src))
1554  
1555 #if MAINT_DEBUG > 3
1556 int CSV_GET_ (pTHX_ csv_t *csv, SV *src, int l) {
1557 int c;
1558 (void)fprintf (stderr, "# %04d 1-CSV_GET: (used: %d, size: %d, eol_pos: %d, eolx = %d)\n", l, csv->used, csv->size, csv->eol_pos, csv->eolx);
1559 c = CSV_GET1;
1560 (void)fprintf (stderr, "# %04d 2-CSV_GET: 0x%02x '%c'\n", l, c, isprint (c) ? c : '?');
1561 return (c);
1562 } /* CSV_GET_ */
1563 #define CSV_GET CSV_GET_ (aTHX_ csv, src, __LINE__)
1564 #else
1565 #define CSV_GET CSV_GET1
1566 #endif
1567  
1568 #define AV_PUSH { \
1569 int svc; \
1570 *SvEND (sv) = (char)0; \
1571 svc = SvCUR (sv); \
1572 SvUTF8_off (sv); \
1573 if (svc && csv->formula && *(SvPV_nolen (sv)) == '=') \
1574 (void)_formula (csv, sv, NULL, fnum); \
1575 if (svc == 0 && ( \
1576 csv->empty_is_undef || \
1577 (!(f & CSV_FLAGS_QUO) && csv->blank_is_undef))) \
1578 SvSetUndef (sv); \
1579 else { \
1580 if (csv->allow_whitespace && ! (f & CSV_FLAGS_QUO)) \
1581 strip_trail_whitespace (sv); \
1582 if (f & CSV_FLAGS_BIN && csv->decode_utf8 \
1583 && (csv->utf8 || is_utf8_sv (sv))) \
1584 SvUTF8_on (sv); \
1585 } \
1586 SvSETMAGIC (sv); \
1587 unless (csv->is_bound) av_push (fields, sv); \
1588 PUSH_RPT; \
1589 sv = NULL; \
1590 if (csv->keep_meta_info && fflags) \
1591 av_push (fflags, newSViv (f)); \
1592 waitingForField = 1; \
1593 }
1594  
1595 #define strip_trail_whitespace(sv) cx_strip_trail_whitespace (aTHX_ sv)
1596 1752 static void cx_strip_trail_whitespace (pTHX_ SV *sv) {
1597 STRLEN len;
1598 1752 char *s = SvPV (sv, len);
1599 1752 ▶ unless (s && len) return;
Branch: 2 branches
BranchTrueFalseTotal
unless (s && len) return; 1752 0 1752
unless (s && len) return; 0 1752 1752
1600 1950 ▶ while (len && (s[len - 1] == CH_SPACE || s[len - 1] == CH_TAB))
Branch: 3 branches
BranchTrueFalseTotal
while (len && (s[len - 1] == CH_SPACE || s[len - 1] == CH_TAB)) 1947 3 1950
while (len && (s[len - 1] == CH_SPACE || s[len - 1] == CH_TAB)) 196 1751 1947
while (len && (s[len - 1] == CH_SPACE || s[len - 1] == CH_TAB)) 2 1749 1751
1601 198 s[--len] = (char)0;
1602 1752 SvCUR_set (sv, len);
1603 } /* strip_trail_whitespace */
1604  
1605 #define NewField \
1606 unless (sv) { \
1607 if (csv->is_bound) \
1608 sv = bound_field (csv, fnum, 0); \
1609 else \
1610 sv = newSVpvs (""); \
1611 fnum++; \
1612 unless (sv) return FALSE; \
1613 f = 0; csv->fld_idx++; c0 = 0; \
1614 }
1615  
1616 #if MAINT_DEBUG
1617 static char str_parsed[40];
1618 #endif
1619  
1620 #if MAINT_DEBUG > 1
1621 static char _sep[64];
1622 static char *_sep_string (csv_t *csv) {
1623 if (csv->sep_len) {
1624 int x;
1625 for (x = 0; x < csv->sep_len; x++)
1626 (void)sprintf (_sep + x * 3, "%02x ", csv->sep[x]);
1627 }
1628 else
1629 (void)sprintf (_sep, "'%c' (0x%02x)", CH_SEP, CH_SEP);
1630 return _sep;
1631 } /* _sep_string */
1632 #endif
1633  
1634 #define Parse(csv,src,fields,fflags) cx_Parse (aTHX_ csv, src, fields, fflags)
1635 5191 static int cx_Parse (pTHX_ csv_t *csv, SV *src, AV *fields, AV *fflags) {
1636 5191 int c, c0, f = 0;
1637 5191 int waitingForField = 1;
1638 5191 SV *sv = NULL;
1639 STRLEN len;
1640 5191 int seenSomething = FALSE;
1641 5191 int fnum = 0;
1642 5191 int spl = -1;
1643 #if MAINT_DEBUG
1644 (void)memset (str_parsed, 0, 40);
1645 #endif
1646  
1647 5191 csv->fld_idx = 0;
1648  
1649 1912095 ▶ while ((c = CSV_GET) != EOF) {
Branch: 2 branches
BranchTrueFalseTotal
while ((c = CSV_GET) != EOF) { 1908063 4032 1912095
while ((c = CSV_GET) != EOF) { 1911250 845 1912095
1650  
1651 1911250 ▶ NewField;
Branch: 3 branches
BranchTrueFalseTotal
NewField; 1744160 167090 1911250
NewField; 165 1743995 1744160
NewField; 4 1744156 1744160
1652  
1653 1911246 seenSomething = TRUE;
1654 1911246 spl++;
1655 #if MAINT_DEBUG
1656 if (spl < 39) str_parsed[spl] = c;
1657 #endif
1658 11714 restart:
1659 #if MAINT_DEBUG > 9
1660 (void)fprintf (stderr, "# %04d at restart: %d/%d/%03x pos %d = 0x%02x\n",
1661 __LINE__, waitingForField ? 1 : 0, sv ? 1 : 0, f, spl, c);
1662 #endif
1663 1922960 ▶ if (is_SEP (c)) {
Branch: 5 branches
BranchTrueFalseTotal
if (is_SEP (c)) { 1732660 190300 1922960
if (is_SEP (c)) { 88 1732572 1732660
if (is_SEP (c)) { 88 0 88
if (is_SEP (c)) { 30 58 88
if (is_SEP (c)) { 30 0 30
1664 #if MAINT_DEBUG > 1
1665 (void)fprintf (stderr, "# %04d %d/%d/%03x pos %d = SEP %s\t%s\n",
1666 __LINE__, waitingForField ? 1 : 0, sv ? 1 : 0, f, spl,
1667 _sep_string (csv), _pretty_strl (csv->bptr + csv->used));
1668 #endif
1669 1732602 ▶ if (waitingForField) {
Branch: 1 branch
BranchTrueFalseTotal
if (waitingForField) { 1721307 11295 1732602
1670 /* ,1,"foo, 3",,bar,
1671 * ^ ^
1672 */
1673 1721307 ▶ if (csv->blank_is_undef || csv->empty_is_undef)
Branch: 2 branches
BranchTrueFalseTotal
if (csv->blank_is_undef || csv->empty_is_undef) 1721281 26 1721307
if (csv->blank_is_undef || csv->empty_is_undef) 24 1721257 1721281
1674 50 SvSetUndef (sv);
1675 else
1676 1721257 SvSetEmpty (sv);
1677 1721307 ▶ unless (csv->is_bound)
Branch: 1 branch
BranchTrueFalseTotal
unless (csv->is_bound) 1721307 0 1721307
1678 1721307 av_push (fields, sv);
1679 1721307 sv = NULL;
1680 1721307 ▶ if (csv->keep_meta_info && fflags)
Branch: 2 branches
BranchTrueFalseTotal
if (csv->keep_meta_info && fflags) 8 1721299 1721307
if (csv->keep_meta_info && fflags) 8 0 8
1681 8 av_push (fflags, newSViv (f));
1682 }
1683 else
1684 11295 ▶ if (f & CSV_FLAGS_QUO) {
Branch: 1 branch
BranchTrueFalseTotal
if (f & CSV_FLAGS_QUO) { 2194 9101 11295
1685 /* ,1,"foo, 3",,bar,
1686 * ^
1687 */
1688 2194 ▶ CSV_PUT_SV (c)
Branch: 15 branches
BranchTrueFalseTotal
CSV_PUT_SV (c) 0 2194 2194
CSV_PUT_SV (c) 0 0 0
CSV_PUT_SV (c) 0 0 0
CSV_PUT_SV (c) 0 0 0
CSV_PUT_SV (c) 0 0 0
CSV_PUT_SV (c) 0 2194 2194
CSV_PUT_SV (c) 0 0 0
CSV_PUT_SV (c) 0 0 0
CSV_PUT_SV (c) 0 0 0
CSV_PUT_SV (c) 0 2194 2194
CSV_PUT_SV (c) 0 0 0
CSV_PUT_SV (c) 0 0 0
CSV_PUT_SV (c) 0 0 0
CSV_PUT_SV (c) 2194 0 2194
CSV_PUT_SV (c) 0 2194 2194
1689 }
1690 else {
1691 /* ,1,"foo, 3",,bar,
1692 * ^ ^ ^
1693 */
1694 9227 ▶ AV_PUSH;
Branch: 17 branches
BranchTrueFalseTotal
AV_PUSH; 9099 2 9101
AV_PUSH; 90 9009 9099
AV_PUSH; 19 71 90
AV_PUSH; 2 9097 9099
AV_PUSH; 2 0 2
AV_PUSH; 2 0 2
AV_PUSH; 0 2 2
AV_PUSH; 1648 7451 9099
AV_PUSH; 1648 0 1648
AV_PUSH; 38 9061 9099
AV_PUSH; 38 0 38
AV_PUSH; 36 2 38
AV_PUSH; 23 13 36
AV_PUSH; 5 9094 9099
AV_PUSH; 9006 93 9099
AV_PUSH; 21 9078 9099
AV_PUSH; 21 0 21
1695 }
1696 } /* SEP char */
1697 else
1698 190358 ▶ if (is_QUOTE (c)) {
Branch: 6 branches
BranchTrueFalseTotal
if (is_QUOTE (c)) { 189327 1031 190358
if (is_QUOTE (c)) { 23167 166160 189327
if (is_QUOTE (c)) { 86 23081 23167
if (is_QUOTE (c)) { 86 0 86
if (is_QUOTE (c)) { 70 16 86
if (is_QUOTE (c)) { 70 0 70
1699 #if MAINT_DEBUG > 1
1700 (void)fprintf (stderr, "# %04d %d/%d/%03x pos %d = QUO '%c'\t\t%s\n",
1701 __LINE__, waitingForField ? 1 : 0, sv ? 1 : 0, f, spl, c,
1702 _pretty_strl (csv->bptr + csv->used));
1703 #endif
1704 23151 ▶ if (waitingForField) {
Branch: 1 branch
BranchTrueFalseTotal
if (waitingForField) { 11066 12085 23151
1705 /* ,1,"foo, 3",,bar,\r\n
1706 * ^
1707 */
1708 11066 f |= CSV_FLAGS_QUO;
1709 11066 waitingForField = 0;
1710 11066 continue;
1711 }
1712  
1713 12085 ▶ if (f & CSV_FLAGS_QUO) {
Branch: 1 branch
BranchTrueFalseTotal
if (f & CSV_FLAGS_QUO) { 12017 68 12085
1714  
1715 /* ,1,"foo, 3",,bar,\r\n
1716 * ^
1717 */
1718  
1719 12017 int quoesc = 0;
1720 12017 ▶ int c2 = CSV_GET;
Branch: 1 branch
BranchTrueFalseTotal
int c2 = CSV_GET; 10694 1323 12017
1721  
1722 12017 ▶ if (csv->allow_whitespace) {
Branch: 1 branch
BranchTrueFalseTotal
if (csv->allow_whitespace) { 4241 7776 12017
1723 /* , 1 , "foo, 3" , , bar , \r\n
1724 * ^
1725 */
1726 4331 ▶ while (is_whitespace (c2)) {
Branch: 5 branches
BranchTrueFalseTotal
while (is_whitespace (c2)) { 925 3406 4331
while (is_whitespace (c2)) { 667 258 925
while (is_whitespace (c2)) { 667 0 667
while (is_whitespace (c2)) { 69 598 667
while (is_whitespace (c2)) { 21 577 598
1727 90 ▶ if (csv->allow_loose_quotes &&
Branch: 1 branch
BranchTrueFalseTotal
if (csv->allow_loose_quotes && 1 89 90
1728 1 ▶ !(csv->escape_char && c2 == csv->escape_char)) {
Branch: 2 branches
BranchTrueFalseTotal
!(csv->escape_char && c2 == csv->escape_char)) { 0 1 1
!(csv->escape_char && c2 == csv->escape_char)) { 0 0 0
1729 /* This feels like a brittle fix for RT115953, where
1730 * ["foo "bar" baz"] got parsed as [foo "bar"baz]
1731 * when both allow_whitespace and allow_loose_quotes
1732 * are true and escape does not equal quote
1733 */
1734 1 ▶ CSV_PUT_SV (c);
Branch: 15 branches
BranchTrueFalseTotal
CSV_PUT_SV (c); 0 1 1
CSV_PUT_SV (c); 0 0 0
CSV_PUT_SV (c); 0 0 0
CSV_PUT_SV (c); 0 0 0
CSV_PUT_SV (c); 0 0 0
CSV_PUT_SV (c); 0 1 1
CSV_PUT_SV (c); 0 0 0
CSV_PUT_SV (c); 0 0 0
CSV_PUT_SV (c); 0 0 0
CSV_PUT_SV (c); 0 1 1
CSV_PUT_SV (c); 0 0 0
CSV_PUT_SV (c); 0 0 0
CSV_PUT_SV (c); 0 0 0
CSV_PUT_SV (c); 1 0 1
CSV_PUT_SV (c); 0 1 1
1735 1 c = c2;
1736 }
1737 90 ▶ c2 = CSV_GET;
Branch: 1 branch
BranchTrueFalseTotal
c2 = CSV_GET; 87 3 90
1738 }
1739 }
1740  
1741 12017 ▶ if (is_SEP (c2)) {
Branch: 5 branches
BranchTrueFalseTotal
if (is_SEP (c2)) { 9027 2990 12017
if (is_SEP (c2)) { 15 9012 9027
if (is_SEP (c2)) { 15 0 15
if (is_SEP (c2)) { 15 0 15
if (is_SEP (c2)) { 15 0 15
1742 /* ,1,"foo, 3",,bar,\r\n
1743 * ^
1744 */
1745 11169 ▶ AV_PUSH;
Branch: 17 branches
BranchTrueFalseTotal
AV_PUSH; 8327 700 9027
AV_PUSH; 0 8327 8327
AV_PUSH; 0 0 0
AV_PUSH; 700 8327 9027
AV_PUSH; 688 12 700
AV_PUSH; 0 688 688
AV_PUSH; 0 0 0
AV_PUSH; 3400 5615 9015
AV_PUSH; 0 3400 3400
AV_PUSH; 2161 6854 9015
AV_PUSH; 2161 0 2161
AV_PUSH; 2142 19 2161
AV_PUSH; 906 1236 2142
AV_PUSH; 0 9027 9027
AV_PUSH; 9023 4 9027
AV_PUSH; 45 8982 9027
AV_PUSH; 45 0 45
1746 9027 continue;
1747 }
1748  
1749 2990 ▶ if (c2 == CH_NL || c2 == CH_EOLX) {
Branch: 2 branches
BranchTrueFalseTotal
if (c2 == CH_NL || c2 == CH_EOLX) { 2795 195 2990
if (c2 == CH_NL || c2 == CH_EOLX) { 20 2775 2795
1750 215 ▶ unsigned short eolt = EOL_TYPE (c2);
Branch: 2 branches
BranchTrueFalseTotal
unsigned short eolt = EOL_TYPE (c2); 20 195 215
unsigned short eolt = EOL_TYPE (c2); 0 20 20
1751 /* ,1,"foo, 3",,"bar"\n
1752 * ^
1753 */
1754 #if MAINT_DEBUG_EOL > 0
1755 (void)fprintf (stderr, "# %04d parse eol NL/EOLX: '%s'\t(len: %d, is_cr: %d, x: %d, pos: %d, tp: %02x, c: %d, c2: %d)\n",
1756 __LINE__, _pretty_str (csv->eol, csv->eol_len), csv->eol_len, csv->eol_is_cr, csv->eolx, csv->eol_pos, csv->eol_type, c, c2);
1757 #endif
1758 215 ▶ if (csv->strict_eol && csv->eol_type && csv->eol_type != eolt)
Branch: 3 branches
BranchTrueFalseTotal
if (csv->strict_eol && csv->eol_type && csv->eol_type != eolt) 71 144 215
if (csv->strict_eol && csv->eol_type && csv->eol_type != eolt) 31 40 71
if (csv->strict_eol && csv->eol_type && csv->eol_type != eolt) 6 25 31
1759 6 ▶ ERROR_EOL;
Branch: 3 branches
BranchTrueFalseTotal
ERROR_EOL; 4 2 6
ERROR_EOL; 2 4 6
ERROR_EOL; 2 0 2
1760 213 ▶ SET_EOL_TYPE (csv, eolt);
Branch: 1 branch
BranchTrueFalseTotal
SET_EOL_TYPE (csv, eolt); 61 152 213
1761  
1762 309 ▶ AV_PUSH;
Branch: 17 branches
BranchTrueFalseTotal
AV_PUSH; 203 10 213
AV_PUSH; 0 203 203
AV_PUSH; 0 0 0
AV_PUSH; 10 203 213
AV_PUSH; 10 0 10
AV_PUSH; 0 10 10
AV_PUSH; 0 0 0
AV_PUSH; 6 207 213
AV_PUSH; 0 6 6
AV_PUSH; 126 87 213
AV_PUSH; 126 0 126
AV_PUSH; 96 30 126
AV_PUSH; 92 4 96
AV_PUSH; 0 213 213
AV_PUSH; 211 2 213
AV_PUSH; 1 212 213
AV_PUSH; 1 0 1
1763 213 return TRUE;
1764 }
1765  
1766 /* ---
1767 * if QUOTE eq ESCAPE
1768 * AND ( c2 eq QUOTE 1,"abc""def",2
1769 * OR c2 eq ESCAPE 1,"abc""def",2 (QUO eq ESC)
1770 * OR c2 eq NULL ) 1,"abc"0def",2
1771 * ---
1772 */
1773 2775 ▶ if (csv->escape_char && c == csv->escape_char) {
Branch: 2 branches
BranchTrueFalseTotal
if (csv->escape_char && c == csv->escape_char) { 2758 17 2775
if (csv->escape_char && c == csv->escape_char) { 1678 1080 2758
1774  
1775 1678 quoesc = 1;
1776 1678 ▶ if (c2 == '0') {
Branch: 1 branch
BranchTrueFalseTotal
if (c2 == '0') { 25 1653 1678
1777 /* ,1,"foo, 3"056",,bar,\r\n
1778 * ^
1779 */
1780 25 ▶ CSV_PUT_SV (0)
Branch: 2 branches
BranchTrueFalseTotal
CSV_PUT_SV (0) 25 0 25
CSV_PUT_SV (0) 0 25 25
1781 25 continue;
1782 }
1783  
1784 1653 ▶ if (is_QUOTE (c2)) {
Branch: 6 branches
BranchTrueFalseTotal
if (is_QUOTE (c2)) { 1653 0 1653
if (is_QUOTE (c2)) { 1061 592 1653
if (is_QUOTE (c2)) { 0 1061 1061
if (is_QUOTE (c2)) { 0 0 0
if (is_QUOTE (c2)) { 0 0 0
if (is_QUOTE (c2)) { 0 0 0
1785 /* ,1,"foo, 3""56",,bar,\r\n
1786 * ^
1787 */
1788 1061 ▶ if (csv->utf8)
Branch: 1 branch
BranchTrueFalseTotal
if (csv->utf8) 1 1060 1061
1789 1 f |= CSV_FLAGS_BIN;
1790 1061 ▶ CSV_PUT_SV (c2)
Branch: 15 branches
BranchTrueFalseTotal
CSV_PUT_SV (c2) 0 1061 1061
CSV_PUT_SV (c2) 0 0 0
CSV_PUT_SV (c2) 0 0 0
CSV_PUT_SV (c2) 0 0 0
CSV_PUT_SV (c2) 0 0 0
CSV_PUT_SV (c2) 0 1061 1061
CSV_PUT_SV (c2) 0 0 0
CSV_PUT_SV (c2) 0 0 0
CSV_PUT_SV (c2) 0 0 0
CSV_PUT_SV (c2) 0 1061 1061
CSV_PUT_SV (c2) 0 0 0
CSV_PUT_SV (c2) 0 0 0
CSV_PUT_SV (c2) 0 0 0
CSV_PUT_SV (c2) 1061 0 1061
CSV_PUT_SV (c2) 2 1059 1061
1791 1061 continue;
1792 }
1793  
1794 592 ▶ if (csv->allow_loose_escapes && c2 != CH_CR) {
Branch: 2 branches
BranchTrueFalseTotal
if (csv->allow_loose_escapes && c2 != CH_CR) { 3 589 592
if (csv->allow_loose_escapes && c2 != CH_CR) { 2 1 3
1795 /* ,1,"foo, 3"56",,bar,\r\n
1796 * ^
1797 */
1798 2 ▶ CSV_PUT_SV (c);
Branch: 15 branches
BranchTrueFalseTotal
CSV_PUT_SV (c); 0 2 2
CSV_PUT_SV (c); 0 0 0
CSV_PUT_SV (c); 0 0 0
CSV_PUT_SV (c); 0 0 0
CSV_PUT_SV (c); 0 0 0
CSV_PUT_SV (c); 0 2 2
CSV_PUT_SV (c); 0 0 0
CSV_PUT_SV (c); 0 0 0
CSV_PUT_SV (c); 0 0 0
CSV_PUT_SV (c); 0 2 2
CSV_PUT_SV (c); 0 0 0
CSV_PUT_SV (c); 0 0 0
CSV_PUT_SV (c); 0 0 0
CSV_PUT_SV (c); 2 0 2
CSV_PUT_SV (c); 0 2 2
1799 2 c = c2;
1800 2 goto restart;
1801 }
1802 }
1803  
1804 1687 ▶ if (c2 == CH_CR) {
Branch: 1 branch
BranchTrueFalseTotal
if (c2 == CH_CR) { 281 1406 1687
1805 int c3;
1806  
1807 281 ▶ if (csv->eol_is_cr) {
Branch: 1 branch
BranchTrueFalseTotal
if (csv->eol_is_cr) { 109 172 281
1808 /* ,1,"foo, 3"\r
1809 * ^
1810 */
1811 #if MAINT_DEBUG_EOL > 0
1812 (void)fprintf (stderr, "# %04d parse eol CR: '%s'\t(len: %d, is_cr: %d, x: %d, pos: %d, tp: %02x, c: %d, c2: %d, c3: %d)\n",
1813 __LINE__, _pretty_str (csv->eol, csv->eol_len), csv->eol_len, csv->eol_is_cr, csv->eolx, csv->eol_pos, csv->eol_type, c, c2);
1814 #endif
1815 191 ▶ AV_PUSH;
Branch: 17 branches
BranchTrueFalseTotal
AV_PUSH; 105 4 109
AV_PUSH; 0 105 105
AV_PUSH; 0 0 0
AV_PUSH; 4 105 109
AV_PUSH; 4 0 4
AV_PUSH; 0 4 4
AV_PUSH; 0 0 0
AV_PUSH; 18 91 109
AV_PUSH; 0 18 18
AV_PUSH; 82 27 109
AV_PUSH; 82 0 82
AV_PUSH; 82 0 82
AV_PUSH; 82 0 82
AV_PUSH; 0 109 109
AV_PUSH; 109 0 109
AV_PUSH; 0 109 109
AV_PUSH; 0 0 0
1816 109 return TRUE;
1817 }
1818  
1819 172 ▶ c3 = CSV_GET;
Branch: 1 branch
BranchTrueFalseTotal
c3 = CSV_GET; 167 5 172
1820  
1821 172 ▶ if (c3 == CH_NL) { /* \r is not optional before EOLX! */
Branch: 1 branch
BranchTrueFalseTotal
if (c3 == CH_NL) { /* \r is not optional before EOLX! */ 139 33 172
1822 /* ,1,"foo, 3"\r\n
1823 * ^
1824 */
1825 #if MAINT_DEBUG_EOL > 0
1826 (void)fprintf (stderr, "# %04d parse eol CRNL: '%s'\t(len: %d, is_cr: %d, x: %d, pos: %d, tp: %02x, c: %d, c2: %d, c3: %d)\n",
1827 __LINE__, _pretty_str (csv->eol, csv->eol_len), csv->eol_len, csv->eol_is_cr, csv->eolx, csv->eol_pos, csv->eol_type, c, c2, c3);
1828 #endif
1829 139 ▶ if (csv->strict_eol && csv->eol_type && csv->eol_type != EOL_TYPE_CRNL)
Branch: 3 branches
BranchTrueFalseTotal
if (csv->strict_eol && csv->eol_type && csv->eol_type != EOL_TYPE_CRNL) 82 57 139
if (csv->strict_eol && csv->eol_type && csv->eol_type != EOL_TYPE_CRNL) 37 45 82
if (csv->strict_eol && csv->eol_type && csv->eol_type != EOL_TYPE_CRNL) 0 37 37
1830 0 ▶ ERROR_EOL;
Branch: 3 branches
BranchTrueFalseTotal
ERROR_EOL; 0 0 0
ERROR_EOL; 0 0 0
ERROR_EOL; 0 0 0
1831 139 ▶ SET_EOL_TYPE (csv, EOL_TYPE_CRNL);
Branch: 1 branch
BranchTrueFalseTotal
SET_EOL_TYPE (csv, EOL_TYPE_CRNL); 68 71 139
1832  
1833 179 ▶ AV_PUSH;
Branch: 17 branches
BranchTrueFalseTotal
AV_PUSH; 137 2 139
AV_PUSH; 0 137 137
AV_PUSH; 0 0 0
AV_PUSH; 2 137 139
AV_PUSH; 2 0 2
AV_PUSH; 0 2 2
AV_PUSH; 0 0 0
AV_PUSH; 5 134 139
AV_PUSH; 0 5 5
AV_PUSH; 70 69 139
AV_PUSH; 70 0 70
AV_PUSH; 40 30 70
AV_PUSH; 40 0 40
AV_PUSH; 0 139 139
AV_PUSH; 139 0 139
AV_PUSH; 0 139 139
AV_PUSH; 0 0 0
1834 139 return TRUE;
1835 }
1836  
1837 33 ▶ if (csv->useIO && csv->eol_len == 0) {
Branch: 2 branches
BranchTrueFalseTotal
if (csv->useIO && csv->eol_len == 0) { 20 13 33
if (csv->useIO && csv->eol_len == 0) { 20 0 20
1838 20 ▶ if (c3 == CH_CR) { /* \r followed by an empty line */
Branch: 1 branch
BranchTrueFalseTotal
if (c3 == CH_CR) { /* \r followed by an empty line */ 9 11 20
1839 /* ,1,"foo, 3"\r\r
1840 * ^
1841 */
1842 #if MAINT_DEBUG_EOL > 0
1843 (void)fprintf (stderr, "# %04d parse set CR: '%s'\t(len: %d, is_cr: %d, x: %d, pos: %d, tp: %02x, c: %d, c2: %d, c3: %d)\n",
1844 __LINE__, _pretty_str (csv->eol, csv->eol_len), csv->eol_len, csv->eol_is_cr, csv->eolx, csv->eol_pos, csv->eol_type, c, c2, c3);
1845 #endif
1846 9 ▶ if (csv->strict_eol && csv->eol_type) {
Branch: 2 branches
BranchTrueFalseTotal
if (csv->strict_eol && csv->eol_type) { 6 3 9
if (csv->strict_eol && csv->eol_type) { 2 4 6
1847 2 ▶ unless (csv->eol_type == EOL_TYPE_CR)
Branch: 1 branch
BranchTrueFalseTotal
unless (csv->eol_type == EOL_TYPE_CR) 2 0 2
1848 2 ▶ ERROR_EOL;
Branch: 3 branches
BranchTrueFalseTotal
ERROR_EOL; 0 2 2
ERROR_EOL; 0 2 2
ERROR_EOL; 0 0 0
1849 2 csv->used--;
1850 2 csv->has_ahead++;
1851 2 ▶ AV_PUSH;
Branch: 17 branches
BranchTrueFalseTotal
AV_PUSH; 2 0 2
AV_PUSH; 0 2 2
AV_PUSH; 0 0 0
AV_PUSH; 0 2 2
AV_PUSH; 0 0 0
AV_PUSH; 0 0 0
AV_PUSH; 0 0 0
AV_PUSH; 0 2 2
AV_PUSH; 0 0 0
AV_PUSH; 0 2 2
AV_PUSH; 0 0 0
AV_PUSH; 0 0 0
AV_PUSH; 0 0 0
AV_PUSH; 0 2 2
AV_PUSH; 2 0 2
AV_PUSH; 0 2 2
AV_PUSH; 0 0 0
1852 2 return TRUE;
1853 }
1854  
1855 7 set_eol_is_cr (csv);
1856 7 ▶ if (f & CSV_FLAGS_QUO) f ^= CSV_FLAGS_QUO;
Branch: 1 branch
BranchTrueFalseTotal
if (f & CSV_FLAGS_QUO) f ^= CSV_FLAGS_QUO; 7 0 7
1857 7 c = c0 = CH_CR;
1858 7 goto EOLX;
1859 }
1860  
1861 11 ▶ if (!is_csv_binary (c3)) {
Branch: 3 branches
BranchTrueFalseTotal
if (!is_csv_binary (c3)) { 11 0 11
if (!is_csv_binary (c3)) { 0 11 11
if (!is_csv_binary (c3)) { 0 0 0
1862 /* ,1,"foo\n 3",,"bar"\r
1863 * baz,4
1864 * ^
1865 */
1866 #if MAINT_DEBUG_EOL > 0
1867 (void)fprintf (stderr, "# %04d parse set CR/BIN: '%s'\t(len: %d, is_cr: %d, x: %d, pos: %d, tp: %02x, c: %d, c2: %d, c3: %d)\n",
1868 __LINE__, _pretty_str (csv->eol, csv->eol_len), csv->eol_len, csv->eol_is_cr, csv->eolx, csv->eol_pos, csv->eol_type, c, c2, c3);
1869 #endif
1870 11 ▶ if (csv->strict_eol && csv->eol_type) {
Branch: 2 branches
BranchTrueFalseTotal
if (csv->strict_eol && csv->eol_type) { 6 5 11
if (csv->strict_eol && csv->eol_type) { 2 4 6
1871 2 ▶ unless (csv->eol_type == EOL_TYPE_CR)
Branch: 1 branch
BranchTrueFalseTotal
unless (csv->eol_type == EOL_TYPE_CR) 2 0 2
1872 2 ▶ ERROR_EOL;
Branch: 3 branches
BranchTrueFalseTotal
ERROR_EOL; 0 2 2
ERROR_EOL; 0 2 2
ERROR_EOL; 0 0 0
1873 2 csv->eol_is_cr = 1;
1874 }
1875 else
1876 9 set_eol_is_cr (csv);
1877 11 csv->used--;
1878 11 csv->has_ahead++;
1879 11 ▶ AV_PUSH;
Branch: 17 branches
BranchTrueFalseTotal
AV_PUSH; 11 0 11
AV_PUSH; 0 11 11
AV_PUSH; 0 0 0
AV_PUSH; 0 11 11
AV_PUSH; 0 0 0
AV_PUSH; 0 0 0
AV_PUSH; 0 0 0
AV_PUSH; 0 11 11
AV_PUSH; 0 0 0
AV_PUSH; 0 11 11
AV_PUSH; 0 0 0
AV_PUSH; 0 0 0
AV_PUSH; 0 0 0
AV_PUSH; 0 11 11
AV_PUSH; 11 0 11
AV_PUSH; 0 11 11
AV_PUSH; 0 0 0
1880 11 return TRUE;
1881 }
1882 }
1883  
1884 13 ▶ ParseError (csv, quoesc ? 2023 : 2010, csv->used - 2);
Branch: 1 branch
BranchTrueFalseTotal
ParseError (csv, quoesc ? 2023 : 2010, csv->used - 2); 12 1 13
1885 13 return FALSE;
1886 }
1887  
1888 1406 ▶ if (c2 == EOF) {
Branch: 1 branch
BranchTrueFalseTotal
if (c2 == EOF) { 1306 100 1406
1889 /* ,1,"foo, 3"
1890 * ^
1891 */
1892 1315 ▶ AV_PUSH;
Branch: 17 branches
BranchTrueFalseTotal
AV_PUSH; 1294 12 1306
AV_PUSH; 0 1294 1294
AV_PUSH; 0 0 0
AV_PUSH; 12 1294 1306
AV_PUSH; 12 0 12
AV_PUSH; 0 12 12
AV_PUSH; 0 0 0
AV_PUSH; 533 773 1306
AV_PUSH; 0 533 533
AV_PUSH; 14 1292 1306
AV_PUSH; 14 0 14
AV_PUSH; 9 5 14
AV_PUSH; 7 2 9
AV_PUSH; 0 1306 1306
AV_PUSH; 1306 0 1306
AV_PUSH; 11 1295 1306
AV_PUSH; 11 0 11
1893 1306 return TRUE;
1894 }
1895  
1896 100 ▶ if (csv->allow_loose_quotes && !quoesc) {
Branch: 2 branches
BranchTrueFalseTotal
if (csv->allow_loose_quotes && !quoesc) { 12 88 100
if (csv->allow_loose_quotes && !quoesc) { 10 2 12
1897 /* ,1,"foo, 3"456",,bar,\r\n
1898 * ^
1899 */
1900 10 ▶ CSV_PUT_SV (c);
Branch: 15 branches
BranchTrueFalseTotal
CSV_PUT_SV (c); 0 10 10
CSV_PUT_SV (c); 0 0 0
CSV_PUT_SV (c); 0 0 0
CSV_PUT_SV (c); 0 0 0
CSV_PUT_SV (c); 0 0 0
CSV_PUT_SV (c); 0 10 10
CSV_PUT_SV (c); 0 0 0
CSV_PUT_SV (c); 0 0 0
CSV_PUT_SV (c); 0 0 0
CSV_PUT_SV (c); 0 10 10
CSV_PUT_SV (c); 0 0 0
CSV_PUT_SV (c); 0 0 0
CSV_PUT_SV (c); 0 0 0
CSV_PUT_SV (c); 10 0 10
CSV_PUT_SV (c); 0 10 10
1901 10 c = c2;
1902 10 goto restart;
1903 }
1904  
1905 /* 1,"foo" ",3
1906 * ^
1907 */
1908 90 ▶ if (quoesc) {
Branch: 1 branch
BranchTrueFalseTotal
if (quoesc) { 82 8 90
1909 82 csv->used--;
1910 82 ▶ ERROR_INSIDE_QUOTES (2023);
Branch: 1 branch
BranchTrueFalseTotal
ERROR_INSIDE_QUOTES (2023); 82 0 82
1911 }
1912  
1913 8 ▶ ERROR_INSIDE_QUOTES (2011);
Branch: 1 branch
BranchTrueFalseTotal
ERROR_INSIDE_QUOTES (2011); 8 0 8
1914 }
1915  
1916 /* !waitingForField, !InsideQuotes */
1917 68 ▶ if (csv->allow_loose_quotes) { /* 1,foo "boo" d'uh,1 */
Branch: 1 branch
BranchTrueFalseTotal
if (csv->allow_loose_quotes) { /* 1,foo "boo" d'uh,1 */ 16 52 68
1918 16 f |= CSV_FLAGS_EIF; /* Mark as error-in-field */
1919 16 ▶ CSV_PUT_SV (c);
Branch: 15 branches
BranchTrueFalseTotal
CSV_PUT_SV (c); 0 16 16
CSV_PUT_SV (c); 0 0 0
CSV_PUT_SV (c); 0 0 0
CSV_PUT_SV (c); 0 0 0
CSV_PUT_SV (c); 0 0 0
CSV_PUT_SV (c); 0 16 16
CSV_PUT_SV (c); 0 0 0
CSV_PUT_SV (c); 0 0 0
CSV_PUT_SV (c); 0 0 0
CSV_PUT_SV (c); 0 16 16
CSV_PUT_SV (c); 0 0 0
CSV_PUT_SV (c); 0 0 0
CSV_PUT_SV (c); 0 0 0
CSV_PUT_SV (c); 16 0 16
CSV_PUT_SV (c); 0 16 16
1920 }
1921 else
1922 52 ▶ ERROR_INSIDE_FIELD (2034);
Branch: 1 branch
BranchTrueFalseTotal
ERROR_INSIDE_FIELD (2034); 51 1 52
1923 } /* QUO char */
1924 else
1925 167207 ▶ if (c == csv->escape_char && csv->escape_char) {
Branch: 2 branches
BranchTrueFalseTotal
if (c == csv->escape_char && csv->escape_char) { 4655 162552 167207
if (c == csv->escape_char && csv->escape_char) { 4653 2 4655
1926 #if MAINT_DEBUG > 1
1927 (void)fprintf (stderr, "# %04d %d/%d/%03x pos %d = ESC '%c'\t%s\n",
1928 __LINE__, waitingForField ? 1 : 0, sv ? 1 : 0, f, spl, c,
1929 _pretty_strl (csv->bptr + csv->used));
1930 #endif
1931 /* This means quote_char != escape_char */
1932 4653 ▶ if (waitingForField) {
Branch: 1 branch
BranchTrueFalseTotal
if (waitingForField) { 35 4618 4653
1933 35 waitingForField = 0;
1934 35 ▶ if (csv->allow_unquoted_escape) {
Branch: 1 branch
BranchTrueFalseTotal
if (csv->allow_unquoted_escape) { 3 32 35
1935 /* The escape character is the first character of an
1936 * unquoted field */
1937 /* ... get and store next character */
1938 3 ▶ int c2 = CSV_GET;
Branch: 1 branch
BranchTrueFalseTotal
int c2 = CSV_GET; 2 1 3
1939  
1940 3 SvSetEmpty (sv);
1941  
1942 3 ▶ if (c2 == EOF) {
Branch: 1 branch
BranchTrueFalseTotal
if (c2 == EOF) { 1 2 3
1943 1 csv->used--;
1944 1 ▶ ERROR_INSIDE_FIELD (2035);
Branch: 1 branch
BranchTrueFalseTotal
ERROR_INSIDE_FIELD (2035); 1 0 1
1945 }
1946  
1947 2 ▶ if (c2 == '0')
Branch: 1 branch
BranchTrueFalseTotal
if (c2 == '0') 1 1 2
1948 1 ▶ CSV_PUT_SV (0)
Branch: 2 branches
BranchTrueFalseTotal
CSV_PUT_SV (0) 1 0 1
CSV_PUT_SV (0) 0 1 1
1949 else
1950 1 ▶ if ( is_QUOTE (c2) || is_SEP (c2) ||
Branch: 11 branches
BranchTrueFalseTotal
if ( is_QUOTE (c2) || is_SEP (c2) || 1 0 1
if ( is_QUOTE (c2) || is_SEP (c2) || 0 1 1
if ( is_QUOTE (c2) || is_SEP (c2) || 0 0 0
if ( is_QUOTE (c2) || is_SEP (c2) || 0 0 0
if ( is_QUOTE (c2) || is_SEP (c2) || 0 0 0
if ( is_QUOTE (c2) || is_SEP (c2) || 0 0 0
if ( is_QUOTE (c2) || is_SEP (c2) || 1 0 1
if ( is_QUOTE (c2) || is_SEP (c2) || 0 1 1
if ( is_QUOTE (c2) || is_SEP (c2) || 0 0 0
if ( is_QUOTE (c2) || is_SEP (c2) || 0 0 0
if ( is_QUOTE (c2) || is_SEP (c2) || 0 0 0
1951 0 ▶ c2 == csv->escape_char || csv->allow_loose_escapes) {
Branch: 2 branches
BranchTrueFalseTotal
c2 == csv->escape_char || csv->allow_loose_escapes) { 0 0 0
c2 == csv->escape_char || csv->allow_loose_escapes) { 0 0 0
1952 1 ▶ if (csv->utf8)
Branch: 1 branch
BranchTrueFalseTotal
if (csv->utf8) 0 1 1
1953 0 f |= CSV_FLAGS_BIN;
1954 1 ▶ CSV_PUT_SV (c2)
Branch: 15 branches
BranchTrueFalseTotal
CSV_PUT_SV (c2) 0 1 1
CSV_PUT_SV (c2) 0 0 0
CSV_PUT_SV (c2) 0 0 0
CSV_PUT_SV (c2) 0 0 0
CSV_PUT_SV (c2) 0 0 0
CSV_PUT_SV (c2) 0 1 1
CSV_PUT_SV (c2) 0 0 0
CSV_PUT_SV (c2) 0 0 0
CSV_PUT_SV (c2) 0 0 0
CSV_PUT_SV (c2) 0 1 1
CSV_PUT_SV (c2) 0 0 0
CSV_PUT_SV (c2) 0 0 0
CSV_PUT_SV (c2) 0 0 0
CSV_PUT_SV (c2) 1 0 1
CSV_PUT_SV (c2) 0 1 1
1955 }
1956 else {
1957 0 csv->used--;
1958 0 ▶ ERROR_INSIDE_QUOTES (2025);
Branch: 1 branch
BranchTrueFalseTotal
ERROR_INSIDE_QUOTES (2025); 0 0 0
1959 }
1960 }
1961 }
1962 else
1963 4618 ▶ if (f & CSV_FLAGS_QUO) {
Branch: 1 branch
BranchTrueFalseTotal
if (f & CSV_FLAGS_QUO) { 4610 8 4618
1964 4610 ▶ int c2 = CSV_GET;
Branch: 1 branch
BranchTrueFalseTotal
int c2 = CSV_GET; 4607 3 4610
1965  
1966 4610 ▶ if (c2 == EOF) {
Branch: 1 branch
BranchTrueFalseTotal
if (c2 == EOF) { 3 4607 4610
1967 3 csv->used--;
1968 3 ▶ ERROR_INSIDE_QUOTES (2024);
Branch: 1 branch
BranchTrueFalseTotal
ERROR_INSIDE_QUOTES (2024); 3 0 3
1969 }
1970  
1971 4607 ▶ if (c2 == '0')
Branch: 1 branch
BranchTrueFalseTotal
if (c2 == '0') 2 4605 4607
1972 2 ▶ CSV_PUT_SV (0)
Branch: 2 branches
BranchTrueFalseTotal
CSV_PUT_SV (0) 2 0 2
CSV_PUT_SV (0) 0 2 2
1973 else
1974 4605 ▶ if ( is_QUOTE (c2) || is_SEP (c2) ||
Branch: 11 branches
BranchTrueFalseTotal
if ( is_QUOTE (c2) || is_SEP (c2) || 4605 0 4605
if ( is_QUOTE (c2) || is_SEP (c2) || 2411 2194 4605
if ( is_QUOTE (c2) || is_SEP (c2) || 1 2410 2411
if ( is_QUOTE (c2) || is_SEP (c2) || 1 0 1
if ( is_QUOTE (c2) || is_SEP (c2) || 1 0 1
if ( is_QUOTE (c2) || is_SEP (c2) || 1 0 1
if ( is_QUOTE (c2) || is_SEP (c2) || 1 2193 2194
if ( is_QUOTE (c2) || is_SEP (c2) || 0 1 1
if ( is_QUOTE (c2) || is_SEP (c2) || 0 0 0
if ( is_QUOTE (c2) || is_SEP (c2) || 0 0 0
if ( is_QUOTE (c2) || is_SEP (c2) || 0 0 0
1975 2193 ▶ c2 == csv->escape_char || csv->allow_loose_escapes) {
Branch: 2 branches
BranchTrueFalseTotal
c2 == csv->escape_char || csv->allow_loose_escapes) { 28 2165 2193
c2 == csv->escape_char || csv->allow_loose_escapes) { 2 26 28
1976 4579 ▶ if (csv->utf8)
Branch: 1 branch
BranchTrueFalseTotal
if (csv->utf8) 1 4578 4579
1977 1 f |= CSV_FLAGS_BIN;
1978 4582 ▶ CSV_PUT_SV (c2)
Branch: 15 branches
BranchTrueFalseTotal
CSV_PUT_SV (c2) 0 4579 4579
CSV_PUT_SV (c2) 0 0 0
CSV_PUT_SV (c2) 0 0 0
CSV_PUT_SV (c2) 0 0 0
CSV_PUT_SV (c2) 0 0 0
CSV_PUT_SV (c2) 0 4579 4579
CSV_PUT_SV (c2) 0 0 0
CSV_PUT_SV (c2) 0 0 0
CSV_PUT_SV (c2) 0 0 0
CSV_PUT_SV (c2) 1 4578 4579
CSV_PUT_SV (c2) 3 0 3
CSV_PUT_SV (c2) 0 3 3
CSV_PUT_SV (c2) 3 1 4
CSV_PUT_SV (c2) 4578 0 4578
CSV_PUT_SV (c2) 0 4578 4578
1979 }
1980 else {
1981 26 csv->used--;
1982 26 ▶ ERROR_INSIDE_QUOTES (2025);
Branch: 1 branch
BranchTrueFalseTotal
ERROR_INSIDE_QUOTES (2025); 26 0 26
1983 }
1984 }
1985 else
1986 8 ▶ if (sv) {
Branch: 1 branch
BranchTrueFalseTotal
if (sv) { 8 0 8
1987 8 ▶ int c2 = CSV_GET;
Branch: 1 branch
BranchTrueFalseTotal
int c2 = CSV_GET; 4 4 8
1988  
1989 8 ▶ if (c2 == EOF) {
Branch: 1 branch
BranchTrueFalseTotal
if (c2 == EOF) { 4 4 8
1990 4 csv->used--;
1991 4 ▶ ERROR_INSIDE_FIELD (2035);
Branch: 1 branch
BranchTrueFalseTotal
ERROR_INSIDE_FIELD (2035); 4 0 4
1992 }
1993  
1994 4 ▶ CSV_PUT_SV (c2);
Branch: 15 branches
BranchTrueFalseTotal
CSV_PUT_SV (c2); 0 4 4
CSV_PUT_SV (c2); 0 0 0
CSV_PUT_SV (c2); 0 0 0
CSV_PUT_SV (c2); 0 0 0
CSV_PUT_SV (c2); 0 0 0
CSV_PUT_SV (c2); 0 4 4
CSV_PUT_SV (c2); 0 0 0
CSV_PUT_SV (c2); 0 0 0
CSV_PUT_SV (c2); 0 0 0
CSV_PUT_SV (c2); 0 4 4
CSV_PUT_SV (c2); 0 0 0
CSV_PUT_SV (c2); 0 0 0
CSV_PUT_SV (c2); 0 0 0
CSV_PUT_SV (c2); 4 0 4
CSV_PUT_SV (c2); 0 4 4
1995 }
1996 else
1997 0 ▶ ERROR_INSIDE_FIELD (2036); /* uncoverable statement I think there's no way to get here */
Branch: 1 branch
BranchTrueFalseTotal
ERROR_INSIDE_FIELD (2036); /* uncoverable statement I think there's no way to get here */ 0 0 0
1998 } /* ESC char */
1999 else
2000 163293 ▶ if (c == CH_NL || is_EOL (c)) {
Branch: 2 branches
BranchTrueFalseTotal
if (c == CH_NL || is_EOL (c)) { 2037 160517 162554
if (c == CH_NL || is_EOL (c)) { 334 160183 160517
2001 unsigned short eolt;
2002 2371 EOLX:
2003 3024 ▶ eolt = ((c == CH_NL || c == CH_CR) && c0 == CH_CR) ? EOL_TYPE_CRNL : EOL_TYPE (c);
Branch: 5 branches
BranchTrueFalseTotal
eolt = ((c == CH_NL || c == CH_CR) && c0 == CH_CR) ? EOL_TYPE_CRNL : EOL_TYPE (c); 846 2178 3024
eolt = ((c == CH_NL || c == CH_CR) && c0 == CH_CR) ? EOL_TYPE_CRNL : EOL_TYPE (c); 504 342 846
eolt = ((c == CH_NL || c == CH_CR) && c0 == CH_CR) ? EOL_TYPE_CRNL : EOL_TYPE (c); 1821 861 2682
eolt = ((c == CH_NL || c == CH_CR) && c0 == CH_CR) ? EOL_TYPE_CRNL : EOL_TYPE (c); 342 1821 2163
eolt = ((c == CH_NL || c == CH_CR) && c0 == CH_CR) ? EOL_TYPE_CRNL : EOL_TYPE (c); 0 342 342
2004 #if MAINT_DEBUG > 1 || MAINT_DEBUG_EOL > 0
2005 (void)fprintf (stderr, "# %04d EOLX: %d/%d/%03x pos %d = NL, eolx = %d, eol_pos = %d, tp: %02x/%02x\t%s (eol = %s, strict_eol = %d, c = 0x%04x, c0 = 0x%04x)\n",
2006 __LINE__, waitingForField ? 1 : 0, sv ? 1 : 0, f, spl, csv->eolx, csv->eol_pos, csv->eol_type, eolt,
2007 _pretty_strl (csv->bptr + csv->used), _pretty_strl (csv->eol), csv->strict_eol, c, c0);
2008 #endif
2009 3024 c0 = 0;
2010 3024 ▶ unless (f & CSV_FLAGS_QUO) {
Branch: 1 branch
BranchTrueFalseTotal
unless (f & CSV_FLAGS_QUO) { 2274 750 3024
2011 2274 ▶ if (csv->strict_eol && csv->eol_type && csv->eol_type != eolt)
Branch: 3 branches
BranchTrueFalseTotal
if (csv->strict_eol && csv->eol_type && csv->eol_type != eolt) 689 1585 2274
if (csv->strict_eol && csv->eol_type && csv->eol_type != eolt) 543 146 689
if (csv->strict_eol && csv->eol_type && csv->eol_type != eolt) 37 506 543
2012 37 ▶ ERROR_EOL;
Branch: 3 branches
BranchTrueFalseTotal
ERROR_EOL; 12 25 37
ERROR_EOL; 5 32 37
ERROR_EOL; 5 0 5
2013 2269 ▶ SET_EOL_TYPE (csv, eolt);
Branch: 1 branch
BranchTrueFalseTotal
SET_EOL_TYPE (csv, eolt); 284 1985 2269
2014 }
2015  
2016 3019 ▶ if (fnum == 1 && f == 0 && SvCUR (sv) == 0 && csv->skip_empty_rows) {
Branch: 4 branches
BranchTrueFalseTotal
if (fnum == 1 && f == 0 && SvCUR (sv) == 0 && csv->skip_empty_rows) { 354 2665 3019
if (fnum == 1 && f == 0 && SvCUR (sv) == 0 && csv->skip_empty_rows) { 271 83 354
if (fnum == 1 && f == 0 && SvCUR (sv) == 0 && csv->skip_empty_rows) { 159 112 271
if (fnum == 1 && f == 0 && SvCUR (sv) == 0 && csv->skip_empty_rows) { 94 65 159
2017 146 ▶ SkipEmptyRow;
Branch: 50 branches
BranchTrueFalseTotal
SkipEmptyRow; 3 91 94
SkipEmptyRow; 3 88 91
SkipEmptyRow; 2 86 88
SkipEmptyRow; 76 10 86
SkipEmptyRow; 11 65 76
SkipEmptyRow; 69 7 76
SkipEmptyRow; 3 66 69
SkipEmptyRow; 8 2 10
SkipEmptyRow; 3 7 10
SkipEmptyRow; 10 66 76
SkipEmptyRow; 10 0 10
SkipEmptyRow; 10 0 10
SkipEmptyRow; 0 10 10
SkipEmptyRow; 0 0 0
SkipEmptyRow; 10 0 10
SkipEmptyRow; 0 10 10
SkipEmptyRow; 10 0 10
SkipEmptyRow; 0 10 10
SkipEmptyRow; 0 10 10
SkipEmptyRow; 0 0 0
SkipEmptyRow; 10 0 10
SkipEmptyRow; 0 10 10
SkipEmptyRow; 0 0 0
SkipEmptyRow; 8 2 10
SkipEmptyRow; 0 8 8
SkipEmptyRow; 0 8 8
SkipEmptyRow; 0 8 8
SkipEmptyRow; 0 8 8
SkipEmptyRow; 0 0 0
SkipEmptyRow; 32 0 32
SkipEmptyRow; 32 0 32
SkipEmptyRow; 32 0 32
SkipEmptyRow; 32 0 32
SkipEmptyRow; 0 32 32
SkipEmptyRow; 0 0 0
SkipEmptyRow; 0 32 32
SkipEmptyRow; 0 0 0
SkipEmptyRow; 0 0 0
SkipEmptyRow; 0 0 0
SkipEmptyRow; 0 32 32
SkipEmptyRow; 0 0 0
SkipEmptyRow; 0 32 32
SkipEmptyRow; 0 0 0
SkipEmptyRow; 0 0 0
SkipEmptyRow; 0 0 0
SkipEmptyRow; 0 32 32
SkipEmptyRow; 32 0 32
SkipEmptyRow; 0 32 32
SkipEmptyRow; 0 0 0
SkipEmptyRow; 32 8 40
2018 66 goto restart;
2019 }
2020  
2021 2925 ▶ if (waitingForField) {
Branch: 1 branch
BranchTrueFalseTotal
if (waitingForField) { 304 2621 2925
2022 /* ,1,"foo, 3",,bar,
2023 * ^
2024 */
2025 304 ▶ if (csv->blank_is_undef || csv->empty_is_undef)
Branch: 2 branches
BranchTrueFalseTotal
if (csv->blank_is_undef || csv->empty_is_undef) 296 8 304
if (csv->blank_is_undef || csv->empty_is_undef) 8 288 296
2026 16 SvSetUndef (sv);
2027 else
2028 288 SvSetEmpty (sv);
2029 304 ▶ unless (csv->is_bound)
Branch: 1 branch
BranchTrueFalseTotal
unless (csv->is_bound) 304 0 304
2030 304 av_push (fields, sv);
2031 304 ▶ if (csv->keep_meta_info && fflags)
Branch: 2 branches
BranchTrueFalseTotal
if (csv->keep_meta_info && fflags) 14 290 304
if (csv->keep_meta_info && fflags) 14 0 14
2032 14 av_push (fflags, newSViv (f));
2033 304 return TRUE;
2034 }
2035  
2036 2621 ▶ if (f & CSV_FLAGS_QUO) {
Branch: 1 branch
BranchTrueFalseTotal
if (f & CSV_FLAGS_QUO) { 750 1871 2621
2037 /* ,1,"foo\n 3",,bar,
2038 * ^
2039 */
2040 750 f |= CSV_FLAGS_BIN;
2041 750 ▶ unless (csv->binary)
Branch: 1 branch
BranchTrueFalseTotal
unless (csv->binary) 19 731 750
2042 19 ▶ ERROR_INSIDE_QUOTES (2021);
Branch: 1 branch
BranchTrueFalseTotal
ERROR_INSIDE_QUOTES (2021); 19 0 19
2043  
2044 805 ▶ CSV_PUT_SV (c);
Branch: 15 branches
BranchTrueFalseTotal
CSV_PUT_SV (c); 40 691 731
CSV_PUT_SV (c); 35 5 40
CSV_PUT_SV (c); 74 0 74
CSV_PUT_SV (c); 0 74 74
CSV_PUT_SV (c); 74 40 114
CSV_PUT_SV (c); 0 691 691
CSV_PUT_SV (c); 0 0 0
CSV_PUT_SV (c); 0 0 0
CSV_PUT_SV (c); 0 0 0
CSV_PUT_SV (c); 0 691 691
CSV_PUT_SV (c); 0 0 0
CSV_PUT_SV (c); 0 0 0
CSV_PUT_SV (c); 0 0 0
CSV_PUT_SV (c); 691 0 691
CSV_PUT_SV (c); 0 691 691
2045 }
2046 else
2047 1871 ▶ if (csv->verbatim) {
Branch: 1 branch
BranchTrueFalseTotal
if (csv->verbatim) { 9 1862 1871
2048 /* ,1,foo\n 3,,bar,
2049 * This feature should be deprecated
2050 */
2051 9 f |= CSV_FLAGS_BIN;
2052 9 ▶ unless (csv->binary)
Branch: 1 branch
BranchTrueFalseTotal
unless (csv->binary) 1 8 9
2053 1 ▶ ERROR_INSIDE_FIELD (2030);
Branch: 1 branch
BranchTrueFalseTotal
ERROR_INSIDE_FIELD (2030); 1 0 1
2054  
2055 14 ▶ CSV_PUT_SV (c);
Branch: 15 branches
BranchTrueFalseTotal
CSV_PUT_SV (c); 2 6 8
CSV_PUT_SV (c); 0 2 2
CSV_PUT_SV (c); 6 0 6
CSV_PUT_SV (c); 1 5 6
CSV_PUT_SV (c); 6 2 8
CSV_PUT_SV (c); 0 6 6
CSV_PUT_SV (c); 0 0 0
CSV_PUT_SV (c); 0 0 0
CSV_PUT_SV (c); 0 0 0
CSV_PUT_SV (c); 0 6 6
CSV_PUT_SV (c); 0 0 0
CSV_PUT_SV (c); 0 0 0
CSV_PUT_SV (c); 0 0 0
CSV_PUT_SV (c); 6 0 6
CSV_PUT_SV (c); 1 5 6
2056 }
2057 else {
2058 /* sep=,
2059 * ^
2060 */
2061 1862 ▶ if (csv->recno == 0 && csv->fld_idx == 1 && csv->useIO &&
Branch: 3 branches
BranchTrueFalseTotal
if (csv->recno == 0 && csv->fld_idx == 1 && csv->useIO && 351 1511 1862
if (csv->recno == 0 && csv->fld_idx == 1 && csv->useIO && 30 321 351
if (csv->recno == 0 && csv->fld_idx == 1 && csv->useIO && 30 0 30
2062 30 ▶ (csv->bptr[0] == 's' || csv->bptr[0] == 'S') &&
Branch: 2 branches
BranchTrueFalseTotal
(csv->bptr[0] == 's' || csv->bptr[0] == 'S') && 25 5 30
(csv->bptr[0] == 's' || csv->bptr[0] == 'S') && 0 25 25
2063 5 ▶ (csv->bptr[1] == 'e' || csv->bptr[1] == 'E') &&
Branch: 2 branches
BranchTrueFalseTotal
(csv->bptr[1] == 'e' || csv->bptr[1] == 'E') && 0 5 5
(csv->bptr[1] == 'e' || csv->bptr[1] == 'E') && 0 0 0
2064 5 ▶ (csv->bptr[2] == 'p' || csv->bptr[2] == 'P') &&
Branch: 2 branches
BranchTrueFalseTotal
(csv->bptr[2] == 'p' || csv->bptr[2] == 'P') && 0 5 5
(csv->bptr[2] == 'p' || csv->bptr[2] == 'P') && 0 0 0
2065 5 ▶ csv->bptr[3] == '=') {
Branch: 1 branch
BranchTrueFalseTotal
csv->bptr[3] == '=') { 5 0 5
2066 5 char *sep = csv->bptr + 4;
2067 5 STRLEN lnu = csv->used > 5 ? csv->used - 5 : 0;
2068 5 ▶ if (lnu <= MAX_ATTR_LEN) {
Branch: 1 branch
BranchTrueFalseTotal
if (lnu <= MAX_ATTR_LEN) { 4 1 5
2069 4 sep[lnu] = (char)0;
2070 4 (void)memcpy (csv->sep, sep, lnu);
2071 4 ▶ csv->sep_len = lnu == 1 ? 0 : lnu;
Branch: 1 branch
BranchTrueFalseTotal
csv->sep_len = lnu == 1 ? 0 : lnu; 1 3 4
2072 4 return Parse (csv, src, fields, fflags);
2073 }
2074 }
2075  
2076 /* ,1,"foo\n 3",,bar
2077 * ^
2078 */
2079 1946 ▶ AV_PUSH;
Branch: 17 branches
BranchTrueFalseTotal
AV_PUSH; 1851 7 1858
AV_PUSH; 4 1847 1851
AV_PUSH; 1 3 4
AV_PUSH; 7 1851 1858
AV_PUSH; 7 0 7
AV_PUSH; 7 0 7
AV_PUSH; 0 7 7
AV_PUSH; 79 1779 1858
AV_PUSH; 79 0 79
AV_PUSH; 85 1773 1858
AV_PUSH; 85 0 85
AV_PUSH; 84 1 85
AV_PUSH; 37 47 84
AV_PUSH; 1 1857 1858
AV_PUSH; 1809 49 1858
AV_PUSH; 9 1849 1858
AV_PUSH; 9 0 9
2080 1858 return TRUE;
2081 }
2082 } /* CH_NL */
2083 else
2084 160183 ▶ if (c == CH_CR && !(csv->verbatim)) {
Branch: 2 branches
BranchTrueFalseTotal
if (c == CH_CR && !(csv->verbatim)) { 1348 158835 160183
if (c == CH_CR && !(csv->verbatim)) { 1345 3 1348
2085 #if MAINT_DEBUG > 1 || MAINT_DEBUG_EOL > 0
2086 (void)fprintf (stderr, "# %04d %d/%d/%03x pos %d = CR, eolx = %d, eol_pos = %d, tp: %02x (cr: %d)\t%s (eol = %s)\n",
2087 __LINE__, waitingForField ? 1 : 0, sv ? 1 : 0, f, spl, csv->eolx, csv->eol_pos, csv->eol_type, csv->eol_is_cr,
2088 _pretty_strl (csv->bptr + csv->used), _pretty_strl (csv->eol));
2089 #endif
2090 1345 c0 = CH_CR;
2091 1345 ▶ if (waitingForField) {
Branch: 1 branch
BranchTrueFalseTotal
if (waitingForField) { 170 1175 1345
2092 int c2;
2093  
2094 170 ▶ if (csv->eol_is_cr) {
Branch: 1 branch
BranchTrueFalseTotal
if (csv->eol_is_cr) { 46 124 170
2095 /* ,1,"foo\n 3",,bar,\r
2096 * ^
2097 */
2098 46 c = CH_NL;
2099 46 goto EOLX;
2100 }
2101  
2102 124 ▶ c2 = CSV_GET;
Branch: 1 branch
BranchTrueFalseTotal
c2 = CSV_GET; 116 8 124
2103  
2104 124 ▶ if (c2 == EOF) {
Branch: 1 branch
BranchTrueFalseTotal
if (c2 == EOF) { 8 116 124
2105 /* ,1,"foo\n 3",,bar,\r
2106 * ^
2107 */
2108 8 c = EOF;
2109  
2110 #if MAINT_DEBUG > 9
2111 (void)fprintf (stderr, "# %04d (%d) ... CR EOF 0x%x\n",
2112 __LINE__, seenSomething, c);
2113 #endif
2114 8 ▶ unless (seenSomething)
Branch: 1 branch
BranchTrueFalseTotal
unless (seenSomething) 0 8 8
2115 0 break;
2116 /* parse (): a CR at the very end of the input is not part
2117 * of an EOL, as for a non-empty last field; do not go on
2118 * with EOF as if it were a data byte */
2119 8 ▶ unless (csv->useIO)
Branch: 1 branch
BranchTrueFalseTotal
unless (csv->useIO) 5 3 8
2120 5 ▶ ERROR_INSIDE_FIELD (2032);
Branch: 1 branch
BranchTrueFalseTotal
ERROR_INSIDE_FIELD (2032); 5 0 5
2121 3 goto restart;
2122 }
2123  
2124 116 ▶ if (c2 == CH_NL) { /* \r is not optional before EOLX! */
Branch: 1 branch
BranchTrueFalseTotal
if (c2 == CH_NL) { /* \r is not optional before EOLX! */ 95 21 116
2125 /* ,1,"foo\n 3",,bar,\r\n
2126 * ^
2127 */
2128 95 ▶ if (csv->strict_eol && csv->eol_type && csv->eol_type != EOL_TYPE_CRNL)
Branch: 3 branches
BranchTrueFalseTotal
if (csv->strict_eol && csv->eol_type && csv->eol_type != EOL_TYPE_CRNL) 19 76 95
if (csv->strict_eol && csv->eol_type && csv->eol_type != EOL_TYPE_CRNL) 11 8 19
if (csv->strict_eol && csv->eol_type && csv->eol_type != EOL_TYPE_CRNL) 0 11 11
2129 0 ▶ ERROR_EOL;
Branch: 3 branches
BranchTrueFalseTotal
ERROR_EOL; 0 0 0
ERROR_EOL; 0 0 0
ERROR_EOL; 0 0 0
2130 95 ▶ SET_EOL_TYPE (csv, EOL_TYPE_CRNL);
Branch: 1 branch
BranchTrueFalseTotal
SET_EOL_TYPE (csv, EOL_TYPE_CRNL); 16 79 95
2131  
2132 #if MAINT_DEBUG > 1 || MAINT_DEBUG_EOL > 0
2133 (void)fprintf (stderr, "# %04d %d/%d/%03x pos %d = CRNL, eolx = %d, eol_pos = %d, tp: %02x (cr: %d, c0: %d)\t%s (eol = %s)\n",
2134 __LINE__, waitingForField ? 1 : 0, sv ? 1 : 0, f, spl, csv->eolx, csv->eol_pos, csv->eol_type, csv->eol_is_cr, c0,
2135 _pretty_strl (csv->bptr + csv->used), _pretty_strl (csv->eol));
2136 #endif
2137 95 c = c2;
2138 95 goto EOLX;
2139 }
2140  
2141 21 ▶ if (csv->useIO && csv->eol_len == 0) {
Branch: 2 branches
BranchTrueFalseTotal
if (csv->useIO && csv->eol_len == 0) { 16 5 21
if (csv->useIO && csv->eol_len == 0) { 16 0 16
2142 16 ▶ if (c2 == CH_CR) { /* \r followed by an empty line */
Branch: 1 branch
BranchTrueFalseTotal
if (c2 == CH_CR) { /* \r followed by an empty line */ 0 16 16
2143 /* ,1,"foo\n 3",,bar,\r\r
2144 * ^
2145 */
2146 0 ▶ if (csv->strict_eol && csv->eol_type) {
Branch: 2 branches
BranchTrueFalseTotal
if (csv->strict_eol && csv->eol_type) { 0 0 0
if (csv->strict_eol && csv->eol_type) { 0 0 0
2147 0 ▶ unless (csv->eol_type == EOL_TYPE_CR)
Branch: 1 branch
BranchTrueFalseTotal
unless (csv->eol_type == EOL_TYPE_CR) 0 0 0
2148 0 ▶ ERROR_EOL;
Branch: 3 branches
BranchTrueFalseTotal
ERROR_EOL; 0 0 0
ERROR_EOL; 0 0 0
ERROR_EOL; 0 0 0
2149 0 csv->eol_is_cr = 1;
2150 }
2151 else
2152 0 set_eol_is_cr (csv);
2153 0 goto EOLX;
2154 }
2155  
2156 16 waitingForField = 0;
2157  
2158 16 ▶ if (!is_csv_binary (c2)) {
Branch: 3 branches
BranchTrueFalseTotal
if (!is_csv_binary (c2)) { 13 3 16
if (!is_csv_binary (c2)) { 0 13 13
if (!is_csv_binary (c2)) { 0 3 3
2159 /* ,1,"foo\n 3",,bar,\r
2160 * baz,4
2161 * ^
2162 */
2163 13 ▶ if (csv->strict_eol && csv->eol_type) {
Branch: 2 branches
BranchTrueFalseTotal
if (csv->strict_eol && csv->eol_type) { 9 4 13
if (csv->strict_eol && csv->eol_type) { 4 5 9
2164 4 ▶ unless (csv->eol_type == EOL_TYPE_CR)
Branch: 1 branch
BranchTrueFalseTotal
unless (csv->eol_type == EOL_TYPE_CR) 4 0 4
2165 4 ▶ ERROR_EOL;
Branch: 3 branches
BranchTrueFalseTotal
ERROR_EOL; 0 4 4
ERROR_EOL; 0 4 4
ERROR_EOL; 0 0 0
2166 }
2167 else
2168 9 set_eol_is_cr (csv);
2169 13 csv->used--;
2170 13 csv->has_ahead++;
2171 13 ▶ if (fnum == 1 && f == 0 && SvCUR (sv) == 0 && csv->skip_empty_rows) {
Branch: 4 branches
BranchTrueFalseTotal
if (fnum == 1 && f == 0 && SvCUR (sv) == 0 && csv->skip_empty_rows) { 11 2 13
if (fnum == 1 && f == 0 && SvCUR (sv) == 0 && csv->skip_empty_rows) { 11 0 11
if (fnum == 1 && f == 0 && SvCUR (sv) == 0 && csv->skip_empty_rows) { 11 0 11
if (fnum == 1 && f == 0 && SvCUR (sv) == 0 && csv->skip_empty_rows) { 6 5 11
2172 6 ▶ SkipEmptyRow;
Branch: 50 branches
BranchTrueFalseTotal
SkipEmptyRow; 0 6 6
SkipEmptyRow; 0 6 6
SkipEmptyRow; 0 6 6
SkipEmptyRow; 6 0 6
SkipEmptyRow; 6 0 6
SkipEmptyRow; 6 0 6
SkipEmptyRow; 0 6 6
SkipEmptyRow; 0 0 0
SkipEmptyRow; 0 0 0
SkipEmptyRow; 0 6 6
SkipEmptyRow; 0 0 0
SkipEmptyRow; 0 0 0
SkipEmptyRow; 0 0 0
SkipEmptyRow; 0 0 0
SkipEmptyRow; 0 0 0
SkipEmptyRow; 0 0 0
SkipEmptyRow; 0 0 0
SkipEmptyRow; 0 0 0
SkipEmptyRow; 0 0 0
SkipEmptyRow; 0 0 0
SkipEmptyRow; 0 0 0
SkipEmptyRow; 0 0 0
SkipEmptyRow; 0 0 0
SkipEmptyRow; 0 0 0
SkipEmptyRow; 0 0 0
SkipEmptyRow; 0 0 0
SkipEmptyRow; 0 0 0
SkipEmptyRow; 0 0 0
SkipEmptyRow; 0 0 0
SkipEmptyRow; 0 0 0
SkipEmptyRow; 0 0 0
SkipEmptyRow; 0 0 0
SkipEmptyRow; 0 0 0
SkipEmptyRow; 0 0 0
SkipEmptyRow; 0 0 0
SkipEmptyRow; 0 0 0
SkipEmptyRow; 0 0 0
SkipEmptyRow; 0 0 0
SkipEmptyRow; 0 0 0
SkipEmptyRow; 0 0 0
SkipEmptyRow; 0 0 0
SkipEmptyRow; 0 0 0
SkipEmptyRow; 0 0 0
SkipEmptyRow; 0 0 0
SkipEmptyRow; 0 0 0
SkipEmptyRow; 0 0 0
SkipEmptyRow; 0 0 0
SkipEmptyRow; 0 0 0
SkipEmptyRow; 0 0 0
SkipEmptyRow; 0 0 0
2173 6 goto restart;
2174 }
2175 7 ▶ AV_PUSH;
Branch: 17 branches
BranchTrueFalseTotal
AV_PUSH; 0 7 7
AV_PUSH; 0 0 0
AV_PUSH; 0 0 0
AV_PUSH; 7 0 7
AV_PUSH; 7 0 7
AV_PUSH; 7 0 7
AV_PUSH; 0 7 7
AV_PUSH; 0 7 7
AV_PUSH; 0 0 0
AV_PUSH; 0 7 7
AV_PUSH; 0 0 0
AV_PUSH; 0 0 0
AV_PUSH; 0 0 0
AV_PUSH; 0 7 7
AV_PUSH; 7 0 7
AV_PUSH; 0 7 7
AV_PUSH; 0 0 0
2176 7 return TRUE;
2177 }
2178 }
2179  
2180 /* ,1,"foo\n 3",,bar,\r\t
2181 * ^
2182 */
2183 8 csv->used--;
2184 8 ▶ ERROR_INSIDE_FIELD (2031);
Branch: 1 branch
BranchTrueFalseTotal
ERROR_INSIDE_FIELD (2031); 8 0 8
2185 }
2186  
2187 1175 ▶ if (f & CSV_FLAGS_QUO) {
Branch: 1 branch
BranchTrueFalseTotal
if (f & CSV_FLAGS_QUO) { 641 534 1175
2188 /* ,1,"foo\r 3",,bar,\r\t
2189 * ^
2190 */
2191 641 f |= CSV_FLAGS_BIN;
2192 641 ▶ unless (csv->binary)
Branch: 1 branch
BranchTrueFalseTotal
unless (csv->binary) 70 571 641
2193 70 ▶ ERROR_INSIDE_QUOTES (2022);
Branch: 1 branch
BranchTrueFalseTotal
ERROR_INSIDE_QUOTES (2022); 70 0 70
2194  
2195 571 ▶ CSV_PUT_SV (c);
Branch: 15 branches
BranchTrueFalseTotal
CSV_PUT_SV (c); 0 571 571
CSV_PUT_SV (c); 0 0 0
CSV_PUT_SV (c); 0 0 0
CSV_PUT_SV (c); 0 0 0
CSV_PUT_SV (c); 0 0 0
CSV_PUT_SV (c); 0 571 571
CSV_PUT_SV (c); 0 0 0
CSV_PUT_SV (c); 0 0 0
CSV_PUT_SV (c); 0 0 0
CSV_PUT_SV (c); 0 571 571
CSV_PUT_SV (c); 0 0 0
CSV_PUT_SV (c); 0 0 0
CSV_PUT_SV (c); 0 0 0
CSV_PUT_SV (c); 571 0 571
CSV_PUT_SV (c); 2 569 571
2196 }
2197 else {
2198 int c2;
2199  
2200 534 ▶ if (csv->eol_is_cr) {
Branch: 1 branch
BranchTrueFalseTotal
if (csv->eol_is_cr) { 201 333 534
2201 /* ,1,"foo\n 3",,bar\r
2202 * ^
2203 */
2204 201 goto EOLX;
2205 }
2206  
2207 333 ▶ c2 = CSV_GET;
Branch: 1 branch
BranchTrueFalseTotal
c2 = CSV_GET; 326 7 333
2208  
2209 333 ▶ if (c2 == CH_NL) { /* \r is not optional before EOLX! */
Branch: 1 branch
BranchTrueFalseTotal
if (c2 == CH_NL) { /* \r is not optional before EOLX! */ 296 37 333
2210 /* ,1,"foo\n 3",,bar\r\n
2211 * ^
2212 */
2213 296 ▶ if (csv->strict_eol && csv->eol_type && csv->eol_type != EOL_TYPE_CRNL)
Branch: 3 branches
BranchTrueFalseTotal
if (csv->strict_eol && csv->eol_type && csv->eol_type != EOL_TYPE_CRNL) 165 131 296
if (csv->strict_eol && csv->eol_type && csv->eol_type != EOL_TYPE_CRNL) 89 76 165
if (csv->strict_eol && csv->eol_type && csv->eol_type != EOL_TYPE_CRNL) 10 79 89
2214 10 ▶ ERROR_EOL;
Branch: 3 branches
BranchTrueFalseTotal
ERROR_EOL; 1 9 10
ERROR_EOL; 0 10 10
ERROR_EOL; 0 0 0
2215 296 ▶ SET_EOL_TYPE (csv, EOL_TYPE_CRNL);
Branch: 1 branch
BranchTrueFalseTotal
SET_EOL_TYPE (csv, EOL_TYPE_CRNL); 103 193 296
2216  
2217 #if MAINT_DEBUG > 1 || MAINT_DEBUG_EOL > 0
2218 (void)fprintf (stderr, "# %04d %d/%d/%03x pos %d = CRNL, eolx = %d, eol_pos = %d, tp: %02x (cr: %d, c0: %d)\t%s (eol = %s)\n",
2219 __LINE__, waitingForField ? 1 : 0, sv ? 1 : 0, f, spl, csv->eolx, csv->eol_pos, csv->eol_type, csv->eol_is_cr, c0,
2220 _pretty_strl (csv->bptr + csv->used), _pretty_strl (csv->eol));
2221 #endif
2222 296 goto EOLX;
2223 }
2224  
2225 37 ▶ if (csv->useIO && csv->eol_len == 0) {
Branch: 2 branches
BranchTrueFalseTotal
if (csv->useIO && csv->eol_len == 0) { 30 7 37
if (csv->useIO && csv->eol_len == 0) { 30 0 30
2226 30 ▶ if (!is_csv_binary (c2)
Branch: 3 branches
BranchTrueFalseTotal
if (!is_csv_binary (c2) 15 15 30
if (!is_csv_binary (c2) 0 15 15
if (!is_csv_binary (c2) 15 0 15
2227 /* ,1,"foo\n 3",,bar\r
2228 * baz,4
2229 * ^
2230 */
2231 15 ▶ || c2 == CH_CR) {
Branch: 1 branch
BranchTrueFalseTotal
|| c2 == CH_CR) { 9 6 15
2232 /* ,1,"foo\n 3",,bar,\r\r
2233 * ^
2234 */
2235 #if MAINT_DEBUG_EOL > 0
2236 (void)fprintf (stderr, "# %04d parse eol CR/IO: '%s'\t(len: %d, is_cr: %d, x: %d, pos: %d, tp: %02x, c: %d, c2: %d)\n",
2237 __LINE__, _pretty_str (csv->eol, csv->eol_len), csv->eol_len, csv->eol_is_cr, csv->eolx, csv->eol_pos, csv->eol_type, c, c2);
2238 #endif
2239 24 ▶ if (csv->strict_eol && csv->eol_type) {
Branch: 2 branches
BranchTrueFalseTotal
if (csv->strict_eol && csv->eol_type) { 12 12 24
if (csv->strict_eol && csv->eol_type) { 4 8 12
2240 4 ▶ unless (csv->eol_type == EOL_TYPE_CR)
Branch: 1 branch
BranchTrueFalseTotal
unless (csv->eol_type == EOL_TYPE_CR) 4 0 4
2241 4 ▶ ERROR_EOL;
Branch: 3 branches
BranchTrueFalseTotal
ERROR_EOL; 0 4 4
ERROR_EOL; 0 4 4
ERROR_EOL; 0 0 0
2242 }
2243 else
2244 20 set_eol_is_cr (csv);
2245 24 csv->used--;
2246 24 csv->has_ahead++;
2247 24 ▶ if (fnum == 1 && f == 0 && SvCUR (sv) == 0 && csv->skip_empty_rows) {
Branch: 4 branches
BranchTrueFalseTotal
if (fnum == 1 && f == 0 && SvCUR (sv) == 0 && csv->skip_empty_rows) { 0 24 24
if (fnum == 1 && f == 0 && SvCUR (sv) == 0 && csv->skip_empty_rows) { 0 0 0
if (fnum == 1 && f == 0 && SvCUR (sv) == 0 && csv->skip_empty_rows) { 0 0 0
if (fnum == 1 && f == 0 && SvCUR (sv) == 0 && csv->skip_empty_rows) { 0 0 0
2248 0 ▶ SkipEmptyRow;
Branch: 50 branches
BranchTrueFalseTotal
SkipEmptyRow; 0 0 0
SkipEmptyRow; 0 0 0
SkipEmptyRow; 0 0 0
SkipEmptyRow; 0 0 0
SkipEmptyRow; 0 0 0
SkipEmptyRow; 0 0 0
SkipEmptyRow; 0 0 0
SkipEmptyRow; 0 0 0
SkipEmptyRow; 0 0 0
SkipEmptyRow; 0 0 0
SkipEmptyRow; 0 0 0
SkipEmptyRow; 0 0 0
SkipEmptyRow; 0 0 0
SkipEmptyRow; 0 0 0
SkipEmptyRow; 0 0 0
SkipEmptyRow; 0 0 0
SkipEmptyRow; 0 0 0
SkipEmptyRow; 0 0 0
SkipEmptyRow; 0 0 0
SkipEmptyRow; 0 0 0
SkipEmptyRow; 0 0 0
SkipEmptyRow; 0 0 0
SkipEmptyRow; 0 0 0
SkipEmptyRow; 0 0 0
SkipEmptyRow; 0 0 0
SkipEmptyRow; 0 0 0
SkipEmptyRow; 0 0 0
SkipEmptyRow; 0 0 0
SkipEmptyRow; 0 0 0
SkipEmptyRow; 0 0 0
SkipEmptyRow; 0 0 0
SkipEmptyRow; 0 0 0
SkipEmptyRow; 0 0 0
SkipEmptyRow; 0 0 0
SkipEmptyRow; 0 0 0
SkipEmptyRow; 0 0 0
SkipEmptyRow; 0 0 0
SkipEmptyRow; 0 0 0
SkipEmptyRow; 0 0 0
SkipEmptyRow; 0 0 0
SkipEmptyRow; 0 0 0
SkipEmptyRow; 0 0 0
SkipEmptyRow; 0 0 0
SkipEmptyRow; 0 0 0
SkipEmptyRow; 0 0 0
SkipEmptyRow; 0 0 0
SkipEmptyRow; 0 0 0
SkipEmptyRow; 0 0 0
SkipEmptyRow; 0 0 0
SkipEmptyRow; 0 0 0
2249 0 goto restart;
2250 }
2251 24 ▶ AV_PUSH;
Branch: 17 branches
BranchTrueFalseTotal
AV_PUSH; 24 0 24
AV_PUSH; 0 24 24
AV_PUSH; 0 0 0
AV_PUSH; 0 24 24
AV_PUSH; 0 0 0
AV_PUSH; 0 0 0
AV_PUSH; 0 0 0
AV_PUSH; 0 24 24
AV_PUSH; 0 0 0
AV_PUSH; 0 24 24
AV_PUSH; 0 0 0
AV_PUSH; 0 0 0
AV_PUSH; 0 0 0
AV_PUSH; 0 24 24
AV_PUSH; 24 0 24
AV_PUSH; 0 24 24
AV_PUSH; 0 0 0
2252 24 return TRUE;
2253 }
2254 }
2255  
2256 /* ,1,"foo\n 3",,bar\r\t
2257 * ^
2258 */
2259 13 ▶ ERROR_INSIDE_FIELD (2032);
Branch: 1 branch
BranchTrueFalseTotal
ERROR_INSIDE_FIELD (2032); 13 0 13
2260 }
2261 } /* CH_CR */
2262 else {
2263 #if MAINT_DEBUG > 1
2264 (void)fprintf (stderr, "# %04d %d/%d/%03x pos %d = CCC '%c'\t\t%s\n",
2265 __LINE__, waitingForField ? 1 : 0, sv ? 1 : 0, f, spl, c,
2266 _pretty_strl (csv->bptr + csv->used));
2267 #endif
2268 /* Needed for non-IO parse, where EOL is not set during read */
2269 158838 ▶ if (csv->eolx && c == CH_EOL &&
Branch: 2 branches
BranchTrueFalseTotal
if (csv->eolx && c == CH_EOL && 3646 155192 158838
if (csv->eolx && c == CH_EOL && 8 3638 3646
2270 8 ▶ csv->size - csv->used >= (STRLEN)csv->eol_len - 1 &&
Branch: 1 branch
BranchTrueFalseTotal
csv->size - csv->used >= (STRLEN)csv->eol_len - 1 && 8 0 8
2271 8 ▶ !memcmp (csv->bptr + csv->used, csv->eol + 1, csv->eol_len - 1) &&
Branch: 1 branch
BranchTrueFalseTotal
!memcmp (csv->bptr + csv->used, csv->eol + 1, csv->eol_len - 1) && 8 0 8
2272 8 ▶ (csv->used += csv->eol_len - 1)) {
Branch: 1 branch
BranchTrueFalseTotal
(csv->used += csv->eol_len - 1)) { 8 0 8
2273 8 c = CH_EOLX;
2274 #if MAINT_DEBUG > 5 || MAINT_DEBUG_EOL > 0
2275 (void)fprintf (stderr, "# %04d -> EOLX (0x%x)\n", __LINE__, c);
2276 #endif
2277 8 goto EOLX;
2278 }
2279  
2280 158830 ▶ if (waitingForField) {
Branch: 1 branch
BranchTrueFalseTotal
if (waitingForField) { 11632 147198 158830
2281 11632 ▶ if (csv->comment_str && !f && !spl && c == *csv->comment_str) {
Branch: 4 branches
BranchTrueFalseTotal
if (csv->comment_str && !f && !spl && c == *csv->comment_str) { 193 11439 11632
if (csv->comment_str && !f && !spl && c == *csv->comment_str) { 193 0 193
if (csv->comment_str && !f && !spl && c == *csv->comment_str) { 113 80 193
if (csv->comment_str && !f && !spl && c == *csv->comment_str) { 35 78 113
2282 35 STRLEN cl = strlen ((char *)csv->comment_str);
2283  
2284 #if MAINT_DEBUG > 5
2285 (void)fprintf (stderr,
2286 "# %04d COMMENT? cl = %d, size = %d, used = %d\n",
2287 __LINE__, cl, csv->size, csv->used);
2288 #endif
2289 35 ▶ if (cl == 1 || (
Branch: 1 branch
BranchTrueFalseTotal
if (cl == 1 || ( 18 17 35
2290 18 ▶ (csv->size - csv->used >= cl - 1 &&
Branch: 1 branch
BranchTrueFalseTotal
(csv->size - csv->used >= cl - 1 && 18 0 18
2291 18 ▶ !memcmp (csv->bptr + csv->used, csv->comment_str + 1, cl - 1) &&
Branch: 1 branch
BranchTrueFalseTotal
!memcmp (csv->bptr + csv->used, csv->comment_str + 1, cl - 1) && 18 0 18
2292 18 ▶ (csv->used += cl - 1)))) {
Branch: 1 branch
BranchTrueFalseTotal
(csv->used += cl - 1)))) { 18 0 18
2293 35 csv->used = csv->size;
2294 35 ▶ csv->fld_idx = csv->strict_n ? csv->strict_n - 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
csv->fld_idx = csv->strict_n ? csv->strict_n - 1 : 0; 6 29 35
2295 35 ▶ c = CSV_GET;
Branch: 1 branch
BranchTrueFalseTotal
c = CSV_GET; 0 35 35
2296 35 seenSomething = FALSE;
2297 #if MAINT_DEBUG > 5
2298 (void)fprintf (stderr, "# %04d COMMENT, SKIPPED\n", __LINE__);
2299 #endif
2300 35 ▶ unless (csv->useIO)
Branch: 1 branch
BranchTrueFalseTotal
unless (csv->useIO) 1 34 35
2301 1 csv->has_ahead = 214; /* abuse */
2302 35 ▶ if (c == EOF)
Branch: 1 branch
BranchTrueFalseTotal
if (c == EOF) 4 31 35
2303 4 break;
2304 31 goto restart;
2305 }
2306 }
2307  
2308 11597 ▶ if (csv->allow_whitespace && is_whitespace (c)) {
Branch: 6 branches
BranchTrueFalseTotal
if (csv->allow_whitespace && is_whitespace (c)) { 1961 9636 11597
if (csv->allow_whitespace && is_whitespace (c)) { 1961 0 1961
if (csv->allow_whitespace && is_whitespace (c)) { 1961 0 1961
if (csv->allow_whitespace && is_whitespace (c)) { 1961 0 1961
if (csv->allow_whitespace && is_whitespace (c)) { 1749 212 1961
if (csv->allow_whitespace && is_whitespace (c)) { 0 1749 1749
2309 do {
2310 322 ▶ c = CSV_GET;
Branch: 1 branch
BranchTrueFalseTotal
c = CSV_GET; 321 1 322
2311 #if MAINT_DEBUG > 5
2312 (void)fprintf (stderr, "# %04d WS next got (0x%x)\n", __LINE__, c);
2313 #endif
2314 322 ▶ } while (is_whitespace (c));
Branch: 5 branches
BranchTrueFalseTotal
} while (is_whitespace (c)); 284 38 322
} while (is_whitespace (c)); 252 32 284
} while (is_whitespace (c)); 252 0 252
} while (is_whitespace (c)); 110 142 252
} while (is_whitespace (c)); 0 142 142
2315 212 ▶ if (c == EOF)
Branch: 1 branch
BranchTrueFalseTotal
if (c == EOF) 1 211 212
2316 1 break;
2317 211 goto restart;
2318 }
2319 11385 waitingForField = 0;
2320 11385 goto restart;
2321 }
2322  
2323 #if MAINT_DEBUG > 5
2324 (void)fprintf (stderr, "# %04d %sc 0x%x is%s binary %s utf8\n",
2325 __LINE__, f & CSV_FLAGS_QUO ? "quoted " : "", c,
2326 is_csv_binary (c) ? "" : " not",
2327 csv->utf8 ? "is" : "not");
2328 #endif
2329 147198 ▶ if (f & CSV_FLAGS_QUO) {
Branch: 1 branch
BranchTrueFalseTotal
if (f & CSV_FLAGS_QUO) { 111650 35548 147198
2330 111650 ▶ if (is_csv_binary (c)) {
Branch: 3 branches
BranchTrueFalseTotal
if (is_csv_binary (c)) { 111202 448 111650
if (is_csv_binary (c)) { 3022 108180 111202
if (is_csv_binary (c)) { 3455 15 3470
2331 3455 f |= CSV_FLAGS_BIN;
2332 3455 ▶ unless (csv->binary || csv->utf8)
Branch: 2 branches
BranchTrueFalseTotal
unless (csv->binary || csv->utf8) 31 3424 3455
unless (csv->binary || csv->utf8) 5 26 31
2333 5 ▶ ERROR_INSIDE_QUOTES (2026);
Branch: 1 branch
BranchTrueFalseTotal
ERROR_INSIDE_QUOTES (2026); 5 0 5
2334 }
2335 111645 ▶ CSV_PUT_SV (c);
Branch: 15 branches
BranchTrueFalseTotal
CSV_PUT_SV (c); 0 111645 111645
CSV_PUT_SV (c); 0 0 0
CSV_PUT_SV (c); 0 0 0
CSV_PUT_SV (c); 0 0 0
CSV_PUT_SV (c); 0 0 0
CSV_PUT_SV (c); 0 111645 111645
CSV_PUT_SV (c); 0 0 0
CSV_PUT_SV (c); 0 0 0
CSV_PUT_SV (c); 0 0 0
CSV_PUT_SV (c); 0 111645 111645
CSV_PUT_SV (c); 0 0 0
CSV_PUT_SV (c); 0 0 0
CSV_PUT_SV (c); 0 0 0
CSV_PUT_SV (c); 111645 0 111645
CSV_PUT_SV (c); 3759 107886 111645
2336 }
2337 else {
2338 35548 ▶ if (is_csv_binary (c)) {
Branch: 3 branches
BranchTrueFalseTotal
if (is_csv_binary (c)) { 35510 38 35548
if (is_csv_binary (c)) { 435 35075 35510
if (is_csv_binary (c)) { 459 14 473
2339 459 ▶ if (csv->useIO && c == EOF)
Branch: 2 branches
BranchTrueFalseTotal
if (csv->useIO && c == EOF) 421 38 459
if (csv->useIO && c == EOF) 3 418 421
2340 3 break;
2341 456 f |= CSV_FLAGS_BIN;
2342 456 ▶ unless (csv->binary || csv->utf8)
Branch: 2 branches
BranchTrueFalseTotal
unless (csv->binary || csv->utf8) 7 449 456
unless (csv->binary || csv->utf8) 7 0 7
2343 7 ▶ ERROR_INSIDE_FIELD (2037);
Branch: 1 branch
BranchTrueFalseTotal
ERROR_INSIDE_FIELD (2037); 7 0 7
2344 }
2345 35538 ▶ CSV_PUT_SV (c);
Branch: 15 branches
BranchTrueFalseTotal
CSV_PUT_SV (c); 0 35538 35538
CSV_PUT_SV (c); 0 0 0
CSV_PUT_SV (c); 0 0 0
CSV_PUT_SV (c); 0 0 0
CSV_PUT_SV (c); 0 0 0
CSV_PUT_SV (c); 0 35538 35538
CSV_PUT_SV (c); 0 0 0
CSV_PUT_SV (c); 0 0 0
CSV_PUT_SV (c); 0 0 0
CSV_PUT_SV (c); 0 35538 35538
CSV_PUT_SV (c); 0 0 0
CSV_PUT_SV (c); 0 0 0
CSV_PUT_SV (c); 0 0 0
CSV_PUT_SV (c); 35538 0 35538
CSV_PUT_SV (c); 178 35360 35538
2346 }
2347 }
2348  
2349 /* continue */
2350 1885728 ▶ if (csv->verbatim && csv->useIO && csv->used == csv->size)
Branch: 3 branches
BranchTrueFalseTotal
if (csv->verbatim && csv->useIO && csv->used == csv->size) 119 1885609 1885728
if (csv->verbatim && csv->useIO && csv->used == csv->size) 47 72 119
if (csv->verbatim && csv->useIO && csv->used == csv->size) 3 44 47
2351 3 break;
2352 }
2353  
2354 863 ▶ if (waitingForField) {
Branch: 1 branch
BranchTrueFalseTotal
if (waitingForField) { 476 387 863
2355 476 ▶ unless (csv->useIO) {
Branch: 1 branch
BranchTrueFalseTotal
unless (csv->useIO) { 27 449 476
2356 27 ▶ if (csv->has_ahead == 214)
Branch: 1 branch
BranchTrueFalseTotal
if (csv->has_ahead == 214) 1 26 27
2357 1 return TRUE;
2358 26 seenSomething++;
2359 }
2360 475 ▶ if (seenSomething) {
Branch: 1 branch
BranchTrueFalseTotal
if (seenSomething) { 35 440 475
2361 35 ▶ NewField;
Branch: 3 branches
BranchTrueFalseTotal
NewField; 34 1 35
NewField; 1 33 34
NewField; 0 34 34
2362 35 ▶ if (csv->blank_is_undef || csv->empty_is_undef)
Branch: 2 branches
BranchTrueFalseTotal
if (csv->blank_is_undef || csv->empty_is_undef) 31 4 35
if (csv->blank_is_undef || csv->empty_is_undef) 4 27 31
2363 8 SvSetUndef (sv);
2364 else
2365 27 SvSetEmpty (sv);
2366 35 ▶ unless (csv->is_bound)
Branch: 1 branch
BranchTrueFalseTotal
unless (csv->is_bound) 34 1 35
2367 34 av_push (fields, sv);
2368 35 ▶ if (csv->keep_meta_info && fflags)
Branch: 2 branches
BranchTrueFalseTotal
if (csv->keep_meta_info && fflags) 3 32 35
if (csv->keep_meta_info && fflags) 3 0 3
2369 3 av_push (fflags, newSViv (f));
2370 35 return TRUE;
2371 }
2372  
2373 440 (void)SetDiag (csv, 2012);
2374 440 return FALSE;
2375 }
2376  
2377 387 ▶ if (f & CSV_FLAGS_QUO)
Branch: 1 branch
BranchTrueFalseTotal
if (f & CSV_FLAGS_QUO) 24 363 387
2378 24 ▶ ERROR_INSIDE_QUOTES (2027);
Branch: 1 branch
BranchTrueFalseTotal
ERROR_INSIDE_QUOTES (2027); 24 0 24
2379  
2380 363 ▶ if (sv) {
Branch: 1 branch
BranchTrueFalseTotal
if (sv) { 363 0 363
2381 555 ▶ AV_PUSH;
Branch: 17 branches
BranchTrueFalseTotal
AV_PUSH; 353 10 363
AV_PUSH; 40 313 353
AV_PUSH; 7 33 40
AV_PUSH; 10 353 363
AV_PUSH; 10 0 10
AV_PUSH; 10 0 10
AV_PUSH; 0 10 10
AV_PUSH; 25 338 363
AV_PUSH; 25 0 25
AV_PUSH; 153 210 363
AV_PUSH; 153 0 153
AV_PUSH; 152 1 153
AV_PUSH; 63 89 152
AV_PUSH; 1 362 363
AV_PUSH; 353 10 363
AV_PUSH; 1 362 363
AV_PUSH; 1 0 1
2382 }
2383 0 ▶ else if (f == 0 && fnum == 1 && csv->skip_empty_rows == 1)
Branch: 3 branches
BranchTrueFalseTotal
else if (f == 0 && fnum == 1 && csv->skip_empty_rows == 1) 0 0 0
else if (f == 0 && fnum == 1 && csv->skip_empty_rows == 1) 0 0 0
else if (f == 0 && fnum == 1 && csv->skip_empty_rows == 1) 0 0 0
2384 0 return FALSE;
2385 363 return TRUE;
2386 } /* Parse */
2387  
2388 154 static int hook (pTHX_ HV *hv, const char *cb_name, AV *av) {
2389 SV **svp;
2390 HV *cb;
2391 int res;
2392  
2393 #if MAINT_DEBUG > 1
2394 (void)fprintf (stderr, "# %04d HOOK %s %x\n", __LINE__, cb_name, av);
2395 #endif
2396 308 ▶ unless ((svp = hv_fetchs (hv, "callbacks", FALSE)) && _is_hashref (*svp))
Branch: 6 branches
BranchTrueFalseTotal
unless ((svp = hv_fetchs (hv, "callbacks", FALSE)) && _is_hashref (*svp)) 154 0 154
unless ((svp = hv_fetchs (hv, "callbacks", FALSE)) && _is_hashref (*svp)) 154 0 154
unless ((svp = hv_fetchs (hv, "callbacks", FALSE)) && _is_hashref (*svp)) 0 154 154
unless ((svp = hv_fetchs (hv, "callbacks", FALSE)) && _is_hashref (*svp)) 0 0 0
unless ((svp = hv_fetchs (hv, "callbacks", FALSE)) && _is_hashref (*svp)) 154 0 154
unless ((svp = hv_fetchs (hv, "callbacks", FALSE)) && _is_hashref (*svp)) 0 154 154
2397 0 return 0; /* uncoverable statement defensive programming */
2398  
2399 154 cb = (HV *)SvRV (*svp);
2400 154 svp = hv_fetch (cb, cb_name, strlen (cb_name), FALSE);
2401 308 ▶ unless (svp && _is_coderef (*svp))
Branch: 6 branches
BranchTrueFalseTotal
unless (svp && _is_coderef (*svp)) 154 0 154
unless (svp && _is_coderef (*svp)) 154 0 154
unless (svp && _is_coderef (*svp)) 0 154 154
unless (svp && _is_coderef (*svp)) 0 0 0
unless (svp && _is_coderef (*svp)) 154 0 154
unless (svp && _is_coderef (*svp)) 0 154 154
2402 0 return 0;
2403  
2404 154 { dSP;
2405 154 ENTER;
2406 154 SAVETMPS;
2407 154 ▶ PUSHMARK (SP);
Branch: 1 branch
BranchTrueFalseTotal
PUSHMARK (SP); 0 154 154
2408 154 ▶ mXPUSHs (newRV_inc ((SV *)hv));
Branch: 1 branch
BranchTrueFalseTotal
mXPUSHs (newRV_inc ((SV *)hv)); 0 154 154
2409 154 ▶ mXPUSHs (newRV_inc ((SV *)av));
Branch: 1 branch
BranchTrueFalseTotal
mXPUSHs (newRV_inc ((SV *)av)); 0 154 154
2410 154 PUTBACK;
2411 154 res = call_sv (*svp, G_SCALAR);
2412 154 SPAGAIN;
2413 154 ▶ if (res) {
Branch: 1 branch
BranchTrueFalseTotal
if (res) { 154 0 154
2414 154 SV *rv = POPs;
2415 154 ▶ if (SvROK (rv) && (rv = SvRV (rv)) && SvPOK (rv)) {
Branch: 3 branches
BranchTrueFalseTotal
if (SvROK (rv) && (rv = SvRV (rv)) && SvPOK (rv)) { 65 89 154
if (SvROK (rv) && (rv = SvRV (rv)) && SvPOK (rv)) { 65 0 65
if (SvROK (rv) && (rv = SvRV (rv)) && SvPOK (rv)) { 65 0 65
2416 65 ▶ if (strcmp (SvPV_nolen (rv), "skip") == 0)
Branch: 1 branch
BranchTrueFalseTotal
if (strcmp (SvPV_nolen (rv), "skip") == 0) 65 0 65
2417 65 res = 0;
2418 }
2419 }
2420 154 PUTBACK;
2421 154 ▶ FREETMPS;
Branch: 1 branch
BranchTrueFalseTotal
FREETMPS; 154 0 154
2422 154 LEAVE;
2423 }
2424 154 return res;
2425 } /* hook */
2426  
2427 #define c_xsParse(csv,hv,av,avf,src,useIO) cx_c_xsParse (aTHX_ csv, hv, av, avf, src, useIO)
2428 5187 static int cx_c_xsParse (pTHX_ csv_t csv, HV *hv, AV *av, AV *avf, SV *src, bool useIO) {
2429 5187 int result, ahead = 0;
2430 5187 SV *pos = NULL;
2431  
2432 5187 ENTER;
2433 5187 ▶ if (csv.eolx || csv.eol_is_cr) {
Branch: 2 branches
BranchTrueFalseTotal
if (csv.eolx || csv.eol_is_cr) { 4782 405 5187
if (csv.eolx || csv.eol_is_cr) { 501 4281 4782
2434 /* local $/ = $eol */
2435 #if MAINT_DEBUG_EOL > 0
2436 (void)fprintf (stderr, "# %04d Parse EOLX/RS: '%s'\t(len: %d, is_cr: %d, x: %d, pos: %d, tp: %02x)\n",
2437 __LINE__, _pretty_str (csv.eol, csv.eol_len), csv.eol_len, csv.eol_is_cr, csv.eolx, csv.eol_pos, csv.eol_type);
2438 #endif
2439 906 SAVEGENERICSV (PL_rs);
2440 906 PL_rs = newSVpvn ((char *)csv.eol, csv.eol_len);
2441 }
2442  
2443 5187 ▶ if ((csv.useIO = useIO)) {
Branch: 1 branch
BranchTrueFalseTotal
if ((csv.useIO = useIO)) { 3241 1946 5187
2444 3241 csv.tmp = NULL;
2445  
2446 3241 ▶ if ((ahead = csv.has_ahead)) {
Branch: 1 branch
BranchTrueFalseTotal
if ((ahead = csv.has_ahead)) { 241 3000 3241
2447 SV **svp;
2448 241 ▶ if ((svp = hv_fetchs (hv, "_AHEAD", FALSE)) && *svp) {
Branch: 2 branches
BranchTrueFalseTotal
if ((svp = hv_fetchs (hv, "_AHEAD", FALSE)) && *svp) { 241 0 241
if ((svp = hv_fetchs (hv, "_AHEAD", FALSE)) && *svp) { 241 0 241
2449 241 csv.bptr = SvPV (csv.tmp = *svp, csv.size);
2450 241 csv.used = 0;
2451 241 ▶ if (pos && SvIV (pos) > (IV)csv.size)
Branch: 2 branches
BranchTrueFalseTotal
if (pos && SvIV (pos) > (IV)csv.size) 0 241 241
if (pos && SvIV (pos) > (IV)csv.size) 0 0 0
2452 0 sv_setiv (pos, SvIV (pos) - csv.size);
2453 }
2454 }
2455 }
2456 else {
2457 1946 csv.tmp = src;
2458 1946 csv.utf8 = SvUTF8 (src) ? 1 : 0;
2459 1946 csv.bptr = SvPV (src, csv.size);
2460 }
2461 5187 ▶ if (csv.has_error_input) {
Branch: 1 branch
BranchTrueFalseTotal
if (csv.has_error_input) { 272 4915 5187
2462 272 (void)hv_store (hv, "_ERROR_INPUT", 12, &PL_sv_undef, 0);
2463 272 csv.has_error_input = 0;
2464 }
2465  
2466 5187 result = Parse (&csv, src, av, avf);
2467 5176 (void)hv_store (hv, "_RECNO", 6, newSViv (++csv.recno), 0);
2468 5176 (void)hv_store (hv, "_EOF", 4, &PL_sv_no, 0);
2469  
2470 5176 ▶ if (csv.strict) {
Branch: 1 branch
BranchTrueFalseTotal
if (csv.strict) { 60 5116 5176
2471 60 ▶ STRLEN nf = csv.is_bound ? csv.fld_idx ? csv.fld_idx - 1 : 0 : av_len (av);
Branch: 2 branches
BranchTrueFalseTotal
STRLEN nf = csv.is_bound ? csv.fld_idx ? csv.fld_idx - 1 : 0 : av_len (av); 11 49 60
STRLEN nf = csv.is_bound ? csv.fld_idx ? csv.fld_idx - 1 : 0 : av_len (av); 11 0 11
2472 #if MAINT_DEBUG > 6
2473 (void)fprintf (stderr, "# %04d Strict nf = %2d, n = %2d, idx = %2d, recno = %2d, res = %d\n",
2474 __LINE__, nf, csv.strict_n, csv.fld_idx, csv.recno, result);
2475 #endif
2476  
2477 60 ▶ if (nf && !csv.strict_n) csv.strict_n = (short)nf;
Branch: 2 branches
BranchTrueFalseTotal
if (nf && !csv.strict_n) csv.strict_n = (short)nf; 56 4 60
if (nf && !csv.strict_n) csv.strict_n = (short)nf; 20 36 56
2478 60 ▶ if (csv.strict_n > 0 && nf != (STRLEN)csv.strict_n) {
Branch: 2 branches
BranchTrueFalseTotal
if (csv.strict_n > 0 && nf != (STRLEN)csv.strict_n) { 60 0 60
if (csv.strict_n > 0 && nf != (STRLEN)csv.strict_n) { 25 35 60
2479 25 ▶ unless (csv.useIO & useIO_EOF) {
Branch: 1 branch
BranchTrueFalseTotal
unless (csv.useIO & useIO_EOF) { 18 7 25
2480 #if MAINT_DEBUG > 6
2481 ErrorDiag (&csv);
2482 #endif
2483 18 ▶ unless (last_error || (!csv.useIO && csv.has_ahead))
Branch: 3 branches
BranchTrueFalseTotal
unless (last_error || (!csv.useIO && csv.has_ahead)) 17 1 18
unless (last_error || (!csv.useIO && csv.has_ahead)) 5 12 17
unless (last_error || (!csv.useIO && csv.has_ahead)) 4 1 5
2484 16 ParseError (&csv, 2014, csv.used);
2485 }
2486 25 ▶ if (last_error) /* an error callback can reset and accept */
Branch: 1 branch
BranchTrueFalseTotal
if (last_error) /* an error callback can reset and accept */ 20 5 25
2487 20 result = FALSE;
2488 }
2489 }
2490  
2491 5176 ▶ if (csv.useIO) {
Branch: 1 branch
BranchTrueFalseTotal
if (csv.useIO) { 3233 1943 5176
2492 3335 ▶ if (csv.tmp && csv.used < csv.size && csv.has_ahead) {
Branch: 3 branches
BranchTrueFalseTotal
if (csv.tmp && csv.used < csv.size && csv.has_ahead) { 3233 0 3233
if (csv.tmp && csv.used < csv.size && csv.has_ahead) { 535 2698 3233
if (csv.tmp && csv.used < csv.size && csv.has_ahead) { 102 433 535
2493 SV **svp;
2494 102 ▶ if (ahead && SvREFCNT (csv.tmp) == 1
Branch: 2 branches
BranchTrueFalseTotal
if (ahead && SvREFCNT (csv.tmp) == 1 62 40 102
if (ahead && SvREFCNT (csv.tmp) == 1 59 3 62
2495 59 ▶ && (svp = hv_fetchs (hv, "_AHEAD", FALSE)) && *svp == csv.tmp)
Branch: 2 branches
BranchTrueFalseTotal
&& (svp = hv_fetchs (hv, "_AHEAD", FALSE)) && *svp == csv.tmp) 59 0 59
&& (svp = hv_fetchs (hv, "_AHEAD", FALSE)) && *svp == csv.tmp) 59 0 59
2496 /* The remainder already lives in _AHEAD: drop the parsed
2497 * part in place instead of copying the whole tail again,
2498 * which made CR-only input quadratic */
2499 59 sv_chop (csv.tmp, csv.bptr + csv.used);
2500 else {
2501 43 SV *sv = newSVpvn (csv.bptr + csv.used, csv.size - csv.used);
2502 43 (void)hv_store (hv, "_AHEAD", 6, sv, 0);
2503 }
2504 }
2505 else {
2506 3131 csv.has_ahead = 0;
2507 3131 ▶ if (csv.useIO & useIO_EOF)
Branch: 1 branch
BranchTrueFalseTotal
if (csv.useIO & useIO_EOF) 658 2473 3131
2508 658 (void)hv_store (hv, "_EOF", 4, &PL_sv_yes, 0);
2509 }
2510 /* csv.cache[CACHE_ID__has_ahead] = csv.has_ahead; */
2511 3233 (void)memcpy (csv.cache, &csv, sizeof (csv_t));
2512  
2513 3233 ▶ if (avf) {
Branch: 1 branch
BranchTrueFalseTotal
if (avf) { 2038 1195 3233
2514 2038 ▶ if (csv.keep_meta_info)
Branch: 1 branch
BranchTrueFalseTotal
if (csv.keep_meta_info) 11 2027 2038
2515 11 (void)hv_store (hv, "_FFLAGS", 7, newRV_noinc ((SV *)avf), 0);
2516 else {
2517 2027 av_undef (avf);
2518 2027 sv_free ((SV *)avf);
2519 }
2520 }
2521 }
2522 else { /* just copy to the cache */
2523 1943 SV **svp = hv_fetchs (hv, "_CACHE", FALSE);
2524  
2525 1943 ▶ if (svp && *svp)
Branch: 2 branches
BranchTrueFalseTotal
if (svp && *svp) 1943 0 1943
if (svp && *svp) 1943 0 1943
2526 3886 csv.cache = (byte *)SvPV_nolen (*svp);
2527 1943 (void)memcpy (csv.cache, &csv, sizeof (csv_t));
2528 }
2529  
2530 5176 ▶ if (result && csv.types) {
Branch: 2 branches
BranchTrueFalseTotal
if (result && csv.types) { 4368 808 5176
if (result && csv.types) { 2 4366 4368
2531 STRLEN i;
2532 2 STRLEN len = av_len (av);
2533 SV **svp;
2534  
2535 8 ▶ for (i = 0; i <= len && i <= csv.types_len; i++) {
Branch: 2 branches
BranchTrueFalseTotal
for (i = 0; i <= len && i <= csv.types_len; i++) { 6 2 8
for (i = 0; i <= len && i <= csv.types_len; i++) { 6 0 6
2536 6 ▶ if ((svp = av_fetch (av, i, FALSE)) && *svp && SvOK (*svp)) {
Branch: 3 branches
BranchTrueFalseTotal
if ((svp = av_fetch (av, i, FALSE)) && *svp && SvOK (*svp)) { 6 0 6
if ((svp = av_fetch (av, i, FALSE)) && *svp && SvOK (*svp)) { 6 0 6
if ((svp = av_fetch (av, i, FALSE)) && *svp && SvOK (*svp)) { 6 0 6
2537 6 switch (csv.types[i]) {
2538 2 case CSV_XS_TYPE_IV:
2539 #ifdef CSV_XS_TYPE_WARN
2540 2 sv_setiv (*svp, SvIV (*svp));
2541 #else
2542 if (SvTRUE (*svp))
2543 sv_setiv (*svp, SvIV (*svp));
2544 else
2545 sv_setiv (*svp, 0);
2546 #endif
2547 2 break;
2548  
2549 2 case CSV_XS_TYPE_NV:
2550 #ifdef CSV_XS_TYPE_WARN
2551 2 sv_setnv (*svp, SvNV (*svp));
2552 #else
2553 if (SvTRUE (*svp))
2554 sv_setnv (*svp, SvNV (*svp));
2555 else
2556 sv_setnv (*svp, 0.0);
2557 #endif
2558 2 break;
2559  
2560 2 default:
2561 2 break;
2562 }
2563 }
2564 }
2565 }
2566  
2567 5176 LEAVE;
2568  
2569 5176 return result;
2570 } /* c_xsParse */
2571  
2572 #define xsParse(self,hv,av,avf,src,useIO) cx_xsParse (aTHX_ self, hv, av, avf, src, useIO)
2573 3989 static int cx_xsParse (pTHX_ SV *self, HV *hv, AV *av, AV *avf, SV *src, bool useIO) {
2574 csv_t csv;
2575 int state;
2576 3989 SetupCsv (&csv, hv, self);
2577 3986 state = c_xsParse (csv, hv, av, avf, src, useIO);
2578 3981 ▶ if (state && csv.has_hooks & HOOK_AFTER_PARSE)
Branch: 2 branches
BranchTrueFalseTotal
if (state && csv.has_hooks & HOOK_AFTER_PARSE) 3532 449 3981
if (state && csv.has_hooks & HOOK_AFTER_PARSE) 5 3527 3532
2579 5 (void)hook (aTHX_ hv, "after_parse", av);
2580 3981 ▶ return (state || !last_error);
Branch: 2 branches
BranchTrueFalseTotal
return (state || !last_error); 449 3532 3981
return (state || !last_error); 3 446 449
2581 } /* xsParse */
2582  
2583 /* API also offers av_clear and av_undef, but they have more overhead */
2584 #define av_empty(av) cx_av_empty (aTHX_ av)
2585 84 static void cx_av_empty (pTHX_ AV *av) {
2586 337 ▶ while (av_len (av) >= 0)
Branch: 1 branch
BranchTrueFalseTotal
while (av_len (av) >= 0) 253 84 337
2587 253 sv_free (av_pop (av));
2588 84 } /* av_empty */
2589  
2590 #define xsParse_all(self,hv,io,off,len) cx_xsParse_all (aTHX_ self, hv, io, off, len)
2591 397 static SV *cx_xsParse_all (pTHX_ SV *self, HV *hv, SV *io, SV *off, SV *len) {
2592 csv_t csv;
2593 397 int n = 0, skip = 0, length = MAXINT, tail = MAXINT;
2594 397 AV *avr = newAV ();
2595 397 AV *row = newAV ();
2596  
2597 397 SetupCsv (&csv, hv, self);
2598  
2599 397 ▶ if (SvOK (off)) {
Branch: 1 branch
BranchTrueFalseTotal
if (SvOK (off)) { 56 341 397
2600 56 skip = SvIV (off);
2601 56 ▶ if (skip < 0) {
Branch: 1 branch
BranchTrueFalseTotal
if (skip < 0) { 12 44 56
2602 12 tail = -skip;
2603 12 skip = -1;
2604 }
2605 }
2606 397 ▶ if (SvOK (len))
Branch: 1 branch
BranchTrueFalseTotal
if (SvOK (len)) 44 353 397
2607 44 length = SvIV (len);
2608  
2609 1201 ▶ while (c_xsParse (csv, hv, row, NULL, io, 1)) {
Branch: 1 branch
BranchTrueFalseTotal
while (c_xsParse (csv, hv, row, NULL, io, 1)) { 836 359 1195
2610  
2611 836 SetupCsv (&csv, hv, self);
2612  
2613 836 ▶ if (skip > 0) {
Branch: 1 branch
BranchTrueFalseTotal
if (skip > 0) { 20 816 836
2614 20 skip--;
2615 20 av_empty (row); /* re-use */
2616 20 continue;
2617 }
2618  
2619 816 ▶ if (n++ >= tail) {
Branch: 1 branch
BranchTrueFalseTotal
if (n++ >= tail) { 12 804 816
2620 12 SvREFCNT_dec (av_shift (avr));
2621 12 n--;
2622 }
2623  
2624 816 ▶ if (csv.has_hooks & HOOK_AFTER_PARSE) {
Branch: 1 branch
BranchTrueFalseTotal
if (csv.has_hooks & HOOK_AFTER_PARSE) { 140 676 816
2625 140 ▶ unless (hook (aTHX_ hv, "after_parse", row)) {
Branch: 1 branch
BranchTrueFalseTotal
unless (hook (aTHX_ hv, "after_parse", row)) { 64 76 140
2626 64 av_empty (row); /* re-use */
2627 64 continue;
2628 }
2629 }
2630 752 av_push (avr, newRV_noinc ((SV *)row));
2631  
2632 752 ▶ if (n >= length && skip >= 0) {
Branch: 2 branches
BranchTrueFalseTotal
if (n >= length && skip >= 0) { 52 700 752
if (n >= length && skip >= 0) { 32 20 52
2633 32 row = NULL;
2634 32 break; /* We have enough */
2635 }
2636  
2637 720 row = newAV ();
2638 }
2639 391 ▶ if (row)
Branch: 1 branch
BranchTrueFalseTotal
if (row) 359 32 391
2640 359 SvREFCNT_dec ((SV *)row);
2641 399 ▶ while (n > length) {
Branch: 1 branch
BranchTrueFalseTotal
while (n > length) { 8 391 399
2642 8 SvREFCNT_dec (av_pop (avr));
2643 8 n--;
2644 }
2645  
2646 391 return (SV *)sv_2mortal (newRV_noinc ((SV *)avr));
2647 } /* xsParse_all */
2648  
2649 #define xsCombine(self,hv,av,io,useIO) cx_xsCombine (aTHX_ self, hv, av, io, useIO)
2650 221687 static int cx_xsCombine (pTHX_ SV *self, HV *hv, AV *av, SV *io, bool useIO) {
2651 csv_t csv;
2652 int result;
2653 #if (PERL_BCDVERSION >= 0x5008000)
2654 221687 SV *ors = PL_ors_sv;
2655 #endif
2656  
2657 221687 SetupCsv (&csv, hv, self);
2658 221687 csv.useIO = useIO;
2659 #if (PERL_BCDVERSION >= 0x5008000)
2660 221687 ▶ if (*csv.eol)
Branch: 1 branch
BranchTrueFalseTotal
if (*csv.eol) 259 221428 221687
2661 259 PL_ors_sv = NULL;
2662 #endif
2663 221687 ▶ if (useIO && csv.has_hooks & HOOK_BEFORE_PRINT)
Branch: 2 branches
BranchTrueFalseTotal
if (useIO && csv.has_hooks & HOOK_BEFORE_PRINT) 220285 1402 221687
if (useIO && csv.has_hooks & HOOK_BEFORE_PRINT) 9 220276 220285
2664 9 (void)hook (aTHX_ hv, "before_print", av);
2665 221687 result = Combine (&csv, io, av);
2666 #if (PERL_BCDVERSION >= 0x5008000)
2667 221683 PL_ors_sv = ors;
2668 #endif
2669 221683 ▶ if (result && !useIO && csv.utf8)
Branch: 3 branches
BranchTrueFalseTotal
if (result && !useIO && csv.utf8) 221675 8 221683
if (result && !useIO && csv.utf8) 1397 220278 221675
if (result && !useIO && csv.utf8) 25 1372 1397
2670 25 sv_utf8_upgrade (io);
2671 221683 return result;
2672 } /* xsCombine */
2673  
2674 MODULE = Text::CSV_XS PACKAGE = Text::CSV_XS
2675  
2676 PROTOTYPES: DISABLE
2677  
2678 BOOT:
2679 38 m_getline = newSVpvs ("getline");
2680 38 m_print = newSVpvs ("print");
2681 38 Perl_load_module (aTHX_ PERL_LOADMOD_NOIMPORT, newSVpvs ("IO::Handle"), NULL, NULL, NULL);
2682  
2683 void
2684 SetDiag (SV *self, int xse, SV *line = undef)
2685  
2686 PPCODE:
2687 HV *hv;
2688 csv_t csv;
2689  
2690 3164 ▶ if (SvOK (self) && SvROK (self)) {
Branch: 2 branches
BranchTrueFalseTotal
if (SvOK (self) && SvROK (self)) { 3164 0 3164
if (SvOK (self) && SvROK (self)) { 1048 2116 3164
2691 1048 ▶ CSV_XS_SELF;
Branch: 4 branches
BranchTrueFalseTotal
CSV_XS_SELF; 1048 0 1048
CSV_XS_SELF; 1048 0 1048
CSV_XS_SELF; 1048 0 1048
CSV_XS_SELF; 0 1048 1048
2692 1048 SetupCsv (&csv, hv, self);
2693 1048 ST (0) = SetDiag (&csv, xse);
2694 }
2695 else {
2696 2116 last_error = xse;
2697 2116 ST (0) = sv_2mortal (SvDiag (xse));
2698 }
2699  
2700 3164 ▶ if (xse && SvPOK (line)) {
Branch: 2 branches
BranchTrueFalseTotal
if (xse && SvPOK (line)) { 2127 1037 3164
if (xse && SvPOK (line)) { 1049 1078 2127
2701 1049 sv_setpvn (ST (0), SvPVX (line), SvCUR (line));
2702 1049 SvIOK_on (ST (0));
2703 }
2704  
2705 3164 XSRETURN (1);
2706 /* XS SetDiag */
2707  
2708 void
2709 error_input (SV *self)
2710  
2711 PPCODE:
2712 12 ▶ if (self && SvOK (self) && SvROK (self) && SvTYPE (SvRV (self)) == SVt_PVHV) {
Branch: 4 branches
BranchTrueFalseTotal
if (self && SvOK (self) && SvROK (self) && SvTYPE (SvRV (self)) == SVt_PVHV) { 8 0 8
if (self && SvOK (self) && SvROK (self) && SvTYPE (SvRV (self)) == SVt_PVHV) { 7 1 8
if (self && SvOK (self) && SvROK (self) && SvTYPE (SvRV (self)) == SVt_PVHV) { 5 2 7
if (self && SvOK (self) && SvROK (self) && SvTYPE (SvRV (self)) == SVt_PVHV) { 4 1 5
2713 4 HV *hv = (HV *)SvRV (self);
2714 4 SV **sv = hv_fetchs (hv, "_ERROR_INPUT", FALSE);
2715 4 ▶ if (SvOK (*sv))
Branch: 1 branch
BranchTrueFalseTotal
if (SvOK (*sv)) 3 1 4
2716 3 ST (0) = *sv;
2717 else
2718 1 ST (0) = newSV (0);
2719 }
2720 else
2721 4 ST (0) = newSV (0);
2722  
2723 8 XSRETURN (1);
2724 /* XS error_input */
2725  
2726 void
2727 Combine (SV *self, SV *dst, SV *fields, bool useIO)
2728  
2729 PPCODE:
2730 HV *hv;
2731 AV *av;
2732  
2733 1402 ▶ CSV_XS_SELF;
Branch: 4 branches
BranchTrueFalseTotal
CSV_XS_SELF; 1402 0 1402
CSV_XS_SELF; 1402 0 1402
CSV_XS_SELF; 1402 0 1402
CSV_XS_SELF; 0 1402 1402
2734 1402 av = (AV *)SvRV (fields);
2735 1402 ▶ ST (0) = xsCombine (self, hv, av, dst, useIO) ? &PL_sv_yes : &PL_sv_undef;
Branch: 1 branch
BranchTrueFalseTotal
ST (0) = xsCombine (self, hv, av, dst, useIO) ? &PL_sv_yes : &PL_sv_undef; 1397 1 1398
2736 1398 XSRETURN (1);
2737 /* XS Combine */
2738  
2739 void
2740 Parse (SV *self, SV *src, SV *fields, SV *fflags)
2741  
2742 PPCODE:
2743 HV *hv;
2744 AV *av;
2745 AV *avf;
2746 int r;
2747  
2748 1946 ▶ CSV_XS_SELF;
Branch: 4 branches
BranchTrueFalseTotal
CSV_XS_SELF; 1946 0 1946
CSV_XS_SELF; 1946 0 1946
CSV_XS_SELF; 1946 0 1946
CSV_XS_SELF; 0 1946 1946
2749 1946 av = (AV *)SvRV (fields);
2750 1946 avf = (AV *)SvRV (fflags);
2751  
2752 1946 r = xsParse (self, hv, av, avf, src, 0);
2753 1943 ▶ PUT_RETURN (r ? &PL_sv_yes : &PL_sv_no);
Branch: 1 branch
BranchTrueFalseTotal
PUT_RETURN (r ? &PL_sv_yes : &PL_sv_no); 1733 210 1943
2754 /* XS Parse */
2755  
2756 void
2757 print (SV *self, SV *io, SV *fields)
2758  
2759 PPCODE:
2760 HV *hv;
2761 AV *av;
2762 int r;
2763  
2764 220290 ▶ CSV_XS_SELF;
Branch: 4 branches
BranchTrueFalseTotal
CSV_XS_SELF; 220290 0 220290
CSV_XS_SELF; 220290 0 220290
CSV_XS_SELF; 220290 0 220290
CSV_XS_SELF; 0 220290 220290
2765 220290 ▶ if (fields == &PL_sv_undef)
Branch: 1 branch
BranchTrueFalseTotal
if (fields == &PL_sv_undef) 200005 20285 220290
2766 200005 av = (AV *)sv_2mortal ((SV *)newAV ());
2767 else {
2768 40570 ▶ unless (_is_arrayref (fields))
Branch: 5 branches
BranchTrueFalseTotal
unless (_is_arrayref (fields)) 20285 0 20285
unless (_is_arrayref (fields)) 1 20284 20285
unless (_is_arrayref (fields)) 1 0 1
unless (_is_arrayref (fields)) 20282 3 20285
unless (_is_arrayref (fields)) 2 20280 20282
2769 5 croak ("Expected fields to be an array ref");
2770  
2771 20280 av = (AV *)SvRV (fields);
2772 }
2773  
2774 220285 r = xsCombine (self, hv, av, io, 1);
2775 220285 ▶ PUT_RETURN (r ? &PL_sv_yes : &PL_sv_no);
Branch: 1 branch
BranchTrueFalseTotal
PUT_RETURN (r ? &PL_sv_yes : &PL_sv_no); 220278 7 220285
2776 /* XS print */
2777  
2778 void
2779 getline (SV *self, SV *io)
2780  
2781 PPCODE:
2782 HV *hv;
2783 AV *av;
2784 AV *avf;
2785 int r;
2786  
2787 2043 ▶ CSV_XS_SELF;
Branch: 4 branches
BranchTrueFalseTotal
CSV_XS_SELF; 2043 0 2043
CSV_XS_SELF; 2043 0 2043
CSV_XS_SELF; 2043 0 2043
CSV_XS_SELF; 0 2043 2043
2788 2043 av = newAV ();
2789 2043 avf = newAV ();
2790 2043 r = xsParse (self, hv, av, avf, io, 1);
2791 2038 ▶ unless (r)
Branch: 1 branch
BranchTrueFalseTotal
unless (r) 236 1802 2038
2792 236 SvREFCNT_dec ((SV *)av);
2793 2038 ▶ PUT_RETURN (r ? sv_2mortal (newRV_noinc ((SV *)av)) : undef);
Branch: 1 branch
BranchTrueFalseTotal
PUT_RETURN (r ? sv_2mortal (newRV_noinc ((SV *)av)) : undef); 1802 236 2038
2794 /* XS getline */
2795  
2796 void
2797 getline_all (SV *self, SV *io, SV *offset = undef, SV *length = undef)
2798  
2799 PPCODE:
2800 HV *hv;
2801 SV *rv;
2802  
2803 397 ▶ CSV_XS_SELF;
Branch: 4 branches
BranchTrueFalseTotal
CSV_XS_SELF; 397 0 397
CSV_XS_SELF; 397 0 397
CSV_XS_SELF; 397 0 397
CSV_XS_SELF; 0 397 397
2804  
2805 397 rv = xsParse_all (self, hv, io, offset, length);
2806 391 PUT_RETURN (rv);
2807 /* XS getline_all */
2808  
2809 void
2810 _cache_get_eolt (SV *self)
2811  
2812 PPCODE:
2813 HV *hv;
2814 SV *sve;
2815 char *eol;
2816  
2817 32 ▶ CSV_XS_SELF;
Branch: 4 branches
BranchTrueFalseTotal
CSV_XS_SELF; 32 0 32
CSV_XS_SELF; 32 0 32
CSV_XS_SELF; 32 0 32
CSV_XS_SELF; 0 32 32
2818 32 sve = newSVpvs_flags ("", SVs_TEMP);
2819 32 eol = xs_cache_get_eolt (hv);
2820 32 ▶ if (eol)
Branch: 1 branch
BranchTrueFalseTotal
if (eol) 21 11 32
2821 21 sv_setpvn (sve, eol, strlen (eol));
2822 else
2823 11 sv_setpvn (sve, NULL, 0);
2824 32 ST (0) = sve;
2825 32 XSRETURN (1);
2826 /* XS _cache_get_eolt */
2827  
2828 void
2829 _cache_set (SV *self, int idx, SV *val)
2830  
2831 PPCODE:
2832 HV *hv;
2833  
2834 23365 ▶ CSV_XS_SELF;
Branch: 4 branches
BranchTrueFalseTotal
CSV_XS_SELF; 23365 0 23365
CSV_XS_SELF; 23365 0 23365
CSV_XS_SELF; 23365 0 23365
CSV_XS_SELF; 0 23365 23365
2835 23365 xs_cache_set (hv, idx, val);
2836 23365 XSRETURN (1);
2837 /* XS _cache_set */
2838  
2839 void
2840 _cache_diag (SV *self)
2841  
2842 PPCODE:
2843 HV *hv;
2844  
2845 2 ▶ CSV_XS_SELF;
Branch: 4 branches
BranchTrueFalseTotal
CSV_XS_SELF; 2 0 2
CSV_XS_SELF; 2 0 2
CSV_XS_SELF; 2 0 2
CSV_XS_SELF; 0 2 2
2846 2 xs_cache_diag (hv);
2847 2 XSRETURN (1);
2848 /* XS _cache_diag */
« blib/lib/Text/CSV_XS.pm ↑ Summary