Skip to content

Commit

Permalink
Start implementing Uni type and its subclasses.
Browse files Browse the repository at this point in the history
  • Loading branch information
jnthn committed Apr 8, 2015
1 parent 993c659 commit 3c96069
Show file tree
Hide file tree
Showing 2 changed files with 77 additions and 0 deletions.
76 changes: 76 additions & 0 deletions src/core/Uni.pm
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
my class NFC is repr('VMArray') is array_type(uint32) { ... }
my class NFD is repr('VMArray') is array_type(uint32) { ... }
my class NFKC is repr('VMArray') is array_type(uint32) { ... }
my class NFKD is repr('VMArray') is array_type(uint32) { ... }

my class Uni does Positional[uint32] does Stringy is repr('VMArray') is array_type(uint32) {
method new(*@codes) {
my $uni := nqp::create(self);
my int $n = @codes.elems;
loop (my int $i = 0; $i < $n; $i++) {
nqp::bindpos_i($uni, $i, @codes.AT-POS($i));
}
$uni
}

method list() {
gather {
my int $n = nqp::elems(self);
loop (my int $i = 0; $i < $n; $i++) {
take nqp::atpos_i(self, $i);
}
}
}

method Uni() {
self
}

method NFC() {
nqp::normalizecodes(self, nqp::const::NORMALIZE_NFC, nqp::create(NFC))
}

method NFD() {
nqp::normalizecodes(self, nqp::const::NORMALIZE_NFD, nqp::create(NFD))
}

method NFKC() {
nqp::normalizecodes(self, nqp::const::NORMALIZE_NFKC, nqp::create(NFKC))
}

method NFKD() {
nqp::normalizecodes(self, nqp::const::NORMALIZE_NFKD, nqp::create(NFKD))
}
}

my class NFD is Uni {
method new(|) {
die "Cannot create an NFD directly"; # XXX typed, better message
}

method NFD() { self }
}

my class NFC is Uni {
method new(|) {
die "Cannot create an NFD directly"; # XXX typed, better message
}

method NFC() { self }
}

my class NFKD is Uni {
method new(|) {
die "Cannot create an NFD directly"; # XXX typed, better message
}

method NFKD() { self }
}

my class NFKC is Uni {
method NFKC() { self }

method new(|) {
die "Cannot create an NFD directly"; # XXX typed, better message
}
}
1 change: 1 addition & 0 deletions tools/build/moar_core_sources
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ src/core/Order.pm
src/core/UInt64.pm
src/core/Num.pm
src/core/Buf.pm
src/core/Uni.pm
src/core/Str.pm
src/core/Capture.pm
src/core/Parcel.pm
Expand Down

0 comments on commit 3c96069

Please sign in to comment.