Skip to content

Instantly share code, notes, and snippets.

Created September 14, 2010 01:00
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/578359 to your computer and use it in GitHub Desktop.
Save anonymous/578359 to your computer and use it in GitHub Desktop.
pmichaud@plum:~/rakudo$ head -36 src/core/Buf.pm
role Buf[::T = Int] does Stringy does Positional {
has T @.contents;
multi method new(*@contents) {
self.bless(*, :contents(@contents.list));
}
multi method decode($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:"")
$I0 = encoding s
$S0 = encodingname $I0
say $S0
%r = box s
};
return $str;
}
pmichaud@plum:~/rakudo$ cat z
my $buf = Buf.new(195, 182);
my $x = $buf.decode;
say $x;
pmichaud@plum:~/rakudo$ ./perl6 z
ascii
ö
pmichaud@plum:~/rakudo$
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment