summaryrefslogtreecommitdiff
path: root/pp.c
diff options
context:
space:
mode:
authorGisle Aas <gisle@aas.no>1998-06-25 12:32:43 +0200
committerGurusamy Sarathy <gsar@cpan.org>1998-06-28 20:01:28 +0000
commit5d82c45359f0afca7589620b2f4a39c32f3875eb (patch)
tree93c585d306d0f80a0ed359a193cebc79377b5021 /pp.c
parent5d11ae5e5fc47938f54836457b96550ad1d9d787 (diff)
downloadperl-5d82c45359f0afca7589620b2f4a39c32f3875eb.tar.gz
Re: [PATCH] 4-arg substr update for perl5.004_68
Message-ID: <m3iulpubis.fsf@furu.g.aas.no> p4raw-id: //depot/perl@1242
Diffstat (limited to 'pp.c')
-rw-r--r--pp.c73
1 files changed, 32 insertions, 41 deletions
diff --git a/pp.c b/pp.c
index 6cc98fd617..3d7638e5db 100644
--- a/pp.c
+++ b/pp.c
@@ -1795,7 +1795,6 @@ PP(pp_substr)
djSP; dTARGET;
SV *sv;
I32 len;
- I32 len_ok = 0;
STRLEN curlen;
I32 pos;
I32 rem;
@@ -1807,21 +1806,13 @@ PP(pp_substr)
STRLEN repl_len;
SvTAINTED_off(TARG); /* decontaminate */
- if (MAXARG > 3) {
- /* pop off replacement string */
- sv = POPs;
- repl = SvPV(sv, repl_len);
- /* pop off length */
- sv = POPs;
- if (SvOK(sv)) {
- len = SvIV(sv);
- len_ok++;
+ if (MAXARG > 2) {
+ if (MAXARG > 3) {
+ sv = POPs;
+ repl = SvPV(sv, repl_len);
}
- } else if (MAXARG == 3) {
len = POPi;
- len_ok++;
- }
-
+ }
pos = POPi;
sv = POPs;
PUTBACK;
@@ -1830,34 +1821,34 @@ PP(pp_substr)
pos -= arybase;
rem = curlen-pos;
fail = rem;
- if (len_ok) {
- if (len < 0) {
- rem += len;
- if (rem < 0)
- rem = 0;
- }
- else if (rem > len)
- rem = len;
- }
+ if (MAXARG > 2) {
+ if (len < 0) {
+ rem += len;
+ if (rem < 0)
+ rem = 0;
+ }
+ else if (rem > len)
+ rem = len;
+ }
}
else {
- pos += curlen;
- if (!len_ok)
- rem = curlen;
- else if (len >= 0) {
- rem = pos+len;
- if (rem > (I32)curlen)
- rem = curlen;
- }
- else {
- rem = curlen+len;
- if (rem < pos)
- rem = pos;
- }
- if (pos < 0)
- pos = 0;
- fail = rem;
- rem -= pos;
+ pos += curlen;
+ if (MAXARG < 3)
+ rem = curlen;
+ else if (len >= 0) {
+ rem = pos+len;
+ if (rem > (I32)curlen)
+ rem = curlen;
+ }
+ else {
+ rem = curlen+len;
+ if (rem < pos)
+ rem = pos;
+ }
+ if (pos < 0)
+ pos = 0;
+ fail = rem;
+ rem -= pos;
}
if (fail < 0) {
if (dowarn || lvalue || repl)
@@ -1894,7 +1885,7 @@ PP(pp_substr)
LvTARGOFF(TARG) = pos;
LvTARGLEN(TARG) = rem;
}
- else if (repl)
+ else if (repl)
sv_insert(sv, pos, rem, repl, repl_len);
}
SPAGAIN;