Created
April 17, 2021 10:36
-
-
Save dogbert17/cf91cd2b2f324164b4895b60857958d9 to your computer and use it in GitHub Desktop.
Double bogey
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Given a single character, output hex, char itself, name, and props | |
multi sub uni-gist(Str $char) { | |
my $props = ' [' ~ $char.uniprops ~ ']'; | |
($char, "U+" ~ $char.ord.fmt('%06X'), $char.uninames).join(' - ') ~ $props | |
} | |
multi sub uni-gist(Int $code) { | |
uni-gist($code.chr); | |
} | |
sub uni-search(@criteria) { | |
my $w = True; | |
my @strings; | |
my @regexes; | |
for @criteria -> $criteria { | |
if $criteria.starts-with('/') && $criteria.ends-with('/') { | |
my $re = $criteria.substr(1,$criteria.chars-2).fc; | |
if $w { | |
@regexes.push(/« <$re> »/); | |
} else { | |
@regexes.push(/<$re>/); | |
} | |
} else { | |
my $string = $criteria.fc; | |
if $w { | |
@regexes.push(/« <$string> »/); | |
} | |
@strings.push($string); | |
} | |
} | |
my $sieve = 0..0x10FFFF; | |
# If we can do a search by string first, do so - faster and trims the list for regexes | |
note "Strings = {@strings} ", @strings.elems; | |
hyper for @strings -> $criteria { $sieve .= grep({uniname($_).fc.contains($criteria)}) }; | |
hyper for @regexes -> $criteria { $sieve .= grep({uniname($_).fc ~~ $criteria}) }; | |
$sieve.sort.unique.map({say uni-gist $_}); | |
} | |
my @a = <cat eyes>; | |
uni-search(@a); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment