Help language development. Donate to The Perl Foundation

uniname-words zef:lizmat last updated on 2022-09-26

bin/un
my %*SUB-MAIN-OPTS = :named-anywhere;

unit sub MAIN(
       *@strings,  #= one or more strings
  Bool :$hex,      #= show hex representation, default: no
  Bool :$name,     #= show name, default: no
  Bool :$char,     #= show the actual character, default: no
);

sub hex(        int $_) { .fmt: ' %X'                             }
sub name(       int $_) { "$_.uniname()\n"                        }
sub char(       int $_) { .chr ~ ' '                              }
sub namechar(   int $_) { "$_.uniname() $_.chr()\n"               }
sub hexname(    int $_) { "$_.fmt('%5X') $_.uniname()\n"          }
sub hexchar(    int $_) { "$_.fmt('%5X') $_.chr()\n"              }
sub hexnamechar(int $_) { "$_.fmt('%5X') $_.uniname() $_.chr()\n" }

my &mapper = &::(
  ("hex" if $hex) ~ ("name" if $name) ~ ("char" if $char)
) || &hexnamechar;

if @strings.map(*.comb.map(*.ords.Slip).Slip) -> @cp {
    print mapper($_) for @cp;
    print "\n";
}
else {
    note "un - Show unicode names of given strings.\n";
    note $*USAGE;
    note "\nDefaults to --hex --name --char if none of these specified.";
    exit 1;
}

# vim: expandtab shiftwidth=4