| 1 |
|
| #include "EXTERN.h" |
| 2 |
|
| #include "perl.h" |
| 3 |
|
| #include "XSUB.h" |
| 4 |
|
| |
| 5 |
|
| #include "sxmuni.h" |
| 6 |
|
| |
| 7 |
|
| #include "fmsj0213.h" |
| 8 |
|
| #include "tosj0213.h" |
| 9 |
|
| |
| 10 |
|
| #define PkgName "ShiftJIS::X0213::MapUTF" |
| 11 |
|
| |
| 12 |
|
| #define Is_SJIS_SNG(i) (0x00<=(i) && (i)<=0x7F || 0xA1<=(i) && (i)<=0xDF) |
| 13 |
|
| #define Is_SJIS_LED(i) (0x81<=(i) && (i)<=0x9F || 0xE0<=(i) && (i)<=0xFC) |
| 14 |
|
| #define Is_SJIS_TRL(i) (0x40<=(i) && (i)<=0x7E || 0x80<=(i) && (i)<=0xFC) |
| 15 |
|
| |
| 16 |
|
| #define STMT_ASSIGN_CVREF_AND_SRC(func_name) \ |
| 17 |
|
| cvref = NULL; \ |
| 18 |
|
| if (SvROK(ST(0))) { \ |
| 19 |
|
| if (SvTYPE(SvRV(ST(0))) == SVt_PVCV) \ |
| 20 |
|
| cvref = SvRV(ST(0)); \ |
| 21 |
|
| else \ |
| 22 |
|
| croak("RV other than CODEREF " \ |
| 23 |
|
| "cannot be used in %s", func_name); \ |
| 24 |
|
| } \ |
| 25 |
|
| src = cvref \ |
| 26 |
|
| ? (1 < items) ? ST(1) : &PL_sv_undef \ |
| 27 |
|
| : ST(0); \ |
| 28 |
|
| |
| 29 |
|
| |
| 30 |
|
| #define STMT_ASSIGN_LENDST(maxlen) \ |
| 31 |
|
| s = (U8*)SvPV(src,srclen); \ |
| 32 |
|
| e = s + srclen; \ |
| 33 |
|
| dstlen = srclen * maxlen + 1; \ |
| 34 |
|
| dst = sv_2mortal(newSV(dstlen)); \ |
| 35 |
|
| (void)SvPOK_only(dst); |
| 36 |
|
| |
| 37 |
|
| |
| 38 |
|
| #define STMT_GET_MBLEN \ |
| 39 |
|
| mblen = Is_SJIS_LED(*(p)) && 2 <= (e - p) \ |
| 40 |
|
| ? (Is_SJIS_TRL((p)[1])) ? 2 : 0 \ |
| 41 |
|
| : Is_SJIS_SNG(*(p)) ? 1 : 0; |
| 42 |
|
| |
| 43 |
|
| |
| 44 |
|
| #define STMT_GET_UV_FROM_MB \ |
| 45 |
|
| lb = fmsjis0213_tbl[*p]; \ |
| 46 |
|
| uv = lb.tbl ? lb.tbl[p[1]] : lb.sbc; \ |
| 47 |
|
| if (!use2004 && isADDED2004(uv)) \ |
| 48 |
|
| uv = 0; |
| 49 |
|
| |
| 50 |
|
| |
| 51 |
|
| #define STMT_FETCH_FROM_UV_AND_UV2 \ |
| 52 |
|
| j = 0; \ |
| 53 |
|
| if (p < e && isbase(uv)) { \ |
| 54 |
|
| uv2 = id_utf \ |
| 55 |
|
| ? ord_uv(p, e - p, &retlen) \ |
| 56 |
|
| : utf8n_to_uvuni(p, (e - p), &retlen, 0); \ |
| 57 |
|
| if (retlen) \ |
| 58 |
|
| j = (U16)getcomposite(uv, uv2); \ |
| 59 |
|
| if (j) \ |
| 60 |
|
| p += retlen; \ |
| 61 |
|
| } \ |
| 62 |
|
| if (!use2004 && isADDED2004(uv)) \ |
| 63 |
|
| j = 0; \ |
| 64 |
|
| else if (!j) { \ |
| 65 |
|
| tbl_plain = Is_VALID_UTF(uv) \ |
| 66 |
|
| ? tosjis0213_tbl[uv >> 16] \ |
| 67 |
|
| : NULL; \ |
| 68 |
|
| tbl_row = tbl_plain \ |
| 69 |
|
| ? tbl_plain[(uv >> 8) & 0xff] \ |
| 70 |
|
| : NULL; \ |
| 71 |
|
| j = tbl_row ? tbl_row[uv & 0xff] : 0; \ |
| 72 |
|
| } |
| 73 |
|
| |
| 74 |
|
| |
| 75 |
|
| /* Perl 5.6.1 ? */ |
| 76 |
|
| #ifndef uvuni_to_utf8 |
| 77 |
|
| #define uvuni_to_utf8 uv_to_utf8 |
| 78 |
|
| #endif /* uvuni_to_utf8 */ |
| 79 |
|
| |
| 80 |
|
| /* Perl 5.6.1 ? */ |
| 81 |
|
| #ifndef utf8n_to_uvuni |
| 82 |
|
| #define utf8n_to_uvuni utf8_to_uv |
| 83 |
|
| #endif /* utf8n_to_uvuni */ |
| 84 |
|
| |
| 85 |
|
| static void |
| 86 |
201606 |
| sv_cat_retcvref (SV *dst, SV *cv, SV *sv, bool isbyte) |
| 87 |
|
| { |
| 88 |
201606 |
| dSP; |
| 89 |
|
| int count; |
| 90 |
201606 |
| ENTER; |
| 91 |
201606 |
| SAVETMPS; |
| 92 |
201606 |
▶ | PUSHMARK(SP); |
Branch: 1 branch
| Branch | True | False | Total |
| PUSHMARK(SP); |
0 |
201606 |
201606 |
|
| 93 |
201606 |
▶ | if (isbyte) |
Branch: 1 branch
| Branch | True | False | Total |
| if (isbyte) |
252 |
201354 |
201606 |
|
| 94 |
252 |
▶ | XPUSHs(&PL_sv_undef); |
Branch: 1 branch
| Branch | True | False | Total |
| XPUSHs(&PL_sv_undef); |
0 |
252 |
252 |
|
| 95 |
201606 |
▶ | XPUSHs(sv_2mortal(sv)); |
Branch: 1 branch
| Branch | True | False | Total |
| XPUSHs(sv_2mortal(sv)); |
0 |
201606 |
201606 |
|
| 96 |
201606 |
| PUTBACK; |
| 97 |
201606 |
| count = call_sv(cv, (G_EVAL|G_SCALAR)); |
| 98 |
201606 |
| SPAGAIN; |
| 99 |
201606 |
▶ | if (SvTRUE(ERRSV) || count != 1) { |
Branch: 3 branches
| Branch | True | False | Total |
| if (SvTRUE(ERRSV) || count != 1) { |
201606 |
0 |
201606 |
| if (SvTRUE(ERRSV) || count != 1) { |
201606 |
0 |
201606 |
| if (SvTRUE(ERRSV) || count != 1) { |
0 |
201606 |
201606 |
|
| 100 |
0 |
| croak("died in XS, " PkgName "\n"); |
| 101 |
|
| } |
| 102 |
201606 |
| sv_catsv(dst,POPs); |
| 103 |
201606 |
| PUTBACK; |
| 104 |
201606 |
▶ | FREETMPS; |
Branch: 1 branch
| Branch | True | False | Total |
| FREETMPS; |
201606 |
0 |
201606 |
|
| 105 |
201606 |
| LEAVE; |
| 106 |
201606 |
| } |
| 107 |
|
| |
| 108 |
|
| #define NUM_toUTF (6) |
| 109 |
|
| #define NUM_fromUTF (8) |
| 110 |
|
| |
| 111 |
|
| static char* funcname_to[2 * NUM_toUTF] = { |
| 112 |
|
| "sjis2004_to_unicode", |
| 113 |
|
| "sjis2004_to_utf8", |
| 114 |
|
| "sjis2004_to_utf16le", |
| 115 |
|
| "sjis2004_to_utf16be", |
| 116 |
|
| "sjis2004_to_utf32le", |
| 117 |
|
| "sjis2004_to_utf32be", |
| 118 |
|
| "sjis0213_to_unicode", |
| 119 |
|
| "sjis0213_to_utf8", |
| 120 |
|
| "sjis0213_to_utf16le", |
| 121 |
|
| "sjis0213_to_utf16be", |
| 122 |
|
| "sjis0213_to_utf32le", |
| 123 |
|
| "sjis0213_to_utf32be", |
| 124 |
|
| }; |
| 125 |
|
| |
| 126 |
|
| static char* funcname_fm[2 * NUM_fromUTF] = { |
| 127 |
|
| "unicode_to_sjis2004", |
| 128 |
|
| "utf8_to_sjis2004", |
| 129 |
|
| "utf16le_to_sjis2004", |
| 130 |
|
| "utf16be_to_sjis2004", |
| 131 |
|
| "utf32le_to_sjis2004", |
| 132 |
|
| "utf32be_to_sjis2004", |
| 133 |
|
| "utf16_to_sjis2004", |
| 134 |
|
| "utf32_to_sjis2004", |
| 135 |
|
| "unicode_to_sjis0213", |
| 136 |
|
| "utf8_to_sjis0213", |
| 137 |
|
| "utf16le_to_sjis0213", |
| 138 |
|
| "utf16be_to_sjis0213", |
| 139 |
|
| "utf32le_to_sjis0213", |
| 140 |
|
| "utf32be_to_sjis0213", |
| 141 |
|
| "utf16_to_sjis0213", |
| 142 |
|
| "utf32_to_sjis0213", |
| 143 |
|
| }; |
| 144 |
|
| |
| 145 |
|
| static STRLEN maxlen_to[NUM_toUTF] = { |
| 146 |
|
| MaxLenToUni, |
| 147 |
|
| MaxLenToU8, |
| 148 |
|
| MaxLenToU16, |
| 149 |
|
| MaxLenToU16, |
| 150 |
|
| MaxLenToU32, |
| 151 |
|
| MaxLenToU32, |
| 152 |
|
| }; |
| 153 |
|
| |
| 154 |
|
| static STRLEN maxlen_fm[NUM_fromUTF] = { |
| 155 |
|
| MaxLenFmUni, |
| 156 |
|
| MaxLenFmU8, |
| 157 |
|
| MaxLenFmU16, |
| 158 |
|
| MaxLenFmU16, |
| 159 |
|
| MaxLenFmU32, |
| 160 |
|
| MaxLenFmU32, |
| 161 |
|
| MaxLenFmU16, |
| 162 |
|
| MaxLenFmU32, |
| 163 |
|
| }; |
| 164 |
|
| |
| 165 |
|
| static U8* (*app_uv_in[NUM_toUTF])(U8*, UV) = { |
| 166 |
|
| NULL, |
| 167 |
|
| app_in_utf8, |
| 168 |
|
| app_in_utf16le, |
| 169 |
|
| app_in_utf16be, |
| 170 |
|
| app_in_utf32le, |
| 171 |
|
| app_in_utf32be, |
| 172 |
|
| }; |
| 173 |
|
| |
| 174 |
|
| static UV (*ord_uv_in[NUM_fromUTF])(U8 *, STRLEN, STRLEN *) = { |
| 175 |
|
| NULL, |
| 176 |
|
| ord_in_utf8, |
| 177 |
|
| ord_in_utf16le, |
| 178 |
|
| ord_in_utf16be, |
| 179 |
|
| ord_in_utf32le, |
| 180 |
|
| ord_in_utf32be, |
| 181 |
|
| ord_in_utf16be, /* w/o BOM*/ |
| 182 |
|
| ord_in_utf32be, /* w/o BOM*/ |
| 183 |
|
| }; |
| 184 |
|
| |
| 185 |
|
| MODULE = ShiftJIS::X0213::MapUTF PACKAGE = ShiftJIS::X0213::MapUTF |
| 186 |
|
| |
| 187 |
|
| PROTOTYPES: DISABLE |
| 188 |
|
| |
| 189 |
|
| void |
| 190 |
|
| sjis2004_to_unicode (...) |
| 191 |
|
| ALIAS: |
| 192 |
|
| sjis2004_to_utf8 = 1 |
| 193 |
|
| sjis2004_to_utf16le = 2 |
| 194 |
|
| sjis2004_to_utf16be = 3 |
| 195 |
|
| sjis2004_to_utf32le = 4 |
| 196 |
|
| sjis2004_to_utf32be = 5 |
| 197 |
|
| sjis0213_to_unicode = 6 |
| 198 |
|
| sjis0213_to_utf8 = 7 |
| 199 |
|
| sjis0213_to_utf16le = 8 |
| 200 |
|
| sjis0213_to_utf16be = 9 |
| 201 |
|
| sjis0213_to_utf32le = 10 |
| 202 |
|
| sjis0213_to_utf32be = 11 |
| 203 |
|
| PREINIT: |
| 204 |
|
| SV *src, *dst, *cvref; |
| 205 |
|
| STRLEN srclen, dstlen, mblen, ulen; |
| 206 |
|
| U8 *s, *e, *p, *d, uni[UTF8_MAXLEN + 1]; |
| 207 |
|
| UV uv, u_temp; |
| 208 |
|
| struct leading lb; |
| 209 |
|
| U8* (*app_uv)(U8*, UV); |
| 210 |
|
| int id_utf, use2004; |
| 211 |
|
| PPCODE: |
| 212 |
774 |
| use2004 = ix < NUM_toUTF; |
| 213 |
774 |
| id_utf = ix % NUM_toUTF; |
| 214 |
|
| |
| 215 |
774 |
▶ | STMT_ASSIGN_CVREF_AND_SRC(funcname_to[ix]) |
Branch: 4 branches
| Branch | True | False | Total |
| STMT_ASSIGN_CVREF_AND_SRC(funcname_to[ix]) |
390 |
384 |
774 |
| STMT_ASSIGN_CVREF_AND_SRC(funcname_to[ix]) |
390 |
0 |
390 |
| STMT_ASSIGN_CVREF_AND_SRC(funcname_to[ix]) |
390 |
384 |
774 |
| STMT_ASSIGN_CVREF_AND_SRC(funcname_to[ix]) |
390 |
0 |
390 |
|
| 216 |
774 |
▶ | if (SvUTF8(src)) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (SvUTF8(src)) { |
12 |
762 |
774 |
|
| 217 |
12 |
| src = sv_mortalcopy(src); |
| 218 |
12 |
| sv_utf8_downgrade(src, 0); |
| 219 |
|
| } |
| 220 |
774 |
| STMT_ASSIGN_LENDST(maxlen_to[id_utf]) |
| 221 |
774 |
▶ | if (id_utf == 0) |
Branch: 1 branch
| Branch | True | False | Total |
| if (id_utf == 0) |
129 |
645 |
774 |
|
| 222 |
129 |
| SvUTF8_on(dst); |
| 223 |
|
| |
| 224 |
774 |
| app_uv = app_uv_in[id_utf]; |
| 225 |
|
| |
| 226 |
774 |
▶ | if (cvref) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (cvref) { |
390 |
384 |
774 |
|
| 227 |
1320 |
▶ | for (p = s; p < e; p += mblen) { |
Branch: 1 branch
| Branch | True | False | Total |
| for (p = s; p < e; p += mblen) { |
930 |
390 |
1320 |
|
| 228 |
930 |
▶ | STMT_GET_MBLEN |
Branch: 12 branches
| Branch | True | False | Total |
| STMT_GET_MBLEN |
522 |
408 |
930 |
| STMT_GET_MBLEN |
174 |
348 |
522 |
| STMT_GET_MBLEN |
150 |
432 |
582 |
| STMT_GET_MBLEN |
120 |
30 |
150 |
| STMT_GET_MBLEN |
408 |
60 |
468 |
| STMT_GET_MBLEN |
384 |
24 |
408 |
| STMT_GET_MBLEN |
318 |
66 |
384 |
| STMT_GET_MBLEN |
306 |
36 |
342 |
| STMT_GET_MBLEN |
294 |
12 |
306 |
| STMT_GET_MBLEN |
126 |
396 |
522 |
| STMT_GET_MBLEN |
66 |
60 |
126 |
| STMT_GET_MBLEN |
12 |
54 |
66 |
|
| 229 |
930 |
▶ | if (!mblen) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (!mblen) { |
162 |
768 |
930 |
|
| 230 |
162 |
| sv_cat_retcvref(dst, cvref, newSVuv((UV)*p), TRUE); |
| 231 |
162 |
| p++; |
| 232 |
162 |
| continue; |
| 233 |
|
| } |
| 234 |
768 |
▶ | STMT_GET_UV_FROM_MB |
Branch: 3 branches
| Branch | True | False | Total |
| STMT_GET_UV_FROM_MB |
360 |
408 |
768 |
| STMT_GET_UV_FROM_MB |
408 |
360 |
768 |
| STMT_GET_UV_FROM_MB |
60 |
348 |
408 |
|
| 235 |
|
| |
| 236 |
768 |
▶ | if (uv || !*p) { |
Branch: 2 branches
| Branch | True | False | Total |
| if (uv || !*p) { |
192 |
576 |
768 |
| if (uv || !*p) { |
72 |
120 |
192 |
|
| 237 |
648 |
▶ | if (Is_VALID_UTF(uv)) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (Is_VALID_UTF(uv)) { |
612 |
36 |
648 |
|
| 238 |
510 |
| ulen = id_utf ? app_uv(uni, uv) - uni |
| 239 |
1122 |
▶ | : uvuni_to_utf8(uni, uv) - uni; |
Branch: 1 branch
| Branch | True | False | Total |
| : uvuni_to_utf8(uni, uv) - uni; |
510 |
102 |
612 |
|
| 240 |
612 |
| sv_catpvn(dst, (char*)uni, ulen); |
| 241 |
|
| } |
| 242 |
|
| else { |
| 243 |
36 |
| u_temp = (uv >> 16); |
| 244 |
30 |
| ulen = id_utf ? app_uv(uni, u_temp) - uni |
| 245 |
66 |
▶ | : uvuni_to_utf8(uni, u_temp) - uni; |
Branch: 1 branch
| Branch | True | False | Total |
| : uvuni_to_utf8(uni, u_temp) - uni; |
30 |
6 |
36 |
|
| 246 |
36 |
| sv_catpvn(dst, (char*)uni, ulen); |
| 247 |
|
| |
| 248 |
36 |
| u_temp = (uv & 0xFFFF); |
| 249 |
30 |
| ulen = id_utf ? app_uv(uni, u_temp) - uni |
| 250 |
66 |
▶ | : uvuni_to_utf8(uni, u_temp) - uni; |
Branch: 1 branch
| Branch | True | False | Total |
| : uvuni_to_utf8(uni, u_temp) - uni; |
30 |
6 |
36 |
|
| 251 |
36 |
| sv_catpvn(dst, (char*)uni, ulen); |
| 252 |
|
| } |
| 253 |
|
| } |
| 254 |
|
| else |
| 255 |
120 |
| sv_cat_retcvref(dst, cvref, newSVpvn((char*)p, mblen), FALSE); |
| 256 |
|
| } |
| 257 |
|
| } |
| 258 |
|
| else { |
| 259 |
384 |
| d = (U8*)SvPVX(dst); |
| 260 |
97284 |
▶ | for (p = s; p < e; p += mblen) { |
Branch: 1 branch
| Branch | True | False | Total |
| for (p = s; p < e; p += mblen) { |
96900 |
384 |
97284 |
|
| 261 |
96900 |
▶ | STMT_GET_MBLEN |
Branch: 12 branches
| Branch | True | False | Total |
| STMT_GET_MBLEN |
96504 |
396 |
96900 |
| STMT_GET_MBLEN |
60144 |
36360 |
96504 |
| STMT_GET_MBLEN |
120 |
60420 |
60540 |
| STMT_GET_MBLEN |
102 |
18 |
120 |
| STMT_GET_MBLEN |
36402 |
60 |
36462 |
| STMT_GET_MBLEN |
36402 |
0 |
36402 |
| STMT_GET_MBLEN |
324 |
36078 |
36402 |
| STMT_GET_MBLEN |
324 |
0 |
324 |
| STMT_GET_MBLEN |
324 |
0 |
324 |
| STMT_GET_MBLEN |
60114 |
384 |
60498 |
| STMT_GET_MBLEN |
60054 |
60 |
60114 |
| STMT_GET_MBLEN |
60012 |
42 |
60054 |
|
| 262 |
96900 |
▶ | if (!mblen) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (!mblen) { |
102 |
96798 |
96900 |
|
| 263 |
102 |
| p++; |
| 264 |
102 |
| continue; |
| 265 |
|
| } |
| 266 |
96798 |
▶ | STMT_GET_UV_FROM_MB |
Branch: 3 branches
| Branch | True | False | Total |
| STMT_GET_UV_FROM_MB |
36402 |
60396 |
96798 |
| STMT_GET_UV_FROM_MB |
48408 |
48390 |
96798 |
| STMT_GET_UV_FROM_MB |
60 |
48348 |
48408 |
|
| 267 |
|
| |
| 268 |
96798 |
▶ | if (uv || !*p) { |
Branch: 2 branches
| Branch | True | False | Total |
| if (uv || !*p) { |
180 |
96618 |
96798 |
| if (uv || !*p) { |
60 |
120 |
180 |
|
| 269 |
96678 |
▶ | if (Is_VALID_UTF(uv)) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (Is_VALID_UTF(uv)) { |
84642 |
12036 |
96678 |
|
| 270 |
84642 |
▶ | d = id_utf ? app_uv(d, uv) : uvuni_to_utf8(d, uv); |
Branch: 1 branch
| Branch | True | False | Total |
| d = id_utf ? app_uv(d, uv) : uvuni_to_utf8(d, uv); |
70535 |
14107 |
84642 |
|
| 271 |
|
| } |
| 272 |
|
| else { |
| 273 |
12036 |
| u_temp = (uv >> 16); |
| 274 |
12036 |
▶ | d = id_utf ? app_uv(d, u_temp) : uvuni_to_utf8(d, u_temp); |
Branch: 1 branch
| Branch | True | False | Total |
| d = id_utf ? app_uv(d, u_temp) : uvuni_to_utf8(d, u_temp); |
10030 |
2006 |
12036 |
|
| 275 |
|
| |
| 276 |
12036 |
| u_temp = (uv & 0xFFFF); |
| 277 |
12036 |
▶ | d = id_utf ? app_uv(d, u_temp) : uvuni_to_utf8(d, u_temp); |
Branch: 1 branch
| Branch | True | False | Total |
| d = id_utf ? app_uv(d, u_temp) : uvuni_to_utf8(d, u_temp); |
10030 |
2006 |
12036 |
|
| 278 |
|
| } |
| 279 |
|
| } |
| 280 |
|
| } |
| 281 |
384 |
| *d = '\0'; |
| 282 |
384 |
| SvCUR_set(dst, d - (U8*)SvPVX(dst)); |
| 283 |
|
| } |
| 284 |
774 |
▶ | XPUSHs(dst); |
Branch: 1 branch
| Branch | True | False | Total |
| XPUSHs(dst); |
0 |
774 |
774 |
|
| 285 |
|
| |
| 286 |
|
| |
| 287 |
|
| void |
| 288 |
|
| unicode_to_sjis2004 (...) |
| 289 |
|
| ALIAS: |
| 290 |
|
| utf8_to_sjis2004 = 1 |
| 291 |
|
| utf16le_to_sjis2004 = 2 |
| 292 |
|
| utf16be_to_sjis2004 = 3 |
| 293 |
|
| utf32le_to_sjis2004 = 4 |
| 294 |
|
| utf32be_to_sjis2004 = 5 |
| 295 |
|
| utf16_to_sjis2004 = 6 |
| 296 |
|
| utf32_to_sjis2004 = 7 |
| 297 |
|
| unicode_to_sjis0213 = 8 |
| 298 |
|
| utf8_to_sjis0213 = 9 |
| 299 |
|
| utf16le_to_sjis0213 = 10 |
| 300 |
|
| utf16be_to_sjis0213 = 11 |
| 301 |
|
| utf32le_to_sjis0213 = 12 |
| 302 |
|
| utf32be_to_sjis0213 = 13 |
| 303 |
|
| utf16_to_sjis0213 = 14 |
| 304 |
|
| utf32_to_sjis0213 = 15 |
| 305 |
|
| PREINIT: |
| 306 |
|
| SV *src, *dst, *cvref; |
| 307 |
|
| STRLEN srclen, dstlen, retlen; |
| 308 |
|
| U8 *s, *e, *p, *d, mbc[3]; |
| 309 |
|
| U16 j, *tbl_row, **tbl_plain; |
| 310 |
|
| UV uv, uv2; |
| 311 |
|
| UV (*ord_uv)(U8 *, STRLEN, STRLEN *); |
| 312 |
|
| int id_utf, use2004; |
| 313 |
|
| PPCODE: |
| 314 |
886 |
| use2004 = ix < NUM_fromUTF; |
| 315 |
886 |
| id_utf = ix % NUM_fromUTF; |
| 316 |
|
| |
| 317 |
886 |
▶ | STMT_ASSIGN_CVREF_AND_SRC(funcname_fm[ix]) |
Branch: 4 branches
| Branch | True | False | Total |
| STMT_ASSIGN_CVREF_AND_SRC(funcname_fm[ix]) |
462 |
424 |
886 |
| STMT_ASSIGN_CVREF_AND_SRC(funcname_fm[ix]) |
462 |
0 |
462 |
| STMT_ASSIGN_CVREF_AND_SRC(funcname_fm[ix]) |
462 |
424 |
886 |
| STMT_ASSIGN_CVREF_AND_SRC(funcname_fm[ix]) |
462 |
0 |
462 |
|
| 318 |
886 |
▶ | if (id_utf == 0 && !SvUTF8(src)) { |
Branch: 2 branches
| Branch | True | False | Total |
| if (id_utf == 0 && !SvUTF8(src)) { |
81 |
805 |
886 |
| if (id_utf == 0 && !SvUTF8(src)) { |
14 |
67 |
81 |
|
| 319 |
14 |
| src = sv_mortalcopy(src); |
| 320 |
14 |
| sv_utf8_upgrade(src); |
| 321 |
|
| } |
| 322 |
872 |
▶ | else if (id_utf && SvUTF8(src)) { |
Branch: 2 branches
| Branch | True | False | Total |
| else if (id_utf && SvUTF8(src)) { |
805 |
67 |
872 |
| else if (id_utf && SvUTF8(src)) { |
22 |
783 |
805 |
|
| 323 |
22 |
| src = sv_mortalcopy(src); |
| 324 |
22 |
| sv_utf8_downgrade(src, FALSE); |
| 325 |
|
| } |
| 326 |
886 |
| STMT_ASSIGN_LENDST(maxlen_fm[id_utf]) |
| 327 |
|
| |
| 328 |
886 |
| ord_uv = ord_uv_in[id_utf]; |
| 329 |
|
| |
| 330 |
886 |
▶ | if (id_utf == 6 && 2 <= e - s) { /* UTF-16 */ |
Branch: 2 branches
| Branch | True | False | Total |
| if (id_utf == 6 && 2 <= e - s) { /* UTF-16 */ |
151 |
735 |
886 |
| if (id_utf == 6 && 2 <= e - s) { /* UTF-16 */ |
147 |
4 |
151 |
|
| 331 |
294 |
▶ | if (memEQ("\xFF\xFE",s,2)) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (memEQ("\xFF\xFE",s,2)) { |
51 |
96 |
147 |
|
| 332 |
51 |
| s += 2; |
| 333 |
51 |
| ord_uv = ord_in_utf16le; |
| 334 |
|
| } |
| 335 |
96 |
▶ | else if (memEQ("\xFE\xFF",s,2)) { |
Branch: 1 branch
| Branch | True | False | Total |
| else if (memEQ("\xFE\xFF",s,2)) { |
51 |
45 |
96 |
|
| 336 |
51 |
| s += 2; |
| 337 |
|
| } |
| 338 |
|
| } |
| 339 |
739 |
▶ | else if (id_utf == 7 && 4 <= e - s) { /* UTF-32 */ |
Branch: 2 branches
| Branch | True | False | Total |
| else if (id_utf == 7 && 4 <= e - s) { /* UTF-32 */ |
155 |
584 |
739 |
| else if (id_utf == 7 && 4 <= e - s) { /* UTF-32 */ |
151 |
4 |
155 |
|
| 340 |
151 |
▶ | if (memEQ("\xFF\xFE\x00\x00",s,4)) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (memEQ("\xFF\xFE\x00\x00",s,4)) { |
51 |
100 |
151 |
|
| 341 |
51 |
| s += 4; |
| 342 |
51 |
| ord_uv = ord_in_utf32le; |
| 343 |
|
| } |
| 344 |
100 |
▶ | else if (memEQ("\x00\x00\xFE\xFF",s,4)) { |
Branch: 1 branch
| Branch | True | False | Total |
| else if (memEQ("\x00\x00\xFE\xFF",s,4)) { |
51 |
49 |
100 |
|
| 345 |
51 |
| s += 4; |
| 346 |
|
| } |
| 347 |
|
| } |
| 348 |
|
| |
| 349 |
886 |
▶ | if (cvref) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (cvref) { |
462 |
424 |
886 |
|
| 350 |
239448 |
▶ | for (p = s; p < e;) { |
Branch: 1 branch
| Branch | True | False | Total |
| for (p = s; p < e;) { |
238986 |
462 |
239448 |
|
| 351 |
238986 |
| uv = id_utf |
| 352 |
196772 |
| ? ord_uv(p, e - p, &retlen) |
| 353 |
238986 |
▶ | : utf8n_to_uvuni(p, (e - p), &retlen, 0); |
Branch: 1 branch
| Branch | True | False | Total |
| : utf8n_to_uvuni(p, (e - p), &retlen, 0); |
196772 |
42214 |
238986 |
|
| 354 |
|
| |
| 355 |
238986 |
▶ | if (retlen) |
Branch: 1 branch
| Branch | True | False | Total |
| if (retlen) |
238896 |
90 |
238986 |
|
| 356 |
238896 |
| p += retlen; |
| 357 |
|
| else { |
| 358 |
90 |
| sv_cat_retcvref(dst, cvref, newSVuv((UV)*p), TRUE); |
| 359 |
90 |
| p++; |
| 360 |
90 |
| continue; |
| 361 |
|
| } |
| 362 |
|
| |
| 363 |
238896 |
▶ | STMT_FETCH_FROM_UV_AND_UV2 |
Branch: 11 branches
| Branch | True | False | Total |
| STMT_FETCH_FROM_UV_AND_UV2 |
238516 |
380 |
238896 |
| STMT_FETCH_FROM_UV_AND_UV2 |
120 |
238396 |
238516 |
| STMT_FETCH_FROM_UV_AND_UV2 |
110 |
10 |
120 |
| STMT_FETCH_FROM_UV_AND_UV2 |
108 |
12 |
120 |
| STMT_FETCH_FROM_UV_AND_UV2 |
84 |
36 |
120 |
| STMT_FETCH_FROM_UV_AND_UV2 |
119448 |
119448 |
238896 |
| STMT_FETCH_FROM_UV_AND_UV2 |
0 |
119448 |
119448 |
| STMT_FETCH_FROM_UV_AND_UV2 |
238812 |
84 |
238896 |
| STMT_FETCH_FROM_UV_AND_UV2 |
238810 |
2 |
238812 |
| STMT_FETCH_FROM_UV_AND_UV2 |
208018 |
30794 |
238812 |
| STMT_FETCH_FROM_UV_AND_UV2 |
49782 |
189030 |
238812 |
|
| 364 |
|
| |
| 365 |
238896 |
▶ | if (j || !uv) { |
Branch: 2 branches
| Branch | True | False | Total |
| if (j || !uv) { |
201408 |
37488 |
238896 |
| if (j || !uv) { |
174 |
201234 |
201408 |
|
| 366 |
37662 |
▶ | if (j >= 256) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (j >= 256) { |
36590 |
1072 |
37662 |
|
| 367 |
36590 |
| mbc[0] = (U8)(j >> 8); |
| 368 |
36590 |
| mbc[1] = (U8)(j & 0xff); |
| 369 |
36590 |
| sv_catpvn(dst, (char*)mbc, 2); |
| 370 |
|
| } |
| 371 |
|
| else { |
| 372 |
1072 |
| mbc[0] = (U8)(j & 0xff); |
| 373 |
1072 |
| sv_catpvn(dst, (char*)mbc, 1); |
| 374 |
|
| } |
| 375 |
|
| } |
| 376 |
|
| else |
| 377 |
201234 |
| sv_cat_retcvref(dst, cvref, newSVuv(uv), FALSE); |
| 378 |
|
| } |
| 379 |
|
| } |
| 380 |
|
| else { |
| 381 |
424 |
| d = (U8*)SvPVX(dst); |
| 382 |
|
| |
| 383 |
46282 |
▶ | for (p = s; p < e;) { |
Branch: 1 branch
| Branch | True | False | Total |
| for (p = s; p < e;) { |
45858 |
424 |
46282 |
|
| 384 |
45858 |
| uv = id_utf |
| 385 |
21679 |
| ? ord_uv(p, e - p, &retlen) |
| 386 |
45858 |
▶ | : utf8n_to_uvuni(p, (e - p), &retlen, 0); |
Branch: 1 branch
| Branch | True | False | Total |
| : utf8n_to_uvuni(p, (e - p), &retlen, 0); |
21679 |
24179 |
45858 |
|
| 387 |
|
| |
| 388 |
45858 |
▶ | if (retlen) |
Branch: 1 branch
| Branch | True | False | Total |
| if (retlen) |
45784 |
74 |
45858 |
|
| 389 |
45784 |
| p += retlen; |
| 390 |
|
| else { |
| 391 |
74 |
| p++; |
| 392 |
74 |
| continue; |
| 393 |
|
| } |
| 394 |
|
| |
| 395 |
45784 |
▶ | STMT_FETCH_FROM_UV_AND_UV2 |
Branch: 11 branches
| Branch | True | False | Total |
| STMT_FETCH_FROM_UV_AND_UV2 |
45434 |
350 |
45784 |
| STMT_FETCH_FROM_UV_AND_UV2 |
24120 |
21314 |
45434 |
| STMT_FETCH_FROM_UV_AND_UV2 |
20110 |
4010 |
24120 |
| STMT_FETCH_FROM_UV_AND_UV2 |
24108 |
12 |
24120 |
| STMT_FETCH_FROM_UV_AND_UV2 |
24084 |
36 |
24120 |
| STMT_FETCH_FROM_UV_AND_UV2 |
22862 |
22922 |
45784 |
| STMT_FETCH_FROM_UV_AND_UV2 |
0 |
22862 |
22862 |
| STMT_FETCH_FROM_UV_AND_UV2 |
21700 |
24084 |
45784 |
| STMT_FETCH_FROM_UV_AND_UV2 |
21698 |
2 |
21700 |
| STMT_FETCH_FROM_UV_AND_UV2 |
21662 |
38 |
21700 |
| STMT_FETCH_FROM_UV_AND_UV2 |
21644 |
56 |
21700 |
|
| 396 |
|
| |
| 397 |
45784 |
▶ | if (j || !uv) { |
Branch: 2 branches
| Branch | True | False | Total |
| if (j || !uv) { |
316 |
45468 |
45784 |
| if (j || !uv) { |
168 |
148 |
316 |
|
| 398 |
45636 |
▶ | if (j >= 256) |
Branch: 1 branch
| Branch | True | False | Total |
| if (j >= 256) |
44624 |
1012 |
45636 |
|
| 399 |
44624 |
| *d++ = (U8)(j >> 8); |
| 400 |
45636 |
| *d++ = (U8)(j & 0xff); |
| 401 |
|
| } |
| 402 |
|
| } |
| 403 |
424 |
| *d = '\0'; |
| 404 |
424 |
| SvCUR_set(dst, d - (U8*)SvPVX(dst)); |
| 405 |
|
| } |
| 406 |
886 |
▶ | XPUSHs(dst); |
Branch: 1 branch
| Branch | True | False | Total |
| XPUSHs(dst); |
0 |
886 |
886 |
|
| 407 |
|
| |