This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Make chr() for values >127 to create utf8 when under utf8.
authorSimon Cozens <simon@netthink.co.uk>
Tue, 1 Aug 2000 02:37:02 +0000 (02:37 +0000)
committerJarkko Hietaniemi <jhi@iki.fi>
Tue, 1 Aug 2000 03:35:24 +0000 (03:35 +0000)
Subject: Re: uft8/chr()
Message-ID: <slrn8ocdud.19l.simon@justanother.perlhacker.org>

p4raw-id: //depot/perl@6475

pod/perlfunc.pod
pp.c
t/pragma/utf8.t

index 1e3151a..e19d341 100644 (file)
@@ -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<chr(65)> is C<"A"> in either ASCII or Unicode, and
-chr(0x263a) is a Unicode smiley face (but only within the scope of
-a C<use utf8>).  For the reverse, use L</ord>.  
+chr(0x263a) is a Unicode smiley face. Within the scope of C<use utf8>, 
+characters higher than 127 are encoded in Unicode; if you don't want
+this, temporarily C<use bytes> or use C<pack("C*",...)>
+
+For the reverse, use L</ord>.  
 See L<utf8> for more about Unicode.
 
 If NUMBER is omitted, uses C<$_>.
diff --git a/pp.c b/pp.c
index 988619f..1621df5 100644 (file)
--- 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);
index 8db3d1a..03f7a35 100755 (executable)
@@ -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
+}