| 1 |
|
| /* utf8_to_uvchr_buf is 5.16; ask ppport.h (included from stencil.h) to |
| 2 |
|
| * emit its back-compat implementation into this TU, the only user. */ |
| 3 |
|
| #define NEED_utf8_to_uvchr_buf |
| 4 |
|
| |
| 5 |
|
| #include "stencil.h" |
| 6 |
|
| #include "stencil_expfix.h" |
| 7 |
|
| |
| 8 |
50944 |
| void stencil_filt_case(pTHX_ SV *in, SV *out, int to_upper) |
| 9 |
|
| { |
| 10 |
|
| STRLEN len; |
| 11 |
50944 |
| const char *p = SvPV(in, len); |
| 12 |
|
| |
| 13 |
50944 |
▶ | if (!SvUTF8(in)) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (!SvUTF8(in)) { |
50939 |
5 |
50944 |
|
| 14 |
|
| char *w; |
| 15 |
|
| STRLEN i; |
| 16 |
50939 |
▶ | SvUPGRADE(out, SVt_PV); |
Branch: 1 branch
| Branch | True | False | Total |
| SvUPGRADE(out, SVt_PV); |
0 |
50939 |
50939 |
|
| 17 |
50939 |
▶ | SvGROW(out, len + 1); |
Branch: 2 branches
| Branch | True | False | Total |
| SvGROW(out, len + 1); |
50939 |
0 |
50939 |
| SvGROW(out, len + 1); |
0 |
50939 |
50939 |
|
| 18 |
50939 |
| w = SvPVX(out); |
| 19 |
50939 |
▶ | if (to_upper) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (to_upper) { |
50622 |
317 |
50939 |
|
| 20 |
1006961 |
▶ | for (i = 0; i < len; i++) { |
Branch: 1 branch
| Branch | True | False | Total |
| for (i = 0; i < len; i++) { |
956339 |
50622 |
1006961 |
|
| 21 |
956339 |
| char c = p[i]; |
| 22 |
956339 |
▶ | w[i] = (c >= 'a' && c <= 'z') ? (char)(c - 32) : c; |
Branch: 2 branches
| Branch | True | False | Total |
| w[i] = (c >= 'a' && c <= 'z') ? (char)(c - 32) : c; |
554146 |
402193 |
956339 |
| w[i] = (c >= 'a' && c <= 'z') ? (char)(c - 32) : c; |
554146 |
0 |
554146 |
|
| 23 |
|
| } |
| 24 |
|
| } else { |
| 25 |
4056 |
▶ | for (i = 0; i < len; i++) { |
Branch: 1 branch
| Branch | True | False | Total |
| for (i = 0; i < len; i++) { |
3739 |
317 |
4056 |
|
| 26 |
3739 |
| char c = p[i]; |
| 27 |
3739 |
▶ | w[i] = (c >= 'A' && c <= 'Z') ? (char)(c + 32) : c; |
Branch: 2 branches
| Branch | True | False | Total |
| w[i] = (c >= 'A' && c <= 'Z') ? (char)(c + 32) : c; |
2856 |
883 |
3739 |
| w[i] = (c >= 'A' && c <= 'Z') ? (char)(c + 32) : c; |
2783 |
73 |
2856 |
|
| 28 |
|
| } |
| 29 |
|
| } |
| 30 |
50939 |
| w[len] = '\0'; |
| 31 |
50939 |
| SvCUR_set(out, len); |
| 32 |
50939 |
| SvPOK_only(out); |
| 33 |
50939 |
| SvUTF8_off(out); |
| 34 |
50939 |
| return; |
| 35 |
|
| } |
| 36 |
|
| |
| 37 |
|
| { |
| 38 |
|
| /* to_uni_upper/lower write the full (possibly multi-char) |
| 39 |
|
| * mapping as UTF-8 into a scratch buffer */ |
| 40 |
5 |
| const U8 *s = (const U8 *)p; |
| 41 |
5 |
| const U8 *end = s + len; |
| 42 |
5 |
| STRLEN used = 0; |
| 43 |
|
| U8 tmp[UTF8_MAXBYTES_CASE + 1]; |
| 44 |
5 |
▶ | SvUPGRADE(out, SVt_PV); |
Branch: 1 branch
| Branch | True | False | Total |
| SvUPGRADE(out, SVt_PV); |
0 |
5 |
5 |
|
| 45 |
5 |
▶ | SvGROW(out, len + UTF8_MAXBYTES_CASE + 1); |
Branch: 2 branches
| Branch | True | False | Total |
| SvGROW(out, len + UTF8_MAXBYTES_CASE + 1); |
5 |
0 |
5 |
| SvGROW(out, len + UTF8_MAXBYTES_CASE + 1); |
0 |
5 |
5 |
|
| 46 |
69 |
▶ | while (s < end) { |
Branch: 1 branch
| Branch | True | False | Total |
| while (s < end) { |
64 |
5 |
69 |
|
| 47 |
|
| STRLEN clen, tlen; |
| 48 |
64 |
| UV uv = utf8_to_uvchr_buf(s, end, &clen); |
| 49 |
64 |
▶ | if (to_upper) |
Branch: 1 branch
| Branch | True | False | Total |
| if (to_upper) |
38 |
26 |
64 |
|
| 50 |
38 |
| (void)to_uni_upper(uv, tmp, &tlen); |
| 51 |
|
| else |
| 52 |
26 |
| (void)to_uni_lower(uv, tmp, &tlen); |
| 53 |
64 |
▶ | if (SvLEN(out) < used + tlen + 1) |
Branch: 1 branch
| Branch | True | False | Total |
| if (SvLEN(out) < used + tlen + 1) |
0 |
64 |
64 |
|
| 54 |
0 |
▶ | SvGROW(out, (used + tlen + 1) * 2); |
Branch: 2 branches
| Branch | True | False | Total |
| SvGROW(out, (used + tlen + 1) * 2); |
0 |
0 |
0 |
| SvGROW(out, (used + tlen + 1) * 2); |
0 |
0 |
0 |
|
| 55 |
64 |
| memcpy(SvPVX(out) + used, tmp, tlen); |
| 56 |
64 |
| used += tlen; |
| 57 |
64 |
▶ | s += clen ? clen : 1; |
Branch: 1 branch
| Branch | True | False | Total |
| s += clen ? clen : 1; |
64 |
0 |
64 |
|
| 58 |
|
| } |
| 59 |
5 |
| SvPVX(out)[used] = '\0'; |
| 60 |
5 |
| SvCUR_set(out, used); |
| 61 |
5 |
| SvPOK_only(out); |
| 62 |
5 |
| SvUTF8_on(out); |
| 63 |
|
| } |
| 64 |
|
| } |
| 65 |
|
| |
| 66 |
346 |
| void stencil_filt_trim(pTHX_ SV *in, SV *out) |
| 67 |
|
| { |
| 68 |
|
| STRLEN len; |
| 69 |
346 |
| const char *p = SvPV(in, len); |
| 70 |
346 |
| const char *e = p + len; |
| 71 |
594 |
▶ | while (p < e && isSPACE(*p)) |
Branch: 2 branches
| Branch | True | False | Total |
| while (p < e && isSPACE(*p)) |
593 |
1 |
594 |
| while (p < e && isSPACE(*p)) |
248 |
345 |
593 |
|
| 72 |
248 |
| p++; |
| 73 |
591 |
▶ | while (e > p && isSPACE(e[-1])) |
Branch: 2 branches
| Branch | True | False | Total |
| while (e > p && isSPACE(e[-1])) |
590 |
1 |
591 |
| while (e > p && isSPACE(e[-1])) |
245 |
345 |
590 |
|
| 74 |
245 |
| e--; |
| 75 |
346 |
| sv_setpvn(out, p, (STRLEN)(e - p)); |
| 76 |
346 |
▶ | if (SvUTF8(in)) |
Branch: 1 branch
| Branch | True | False | Total |
| if (SvUTF8(in)) |
1 |
345 |
346 |
|
| 77 |
1 |
| SvUTF8_on(out); |
| 78 |
|
| else |
| 79 |
345 |
| SvUTF8_off(out); |
| 80 |
346 |
| } |
| 81 |
|
| |
| 82 |
12 |
| void stencil_filt_html(pTHX_ SV *in, SV *out) |
| 83 |
|
| { |
| 84 |
|
| STRLEN len; |
| 85 |
12 |
| const char *p = SvPV(in, len); |
| 86 |
|
| stencil_buf b; |
| 87 |
|
| |
| 88 |
|
| /* attach the buffer machinery to the scratch SV so the escaper's |
| 89 |
|
| * reserve/grow reuses its allocation */ |
| 90 |
12 |
▶ | SvUPGRADE(out, SVt_PV); |
Branch: 1 branch
| Branch | True | False | Total |
| SvUPGRADE(out, SVt_PV); |
0 |
12 |
12 |
|
| 91 |
12 |
▶ | SvGROW(out, len + 32); |
Branch: 2 branches
| Branch | True | False | Total |
| SvGROW(out, len + 32); |
12 |
0 |
12 |
| SvGROW(out, len + 32); |
0 |
12 |
12 |
|
| 92 |
12 |
| SvPOK_only(out); |
| 93 |
12 |
| b.sv = out; |
| 94 |
12 |
| b.cur = SvPVX(out); |
| 95 |
12 |
| b.end = SvPVX(out) + SvLEN(out) - 1; |
| 96 |
12 |
| b.utf8 = 0; |
| 97 |
|
| #ifdef PERL_IMPLICIT_CONTEXT |
| 98 |
|
| b.perl = aTHX; |
| 99 |
|
| #endif |
| 100 |
12 |
| stencil_dispatch.escape(&b, p, len); |
| 101 |
12 |
| (void)stencil_buf_done(&b); |
| 102 |
12 |
▶ | if (SvUTF8(in)) |
Branch: 1 branch
| Branch | True | False | Total |
| if (SvUTF8(in)) |
0 |
12 |
12 |
|
| 103 |
0 |
| SvUTF8_on(out); |
| 104 |
|
| else |
| 105 |
12 |
| SvUTF8_off(out); |
| 106 |
12 |
| } |
| 107 |
|
| |
| 108 |
12 |
| void stencil_filt_uri(pTHX_ SV *in, SV *out) |
| 109 |
|
| { |
| 110 |
|
| static const char hex[] = "0123456789ABCDEF"; |
| 111 |
|
| STRLEN len, i; |
| 112 |
12 |
| const char *p = SvPV(in, len); |
| 113 |
|
| char *w; |
| 114 |
|
| |
| 115 |
12 |
▶ | SvUPGRADE(out, SVt_PV); |
Branch: 1 branch
| Branch | True | False | Total |
| SvUPGRADE(out, SVt_PV); |
0 |
12 |
12 |
|
| 116 |
12 |
▶ | SvGROW(out, len * 3 + 1); |
Branch: 2 branches
| Branch | True | False | Total |
| SvGROW(out, len * 3 + 1); |
12 |
0 |
12 |
| SvGROW(out, len * 3 + 1); |
0 |
12 |
12 |
|
| 117 |
12 |
| SvPOK_only(out); |
| 118 |
|
| /* latin-1-repped high bytes are UTF-8 encoded before percent |
| 119 |
|
| * escaping, so %-sequences are always UTF-8 regardless of the |
| 120 |
|
| * input SV's internal form */ |
| 121 |
12 |
▶ | SvGROW(out, len * 6 + 1); |
Branch: 2 branches
| Branch | True | False | Total |
| SvGROW(out, len * 6 + 1); |
12 |
0 |
12 |
| SvGROW(out, len * 6 + 1); |
3 |
9 |
12 |
|
| 122 |
12 |
| w = SvPVX(out); |
| 123 |
119 |
▶ | for (i = 0; i < len; i++) { |
Branch: 1 branch
| Branch | True | False | Total |
| for (i = 0; i < len; i++) { |
107 |
12 |
119 |
|
| 124 |
107 |
| unsigned char c = (unsigned char)p[i]; |
| 125 |
107 |
▶ | if ((c >= 'A' && c <= 'Z') || (c >= 'a' && c <= 'z') |
Branch: 4 branches
| Branch | True | False | Total |
| if ((c >= 'A' && c <= 'Z') || (c >= 'a' && c <= 'z') |
72 |
35 |
107 |
| if ((c >= 'A' && c <= 'Z') || (c >= 'a' && c <= 'z') |
66 |
6 |
72 |
| if ((c >= 'A' && c <= 'Z') || (c >= 'a' && c <= 'z') |
65 |
36 |
101 |
| if ((c >= 'A' && c <= 'Z') || (c >= 'a' && c <= 'z') |
7 |
58 |
65 |
|
| 126 |
43 |
▶ | || (c >= '0' && c <= '9') || c == '-' || c == '.' |
Branch: 4 branches
| Branch | True | False | Total |
| || (c >= '0' && c <= '9') || c == '-' || c == '.' |
22 |
21 |
43 |
| || (c >= '0' && c <= '9') || c == '-' || c == '.' |
20 |
2 |
22 |
| || (c >= '0' && c <= '9') || c == '-' || c == '.' |
40 |
1 |
41 |
| || (c >= '0' && c <= '9') || c == '-' || c == '.' |
37 |
3 |
40 |
|
| 127 |
37 |
▶ | || c == '_' || c == '~') { |
Branch: 2 branches
| Branch | True | False | Total |
| || c == '_' || c == '~') { |
36 |
1 |
37 |
| || c == '_' || c == '~') { |
1 |
35 |
36 |
|
| 128 |
72 |
| *w++ = (char)c; |
| 129 |
35 |
▶ | } else if (c >= 0x80 && !SvUTF8(in)) { |
Branch: 2 branches
| Branch | True | False | Total |
| } else if (c >= 0x80 && !SvUTF8(in)) { |
6 |
29 |
35 |
| } else if (c >= 0x80 && !SvUTF8(in)) { |
2 |
4 |
6 |
|
| 130 |
2 |
| unsigned char u1 = (unsigned char)(0xC0 | (c >> 6)); |
| 131 |
2 |
| unsigned char u2 = (unsigned char)(0x80 | (c & 0x3F)); |
| 132 |
2 |
| *w++ = '%'; *w++ = hex[u1 >> 4]; *w++ = hex[u1 & 0xF]; |
| 133 |
2 |
| *w++ = '%'; *w++ = hex[u2 >> 4]; *w++ = hex[u2 & 0xF]; |
| 134 |
|
| } else { |
| 135 |
33 |
| *w++ = '%'; |
| 136 |
33 |
| *w++ = hex[c >> 4]; |
| 137 |
33 |
| *w++ = hex[c & 0xF]; |
| 138 |
|
| } |
| 139 |
|
| } |
| 140 |
12 |
| *w = '\0'; |
| 141 |
12 |
| SvCUR_set(out, (STRLEN)(w - SvPVX(out))); |
| 142 |
12 |
| SvUTF8_off(out); /* pure ASCII by construction */ |
| 143 |
12 |
| } |
| 144 |
|
| |
| 145 |
|
| /* fmt: sprintf with exactly one conversion, the shape fmt_check |
| 146 |
|
| * (stencil_compile.c) guaranteed at template compile - so this can scan |
| 147 |
|
| * blind. The format is rewritten on the way through: perl's own length |
| 148 |
|
| * modifiers (IVdf and friends) are spliced in so the value passed always |
| 149 |
|
| * matches the conversion's width on every platform; floats go through a |
| 150 |
|
| * plain double, which is what display formatting wants. */ |
| 151 |
35 |
| void stencil_filt_fmt(pTHX_ SV *in, SV *out, const char *fmt, STRLEN flen, |
| 152 |
|
| int src_utf8) |
| 153 |
|
| { |
| 154 |
|
| char rf[96]; /* rewritten format */ |
| 155 |
|
| char obuf[640]; /* capped by STENCIL_FMT_MAXWID */ |
| 156 |
35 |
| const char *p = fmt, *end = fmt + flen; |
| 157 |
35 |
| char *w = rf; |
| 158 |
35 |
| char conv = 's'; |
| 159 |
35 |
| int has_prec = 0; |
| 160 |
35 |
| int fmt_hi = 0; /* a high-bit byte in the literals */ |
| 161 |
|
| int want_utf8; |
| 162 |
35 |
| int olen = 0; |
| 163 |
|
| |
| 164 |
91 |
▶ | while (p < end) { |
Branch: 1 branch
| Branch | True | False | Total |
| while (p < end) { |
56 |
35 |
91 |
|
| 165 |
56 |
▶ | if (((unsigned char)*p) & 0x80) fmt_hi = 1; |
Branch: 1 branch
| Branch | True | False | Total |
| if (((unsigned char)*p) & 0x80) fmt_hi = 1; |
0 |
56 |
56 |
|
| 166 |
56 |
▶ | if (*p != '%') { *w++ = *p++; continue; } |
Branch: 1 branch
| Branch | True | False | Total |
| if (*p != '%') { *w++ = *p++; continue; } |
20 |
36 |
56 |
|
| 167 |
36 |
▶ | if (p + 1 < end && p[1] == '%') { *w++ = '%'; *w++ = '%'; p += 2; continue; } |
Branch: 2 branches
| Branch | True | False | Total |
| if (p + 1 < end && p[1] == '%') { *w++ = '%'; *w++ = '%'; p += 2; continue; } |
36 |
0 |
36 |
| if (p + 1 < end && p[1] == '%') { *w++ = '%'; *w++ = '%'; p += 2; continue; } |
1 |
35 |
36 |
|
| 168 |
35 |
| *w++ = *p++; /* '%' */ |
| 169 |
39 |
▶ | while (p < end && (*p == '-' || *p == '+' || *p == ' ' |
Branch: 4 branches
| Branch | True | False | Total |
| while (p < end && (*p == '-' || *p == '+' || *p == ' ' |
39 |
0 |
39 |
| while (p < end && (*p == '-' || *p == '+' || *p == ' ' |
1 |
38 |
39 |
| while (p < end && (*p == '-' || *p == '+' || *p == ' ' |
1 |
37 |
38 |
| while (p < end && (*p == '-' || *p == '+' || *p == ' ' |
0 |
37 |
37 |
|
| 170 |
37 |
▶ | || *p == '0' || *p == '#')) |
Branch: 2 branches
| Branch | True | False | Total |
| || *p == '0' || *p == '#')) |
1 |
36 |
37 |
| || *p == '0' || *p == '#')) |
1 |
35 |
36 |
|
| 171 |
4 |
| *w++ = *p++; |
| 172 |
40 |
▶ | while (p < end && *p >= '0' && *p <= '9') |
Branch: 3 branches
| Branch | True | False | Total |
| while (p < end && *p >= '0' && *p <= '9') |
40 |
0 |
40 |
| while (p < end && *p >= '0' && *p <= '9') |
27 |
13 |
40 |
| while (p < end && *p >= '0' && *p <= '9') |
5 |
22 |
27 |
|
| 173 |
5 |
| *w++ = *p++; |
| 174 |
35 |
▶ | if (p < end && *p == '.') { |
Branch: 2 branches
| Branch | True | False | Total |
| if (p < end && *p == '.') { |
35 |
0 |
35 |
| if (p < end && *p == '.') { |
13 |
22 |
35 |
|
| 175 |
13 |
| has_prec = 1; |
| 176 |
13 |
| *w++ = *p++; |
| 177 |
26 |
▶ | while (p < end && *p >= '0' && *p <= '9') |
Branch: 3 branches
| Branch | True | False | Total |
| while (p < end && *p >= '0' && *p <= '9') |
26 |
0 |
26 |
| while (p < end && *p >= '0' && *p <= '9') |
26 |
0 |
26 |
| while (p < end && *p >= '0' && *p <= '9') |
13 |
13 |
26 |
|
| 178 |
13 |
| *w++ = *p++; |
| 179 |
|
| } |
| 180 |
35 |
| conv = *p++; |
| 181 |
35 |
| switch (conv) { |
| 182 |
8 |
| case 'd': case 'i': |
| 183 |
24 |
▶ | { const char *m = IVdf; while (*m) *w++ = *m++; } |
Branch: 1 branch
| Branch | True | False | Total |
| { const char *m = IVdf; while (*m) *w++ = *m++; } |
16 |
8 |
24 |
|
| 184 |
8 |
| break; |
| 185 |
1 |
| case 'o': |
| 186 |
3 |
▶ | { const char *m = UVof; while (*m) *w++ = *m++; } |
Branch: 1 branch
| Branch | True | False | Total |
| { const char *m = UVof; while (*m) *w++ = *m++; } |
2 |
1 |
3 |
|
| 187 |
1 |
| break; |
| 188 |
1 |
| case 'u': |
| 189 |
3 |
▶ | { const char *m = UVuf; while (*m) *w++ = *m++; } |
Branch: 1 branch
| Branch | True | False | Total |
| { const char *m = UVuf; while (*m) *w++ = *m++; } |
2 |
1 |
3 |
|
| 190 |
1 |
| break; |
| 191 |
2 |
| case 'x': |
| 192 |
6 |
▶ | { const char *m = UVxf; while (*m) *w++ = *m++; } |
Branch: 1 branch
| Branch | True | False | Total |
| { const char *m = UVxf; while (*m) *w++ = *m++; } |
4 |
2 |
6 |
|
| 193 |
2 |
| break; |
| 194 |
1 |
| case 'X': |
| 195 |
3 |
▶ | { const char *m = UVXf; while (*m) *w++ = *m++; } |
Branch: 1 branch
| Branch | True | False | Total |
| { const char *m = UVXf; while (*m) *w++ = *m++; } |
2 |
1 |
3 |
|
| 196 |
1 |
| break; |
| 197 |
22 |
| default: /* eEfgGs: as written */ |
| 198 |
22 |
| *w++ = conv; |
| 199 |
22 |
| break; |
| 200 |
|
| } |
| 201 |
|
| } |
| 202 |
35 |
| *w = '\0'; |
| 203 |
|
| |
| 204 |
35 |
▶ | want_utf8 = fmt_hi && src_utf8; |
Branch: 2 branches
| Branch | True | False | Total |
| want_utf8 = fmt_hi && src_utf8; |
0 |
35 |
35 |
| want_utf8 = fmt_hi && src_utf8; |
0 |
0 |
0 |
|
| 205 |
35 |
| switch (conv) { |
| 206 |
8 |
| case 'd': case 'i': |
| 207 |
8 |
| olen = my_snprintf(obuf, sizeof obuf, rf, SvIV(in)); |
| 208 |
8 |
| break; |
| 209 |
5 |
| case 'o': case 'u': case 'x': case 'X': |
| 210 |
5 |
| olen = my_snprintf(obuf, sizeof obuf, rf, SvUV(in)); |
| 211 |
5 |
| break; |
| 212 |
8 |
| case 's': { |
| 213 |
|
| const char *s; |
| 214 |
|
| STRLEN sl; |
| 215 |
8 |
▶ | if (SvUTF8(in) || want_utf8) { |
Branch: 2 branches
| Branch | True | False | Total |
| if (SvUTF8(in) || want_utf8) { |
6 |
2 |
8 |
| if (SvUTF8(in) || want_utf8) { |
0 |
6 |
6 |
|
| 216 |
2 |
| s = SvPVutf8(in, sl); |
| 217 |
2 |
| want_utf8 = 1; |
| 218 |
|
| } |
| 219 |
6 |
| else s = SvPV(in, sl); |
| 220 |
8 |
| olen = my_snprintf(obuf, sizeof obuf, rf, s); |
| 221 |
8 |
▶ | if (want_utf8 && has_prec) { |
Branch: 2 branches
| Branch | True | False | Total |
| if (want_utf8 && has_prec) { |
2 |
6 |
8 |
| if (want_utf8 && has_prec) { |
1 |
1 |
2 |
|
| 222 |
|
| /* a byte-counted precision may have cut the final UTF-8 |
| 223 |
|
| * sequence short; strip a trailing incomplete sequence */ |
| 224 |
1 |
| size_t ol = (size_t)(olen < 0 ? 0 : olen); |
| 225 |
|
| size_t st; |
| 226 |
1 |
▶ | if (ol >= sizeof obuf) ol = strlen(obuf); |
Branch: 1 branch
| Branch | True | False | Total |
| if (ol >= sizeof obuf) ol = strlen(obuf); |
0 |
1 |
1 |
|
| 227 |
1 |
| st = ol; |
| 228 |
1 |
▶ | while (st > 0 && (((unsigned char)obuf[st - 1]) & 0xC0) == 0x80) |
Branch: 2 branches
| Branch | True | False | Total |
| while (st > 0 && (((unsigned char)obuf[st - 1]) & 0xC0) == 0x80) |
1 |
0 |
1 |
| while (st > 0 && (((unsigned char)obuf[st - 1]) & 0xC0) == 0x80) |
0 |
1 |
1 |
|
| 229 |
0 |
| st--; |
| 230 |
1 |
▶ | if (st > 0 && (((unsigned char)obuf[st - 1]) & 0x80) |
Branch: 2 branches
| Branch | True | False | Total |
| if (st > 0 && (((unsigned char)obuf[st - 1]) & 0x80) |
1 |
0 |
1 |
| if (st > 0 && (((unsigned char)obuf[st - 1]) & 0x80) |
1 |
0 |
1 |
|
| 231 |
1 |
▶ | && (size_t)UTF8SKIP(&obuf[st - 1]) != ol - (st - 1)) { |
Branch: 1 branch
| Branch | True | False | Total |
| && (size_t)UTF8SKIP(&obuf[st - 1]) != ol - (st - 1)) { |
1 |
0 |
1 |
|
| 232 |
1 |
| obuf[st - 1] = '\0'; |
| 233 |
1 |
| olen = (int)(st - 1); |
| 234 |
|
| } |
| 235 |
|
| } |
| 236 |
8 |
| break; |
| 237 |
|
| } |
| 238 |
14 |
| default: /* eEfgG */ |
| 239 |
|
| /* snprintf, not my_snprintf: on a quadmath perl my_snprintf hands any |
| 240 |
|
| * format that is one bare float spec ("%.2f") to quadmath_snprintf |
| 241 |
|
| * and reads an __float128 from the varargs, so passing a double there |
| 242 |
|
| * panics ("quadmath_snprintf failed") or prints rubbish. Splicing in |
| 243 |
|
| * NVff to match would only move the problem, since the same perl |
| 244 |
|
| * routes "$%.2Qf" - a spec with literal text around it - to vsnprintf, |
| 245 |
|
| * which has no Q modifier. A double and a plain format are well |
| 246 |
|
| * defined everywhere, and display formatting is what this is for. */ |
| 247 |
14 |
| olen = snprintf(obuf, sizeof obuf, rf, (double)SvNV(in)); |
| 248 |
|
| #ifdef _WIN32 |
| 249 |
|
| /* The Windows CRT prints 1.5e+003; make it 1.5e+03 like everyone. */ |
| 250 |
|
| if (olen > 0 && (size_t)olen < sizeof obuf) |
| 251 |
|
| olen = stencil_expfix(obuf, olen); |
| 252 |
|
| #endif |
| 253 |
14 |
| break; |
| 254 |
|
| } |
| 255 |
|
| |
| 256 |
35 |
▶ | if (olen < 0) olen = 0; |
Branch: 1 branch
| Branch | True | False | Total |
| if (olen < 0) olen = 0; |
0 |
35 |
35 |
|
| 257 |
35 |
▶ | if ((size_t)olen >= sizeof obuf) olen = (int)(sizeof obuf) - 1; |
Branch: 1 branch
| Branch | True | False | Total |
| if ((size_t)olen >= sizeof obuf) olen = (int)(sizeof obuf) - 1; |
0 |
35 |
35 |
|
| 258 |
35 |
| sv_setpvn(out, obuf, (STRLEN)olen); |
| 259 |
35 |
▶ | if (want_utf8) SvUTF8_on(out); |
Branch: 1 branch
| Branch | True | False | Total |
| if (want_utf8) SvUTF8_on(out); |
2 |
33 |
35 |
|
| 260 |
33 |
| else SvUTF8_off(out); |
| 261 |
35 |
| } |