Skip to content

Instantly share code, notes, and snippets.

@masak
Created May 28, 2010 10:24
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 masak/417012 to your computer and use it in GitHub Desktop.
Save masak/417012 to your computer and use it in GitHub Desktop.
multi method decode($encoding = 'UTF-8') {
my @contents = @.contents;
my $str = ~Q:PIR {
$P0 = find_lex '@contents'
.local pmc iterator
iterator = iter $P0
.local pmc sb
sb = new 'StringBuilder'
sb = unicode:""
loop:
unless iterator goto done
$P1 = shift iterator
$I1 = $P1
$S1 = chr $I1
sb .= $S1
goto loop
done:
%r = sb
};
return $str;
}
1..10
ok 1 - $str.encode returns a Buf
ok 2 - encoding to ASCII
ok 3 - right length of Buf
ok 4 - # SKIP Parrot breaks on this
ok 5 - right length of Buf
ok 6 - # SKIP Parrot breaks when fed non-ASCII
perl6(75961) malloc: *** error for object 0x106c355c8: pointer being reallocated was not allocated
*** set a breakpoint in malloc_error_break to debug
Abort trap
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment