# New Ticket Created by Leon Brocard
# Please include the string: [perl #17035]
# in the subject line of all future correspondence about this issue.
# <URL: http://rt.perl.org/rt2/Ticket/Display.html?id=17035 >
I realise that proper Unicode support is coming, but it may be a while
to get here. We currently have ord() and it makes sense to have a
chr() as well, so that's what my patch provides. Please apply, thanks ;-)
Leon
--
Leon Brocard.............................http://www.astray.com/
scribot.................................http://www.scribot.com/
....... I'm sure it's in the manual somewhere...
-- attachment 1 ------------------------------------------------------
url: http://rt.perl.org/rt2/attach/36636/29568/60614d/chr.patch
Index: core.ops
===================================================================
RCS file: /cvs/public/parrot/core.ops,v
retrieving revision 1.204
diff -u -r1.204 core.ops
--- core.ops 5 Sep 2002 03:46:44 -0000 1.204
+++ core.ops 5 Sep 2002 14:32:53 -0000
@@ -201,6 +201,22 @@
goto NEXT();
}
+=item B<chr>(out STR, in INT)
+
+Returns the character represented by the $2 number in the ASCII
+character set.
+
+=cut
+
+inline op chr (out STR, in INT) {
+ STRING *s;
+ s = string_make(interpreter, &$1, (UINTVAL)1, NULL, 0, NULL);
+ *(char *)s->bufstart = $2;
+ s->strlen = 1;
+ $1 = s;
+ goto NEXT();
+}
+
########################################
Index: t/op/string.t
===================================================================
RCS file: /cvs/public/parrot/t/op/string.t,v
retrieving revision 1.31
diff -u -r1.31 string.t
--- t/op/string.t 4 Sep 2002 13:49:55 -0000 1.31
+++ t/op/string.t 5 Sep 2002 14:32:53 -0000
@@ -1,6 +1,6 @@
#! perl -w
-use Parrot::Test tests => 91;
+use Parrot::Test tests => 94;
use Test::More;
output_is( <<'CODE', <<OUTPUT, "set_s_s|sc" );
@@ -1000,6 +1000,24 @@
set S0,"ab"
ord I0,S0,-3
print I0
+ end
+CODE
+
+output_is(<<'CODE',chr(32),'chr of 32 is space in ASCII');
+ chr S0, 32
+ print S0
+ end
+CODE
+
+output_is(<<'CODE',chr(65),'chr of 65 is A in ASCII');
+ chr S0, 65
+ print S0
+ end
+CODE
+
+output_is(<<'CODE',chr(122),'chr of 122 is z in ASCII');
+ chr S0, 122
+ print S0
end
CODE