3 * Copyright (c) 1991-2002, Larry Wall
5 * You may distribute under the terms of either the GNU General Public
6 * License or the Artistic License, as specified in the README file.
11 * "'So that was the job I felt I had to do when I started,' thought Sam."
15 #define PERL_IN_DOOP_C
19 #if !defined(NSIG) || defined(M_UNIX) || defined(M_XENIX)
25 S_do_trans_simple(pTHX_ SV *sv)
32 I32 grows = PL_op->op_private & OPpTRANS_GROWS;
37 tbl = (short*)cPVOP->op_pv;
39 Perl_croak(aTHX_ "panic: do_trans_simple line %d",__LINE__);
41 s = (U8*)SvPV(sv, len);
44 /* First, take care of non-UTF8 input strings, because they're easy */
47 if ((ch = tbl[*s]) >= 0) {
58 /* Allow for expansion: $_="a".chr(400); tr/a/\xFE/, FE needs encoding */
60 New(0, d, len*2+1, U8);
68 /* Need to check this, otherwise 128..255 won't match */
69 c = utf8n_to_uvchr(s, send - s, &ulen, 0);
70 if (c < 0x100 && (ch = tbl[c]) >= 0) {
72 d = uvchr_to_utf8(d, ch);
75 else { /* No match -> copy */
82 sv_setpvn(sv, (char*)dstart, d - dstart);
87 SvCUR_set(sv, d - dstart);
95 S_do_trans_count(pTHX_ SV *sv)
102 I32 complement = PL_op->op_private & OPpTRANS_COMPLEMENT;
104 tbl = (short*)cPVOP->op_pv;
106 Perl_croak(aTHX_ "panic: do_trans_count line %d",__LINE__);
108 s = (U8*)SvPV(sv, len);
120 c = utf8n_to_uvchr(s, send - s, &ulen, 0);
124 } else if (complement)
133 S_do_trans_complex(pTHX_ SV *sv)
141 I32 grows = PL_op->op_private & OPpTRANS_GROWS;
142 I32 complement = PL_op->op_private & OPpTRANS_COMPLEMENT;
143 I32 del = PL_op->op_private & OPpTRANS_DELETE;
144 STRLEN len, rlen = 0;
148 tbl = (short*)cPVOP->op_pv;
150 Perl_croak(aTHX_ "panic: do_trans_complex line %d",__LINE__);
152 s = (U8*)SvPV(sv, len);
158 if (PL_op->op_private & OPpTRANS_SQUASH) {
161 if ((ch = tbl[*s]) >= 0) {
164 if (p != d - 1 || *p != *d)
167 else if (ch == -1) /* -1 is unmapped character */
169 else if (ch == -2) /* -2 is delete character */
176 if ((ch = tbl[*s]) >= 0) {
180 else if (ch == -1) /* -1 is unmapped character */
182 else if (ch == -2) /* -2 is delete character */
188 SvCUR_set(sv, d - dstart);
192 New(0, d, len*2+1, U8);
196 if (complement && !del)
199 #ifdef MACOS_TRADITIONAL
200 #define comp CoMP /* "comp" is a keyword in some compilers ... */
203 if (PL_op->op_private & OPpTRANS_SQUASH) {
207 UV comp = utf8_to_uvchr(s, &len);
217 ch = (rlen == 0) ? comp :
218 (comp - 0x100 < rlen) ?
219 tbl[comp+1] : tbl[0x100+rlen];
221 d = uvchr_to_utf8(d, ch);
229 else if ((ch = tbl[comp]) >= 0) {
232 d = uvchr_to_utf8(d, ch);
238 else if (ch == -1) { /* -1 is unmapped character */
242 else if (ch == -2) /* -2 is delete character */
251 UV comp = utf8_to_uvchr(s, &len);
260 if (comp - 0x100 < rlen)
261 d = uvchr_to_utf8(d, tbl[comp+1]);
263 d = uvchr_to_utf8(d, tbl[0x100+rlen]);
267 else if ((ch = tbl[comp]) >= 0) {
268 d = uvchr_to_utf8(d, ch);
271 else if (ch == -1) { /* -1 is unmapped character */
275 else if (ch == -2) /* -2 is delete character */
281 sv_setpvn(sv, (char*)dstart, d - dstart);
286 SvCUR_set(sv, d - dstart);
295 S_do_trans_simple_utf8(pTHX_ SV *sv)
303 I32 grows = PL_op->op_private & OPpTRANS_GROWS;
306 SV* rv = (SV*)cSVOP->op_sv;
307 HV* hv = (HV*)SvRV(rv);
308 SV** svp = hv_fetch(hv, "NONE", 4, FALSE);
309 UV none = svp ? SvUV(*svp) : 0x7fffffff;
316 s = (U8*)SvPV(sv, len);
319 U8 *t = s, *e = s + len;
322 if ((hibit = !NATIVE_IS_INVARIANT(ch)))
326 s = bytes_to_utf8(s, &len);
331 svp = hv_fetch(hv, "FINAL", 5, FALSE);
336 /* d needs to be bigger than s, in case e.g. upgrading is required */
337 New(0, d, len*3+UTF8_MAXLEN, U8);
347 if ((uv = swash_fetch(rv, s, TRUE)) < none) {
350 d = uvuni_to_utf8(d, uv);
352 else if (uv == none) {
358 else if (uv == extra) {
362 d = uvuni_to_utf8(d, final);
368 STRLEN clen = d - dstart;
369 STRLEN nlen = dend - dstart + len + UTF8_MAXLEN;
371 Perl_croak(aTHX_ "panic: do_trans_simple_utf8 line %d",__LINE__);
372 Renew(dstart, nlen+UTF8_MAXLEN, U8);
374 dend = dstart + nlen;
377 if (grows || hibit) {
378 sv_setpvn(sv, (char*)dstart, d - dstart);
385 SvCUR_set(sv, d - dstart);
394 S_do_trans_count_utf8(pTHX_ SV *sv)
397 U8 *start = 0, *send;
401 SV* rv = (SV*)cSVOP->op_sv;
402 HV* hv = (HV*)SvRV(rv);
403 SV** svp = hv_fetch(hv, "NONE", 4, FALSE);
404 UV none = svp ? SvUV(*svp) : 0x7fffffff;
409 s = (U8*)SvPV(sv, len);
411 U8 *t = s, *e = s + len;
414 if ((hibit = !NATIVE_IS_INVARIANT(ch)))
418 start = s = bytes_to_utf8(s, &len);
423 if ((uv = swash_fetch(rv, s, TRUE)) < none || uv == extra)
434 S_do_trans_complex_utf8(pTHX_ SV *sv)
440 I32 squash = PL_op->op_private & OPpTRANS_SQUASH;
441 I32 del = PL_op->op_private & OPpTRANS_DELETE;
442 I32 grows = PL_op->op_private & OPpTRANS_GROWS;
443 SV* rv = (SV*)cSVOP->op_sv;
444 HV* hv = (HV*)SvRV(rv);
445 SV** svp = hv_fetch(hv, "NONE", 4, FALSE);
446 UV none = svp ? SvUV(*svp) : 0x7fffffff;
449 bool havefinal = FALSE;
456 s = (U8*)SvPV(sv, len);
459 U8 *t = s, *e = s + len;
462 if ((hibit = !NATIVE_IS_INVARIANT(ch)))
466 s = bytes_to_utf8(s, &len);
471 svp = hv_fetch(hv, "FINAL", 5, FALSE);
478 /* d needs to be bigger than s, in case e.g. upgrading is required */
479 New(0, d, len*3+UTF8_MAXLEN, U8);
491 uv = swash_fetch(rv, s, TRUE);
494 STRLEN clen = d - dstart;
495 STRLEN nlen = dend - dstart + len + UTF8_MAXLEN;
497 Perl_croak(aTHX_ "panic: do_trans_complex_utf8 line %d",__LINE__);
498 Renew(dstart, nlen+UTF8_MAXLEN, U8);
500 dend = dstart + nlen;
506 d = uvuni_to_utf8(d, uv);
511 else if (uv == none) { /* "none" is unmapped character */
519 else if (uv == extra && !del) {
524 d = uvuni_to_utf8(d, final);
530 uv = utf8_to_uvuni(s, &len);
540 matches++; /* "none+1" is delete character */
546 uv = swash_fetch(rv, s, TRUE);
548 STRLEN clen = d - dstart;
549 STRLEN nlen = dend - dstart + len + UTF8_MAXLEN;
551 Perl_croak(aTHX_ "panic: do_trans_complex_utf8 line %d",__LINE__);
552 Renew(dstart, nlen+UTF8_MAXLEN, U8);
554 dend = dstart + nlen;
559 d = uvuni_to_utf8(d, uv);
562 else if (uv == none) { /* "none" is unmapped character */
569 else if (uv == extra && !del) {
572 d = uvuni_to_utf8(d, final);
575 matches++; /* "none+1" is delete character */
579 if (grows || hibit) {
580 sv_setpvn(sv, (char*)dstart, d - dstart);
587 SvCUR_set(sv, d - dstart);
596 Perl_do_trans(pTHX_ SV *sv)
599 I32 hasutf = (PL_op->op_private &
600 (OPpTRANS_FROM_UTF|OPpTRANS_TO_UTF));
602 if (SvREADONLY(sv)) {
604 sv_force_normal_flags(sv, 0);
605 if (SvREADONLY(sv) && !(PL_op->op_private & OPpTRANS_IDENTICAL))
606 Perl_croak(aTHX_ PL_no_modify);
611 if (!(PL_op->op_private & OPpTRANS_IDENTICAL)) {
613 (void)SvPV_force(sv, len);
614 (void)SvPOK_only_UTF8(sv);
617 DEBUG_t( Perl_deb(aTHX_ "2.TBL\n"));
619 switch (PL_op->op_private & ~hasutf & 63) {
622 return do_trans_simple_utf8(sv);
624 return do_trans_simple(sv);
626 case OPpTRANS_IDENTICAL:
627 case OPpTRANS_IDENTICAL|OPpTRANS_COMPLEMENT:
629 return do_trans_count_utf8(sv);
631 return do_trans_count(sv);
635 return do_trans_complex_utf8(sv);
637 return do_trans_complex(sv);
642 Perl_do_join(pTHX_ register SV *sv, SV *del, register SV **mark, register SV **sp)
645 register I32 items = sp - mark;
650 (void) SvPV(del, delimlen); /* stringify and get the delimlen */
651 /* SvCUR assumes it's SvPOK() and woe betide you if it's not. */
654 len = (items > 0 ? (delimlen * (items - 1) ) : 0);
655 (void)SvUPGRADE(sv, SVt_PV);
656 if (SvLEN(sv) < len + items) { /* current length is way too short */
657 while (items-- > 0) {
658 if (*mark && !SvGAMAGIC(*mark) && SvOK(*mark)) {
664 SvGROW(sv, len + 1); /* so try to pre-extend */
672 if (PL_tainting && SvMAGICAL(sv))
682 for (; items > 0; items--,mark++) {
688 for (; items > 0; items--,mark++)
695 Perl_do_sprintf(pTHX_ SV *sv, I32 len, SV **sarg)
698 char *pat = SvPV(*sarg, patlen);
699 bool do_taint = FALSE;
704 sv_vsetpvfn(sv, pat, patlen, Null(va_list*), sarg + 1, len - 1, &do_taint);
710 /* currently converts input to bytes if possible, but doesn't sweat failure */
712 Perl_do_vecget(pTHX_ SV *sv, I32 offset, I32 size)
715 unsigned char *s = (unsigned char *) SvPV(sv, srclen);
720 if (size < 1 || (size & (size-1))) /* size < 1 or not a power of two */
721 Perl_croak(aTHX_ "Illegal number of bits in vec");
724 (void) Perl_sv_utf8_downgrade(aTHX_ sv, TRUE);
726 offset *= size; /* turn into bit offset */
727 len = (offset + size + 7) / 8; /* required number of bytes */
732 offset >>= 3; /* turn into byte offset */
734 if ((STRLEN)offset >= srclen)
737 retnum = (UV) s[offset] << 8;
739 else if (size == 32) {
740 if ((STRLEN)offset >= srclen)
742 else if ((STRLEN)(offset + 1) >= srclen)
744 ((UV) s[offset ] << 24);
745 else if ((STRLEN)(offset + 2) >= srclen)
747 ((UV) s[offset ] << 24) +
748 ((UV) s[offset + 1] << 16);
751 ((UV) s[offset ] << 24) +
752 ((UV) s[offset + 1] << 16) +
753 ( s[offset + 2] << 8);
756 else if (size == 64) {
757 if (ckWARN(WARN_PORTABLE))
758 Perl_warner(aTHX_ packWARN(WARN_PORTABLE),
759 "Bit vector size > 32 non-portable");
760 if (offset >= srclen)
762 else if (offset + 1 >= srclen)
764 (UV) s[offset ] << 56;
765 else if (offset + 2 >= srclen)
767 ((UV) s[offset ] << 56) +
768 ((UV) s[offset + 1] << 48);
769 else if (offset + 3 >= srclen)
771 ((UV) s[offset ] << 56) +
772 ((UV) s[offset + 1] << 48) +
773 ((UV) s[offset + 2] << 40);
774 else if (offset + 4 >= srclen)
776 ((UV) s[offset ] << 56) +
777 ((UV) s[offset + 1] << 48) +
778 ((UV) s[offset + 2] << 40) +
779 ((UV) s[offset + 3] << 32);
780 else if (offset + 5 >= srclen)
782 ((UV) s[offset ] << 56) +
783 ((UV) s[offset + 1] << 48) +
784 ((UV) s[offset + 2] << 40) +
785 ((UV) s[offset + 3] << 32) +
786 ( s[offset + 4] << 24);
787 else if (offset + 6 >= srclen)
789 ((UV) s[offset ] << 56) +
790 ((UV) s[offset + 1] << 48) +
791 ((UV) s[offset + 2] << 40) +
792 ((UV) s[offset + 3] << 32) +
793 ((UV) s[offset + 4] << 24) +
794 ((UV) s[offset + 5] << 16);
797 ((UV) s[offset ] << 56) +
798 ((UV) s[offset + 1] << 48) +
799 ((UV) s[offset + 2] << 40) +
800 ((UV) s[offset + 3] << 32) +
801 ((UV) s[offset + 4] << 24) +
802 ((UV) s[offset + 5] << 16) +
803 ( s[offset + 6] << 8);
809 retnum = (s[offset >> 3] >> (offset & 7)) & ((1 << size) - 1);
811 offset >>= 3; /* turn into byte offset */
816 ((UV) s[offset] << 8) +
820 ((UV) s[offset ] << 24) +
821 ((UV) s[offset + 1] << 16) +
822 ( s[offset + 2] << 8) +
825 else if (size == 64) {
826 if (ckWARN(WARN_PORTABLE))
827 Perl_warner(aTHX_ packWARN(WARN_PORTABLE),
828 "Bit vector size > 32 non-portable");
830 ((UV) s[offset ] << 56) +
831 ((UV) s[offset + 1] << 48) +
832 ((UV) s[offset + 2] << 40) +
833 ((UV) s[offset + 3] << 32) +
834 ((UV) s[offset + 4] << 24) +
835 ((UV) s[offset + 5] << 16) +
836 ( s[offset + 6] << 8) +
845 /* currently converts input to bytes if possible but doesn't sweat failures,
846 * although it does ensure that the string it clobbers is not marked as
847 * utf8-valid any more
850 Perl_do_vecset(pTHX_ SV *sv)
852 SV *targ = LvTARG(sv);
855 register unsigned char *s;
863 s = (unsigned char*)SvPV_force(targ, targlen);
865 /* This is handled by the SvPOK_only below...
866 if (!Perl_sv_utf8_downgrade(aTHX_ targ, TRUE))
869 (void) Perl_sv_utf8_downgrade(aTHX_ targ, TRUE);
872 (void)SvPOK_only(targ);
874 offset = LvTARGOFF(sv);
876 Perl_croak(aTHX_ "Negative offset to vec in lvalue context");
877 size = LvTARGLEN(sv);
878 if (size < 1 || (size & (size-1))) /* size < 1 or not a power of two */
879 Perl_croak(aTHX_ "Illegal number of bits in vec");
881 offset *= size; /* turn into bit offset */
882 len = (offset + size + 7) / 8; /* required number of bytes */
884 s = (unsigned char*)SvGROW(targ, len + 1);
885 (void)memzero((char *)(s + targlen), len - targlen + 1);
886 SvCUR_set(targ, len);
890 mask = (1 << size) - 1;
893 offset >>= 3; /* turn into byte offset */
894 s[offset] &= ~(mask << size);
895 s[offset] |= lval << size;
898 offset >>= 3; /* turn into byte offset */
900 s[offset ] = (U8)( lval & 0xff);
901 else if (size == 16) {
902 s[offset ] = (U8)((lval >> 8) & 0xff);
903 s[offset+1] = (U8)( lval & 0xff);
905 else if (size == 32) {
906 s[offset ] = (U8)((lval >> 24) & 0xff);
907 s[offset+1] = (U8)((lval >> 16) & 0xff);
908 s[offset+2] = (U8)((lval >> 8) & 0xff);
909 s[offset+3] = (U8)( lval & 0xff);
912 else if (size == 64) {
913 if (ckWARN(WARN_PORTABLE))
914 Perl_warner(aTHX_ packWARN(WARN_PORTABLE),
915 "Bit vector size > 32 non-portable");
916 s[offset ] = (U8)((lval >> 56) & 0xff);
917 s[offset+1] = (U8)((lval >> 48) & 0xff);
918 s[offset+2] = (U8)((lval >> 40) & 0xff);
919 s[offset+3] = (U8)((lval >> 32) & 0xff);
920 s[offset+4] = (U8)((lval >> 24) & 0xff);
921 s[offset+5] = (U8)((lval >> 16) & 0xff);
922 s[offset+6] = (U8)((lval >> 8) & 0xff);
923 s[offset+7] = (U8)( lval & 0xff);
931 Perl_do_chop(pTHX_ register SV *astr, register SV *sv)
936 if (SvTYPE(sv) == SVt_PVAV) {
941 for (i = 0; i <= max; i++) {
942 sv = (SV*)av_fetch(av, i, FALSE);
943 if (sv && ((sv = *(SV**)sv), sv != &PL_sv_undef))
948 else if (SvTYPE(sv) == SVt_PVHV) {
951 (void)hv_iterinit(hv);
953 while ((entry = hv_iternext(hv)))
954 do_chop(astr,hv_iterval(hv,entry));
957 else if (SvREADONLY(sv)) {
959 /* SV is copy-on-write */
960 sv_force_normal_flags(sv, 0);
963 Perl_croak(aTHX_ PL_no_modify);
966 if (len && !SvPOK(sv))
967 s = SvPV_force(sv, len);
970 char *send = s + len;
973 while (s > start && UTF8_IS_CONTINUATION(*s))
975 if (utf8_to_uvchr((U8*)s, 0)) {
976 sv_setpvn(astr, s, send - s);
978 SvCUR_set(sv, s - start);
984 sv_setpvn(astr, "", 0);
988 sv_setpvn(astr, s, 1);
995 sv_setpvn(astr, "", 0);
1000 Perl_do_chomp(pTHX_ register SV *sv)
1009 if (RsRECORD(PL_rs))
1012 if (SvTYPE(sv) == SVt_PVAV) {
1017 for (i = 0; i <= max; i++) {
1018 sv = (SV*)av_fetch(av, i, FALSE);
1019 if (sv && ((sv = *(SV**)sv), sv != &PL_sv_undef))
1020 count += do_chomp(sv);
1024 else if (SvTYPE(sv) == SVt_PVHV) {
1027 (void)hv_iterinit(hv);
1029 while ((entry = hv_iternext(hv)))
1030 count += do_chomp(hv_iterval(hv,entry));
1033 else if (SvREADONLY(sv)) {
1035 /* SV is copy-on-write */
1036 sv_force_normal_flags(sv, 0);
1039 Perl_croak(aTHX_ PL_no_modify);
1044 if (RsPARA(PL_rs)) {
1048 while (len && s[-1] == '\n') {
1056 char *rsptr = SvPV(PL_rs, rslen);
1063 if (len < rslen - 1)
1067 if (memNE(s, rsptr, rslen))
1072 s = SvPV_force(sv, n_a);
1083 Perl_do_vop(pTHX_ I32 optype, SV *sv, SV *left, SV *right)
1099 bool left_utf = DO_UTF8(left);
1100 bool right_utf = DO_UTF8(right);
1103 if (left_utf && !right_utf)
1104 sv_utf8_upgrade(right);
1105 else if (!left_utf && right_utf)
1106 sv_utf8_upgrade(left);
1108 if (sv != left || (optype != OP_BIT_AND && !SvOK(sv) && !SvGMAGICAL(sv)))
1109 sv_setpvn(sv, "", 0); /* avoid undef warning on |= and ^= */
1110 lsave = lc = SvPV(left, leftlen);
1111 rsave = rc = SvPV(right, rightlen);
1112 len = leftlen < rightlen ? leftlen : rightlen;
1114 if ((left_utf || right_utf) && (sv == left || sv == right)) {
1115 needlen = optype == OP_BIT_AND ? len : leftlen + rightlen;
1116 Newz(801, dc, needlen + 1, char);
1118 else if (SvOK(sv) || SvTYPE(sv) > SVt_PVMG) {
1120 dc = SvPV_force(sv, n_a);
1121 if (SvCUR(sv) < (STRLEN)len) {
1122 dc = SvGROW(sv, (STRLEN)(len + 1));
1123 (void)memzero(dc + SvCUR(sv), len - SvCUR(sv) + 1);
1125 if (optype != OP_BIT_AND && (left_utf || right_utf))
1126 dc = SvGROW(sv, leftlen + rightlen + 1);
1129 needlen = ((optype == OP_BIT_AND)
1130 ? len : (leftlen > rightlen ? leftlen : rightlen));
1131 Newz(801, dc, needlen + 1, char);
1132 (void)sv_usepvn(sv, dc, needlen);
1133 dc = SvPVX(sv); /* sv_usepvn() calls Renew() */
1136 (void)SvPOK_only(sv);
1137 if (left_utf || right_utf) {
1140 STRLEN lulen = leftlen;
1141 STRLEN rulen = rightlen;
1146 while (lulen && rulen) {
1147 luc = utf8n_to_uvchr((U8*)lc, lulen, &ulen, UTF8_ALLOW_ANYUV);
1150 ruc = utf8n_to_uvchr((U8*)rc, rulen, &ulen, UTF8_ALLOW_ANYUV);
1154 dc = (char*)uvchr_to_utf8((U8*)dc, duc);
1156 if (sv == left || sv == right)
1157 (void)sv_usepvn(sv, dcsave, needlen);
1158 SvCUR_set(sv, dc - dcsave);
1161 while (lulen && rulen) {
1162 luc = utf8n_to_uvchr((U8*)lc, lulen, &ulen, UTF8_ALLOW_ANYUV);
1165 ruc = utf8n_to_uvchr((U8*)rc, rulen, &ulen, UTF8_ALLOW_ANYUV);
1169 dc = (char*)uvchr_to_utf8((U8*)dc, duc);
1173 while (lulen && rulen) {
1174 luc = utf8n_to_uvchr((U8*)lc, lulen, &ulen, UTF8_ALLOW_ANYUV);
1177 ruc = utf8n_to_uvchr((U8*)rc, rulen, &ulen, UTF8_ALLOW_ANYUV);
1181 dc = (char*)uvchr_to_utf8((U8*)dc, duc);
1184 if (sv == left || sv == right)
1185 (void)sv_usepvn(sv, dcsave, needlen);
1186 SvCUR_set(sv, dc - dcsave);
1188 sv_catpvn(sv, rc, rulen);
1190 sv_catpvn(sv, lc, lulen);
1200 if (len >= sizeof(long)*4 &&
1201 !((long)dc % sizeof(long)) &&
1202 !((long)lc % sizeof(long)) &&
1203 !((long)rc % sizeof(long))) /* It's almost always aligned... */
1205 I32 remainder = len % (sizeof(long)*4);
1206 len /= (sizeof(long)*4);
1215 *dl++ = *ll++ & *rl++;
1216 *dl++ = *ll++ & *rl++;
1217 *dl++ = *ll++ & *rl++;
1218 *dl++ = *ll++ & *rl++;
1223 *dl++ = *ll++ ^ *rl++;
1224 *dl++ = *ll++ ^ *rl++;
1225 *dl++ = *ll++ ^ *rl++;
1226 *dl++ = *ll++ ^ *rl++;
1231 *dl++ = *ll++ | *rl++;
1232 *dl++ = *ll++ | *rl++;
1233 *dl++ = *ll++ | *rl++;
1234 *dl++ = *ll++ | *rl++;
1249 *dc++ = *lc++ & *rc++;
1253 *dc++ = *lc++ ^ *rc++;
1257 *dc++ = *lc++ | *rc++;
1260 if (rightlen > (STRLEN)len)
1261 sv_catpvn(sv, rsave + len, rightlen - len);
1262 else if (leftlen > (STRLEN)len)
1263 sv_catpvn(sv, lsave + len, leftlen - len);
1281 I32 gimme = GIMME_V;
1282 I32 dokeys = (PL_op->op_type == OP_KEYS);
1283 I32 dovalues = (PL_op->op_type == OP_VALUES);
1285 if (PL_op->op_type == OP_RV2HV || PL_op->op_type == OP_PADHV)
1286 dokeys = dovalues = TRUE;
1289 if (PL_op->op_flags & OPf_MOD || LVRET) { /* lvalue */
1290 dTARGET; /* make sure to clear its target here */
1291 if (SvTYPE(TARG) == SVt_PVLV)
1292 LvTARG(TARG) = Nullsv;
1299 (void)hv_iterinit(keys); /* always reset iterator regardless */
1301 if (gimme == G_VOID)
1304 if (gimme == G_SCALAR) {
1308 if (PL_op->op_flags & OPf_MOD || LVRET) { /* lvalue */
1309 if (SvTYPE(TARG) < SVt_PVLV) {
1310 sv_upgrade(TARG, SVt_PVLV);
1311 sv_magic(TARG, Nullsv, PERL_MAGIC_nkeys, Nullch, 0);
1314 if (LvTARG(TARG) != (SV*)keys) {
1316 SvREFCNT_dec(LvTARG(TARG));
1317 LvTARG(TARG) = SvREFCNT_inc(keys);
1323 if (! SvTIED_mg((SV*)keys, PERL_MAGIC_tied))
1328 while (hv_iternext(keys)) i++;
1334 EXTEND(SP, HvKEYS(keys) * (dokeys + dovalues));
1336 PUTBACK; /* hv_iternext and hv_iterval might clobber stack_sp */
1337 while ((entry = hv_iternext(keys))) {
1340 SV* sv = hv_iterkeysv(entry);
1341 XPUSHs(sv); /* won't clobber stack_sp */
1345 tmpstr = hv_iterval(hv,entry);
1346 DEBUG_H(Perl_sv_setpvf(aTHX_ tmpstr, "%lu%%%d=%lu",
1347 (unsigned long)HeHASH(entry),
1349 (unsigned long)(HeHASH(entry) & HvMAX(keys))));