Last active
February 25, 2017 20:49
-
-
Save moritz/0e1d4968212a1b3ef5b23eb802b68481 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
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) |
This file contains hidden or 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
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