Created
September 13, 2010 23:57
-
-
Save anonymous/578279 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$ 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>"; | |
pmichaud@plum:~/rakudo$ ./perl6 x | |
ö | |
ö | |
0 | |
Parrot revision = 48982 | |
pmichaud@plum:~/rakudo$ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment