Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@dogbert17
Created April 17, 2021 10:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dogbert17/cf91cd2b2f324164b4895b60857958d9 to your computer and use it in GitHub Desktop.
Save dogbert17/cf91cd2b2f324164b4895b60857958d9 to your computer and use it in GitHub Desktop.
Double bogey
# 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