Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
implement rudimentary uniname, uniprop, and unival
  • Loading branch information
TimToady committed Mar 4, 2014
1 parent fc2a6e6 commit 5f45799
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions src/core/Str.pm
Expand Up @@ -1191,4 +1191,28 @@ sub substr-rw($s is rw, $from = 0, $chars = $s.chars - $from) {
);
}

# These probably belong in a separate unicodey file

multi uniname(|) {*}
multi uniname(Str $char) { uniname($char.ord) }
multi uniname(Int $codepoint) { nqp::getuniname($codepoint) }

multi uniprop(|) {*}
multi uniprop(Str $char, Stringy $propname) { uniprop($char.ord, $propname) }
multi uniprop(Int $codepoint, Stringy $propname) {
my int $cat = nqp::unipropcode($propname);
my int $val = nqp::unipvalcode($cat, $propname);
my $str = nqp::getuniprop_str($codepoint,$cat,$val);
$str //= nqp::getuniprop_int($codepoint,$cat,$val);
$str;
}

multi unival(|) {*}
multi unival(Str $char) { unival($char.ord) }
multi unival(Int $codepoint) {
my $nu = uniprop $codepoint, "NumericValueNumerator";
my $de = uniprop $codepoint, "NumericValueDenominator";
$de eq '1' ?? $nu.Int !! $nu / $de;
}

# vim: ft=perl6 expandtab sw=4

0 comments on commit 5f45799

Please sign in to comment.