Skip to content

Instantly share code, notes, and snippets.

Created September 14, 2010 00:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anonymous/578339 to your computer and use it in GitHub Desktop.
Save anonymous/578339 to your computer and use it in GitHub Desktop.
pmichaud@plum:~/rakudo$ cat x
use MONKEY_TYPING;
augment class Buf {
multi method decode2($encoding = 'UTF-8') {
my @contents = @.contents;
my $str = ~Q:PIR {
$P0 = find_lex '@contents'
.local pmc bb
.local string s
bb = new ['ByteBuffer']
.local pmc it
.local int i
it = iter $P0
i = 0
loop:
unless it goto done
$P1 = shift it
$I1 = $P1
bb[i] = $I1
inc i
goto loop
done:
s = bb.'get_string_as'(utf8:unicode:"")
%r = box s
};
return $str;
}
}
my $buf = Buf.new(195, 182);
my $x = $buf.decode();
my $y = $buf.decode2();
say $x;
say $y;
say $x eq $y;
say "Parrot revision = $*VM<config><revision>";
say pir::encodingname__Si(pir::encoding__Is($x));
say pir::encodingname__Si(pir::encoding__Is($y));
pmichaud@plum:~/rakudo$ ./perl6 x
ö
ö
0
Parrot revision = 48982
ascii
utf8
pmichaud@plum:~/rakudo$
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment