3 * Copyright (C) 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999,
4 * 2000, 2001, 2002, 2004, by Larry Wall and others
6 * You may distribute under the terms of either the GNU General Public
7 * License or the Artistic License, as specified in the README file.
12 * "'So that was the job I felt I had to do when I started,' thought Sam."
16 #define PERL_IN_DOOP_C
24 S_do_trans_simple(pTHX_ SV *sv)
31 I32 grows = PL_op->op_private & OPpTRANS_GROWS;
36 tbl = (short*)cPVOP->op_pv;
38 Perl_croak(aTHX_ "panic: do_trans_simple line %d",__LINE__);
40 s = (U8*)SvPV(sv, len);
43 /* First, take care of non-UTF-8 input strings, because they're easy */
46 if ((ch = tbl[*s]) >= 0) {
57 /* Allow for expansion: $_="a".chr(400); tr/a/\xFE/, FE needs encoding */
59 New(0, d, len*2+1, U8);
67 /* Need to check this, otherwise 128..255 won't match */
68 c = utf8n_to_uvchr(s, send - s, &ulen, 0);
69 if (c < 0x100 && (ch = tbl[c]) >= 0) {
71 d = uvchr_to_utf8(d, ch);
74 else { /* No match -> copy */
81 sv_setpvn(sv, (char*)dstart, d - dstart);
86 SvCUR_set(sv, d - dstart);
94 S_do_trans_count(pTHX_ SV *sv)
101 I32 complement = PL_op->op_private & OPpTRANS_COMPLEMENT;
103 tbl = (short*)cPVOP->op_pv;
105 Perl_croak(aTHX_ "panic: do_trans_count line %d",__LINE__);
107 s = (U8*)SvPV(sv, len);
119 c = utf8n_to_uvchr(s, send - s, &ulen, 0);
123 } else if (complement)
132 S_do_trans_complex(pTHX_ SV *sv)
140 I32 grows = PL_op->op_private & OPpTRANS_GROWS;
141 I32 complement = PL_op->op_private & OPpTRANS_COMPLEMENT;
142 I32 del = PL_op->op_private & OPpTRANS_DELETE;
143 STRLEN len, rlen = 0;
147 tbl = (short*)cPVOP->op_pv;
149 Perl_croak(aTHX_ "panic: do_trans_complex line %d",__LINE__);
151 s = (U8*)SvPV(sv, len);
157 if (PL_op->op_private & OPpTRANS_SQUASH) {
160 if ((ch = tbl[*s]) >= 0) {
163 if (p != d - 1 || *p != *d)
166 else if (ch == -1) /* -1 is unmapped character */
168 else if (ch == -2) /* -2 is delete character */
175 if ((ch = tbl[*s]) >= 0) {
179 else if (ch == -1) /* -1 is unmapped character */
181 else if (ch == -2) /* -2 is delete character */
187 SvCUR_set(sv, d - dstart);
191 New(0, d, len*2+1, U8);
195 if (complement && !del)
198 #ifdef MACOS_TRADITIONAL
199 #define comp CoMP /* "comp" is a keyword in some compilers ... */
202 if (PL_op->op_private & OPpTRANS_SQUASH) {
206 UV comp = utf8_to_uvchr(s, &len);
216 ch = (rlen == 0) ? comp :
217 (comp - 0x100 < rlen) ?
218 tbl[comp+1] : tbl[0x100+rlen];
220 d = uvchr_to_utf8(d, ch);
228 else if ((ch = tbl[comp]) >= 0) {
231 d = uvchr_to_utf8(d, ch);
237 else if (ch == -1) { /* -1 is unmapped character */
241 else if (ch == -2) /* -2 is delete character */
250 UV comp = utf8_to_uvchr(s, &len);
259 if (comp - 0x100 < rlen)
260 d = uvchr_to_utf8(d, tbl[comp+1]);
262 d = uvchr_to_utf8(d, tbl[0x100+rlen]);
266 else if ((ch = tbl[comp]) >= 0) {
267 d = uvchr_to_utf8(d, ch);
270 else if (ch == -1) { /* -1 is unmapped character */
274 else if (ch == -2) /* -2 is delete character */
280 sv_setpvn(sv, (char*)dstart, d - dstart);
285 SvCUR_set(sv, d - dstart);
294 S_do_trans_simple_utf8(pTHX_ SV *sv)
302 I32 grows = PL_op->op_private & OPpTRANS_GROWS;
305 SV* rv = (SV*)cSVOP->op_sv;
306 HV* hv = (HV*)SvRV(rv);
307 SV** svp = hv_fetch(hv, "NONE", 4, FALSE);
308 UV none = svp ? SvUV(*svp) : 0x7fffffff;
315 s = (U8*)SvPV(sv, len);
318 U8 *t = s, *e = s + len;
321 if ((hibit = !NATIVE_IS_INVARIANT(ch)))
325 s = bytes_to_utf8(s, &len);
330 svp = hv_fetch(hv, "FINAL", 5, FALSE);
335 /* d needs to be bigger than s, in case e.g. upgrading is required */
336 New(0, d, len*3+UTF8_MAXLEN, U8);
346 if ((uv = swash_fetch(rv, s, TRUE)) < none) {
349 d = uvuni_to_utf8(d, uv);
351 else if (uv == none) {
357 else if (uv == extra) {
361 d = uvuni_to_utf8(d, final);
367 STRLEN clen = d - dstart;
368 STRLEN nlen = dend - dstart + len + UTF8_MAXLEN;
370 Perl_croak(aTHX_ "panic: do_trans_simple_utf8 line %d",__LINE__);
371 Renew(dstart, nlen+UTF8_MAXLEN, U8);
373 dend = dstart + nlen;
376 if (grows || hibit) {
377 sv_setpvn(sv, (char*)dstart, d - dstart);
384 SvCUR_set(sv, d - dstart);
393 S_do_trans_count_utf8(pTHX_ SV *sv)
396 U8 *start = 0, *send;
400 SV* rv = (SV*)cSVOP->op_sv;
401 HV* hv = (HV*)SvRV(rv);
402 SV** svp = hv_fetch(hv, "NONE", 4, FALSE);
403 UV none = svp ? SvUV(*svp) : 0x7fffffff;
408 s = (U8*)SvPV(sv, len);
410 U8 *t = s, *e = s + len;
413 if ((hibit = !NATIVE_IS_INVARIANT(ch)))
417 start = s = bytes_to_utf8(s, &len);
422 if ((uv = swash_fetch(rv, s, TRUE)) < none || uv == extra)
433 S_do_trans_complex_utf8(pTHX_ SV *sv)
439 I32 squash = PL_op->op_private & OPpTRANS_SQUASH;
440 I32 del = PL_op->op_private & OPpTRANS_DELETE;
441 I32 grows = PL_op->op_private & OPpTRANS_GROWS;
442 SV* rv = (SV*)cSVOP->op_sv;
443 HV* hv = (HV*)SvRV(rv);
444 SV** svp = hv_fetch(hv, "NONE", 4, FALSE);
445 UV none = svp ? SvUV(*svp) : 0x7fffffff;
448 bool havefinal = FALSE;
455 s = (U8*)SvPV(sv, len);
458 U8 *t = s, *e = s + len;
461 if ((hibit = !NATIVE_IS_INVARIANT(ch)))
465 s = bytes_to_utf8(s, &len);
470 svp = hv_fetch(hv, "FINAL", 5, FALSE);
477 /* d needs to be bigger than s, in case e.g. upgrading is required */
478 New(0, d, len*3+UTF8_MAXLEN, U8);
490 uv = swash_fetch(rv, s, TRUE);
493 STRLEN clen = d - dstart;
494 STRLEN nlen = dend - dstart + len + UTF8_MAXLEN;
496 Perl_croak(aTHX_ "panic: do_trans_complex_utf8 line %d",__LINE__);
497 Renew(dstart, nlen+UTF8_MAXLEN, U8);
499 dend = dstart + nlen;
505 d = uvuni_to_utf8(d, uv);
510 else if (uv == none) { /* "none" is unmapped character */
518 else if (uv == extra && !del) {
523 d = uvuni_to_utf8(d, final);
529 uv = utf8_to_uvuni(s, &len);
539 matches++; /* "none+1" is delete character */
545 uv = swash_fetch(rv, s, TRUE);
547 STRLEN clen = d - dstart;
548 STRLEN nlen = dend - dstart + len + UTF8_MAXLEN;
550 Perl_croak(aTHX_ "panic: do_trans_complex_utf8 line %d",__LINE__);
551 Renew(dstart, nlen+UTF8_MAXLEN, U8);
553 dend = dstart + nlen;
558 d = uvuni_to_utf8(d, uv);
561 else if (uv == none) { /* "none" is unmapped character */
568 else if (uv == extra && !del) {
571 d = uvuni_to_utf8(d, final);
574 matches++; /* "none+1" is delete character */
578 if (grows || hibit) {
579 sv_setpvn(sv, (char*)dstart, d - dstart);
586 SvCUR_set(sv, d - dstart);
595 Perl_do_trans(pTHX_ SV *sv)
598 I32 hasutf = (PL_op->op_private &
599 (OPpTRANS_FROM_UTF|OPpTRANS_TO_UTF));
601 if (SvREADONLY(sv)) {
603 sv_force_normal_flags(sv, 0);
604 if (SvREADONLY(sv) && !(PL_op->op_private & OPpTRANS_IDENTICAL))
605 Perl_croak(aTHX_ PL_no_modify);
610 if (!(PL_op->op_private & OPpTRANS_IDENTICAL)) {
612 (void)SvPV_force(sv, len);
613 (void)SvPOK_only_UTF8(sv);
616 DEBUG_t( Perl_deb(aTHX_ "2.TBL\n"));
618 switch (PL_op->op_private & ~hasutf & (
619 OPpTRANS_FROM_UTF|OPpTRANS_TO_UTF|OPpTRANS_IDENTICAL|
620 OPpTRANS_SQUASH|OPpTRANS_DELETE|OPpTRANS_COMPLEMENT)) {
623 return do_trans_simple_utf8(sv);
625 return do_trans_simple(sv);
627 case OPpTRANS_IDENTICAL:
628 case OPpTRANS_IDENTICAL|OPpTRANS_COMPLEMENT:
630 return do_trans_count_utf8(sv);
632 return do_trans_count(sv);
636 return do_trans_complex_utf8(sv);
638 return do_trans_complex(sv);
643 Perl_do_join(pTHX_ register SV *sv, SV *del, register SV **mark, register SV **sp)
646 register I32 items = sp - mark;
651 (void) SvPV(del, delimlen); /* stringify and get the delimlen */
652 /* SvCUR assumes it's SvPOK() and woe betide you if it's not. */
655 len = (items > 0 ? (delimlen * (items - 1) ) : 0);
656 (void)SvUPGRADE(sv, SVt_PV);
657 if (SvLEN(sv) < len + items) { /* current length is way too short */
658 while (items-- > 0) {
659 if (*mark && !SvGAMAGIC(*mark) && SvOK(*mark)) {
665 SvGROW(sv, len + 1); /* so try to pre-extend */
672 sv_setpvn(sv, "", 0);
673 /* sv_setpv retains old UTF8ness [perl #24846] */
677 if (PL_tainting && SvMAGICAL(sv))
687 for (; items > 0; items--,mark++) {
693 for (; items > 0; items--,mark++)
700 Perl_do_sprintf(pTHX_ SV *sv, I32 len, SV **sarg)
703 char *pat = SvPV(*sarg, patlen);
704 bool do_taint = FALSE;
709 sv_vsetpvfn(sv, pat, patlen, Null(va_list*), sarg + 1, len - 1, &do_taint);
715 /* currently converts input to bytes if possible, but doesn't sweat failure */
717 Perl_do_vecget(pTHX_ SV *sv, I32 offset, I32 size)
720 unsigned char *s = (unsigned char *) SvPV(sv, srclen);
725 if (size < 1 || (size & (size-1))) /* size < 1 or not a power of two */
726 Perl_croak(aTHX_ "Illegal number of bits in vec");
729 (void) Perl_sv_utf8_downgrade(aTHX_ sv, TRUE);
731 offset *= size; /* turn into bit offset */
732 len = (offset + size + 7) / 8; /* required number of bytes */
737 offset >>= 3; /* turn into byte offset */
739 if ((STRLEN)offset >= srclen)
742 retnum = (UV) s[offset] << 8;
744 else if (size == 32) {
745 if ((STRLEN)offset >= srclen)
747 else if ((STRLEN)(offset + 1) >= srclen)
749 ((UV) s[offset ] << 24);
750 else if ((STRLEN)(offset + 2) >= srclen)
752 ((UV) s[offset ] << 24) +
753 ((UV) s[offset + 1] << 16);
756 ((UV) s[offset ] << 24) +
757 ((UV) s[offset + 1] << 16) +
758 ( s[offset + 2] << 8);
761 else if (size == 64) {
762 if (ckWARN(WARN_PORTABLE))
763 Perl_warner(aTHX_ packWARN(WARN_PORTABLE),
764 "Bit vector size > 32 non-portable");
765 if (offset >= srclen)
767 else if (offset + 1 >= srclen)
769 (UV) s[offset ] << 56;
770 else if (offset + 2 >= srclen)
772 ((UV) s[offset ] << 56) +
773 ((UV) s[offset + 1] << 48);
774 else if (offset + 3 >= srclen)
776 ((UV) s[offset ] << 56) +
777 ((UV) s[offset + 1] << 48) +
778 ((UV) s[offset + 2] << 40);
779 else if (offset + 4 >= srclen)
781 ((UV) s[offset ] << 56) +
782 ((UV) s[offset + 1] << 48) +
783 ((UV) s[offset + 2] << 40) +
784 ((UV) s[offset + 3] << 32);
785 else if (offset + 5 >= srclen)
787 ((UV) s[offset ] << 56) +
788 ((UV) s[offset + 1] << 48) +
789 ((UV) s[offset + 2] << 40) +
790 ((UV) s[offset + 3] << 32) +
791 ( s[offset + 4] << 24);
792 else if (offset + 6 >= srclen)
794 ((UV) s[offset ] << 56) +
795 ((UV) s[offset + 1] << 48) +
796 ((UV) s[offset + 2] << 40) +
797 ((UV) s[offset + 3] << 32) +
798 ((UV) s[offset + 4] << 24) +
799 ((UV) s[offset + 5] << 16);
802 ((UV) s[offset ] << 56) +
803 ((UV) s[offset + 1] << 48) +
804 ((UV) s[offset + 2] << 40) +
805 ((UV) s[offset + 3] << 32) +
806 ((UV) s[offset + 4] << 24) +
807 ((UV) s[offset + 5] << 16) +
808 ( s[offset + 6] << 8);
814 retnum = (s[offset >> 3] >> (offset & 7)) & ((1 << size) - 1);
816 offset >>= 3; /* turn into byte offset */
821 ((UV) s[offset] << 8) +
825 ((UV) s[offset ] << 24) +
826 ((UV) s[offset + 1] << 16) +
827 ( s[offset + 2] << 8) +
830 else if (size == 64) {
831 if (ckWARN(WARN_PORTABLE))
832 Perl_warner(aTHX_ packWARN(WARN_PORTABLE),
833 "Bit vector size > 32 non-portable");
835 ((UV) s[offset ] << 56) +
836 ((UV) s[offset + 1] << 48) +
837 ((UV) s[offset + 2] << 40) +
838 ((UV) s[offset + 3] << 32) +
839 ((UV) s[offset + 4] << 24) +
840 ((UV) s[offset + 5] << 16) +
841 ( s[offset + 6] << 8) +
850 /* currently converts input to bytes if possible but doesn't sweat failures,
851 * although it does ensure that the string it clobbers is not marked as
852 * utf8-valid any more
855 Perl_do_vecset(pTHX_ SV *sv)
857 SV *targ = LvTARG(sv);
860 register unsigned char *s;
868 s = (unsigned char*)SvPV_force(targ, targlen);
870 /* This is handled by the SvPOK_only below...
871 if (!Perl_sv_utf8_downgrade(aTHX_ targ, TRUE))
874 (void) Perl_sv_utf8_downgrade(aTHX_ targ, TRUE);
877 (void)SvPOK_only(targ);
879 offset = LvTARGOFF(sv);
881 Perl_croak(aTHX_ "Negative offset to vec in lvalue context");
882 size = LvTARGLEN(sv);
883 if (size < 1 || (size & (size-1))) /* size < 1 or not a power of two */
884 Perl_croak(aTHX_ "Illegal number of bits in vec");
886 offset *= size; /* turn into bit offset */
887 len = (offset + size + 7) / 8; /* required number of bytes */
889 s = (unsigned char*)SvGROW(targ, len + 1);
890 (void)memzero((char *)(s + targlen), len - targlen + 1);
891 SvCUR_set(targ, len);
895 mask = (1 << size) - 1;
898 offset >>= 3; /* turn into byte offset */
899 s[offset] &= ~(mask << size);
900 s[offset] |= lval << size;
903 offset >>= 3; /* turn into byte offset */
905 s[offset ] = (U8)( lval & 0xff);
906 else if (size == 16) {
907 s[offset ] = (U8)((lval >> 8) & 0xff);
908 s[offset+1] = (U8)( lval & 0xff);
910 else if (size == 32) {
911 s[offset ] = (U8)((lval >> 24) & 0xff);
912 s[offset+1] = (U8)((lval >> 16) & 0xff);
913 s[offset+2] = (U8)((lval >> 8) & 0xff);
914 s[offset+3] = (U8)( lval & 0xff);
917 else if (size == 64) {
918 if (ckWARN(WARN_PORTABLE))
919 Perl_warner(aTHX_ packWARN(WARN_PORTABLE),
920 "Bit vector size > 32 non-portable");
921 s[offset ] = (U8)((lval >> 56) & 0xff);
922 s[offset+1] = (U8)((lval >> 48) & 0xff);
923 s[offset+2] = (U8)((lval >> 40) & 0xff);
924 s[offset+3] = (U8)((lval >> 32) & 0xff);
925 s[offset+4] = (U8)((lval >> 24) & 0xff);
926 s[offset+5] = (U8)((lval >> 16) & 0xff);
927 s[offset+6] = (U8)((lval >> 8) & 0xff);
928 s[offset+7] = (U8)( lval & 0xff);
936 Perl_do_chop(pTHX_ register SV *astr, register SV *sv)
941 if (SvTYPE(sv) == SVt_PVAV) {
946 for (i = 0; i <= max; i++) {
947 sv = (SV*)av_fetch(av, i, FALSE);
948 if (sv && ((sv = *(SV**)sv), sv != &PL_sv_undef))
953 else if (SvTYPE(sv) == SVt_PVHV) {
956 (void)hv_iterinit(hv);
958 while ((entry = hv_iternext(hv)))
959 do_chop(astr,hv_iterval(hv,entry));
962 else if (SvREADONLY(sv)) {
964 /* SV is copy-on-write */
965 sv_force_normal_flags(sv, 0);
968 Perl_croak(aTHX_ PL_no_modify);
971 if (len && !SvPOK(sv))
972 s = SvPV_force(sv, len);
975 char *send = s + len;
978 while (s > start && UTF8_IS_CONTINUATION(*s))
980 if (utf8_to_uvchr((U8*)s, 0)) {
981 sv_setpvn(astr, s, send - s);
983 SvCUR_set(sv, s - start);
989 sv_setpvn(astr, "", 0);
993 sv_setpvn(astr, s, 1);
1000 sv_setpvn(astr, "", 0);
1005 Perl_do_chomp(pTHX_ register SV *sv)
1011 char *temp_buffer = NULL;
1012 SV* svrecode = Nullsv;
1016 if (RsRECORD(PL_rs))
1019 if (SvTYPE(sv) == SVt_PVAV) {
1024 for (i = 0; i <= max; i++) {
1025 sv = (SV*)av_fetch(av, i, FALSE);
1026 if (sv && ((sv = *(SV**)sv), sv != &PL_sv_undef))
1027 count += do_chomp(sv);
1031 else if (SvTYPE(sv) == SVt_PVHV) {
1034 (void)hv_iterinit(hv);
1036 while ((entry = hv_iternext(hv)))
1037 count += do_chomp(hv_iterval(hv,entry));
1040 else if (SvREADONLY(sv)) {
1042 /* SV is copy-on-write */
1043 sv_force_normal_flags(sv, 0);
1046 Perl_croak(aTHX_ PL_no_modify);
1051 /* XXX, here sv is utf8-ized as a side-effect!
1052 If encoding.pm is used properly, almost string-generating
1053 operations, including literal strings, chr(), input data, etc.
1054 should have been utf8-ized already, right?
1056 sv_recode_to_utf8(sv, PL_encoding);
1063 if (RsPARA(PL_rs)) {
1067 while (len && s[-1] == '\n') {
1074 STRLEN rslen, rs_charlen;
1075 char *rsptr = SvPV(PL_rs, rslen);
1077 rs_charlen = SvUTF8(PL_rs)
1078 ? sv_len_utf8(PL_rs)
1081 if (SvUTF8(PL_rs) != SvUTF8(sv)) {
1082 /* Assumption is that rs is shorter than the scalar. */
1083 if (SvUTF8(PL_rs)) {
1084 /* RS is utf8, scalar is 8 bit. */
1085 bool is_utf8 = TRUE;
1086 temp_buffer = (char*)bytes_from_utf8((U8*)rsptr,
1089 /* Cannot downgrade, therefore cannot possibly match
1091 assert (temp_buffer == rsptr);
1095 rsptr = temp_buffer;
1097 else if (PL_encoding) {
1098 /* RS is 8 bit, encoding.pm is used.
1099 * Do not recode PL_rs as a side-effect. */
1100 svrecode = newSVpvn(rsptr, rslen);
1101 sv_recode_to_utf8(svrecode, PL_encoding);
1102 rsptr = SvPV(svrecode, rslen);
1103 rs_charlen = sv_len_utf8(svrecode);
1106 /* RS is 8 bit, scalar is utf8. */
1107 temp_buffer = (char*)bytes_to_utf8((U8*)rsptr, &rslen);
1108 rsptr = temp_buffer;
1117 if (len < rslen - 1)
1121 if (memNE(s, rsptr, rslen))
1123 count += rs_charlen;
1126 s = SvPV_force(sv, n_a);
1135 SvREFCNT_dec(svrecode);
1137 Safefree(temp_buffer);
1142 Perl_do_vop(pTHX_ I32 optype, SV *sv, SV *left, SV *right)
1158 bool left_utf = DO_UTF8(left);
1159 bool right_utf = DO_UTF8(right);
1162 if (left_utf && !right_utf)
1163 sv_utf8_upgrade(right);
1164 else if (!left_utf && right_utf)
1165 sv_utf8_upgrade(left);
1167 if (sv != left || (optype != OP_BIT_AND && !SvOK(sv) && !SvGMAGICAL(sv)))
1168 sv_setpvn(sv, "", 0); /* avoid undef warning on |= and ^= */
1169 lsave = lc = SvPV_nomg(left, leftlen);
1170 rsave = rc = SvPV_nomg(right, rightlen);
1171 len = leftlen < rightlen ? leftlen : rightlen;
1173 if ((left_utf || right_utf) && (sv == left || sv == right)) {
1174 needlen = optype == OP_BIT_AND ? len : leftlen + rightlen;
1175 Newz(801, dc, needlen + 1, char);
1177 else if (SvOK(sv) || SvTYPE(sv) > SVt_PVMG) {
1179 dc = SvPV_force_nomg(sv, n_a);
1180 if (SvCUR(sv) < (STRLEN)len) {
1181 dc = SvGROW(sv, (STRLEN)(len + 1));
1182 (void)memzero(dc + SvCUR(sv), len - SvCUR(sv) + 1);
1184 if (optype != OP_BIT_AND && (left_utf || right_utf))
1185 dc = SvGROW(sv, leftlen + rightlen + 1);
1188 needlen = ((optype == OP_BIT_AND)
1189 ? len : (leftlen > rightlen ? leftlen : rightlen));
1190 Newz(801, dc, needlen + 1, char);
1191 (void)sv_usepvn(sv, dc, needlen);
1192 dc = SvPVX(sv); /* sv_usepvn() calls Renew() */
1195 (void)SvPOK_only(sv);
1196 if (left_utf || right_utf) {
1199 STRLEN lulen = leftlen;
1200 STRLEN rulen = rightlen;
1205 while (lulen && rulen) {
1206 luc = utf8n_to_uvchr((U8*)lc, lulen, &ulen, UTF8_ALLOW_ANYUV);
1209 ruc = utf8n_to_uvchr((U8*)rc, rulen, &ulen, UTF8_ALLOW_ANYUV);
1213 dc = (char*)uvchr_to_utf8((U8*)dc, duc);
1215 if (sv == left || sv == right)
1216 (void)sv_usepvn(sv, dcsave, needlen);
1217 SvCUR_set(sv, dc - dcsave);
1220 while (lulen && rulen) {
1221 luc = utf8n_to_uvchr((U8*)lc, lulen, &ulen, UTF8_ALLOW_ANYUV);
1224 ruc = utf8n_to_uvchr((U8*)rc, rulen, &ulen, UTF8_ALLOW_ANYUV);
1228 dc = (char*)uvchr_to_utf8((U8*)dc, duc);
1232 while (lulen && rulen) {
1233 luc = utf8n_to_uvchr((U8*)lc, lulen, &ulen, UTF8_ALLOW_ANYUV);
1236 ruc = utf8n_to_uvchr((U8*)rc, rulen, &ulen, UTF8_ALLOW_ANYUV);
1240 dc = (char*)uvchr_to_utf8((U8*)dc, duc);
1243 if (sv == left || sv == right)
1244 (void)sv_usepvn(sv, dcsave, needlen);
1245 SvCUR_set(sv, dc - dcsave);
1247 sv_catpvn(sv, rc, rulen);
1249 sv_catpvn(sv, lc, lulen);
1259 if (len >= sizeof(long)*4 &&
1260 !((long)dc % sizeof(long)) &&
1261 !((long)lc % sizeof(long)) &&
1262 !((long)rc % sizeof(long))) /* It's almost always aligned... */
1264 I32 remainder = len % (sizeof(long)*4);
1265 len /= (sizeof(long)*4);
1274 *dl++ = *ll++ & *rl++;
1275 *dl++ = *ll++ & *rl++;
1276 *dl++ = *ll++ & *rl++;
1277 *dl++ = *ll++ & *rl++;
1282 *dl++ = *ll++ ^ *rl++;
1283 *dl++ = *ll++ ^ *rl++;
1284 *dl++ = *ll++ ^ *rl++;
1285 *dl++ = *ll++ ^ *rl++;
1290 *dl++ = *ll++ | *rl++;
1291 *dl++ = *ll++ | *rl++;
1292 *dl++ = *ll++ | *rl++;
1293 *dl++ = *ll++ | *rl++;
1308 *dc++ = *lc++ & *rc++;
1312 *dc++ = *lc++ ^ *rc++;
1316 *dc++ = *lc++ | *rc++;
1319 if (rightlen > (STRLEN)len)
1320 sv_catpvn(sv, rsave + len, rightlen - len);
1321 else if (leftlen > (STRLEN)len)
1322 sv_catpvn(sv, lsave + len, leftlen - len);
1340 I32 gimme = GIMME_V;
1341 I32 dokeys = (PL_op->op_type == OP_KEYS);
1342 I32 dovalues = (PL_op->op_type == OP_VALUES);
1344 if (PL_op->op_type == OP_RV2HV || PL_op->op_type == OP_PADHV)
1345 dokeys = dovalues = TRUE;
1348 if (PL_op->op_flags & OPf_MOD || LVRET) { /* lvalue */
1349 dTARGET; /* make sure to clear its target here */
1350 if (SvTYPE(TARG) == SVt_PVLV)
1351 LvTARG(TARG) = Nullsv;
1358 (void)hv_iterinit(keys); /* always reset iterator regardless */
1360 if (gimme == G_VOID)
1363 if (gimme == G_SCALAR) {
1367 if (PL_op->op_flags & OPf_MOD || LVRET) { /* lvalue */
1368 if (SvTYPE(TARG) < SVt_PVLV) {
1369 sv_upgrade(TARG, SVt_PVLV);
1370 sv_magic(TARG, Nullsv, PERL_MAGIC_nkeys, Nullch, 0);
1373 if (LvTARG(TARG) != (SV*)keys) {
1375 SvREFCNT_dec(LvTARG(TARG));
1376 LvTARG(TARG) = SvREFCNT_inc(keys);
1382 if (! SvTIED_mg((SV*)keys, PERL_MAGIC_tied))
1387 while (hv_iternext(keys)) i++;
1393 EXTEND(SP, HvKEYS(keys) * (dokeys + dovalues));
1395 PUTBACK; /* hv_iternext and hv_iterval might clobber stack_sp */
1396 while ((entry = hv_iternext(keys))) {
1399 SV* sv = hv_iterkeysv(entry);
1400 XPUSHs(sv); /* won't clobber stack_sp */
1404 tmpstr = hv_iterval(hv,entry);
1405 DEBUG_H(Perl_sv_setpvf(aTHX_ tmpstr, "%lu%%%d=%lu",
1406 (unsigned long)HeHASH(entry),
1408 (unsigned long)(HeHASH(entry) & HvMAX(keys))));