develooper Front page | perl.perl5.porters | Postings from February 2001

Re: IV preservation (was Re: [PATCH 5.7.0] compiling on OS/2)

From:
nick
Date:
February 16, 2001 14:41
Subject:
Re: IV preservation (was Re: [PATCH 5.7.0] compiling on OS/2)
Message ID:
E14TtVM-0004eq-00@roam1
Graham Barr <gbarr@pobox.com> writes:
>On Fri, Feb 16, 2001 at 09:47:39PM +0000, Nick Ing-Simmons wrote:
>> Case C was Graham's LDAP case. It relied on perl producing UTF8 encoded 
>> form for 128..255 and then did 'use byte' to peak at it.
>> It broke when 5.6+ decided to keep 128...255 as 'byte' anyway.
>> The right way to do this is to export the trivial XS code which 
>> does an upgrade and then turns off the flag. (As current Encode does.)
>
>Right, What I need is a function that when I pass it a string
>it will return the bytes that would be the utf-8 encoding. Which
>in this case is just a downgrade.

Current Encode.xs has

MODULE = Encode		PACKAGE = Encode	PREFIX = sv_

...

void
sv_utf8_encode(sv)
SV *	sv


Which exports sv.c's 

=for apidoc sv_utf8_encode

Convert the PV of an SV to UTF8-encoded, but then turn off the C<SvUTF8>
flag so that it looks like bytes again. Nothing calls this.

=cut
*/

void
Perl_sv_utf8_encode(pTHX_ register SV *sv)
{
    sv_utf8_upgrade(sv);
    SvUTF8_off(sv);
}

Likewise for utf8_decode.


Which sadly have "in-place" semantics rather than function semantics,

so you have to say:

 utf8_encode($encoded = $str);

rather than LISP-ish:

 $encoded = utf8_encode($str); 

-- 
Nick Ing-Simmons




nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About