diff options
author | Larry Wall <lwall@netlabs.com> | 1993-10-07 23:00:00 +0000 |
---|---|---|
committer | Larry Wall <lwall@netlabs.com> | 1993-10-07 23:00:00 +0000 |
commit | 79072805bf63abe5b5978b5928ab00d360ea3e7f (patch) | |
tree | 96688fcd69f9c8d2110e93c350b4d0025eaf240d /do/join | |
parent | e334a159a5616cab575044bafaf68f75b7bb3a16 (diff) | |
download | perl-79072805bf63abe5b5978b5928ab00d360ea3e7f.tar.gz |
perl 5.0 alpha 2perl-5a2
[editor's note: from history.perl.org. The sparc executables
originally included in the distribution are not in this commit.]
Diffstat (limited to 'do/join')
-rw-r--r-- | do/join | 45 |
1 files changed, 45 insertions, 0 deletions
diff --git a/do/join b/do/join new file mode 100644 index 0000000000..c5c5220099 --- /dev/null +++ b/do/join @@ -0,0 +1,45 @@ +void +do_join(TARG,arglast) +register STR *TARG; +int *arglast; +{ + register STR **st = stack->ary_array; + int sp = arglast[1]; + register int items = arglast[2] - sp; + register char *delim = str_get(st[sp]); + register STRLEN len; + int delimlen = st[sp]->str_cur; + + st += sp + 1; + + len = (items > 0 ? (delimlen * (items - 1) ) : 0); + if (TARG->str_len < len + items) { /* current length is way too short */ + while (items-- > 0) { + if (*st) + len += (*st)->str_cur; + st++; + } + STR_GROW(TARG, len + 1); /* so try to pre-extend */ + + items = arglast[2] - sp; + st -= items; + } + + if (items-- > 0) + str_sset(TARG, *st++); + else + str_set(TARG,""); + len = delimlen; + if (len) { + for (; items > 0; items--,st++) { + str_ncat(TARG,delim,len); + str_scat(TARG,*st); + } + } + else { + for (; items > 0; items--,st++) + str_scat(TARG,*st); + } + STABSET(TARG); +} + |