Skip to content

Commit

Permalink
Make Str.ord/ords NFC based on Moar
Browse files Browse the repository at this point in the history
  • Loading branch information
lizmat committed Nov 4, 2015
1 parent c206f8a commit 3f2d858
Showing 1 changed file with 28 additions and 5 deletions.
33 changes: 28 additions & 5 deletions src/core/Str.pm
Expand Up @@ -648,6 +648,27 @@ my class Str does Stringy { # declared in BOOTSTRAP
}
}

#?if moar
method ords(Str:D:) {
Seq.new(class :: does Iterator {
has $!nfc;
has int $!elems;
has int $!pos;
method BUILD(\string) {
$!nfc = string.NFC;
$!elems = $!nfc.elems;
self
}
method new(\string) { nqp::create(self).BUILD(string) }
method pull-one() {
$!pos < $!elems
?? nqp::p6box_i($!nfc.AT-POS($!pos++))
!! IterationEnd
}
}.new(self));
}
#?endif
#?if !moar
method ords(Str:D:) {
Seq.new(class :: does ProcessStr {
has int $!pos;
Expand All @@ -658,6 +679,7 @@ my class Str does Stringy { # declared in BOOTSTRAP
}
}.new(self));
}
#?endif

# constant ???
my str $CRLF = "\r\n";
Expand Down Expand Up @@ -1644,16 +1666,17 @@ my class Str does Stringy { # declared in BOOTSTRAP
}

proto method ord(|) { * }
#?if moar
multi method ord(Str:D:) returns Int { self.NFC.AT-POS(0) }
#?endif
#?if !moar
multi method ord(Str:D:) returns Int {
nqp::chars($!value)
?? nqp::p6box_i(nqp::ord($!value))
!! Int;
}
multi method ord(Str:U:) {
self.Str;
Int
}

#?endif
multi method ord(Str:U:) returns Int { Int }
}


Expand Down

0 comments on commit 3f2d858

Please sign in to comment.