Last active
March 15, 2018 08:27
-
-
Save samcv/ae09060a781bb4c36ae6cac80ea9325f to your computer and use it in GitHub Desktop.
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
sub MAIN { | |
use Test; | |
my $char = 'a'; | |
my @result = what-matches($char); | |
for @result { | |
ok EVAL("'$char' ~~ /$_/"), "$char ~~ /$_/"; | |
} | |
} | |
use nqp; | |
sub what-matches (Str:D $chr) { | |
my @result; | |
my %prefs = prefs(); | |
for %prefs.keys -> $key { | |
given %prefs{$key} { | |
when 'S' { | |
my $propval = $chr.uniprop($key); | |
if $key eq 'Block' { | |
@result.push: "<:In" ~ $propval.trans(' ' => '') ~ ">"; | |
} | |
elsif $propval { | |
@result.push: "<:" ~ $key ~ "<" ~ $chr.uniprop($key) ~ ">>"; | |
} | |
} | |
when 'I' { | |
@result.push: "<:" ~ $key ~ "<" ~ $chr.uniprop($key) ~ ">>"; | |
} | |
when 'B' { | |
@result.push: ($chr.uniprop($key) ?? "<:$key>" !! "<:!$key>"); | |
} | |
} | |
} | |
@result; | |
} | |
sub prefs { | |
my %prefs = nqp::hash( | |
'Other_Grapheme_Extend','B','Titlecase_Mapping','tc','Dash','B', | |
'Emoji_Modifier_Base','B','Emoji_Modifier','B','Pattern_Syntax','B', | |
'IDS_Trinary_Operator','B','ID_Continue','B','Diacritic','B','Cased','B', | |
'Hangul_Syllable_Type','S','Quotation_Mark','B','Radical','B', | |
'NFD_Quick_Check','S','Joining_Type','S','Case_Folding','S','Script','S', | |
'Soft_Dotted','B','Changes_When_Casemapped','B','Simple_Case_Folding','S', | |
'ISO_Comment','S','Lowercase','B','Join_Control','B','Bidi_Class','S', | |
'Joining_Group','S','Decomposition_Mapping','S','Lowercase_Mapping','lc', | |
'NFKC_Casefold','S','Simple_Lowercase_Mapping','S', | |
'Indic_Syllabic_Category','S','Expands_On_NFC','B','Expands_On_NFD','B', | |
'Uppercase','B','White_Space','B','Sentence_Terminal','B', | |
'NFKD_Quick_Check','S','Changes_When_Titlecased','B','Math','B', | |
'Uppercase_Mapping','uc','NFKC_Quick_Check','S','Sentence_Break','S', | |
'Simple_Titlecase_Mapping','S','Alphabetic','B','Composition_Exclusion','B', | |
'Noncharacter_Code_Point','B','Other_Alphabetic','B','XID_Continue','B', | |
'Age','S','Other_ID_Start','B','Unified_Ideograph','B','FC_NFKC_Closure','S', | |
'Case_Ignorable','B','Hyphen','B','Numeric_Value','nv', | |
'Changes_When_NFKC_Casefolded','B','Expands_On_NFKD','B', | |
'Indic_Positional_Category','S','Decomposition_Type','S','Bidi_Mirrored','B', | |
'Changes_When_Uppercased','B','ID_Start','B','Grapheme_Extend','B', | |
'XID_Start','B','Expands_On_NFKC','B','Other_Uppercase','B','Other_Math','B', | |
'Grapheme_Link','B','Bidi_Control','B','Default_Ignorable_Code_Point','B', | |
'Changes_When_Casefolded','B','Word_Break','S','NFC_Quick_Check','S', | |
'Other_Default_Ignorable_Code_Point','B','Logical_Order_Exception','B', | |
'Prepended_Concatenation_Mark','B','Other_Lowercase','B', | |
'Other_ID_Continue','B','Variation_Selector','B','Extender','B', | |
'Full_Composition_Exclusion','B','IDS_Binary_Operator','B','Numeric_Type','S', | |
'kCompatibilityVariant','S','Simple_Uppercase_Mapping','S', | |
'Terminal_Punctuation','B','Line_Break','S','East_Asian_Width','S', | |
'ASCII_Hex_Digit','B','Pattern_White_Space','B','Hex_Digit','B', | |
'Bidi_Paired_Bracket_Type','S','General_Category','S', | |
'Grapheme_Cluster_Break','S','Grapheme_Base','B','Name','na','Ideographic','B', | |
'Block','S','Emoji_Presentation','B','Emoji','B','Deprecated','B', | |
'Changes_When_Lowercased','B','Bidi_Mirroring_Glyph','bmg', | |
'Canonical_Combining_Class','S', | |
); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment