Skip to content

Commit

Permalink
Implement array indexing on Uni.
Browse files Browse the repository at this point in the history
  • Loading branch information
jnthn committed Apr 24, 2015
1 parent 27dfc5e commit 5615b7d
Showing 1 changed file with 27 additions and 0 deletions.
27 changes: 27 additions & 0 deletions src/core/Uni.pm
Expand Up @@ -47,6 +47,33 @@ my class Uni does Positional[uint32] does Stringy is repr('VMArray') is array_ty
}

method codes() { nqp::elems(self) }

multi method EXISTS-POS(Uni:D: int \pos) {
nqp::p6bool(
nqp::islt_i(pos,nqp::elems(self)) && nqp::isge_i(pos,0)
);
}
multi method EXISTS-POS(Uni:D: Int:D \pos) {
pos < nqp::elems(self) && pos >= 0;
}

multi method AT-POS(Uni:D: int \pos) {
fail X::OutOfRange.new(
:what<Index>,
:got(pos),
:range("0..{nqp::elems(self)-1}")
) if nqp::isge_i(pos,nqp::elems(self)) || nqp::islt_i(pos,0);
nqp::atpos_i(self, pos);
}
multi method AT-POS(Uni:D: Int:D \pos) {
my int $pos = nqp::unbox_i(pos);
fail X::OutOfRange.new(
:what<Index>,
:got(pos),
:range("0..{nqp::elems(self)-1}")
) if nqp::isge_i($pos,nqp::elems(self)) || nqp::islt_i($pos,0);
nqp::atpos_i(self,$pos);
}
}

my class NFD is Uni {
Expand Down

0 comments on commit 5615b7d

Please sign in to comment.