From: Simon Cozens Date: Tue, 1 Aug 2000 02:37:02 +0000 (+0000) Subject: Make chr() for values >127 to create utf8 when under utf8. X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=aaa68c4a88ea4a62f62819baf4cacc0ca679c5fa;p=p5sagit%2Fp5-mst-13.2.git Make chr() for values >127 to create utf8 when under utf8. Subject: Re: uft8/chr() Message-ID: p4raw-id: //depot/perl@6475 --- diff --git a/pod/perlfunc.pod b/pod/perlfunc.pod index 1e3151a..e19d341 100644 --- a/pod/perlfunc.pod +++ b/pod/perlfunc.pod @@ -688,8 +688,11 @@ On POSIX systems, you can detect this condition this way: Returns the character represented by that NUMBER in the character set. For example, C is C<"A"> in either ASCII or Unicode, and -chr(0x263a) is a Unicode smiley face (but only within the scope of -a C). For the reverse, use L. +chr(0x263a) is a Unicode smiley face. Within the scope of C, +characters higher than 127 are encoded in Unicode; if you don't want +this, temporarily C or use C + +For the reverse, use L. See L for more about Unicode. If NUMBER is omitted, uses C<$_>. diff --git a/pp.c b/pp.c index 988619f..1621df5 100644 --- a/pp.c +++ b/pp.c @@ -2206,7 +2206,7 @@ PP(pp_chr) (void)SvUPGRADE(TARG,SVt_PV); - if (value > 255 && !IN_BYTE) { + if ((value > 255 && !IN_BYTE) || (value & 0x80 && PL_hints & HINT_UTF8) ) { SvGROW(TARG, UTF8_MAXLEN+1); tmps = SvPVX(TARG); tmps = (char*)uv_to_utf8((U8*)tmps, (UV)value); diff --git a/t/pragma/utf8.t b/t/pragma/utf8.t index 8db3d1a..03f7a35 100755 --- a/t/pragma/utf8.t +++ b/t/pragma/utf8.t @@ -10,7 +10,7 @@ BEGIN { } } -print "1..65\n"; +print "1..67\n"; my $test = 1; @@ -289,3 +289,9 @@ sub ok_bytes { ok "\x{ab}" =~ /^\x{ab}$/, 1; $test++; # 65 } + +{ + use utf8; + ok_bytes chr(0xe2), pack("C*", 0xc3, 0xa2); + $test++; # 66 +}