Skip to content

Commit

Permalink
Move unicodey bits from Int / Cool
Browse files Browse the repository at this point in the history
No functinal changes should have occurred here.
  • Loading branch information
lizmat committed Mar 31, 2021
1 parent 9f73552 commit 009d90b
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 33 deletions.
14 changes: 0 additions & 14 deletions src/core.c/Cool.pm6
Original file line number Diff line number Diff line change
Expand Up @@ -95,20 +95,6 @@ my class Cool { # declared in BOOTSTRAP

method wordcase() { self.Str.wordcase }

method uniname() { uniname(self) }
method uninames() { uninames(self) }

proto method unival() is pure {*}
multi method unival(Cool:D:) { self.Int.unival }

method univals(Cool:D:) { self.Str.univals }
method uniprop(|c) { uniprop(self, |c) }
method uniprop-int(|c) { uniprop-int(self, |c) }
method uniprop-bool(|c) { uniprop-bool(self, |c) }
method uniprop-str(|c) { uniprop-str(self, |c) }
method uniprops(|c) { uniprops(self, |c) }
method unimatch(|c) { unimatch(self, |c) }

method chomp(Cool:D:) { self.Str.chomp }

proto method chop(|) {*}
Expand Down
16 changes: 0 additions & 16 deletions src/core.c/Int.pm6
Original file line number Diff line number Diff line change
Expand Up @@ -246,22 +246,6 @@ my class Int does Real { # declared in BOOTSTRAP
}
}
}

my constant $nuprop = nqp::unipropcode("Numeric_Value_Numerator");
my constant $deprop = nqp::unipropcode("Numeric_Value_Denominator");
multi method unival(Int:D:) {
nqp::isge_I(self,0) # valid?
&& nqp::chars(my str $de = nqp::getuniprop_str(self,$deprop))
?? nqp::iseq_s($de,"NaN") # some string to work with
?? NaN # no value found
!! nqp::iseq_s($de,"1") # some value
?? nqp::coerce_si(nqp::getuniprop_str(self,$nuprop))
!! Rat.new(
nqp::coerce_si(nqp::getuniprop_str(self,$nuprop)),
nqp::coerce_si($de)
)
!! Nil # not valid, so no value
}
}

multi sub prefix:<++>(Int:D $a is rw --> Int:D) {
Expand Down
40 changes: 37 additions & 3 deletions src/core.c/unicodey.pm6
Original file line number Diff line number Diff line change
@@ -1,3 +1,37 @@
augment class Cool {
method uniname() { uniname(self) }
method uninames() { uninames(self) }

proto method unival() is pure {*}
multi method unival(Cool:D:) { self.Int.unival }

method univals(Cool:D:) { self.Str.univals }
method uniprop(|c) { uniprop(self, |c) }
method uniprop-int(|c) { uniprop-int(self, |c) }
method uniprop-bool(|c) { uniprop-bool(self, |c) }
method uniprop-str(|c) { uniprop-str(self, |c) }
method uniprops(|c) { uniprops(self, |c) }
method unimatch(|c) { unimatch(self, |c) }
}

augment class Int {
my constant $nuprop = nqp::unipropcode("Numeric_Value_Numerator");
my constant $deprop = nqp::unipropcode("Numeric_Value_Denominator");
multi method unival(Int:D:) {
nqp::isge_I(self,0) # valid?
&& nqp::chars(my str $de = nqp::getuniprop_str(self,$deprop))
?? nqp::iseq_s($de,"NaN") # some string to work with
?? NaN # no value found
!! nqp::iseq_s($de,"1") # some value
?? nqp::coerce_si(nqp::getuniprop_str(self,$nuprop))
!! Rat.new(
nqp::coerce_si(nqp::getuniprop_str(self,$nuprop)),
nqp::coerce_si($de)
)
!! Nil # not valid, so no value
}
}

augment class Str {

#?if !jvm
Expand Down Expand Up @@ -75,6 +109,9 @@ multi sub uniname(Int:D $code) { nqp::getuniname($code) }
proto sub uninames($, *%) {*}
multi sub uninames(Str:D $str) { $str.NFC.map: { uniname($_) } }

proto sub unival($, *%) is pure {*}
proto sub univals($, *%) {*}

#?if jvm
multi sub unival(|) { die 'unival NYI on jvm backend' }
multi sub univals(|) { die 'univals NYI on jvm backend' }
Expand All @@ -98,10 +135,7 @@ multi sub unimatch(|) { die 'unimatch NYI on js backend' }
#?endif

#?if !jvm
proto sub unival($, *%) is pure {*}
multi sub unival(\what) { what.unival }

proto sub univals($, *%) {*}
multi sub univals(Str:D $str) { $str.univals }
#?endif

Expand Down

0 comments on commit 009d90b

Please sign in to comment.