Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Also a few other goodies, such as the Stringy role. A bunch of tests now pass in t/spec/S32-str/encode.rakudo.
- Loading branch information
Carl Masak
committed
May 28, 2010
1 parent
63c5a5c
commit c5fdb17
Showing
4 changed files
with
72 additions
and
1 deletion.
There are no files selected for viewing
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
role Buf[::T = Int] does Stringy { | ||
has @.contents; | ||
|
||
multi method new(@contents) { | ||
self.bless(*, :contents(@contents.list)); | ||
} | ||
|
||
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 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; | ||
} | ||
|
||
multi method elems() { | ||
@.contents.elems; | ||
} | ||
} | ||
|
||
our multi sub infix:<eqv>(Buf $a, Buf $b) { | ||
return $a.contents ~~ $b.contents; | ||
} |
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
role Stringy { | ||
} |