diff options
author | Mike Guy <mjtg@cam.ac.uk> | 2000-09-01 18:43:33 +0100 |
---|---|---|
committer | Jarkko Hietaniemi <jhi@iki.fi> | 2000-09-01 19:37:40 +0000 |
commit | 246fae53ea6ae12991e7653f136a0f797ce002d4 (patch) | |
tree | 217a07ca92ca48618ff14c8cead58f88b284fbb3 /doop.c | |
parent | 93d73c42a7dc0b497a6a2eb40edcb6429896653c (diff) | |
download | perl-246fae53ea6ae12991e7653f136a0f797ce002d4.tar.gz |
Fix vec() / utf8 (was Re: bitvec ops still broken with utf8 -- or not?)
Message-Id: <E13Utuf-0004Bw-00@draco.cus.cam.ac.uk>
p4raw-id: //depot/perl@6988
Diffstat (limited to 'doop.c')
-rw-r--r-- | doop.c | 25 |
1 files changed, 23 insertions, 2 deletions
@@ -537,7 +537,8 @@ Perl_do_sprintf(pTHX_ SV *sv, I32 len, SV **sarg) SvTAINTED_on(sv); } -/* XXX SvUTF8 support missing! */ +/* currently converts input to bytes if needed and croaks if a character + > 255 is encountered */ UV Perl_do_vecget(pTHX_ SV *sv, I32 offset, I32 size) { @@ -549,6 +550,16 @@ Perl_do_vecget(pTHX_ SV *sv, I32 offset, I32 size) return retnum; if (size < 1 || (size & (size-1))) /* size < 1 or not a power of two */ Perl_croak(aTHX_ "Illegal number of bits in vec"); + + if (SvUTF8(sv)) { + if (Perl_utf8_to_bytes(aTHX_ (U8*) s, &srclen)) { + SvUTF8_off(sv); + SvCUR_set(sv, srclen); + } + else + Perl_croak(aTHX_ "Character > 255 in vec()"); + } + offset *= size; /* turn into bit offset */ len = (offset + size + 7) / 8; /* required number of bytes */ if (len > srclen) { @@ -670,7 +681,8 @@ Perl_do_vecget(pTHX_ SV *sv, I32 offset, I32 size) return retnum; } -/* XXX SvUTF8 support missing! */ +/* currently converts input to bytes if needed and croaks if a character + > 255 is encountered */ void Perl_do_vecset(pTHX_ SV *sv) { @@ -686,6 +698,15 @@ Perl_do_vecset(pTHX_ SV *sv) if (!targ) return; s = (unsigned char*)SvPV_force(targ, targlen); + if (SvUTF8(targ)) { + if (Perl_utf8_to_bytes(aTHX_ (U8*) s, &targlen)) { + /* SvUTF8_off(targ); SvPOK_only below ensures this */ + SvCUR_set(targ, targlen); + } + else + Perl_croak(aTHX_ "Character > 255 in vec()"); + } + (void)SvPOK_only(targ); lval = SvUV(sv); offset = LvTARGOFF(sv); |