summaryrefslogtreecommitdiff
path: root/pp.c
diff options
context:
space:
mode:
authorValeriy E. Ushakov <uwe@ptc.spbu.ru>1997-06-16 07:00:31 +0400
committerGurusamy Sarathy <gsar@cpan.org>1999-02-09 13:53:28 +0000
commit5a929a98cca1fca196d5fd6d9350568e529e8825 (patch)
tree813d42d01b14295df934030c47606a561ce47d01 /pp.c
parent26ef7447c0b4d04a31bae92a55d2f6f9abf46c3c (diff)
downloadperl-5a929a98cca1fca196d5fd6d9350568e529e8825.tar.gz
a modified version of suggested patch for pack template 'Z'; added docs
Message-ID: <%lOHpzIuGV@snark.ptc.spbu.ru> Subject: lack of pack/unpack letter with useful symmetry for C null delimited strings p4raw-id: //depot/perl@2846
Diffstat (limited to 'pp.c')
-rw-r--r--pp.c21
1 files changed, 15 insertions, 6 deletions
diff --git a/pp.c b/pp.c
index cd8c07826e..729d1e7ccc 100644
--- a/pp.c
+++ b/pp.c
@@ -3222,7 +3222,7 @@ PP(pp_unpack)
if (gimme != G_ARRAY) { /* arrange to do first one only */
/*SUPPRESS 530*/
for (patend = pat; !isALPHA(*patend) || *patend == 'x'; patend++) ;
- if (strchr("aAbBhHP", *patend) || *pat == '%') {
+ if (strchr("aAZbBhHP", *patend) || *pat == '%') {
patend++;
while (isDIGIT(*patend) || *patend == '*')
patend++;
@@ -3280,6 +3280,7 @@ PP(pp_unpack)
s += len;
break;
case 'A':
+ case 'Z':
case 'a':
if (len > strend - s)
len = strend - s;
@@ -3288,12 +3289,19 @@ PP(pp_unpack)
sv = NEWSV(35, len);
sv_setpvn(sv, s, len);
s += len;
- if (datumtype == 'A') {
+ if (datumtype == 'A' || datumtype == 'Z') {
aptr = s; /* borrow register */
- s = SvPVX(sv) + len - 1;
- while (s >= SvPVX(sv) && (!*s || isSPACE(*s)))
- s--;
- *++s = '\0';
+ if (datumtype == 'Z') { /* 'Z' strips stuff after first null */
+ s = SvPVX(sv);
+ while (*s)
+ s++;
+ }
+ else { /* 'A' strips both nulls and spaces */
+ s = SvPVX(sv) + len - 1;
+ while (s >= SvPVX(sv) && (!*s || isSPACE(*s)))
+ s--;
+ *++s = '\0';
+ }
SvCUR_set(sv, s - SvPVX(sv));
s = aptr; /* unborrow register */
}
@@ -4128,6 +4136,7 @@ PP(pp_pack)
sv_catpvn(cat, null10, len);
break;
case 'A':
+ case 'Z':
case 'a':
fromstr = NEXTFROM;
aptr = SvPV(fromstr, fromlen);