Created
September 14, 2010 01:00
-
-
Save anonymous/578359 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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