Skip to content

Instantly share code, notes, and snippets.

@moritz
Last active February 25, 2017 20:49
Show Gist options
  • Save moritz/0e1d4968212a1b3ef5b23eb802b68481 to your computer and use it in GitHub Desktop.
Save moritz/0e1d4968212a1b3ef5b23eb802b68481 to your computer and use it in GitHub Desktop.
moritz@pete:~/src/perl6book$ perl6 examples/uni.p6 dog
⺨ - U+02ea8 - CJK RADICAL DOG (2)
⽝ - U+02f5d - KANGXI RADICAL DOG (2)
🌭 - U+1f32d - HOT DOG (2)
🐕 - U+1f415 - DOG (2)
🐶 - U+1f436 - DOG FACE (2)
use v6;
sub width($codepoint) {
given uniprop($codepoint, 'East_Asian_Width') {
when 'W' { 2 }
when 'N' { 0 }
default { 1 }
}
}
sub format-codepoint(Int $codepoint) {
sprintf "%s - U+%05x - %s (%d)\n",
$codepoint.chr ~ ' ' x (3 - width($codepoint)),
$codepoint,
$codepoint.uniname, width($codepoint);
}
multi sub MAIN(Str $x where .chars == 1) {
print format-codepoint($x.ord);
}
multi sub MAIN($search is copy) {
$search.=uc;
for 1..0x10FFFF -> $codepoint {
with $codepoint.uniname.index($search) {
print format-codepoint($codepoint);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment