| 1 | 1 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 2 | 1 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 3 | package App::Uni 9.006; | ||||||||||||||||||||||||||||||||||||||||||||||||
| 4 | # ABSTRACT: command-line utility to find or display Unicode characters | ||||||||||||||||||||||||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 6 | #pod =encoding utf8 | ||||||||||||||||||||||||||||||||||||||||||||||||
| 7 | #pod | ||||||||||||||||||||||||||||||||||||||||||||||||
| 8 | #pod =head1 NAME | ||||||||||||||||||||||||||||||||||||||||||||||||
| 9 | #pod | ||||||||||||||||||||||||||||||||||||||||||||||||
| 10 | #pod App::Uni - Command-line utility to grep UnicodeData.txt | ||||||||||||||||||||||||||||||||||||||||||||||||
| 11 | #pod | ||||||||||||||||||||||||||||||||||||||||||||||||
| 12 | #pod =head1 SYNOPSIS | ||||||||||||||||||||||||||||||||||||||||||||||||
| 13 | #pod | ||||||||||||||||||||||||||||||||||||||||||||||||
| 14 | #pod $ uni smiling face | ||||||||||||||||||||||||||||||||||||||||||||||||
| 15 | #pod 263A ☺ WHITE SMILING FACE | ||||||||||||||||||||||||||||||||||||||||||||||||
| 16 | #pod 263B ☻ BLACK SMILING FACE | ||||||||||||||||||||||||||||||||||||||||||||||||
| 17 | #pod | ||||||||||||||||||||||||||||||||||||||||||||||||
| 18 | #pod $ uni ☺ | ||||||||||||||||||||||||||||||||||||||||||||||||
| 19 | #pod 263A ☺ WHITE SMILING FACE | ||||||||||||||||||||||||||||||||||||||||||||||||
| 20 | #pod | ||||||||||||||||||||||||||||||||||||||||||||||||
| 21 | #pod # Only on Perl 5.14+ | ||||||||||||||||||||||||||||||||||||||||||||||||
| 22 | #pod $ uni wry | ||||||||||||||||||||||||||||||||||||||||||||||||
| 23 | #pod 1F63C <U+1F63C> CAT FACE WITH WRY SMILE | ||||||||||||||||||||||||||||||||||||||||||||||||
| 24 | #pod | ||||||||||||||||||||||||||||||||||||||||||||||||
| 25 | #pod =head1 DESCRIPTION | ||||||||||||||||||||||||||||||||||||||||||||||||
| 26 | #pod | ||||||||||||||||||||||||||||||||||||||||||||||||
| 27 | #pod This module installs a simple program, F<uni>, that helps grepping through | ||||||||||||||||||||||||||||||||||||||||||||||||
| 28 | #pod the Unicode database included in the current Perl 5 installation. | ||||||||||||||||||||||||||||||||||||||||||||||||
| 29 | #pod | ||||||||||||||||||||||||||||||||||||||||||||||||
| 30 | #pod For information on how to use F<uni> consult the L<uni> documentation. | ||||||||||||||||||||||||||||||||||||||||||||||||
| 31 | #pod | ||||||||||||||||||||||||||||||||||||||||||||||||
| 32 | #pod =head1 ACKNOWLEDGEMENTS | ||||||||||||||||||||||||||||||||||||||||||||||||
| 33 | #pod | ||||||||||||||||||||||||||||||||||||||||||||||||
| 34 | #pod This is a re-implementation of a program written by Audrey Tang in Taiwan. I | ||||||||||||||||||||||||||||||||||||||||||||||||
| 35 | #pod used that program for years before deciding I wanted to add a few features, | ||||||||||||||||||||||||||||||||||||||||||||||||
| 36 | #pod which I did by rewriting from scratch. | ||||||||||||||||||||||||||||||||||||||||||||||||
| 37 | #pod | ||||||||||||||||||||||||||||||||||||||||||||||||
| 38 | #pod That program, in turn, was a re-implementation of a same-named program Larry | ||||||||||||||||||||||||||||||||||||||||||||||||
| 39 | #pod copied to me, which accompanied Audrey for years. However, that program was | ||||||||||||||||||||||||||||||||||||||||||||||||
| 40 | #pod lost during a hard disk failure, so she coded it up from memory. | ||||||||||||||||||||||||||||||||||||||||||||||||
| 41 | #pod | ||||||||||||||||||||||||||||||||||||||||||||||||
| 42 | #pod Thank-you, Larry, for everything. ♡ | ||||||||||||||||||||||||||||||||||||||||||||||||
| 43 | #pod | ||||||||||||||||||||||||||||||||||||||||||||||||
| 44 | #pod =cut | ||||||||||||||||||||||||||||||||||||||||||||||||
| 45 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 46 | 1 | ▶ | use 5.10.0; # for \v | ||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 47 | 1 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 48 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 49 | 1 | ▶ | use charnames (); | ||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 50 | 1 | ▶ | use Encode qw(encode_utf8); | ||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 51 | 1 | ▶ | use Getopt::Long; | ||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 52 | 1 | ▶ | use List::Util qw(max); | ||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 53 | 1 | ▶ | use Unicode::GCString; | ||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 54 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 55 | 0 | ▶ | sub _do_help { | ||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_do_help: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 56 | 0 | my $class = shift; | |||||||||||||||||||||||||||||||||||||||||||||||
| 57 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 58 | 0 | ▶ | die | ||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 59 | join qq{\n }, join(qq{\n}, @_, @_ ? "" : (), "usage:"), | ||||||||||||||||||||||||||||||||||||||||||||||||
| 60 | "uni SEARCH-TERMS... - find codepoints with matching names or values", | ||||||||||||||||||||||||||||||||||||||||||||||||
| 61 | "uni [-s] ONE-CHARACTER - print the codepoint and name of one character", | ||||||||||||||||||||||||||||||||||||||||||||||||
| 62 | "uni -n SEARCH-TERMS... - find codepoints with matching names", | ||||||||||||||||||||||||||||||||||||||||||||||||
| 63 | "uni -c STRINGS... - print out the codepoints in a string", | ||||||||||||||||||||||||||||||||||||||||||||||||
| 64 | "uni -u CODEPOINTS... - look up and print hex codepoints", | ||||||||||||||||||||||||||||||||||||||||||||||||
| 65 | "uni -x HEX-OCTETS... - given the sequence of octets, in hex, decode", | ||||||||||||||||||||||||||||||||||||||||||||||||
| 66 | "", | ||||||||||||||||||||||||||||||||||||||||||||||||
| 67 | "Other switches:", | ||||||||||||||||||||||||||||||||||||||||||||||||
| 68 | " -8 - also show the UTF-8 bytes to encode\n"; | ||||||||||||||||||||||||||||||||||||||||||||||||
| 69 | } | ||||||||||||||||||||||||||||||||||||||||||||||||
| 70 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 71 | 1 | ▶ | sub run { | ||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
run: called CC=11 SCAR=26.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 72 | 1 | my ($class, @argv) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||
| 73 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 74 | 1 | my %opt; | |||||||||||||||||||||||||||||||||||||||||||||||
| 75 | { | ||||||||||||||||||||||||||||||||||||||||||||||||
| 76 | 1 | my $exit; | |||||||||||||||||||||||||||||||||||||||||||||||
| 77 | 1 | local @ARGV = @argv; | |||||||||||||||||||||||||||||||||||||||||||||||
| 78 | GetOptions( | ||||||||||||||||||||||||||||||||||||||||||||||||
| 79 | "c" => \$opt{explode}, | ||||||||||||||||||||||||||||||||||||||||||||||||
| 80 | "u" => \$opt{u_numbers}, | ||||||||||||||||||||||||||||||||||||||||||||||||
| 81 | "n" => \$opt{names}, | ||||||||||||||||||||||||||||||||||||||||||||||||
| 82 | "s" => \$opt{single}, | ||||||||||||||||||||||||||||||||||||||||||||||||
| 83 | "x" => \$opt{hex_octets}, | ||||||||||||||||||||||||||||||||||||||||||||||||
| 84 | "8" => \$opt{utf8}, | ||||||||||||||||||||||||||||||||||||||||||||||||
| 85 | "help|?" => \$opt{help}, | ||||||||||||||||||||||||||||||||||||||||||||||||
| 86 | 1 | ); | |||||||||||||||||||||||||||||||||||||||||||||||
| 87 | 1 | @argv = @ARGV; | |||||||||||||||||||||||||||||||||||||||||||||||
| 88 | } | ||||||||||||||||||||||||||||||||||||||||||||||||
| 89 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 90 | 1 | ▶ | $class->_do_help if $opt{help}; | ||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 91 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 92 | 1 | my $n = grep { $_ } @opt{qw(explode u_numbers names single hex_octets)}; | |||||||||||||||||||||||||||||||||||||||||||||||
| 93 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 94 | 1 | ▶ | $class->_do_help("ERROR: only one mode switch allowed!") if $n > 1; | ||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 95 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 96 | 1 | ▶ | $class->_do_help if ! @argv; | ||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 97 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 98 | my $todo = $opt{explode} ? \&do_explode | ||||||||||||||||||||||||||||||||||||||||||||||||
| 99 | : $opt{u_numbers} ? \&do_u_numbers | ||||||||||||||||||||||||||||||||||||||||||||||||
| 100 | : $opt{names} ? \&do_names | ||||||||||||||||||||||||||||||||||||||||||||||||
| 101 | : $opt{single} ? \&do_single | ||||||||||||||||||||||||||||||||||||||||||||||||
| 102 | 1 | ▶ | : $opt{hex_octets} ? \&do_hex_octets | ||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 6 branches
Condition33%1/3
@argv == 1 and length $argv[0] == 1
MC/DC0%0/2
@argv == 1 and length $argv[0] == 1
@argv == 1
length $argv[0] == 1
Truth table33%1/3
A and B
A= @argv == 1B= length $argv[0] == 1
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 103 | : @argv == 1 && length $argv[0] == 1 ? \&do_single | ||||||||||||||||||||||||||||||||||||||||||||||||
| 104 | : \&do_dwim; | ||||||||||||||||||||||||||||||||||||||||||||||||
| 105 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 106 | 1 | $todo->(\@argv, \%opt); | |||||||||||||||||||||||||||||||||||||||||||||||
| 107 | } | ||||||||||||||||||||||||||||||||||||||||||||||||
| 108 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 109 | 0 | ▶ | sub do_single { | ||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
do_single: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 110 | 0 | my @chars = grep { length } @{ $_[0] }; | |||||||||||||||||||||||||||||||||||||||||||||||
| 111 | 0 | ▶ | if (my @too_long = grep { length > 1 } @chars) { | ||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 112 | 0 | die "some arguments were too long for use with -s: @too_long\n"; | |||||||||||||||||||||||||||||||||||||||||||||||
| 113 | } | ||||||||||||||||||||||||||||||||||||||||||||||||
| 114 | 0 | print_chars(\@chars, $_[1]); | |||||||||||||||||||||||||||||||||||||||||||||||
| 115 | } | ||||||||||||||||||||||||||||||||||||||||||||||||
| 116 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 117 | 0 | ▶ | sub do_explode { | ||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
do_explode: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 118 | 0 | print_chars( explode_strings($_[0]), $_[1] ); | |||||||||||||||||||||||||||||||||||||||||||||||
| 119 | } | ||||||||||||||||||||||||||||||||||||||||||||||||
| 120 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 121 | 0 | ▶ | sub do_hex_octets { | ||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
do_hex_octets: not called CC=5 SCAR=34.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 122 | 0 | my $string = ''; | |||||||||||||||||||||||||||||||||||||||||||||||
| 123 | 0 | for my $hunk (@{ $_[0] }) { | |||||||||||||||||||||||||||||||||||||||||||||||
| 124 | 0 | ▶ | die "input hunk $hunk is not an even-length hex string\n" | ||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$hunk =~ /\A[0-9A-F]+\z/i and length($hunk) % 2 == 0
MC/DC0%0/2
$hunk =~ /\A[0-9A-F]+\z/i and length($hunk) % 2 == 0
$hunk =~ /\A[0-9A-F]+\z/i
length($hunk) % 2 == 0
Truth table0%0/3
A and B
A= $hunk =~ /\A[0-9A-F]+\z/iB= length($hunk) % 2 == 0
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 125 | unless $hunk =~ /\A[0-9A-F]+\z/i && length($hunk) % 2 == 0; | ||||||||||||||||||||||||||||||||||||||||||||||||
| 126 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 127 | 0 | $string .= chr oct "0x$_" for $hunk =~ /(..)/g; | |||||||||||||||||||||||||||||||||||||||||||||||
| 128 | } | ||||||||||||||||||||||||||||||||||||||||||||||||
| 129 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 130 | 0 | print_chars( explode_strings([ Encode::decode_utf8($string) ], $_[1]) ); | |||||||||||||||||||||||||||||||||||||||||||||||
| 131 | } | ||||||||||||||||||||||||||||||||||||||||||||||||
| 132 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 133 | 0 | ▶ | sub explode_strings { | ||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
explode_strings: not called CC=3 SCAR=24.8
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 134 | 0 | my ($strings) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||
| 135 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 136 | 0 | my @chars; | |||||||||||||||||||||||||||||||||||||||||||||||
| 137 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 138 | 0 | ▶ | while (my $str = shift @$strings) { | ||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 139 | 0 | push @chars, split '', $str; | |||||||||||||||||||||||||||||||||||||||||||||||
| 140 | 0 | ▶ | push @chars, undef if @$strings; | ||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 141 | } | ||||||||||||||||||||||||||||||||||||||||||||||||
| 142 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 143 | 0 | return \@chars; | |||||||||||||||||||||||||||||||||||||||||||||||
| 144 | } | ||||||||||||||||||||||||||||||||||||||||||||||||
| 145 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 146 | 0 | ▶ | sub do_u_numbers { | ||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
do_u_numbers: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 147 | 0 | print_chars( chars_by_u_numbers($_[0]), $_[1] ); | |||||||||||||||||||||||||||||||||||||||||||||||
| 148 | } | ||||||||||||||||||||||||||||||||||||||||||||||||
| 149 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 150 | 1 | ▶ | sub print_chars { | ||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
print_chars: called CC=11 SCAR=31.4
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 151 | 1 | my ($chars, $opt) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||
| 152 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 153 | my @to_print = $opt->{utf8} | ||||||||||||||||||||||||||||||||||||||||||||||||
| 154 | 0 | ▶ | ? (map {; [ $_ => defined && encode_utf8($_) ] } @$chars) | ||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/3
defined $_ && &encode_utf8($_)
MC/DC0%0/2
defined $_ && &encode_utf8($_)
defined $_
&encode_utf8($_)
Truth table0%0/3
A && B
A= defined $_B= &encode_utf8($_)
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 155 | 1 | ▶ | : (map {; [ $_ ] } @$chars); | ||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 156 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 157 | 1 | my $width; | |||||||||||||||||||||||||||||||||||||||||||||||
| 158 | 1 | ▶ | if ($opt->{utf8}) { | ||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 159 | 0 | my $max_bytes = 0; | |||||||||||||||||||||||||||||||||||||||||||||||
| 160 | 0 | for my $todo (@to_print) { | |||||||||||||||||||||||||||||||||||||||||||||||
| 161 | 0 | $max_bytes = max($max_bytes, length $todo->[1]); | |||||||||||||||||||||||||||||||||||||||||||||||
| 162 | 0 | ▶ | last if $max_bytes == 4; # maximum ever | ||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 163 | } | ||||||||||||||||||||||||||||||||||||||||||||||||
| 164 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 165 | 0 | $width = 2 * $max_bytes + $max_bytes - 1; | |||||||||||||||||||||||||||||||||||||||||||||||
| 166 | } | ||||||||||||||||||||||||||||||||||||||||||||||||
| 167 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 168 | 1 | for my $todo (@to_print) { | |||||||||||||||||||||||||||||||||||||||||||||||
| 169 | 22 | my ($c, $u) = @$todo; | |||||||||||||||||||||||||||||||||||||||||||||||
| 170 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 171 | 0 | ▶ | unless (defined $c) { print "\n"; next } | ||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 172 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 173 | # U+25CC DOTTED CIRCLE | ||||||||||||||||||||||||||||||||||||||||||||||||
| 174 | 22 | ▶ | my $c2 = Unicode::GCString->new( | ||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 175 | $c =~ /\pM/ ? "\x{25CC}$c" : $c | ||||||||||||||||||||||||||||||||||||||||||||||||
| 176 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||
| 177 | 22 | my $l = $c2->columns; | |||||||||||||||||||||||||||||||||||||||||||||||
| 178 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 179 | # I'm not 100% sure why I need this in all cases. It would make sense in | ||||||||||||||||||||||||||||||||||||||||||||||||
| 180 | # some, since for example COMBINING GRAVE beginning a line becomes its | ||||||||||||||||||||||||||||||||||||||||||||||||
| 181 | # own extended grapheme cluster (right?), but why does INVISIBLE TIMES at | ||||||||||||||||||||||||||||||||||||||||||||||||
| 182 | # the beginning of a line take up a column despite being printing width | ||||||||||||||||||||||||||||||||||||||||||||||||
| 183 | # zero? The world may never know. Until Tom tells me. | ||||||||||||||||||||||||||||||||||||||||||||||||
| 184 | # -- rjbs, 2014-10-04 | ||||||||||||||||||||||||||||||||||||||||||||||||
| 185 | 22 | ▶ | $l = 1 if $l == 0; # ??? | ||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 186 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 187 | # Yeah, probably there's some insane %*0s$ invocation of printf to use | ||||||||||||||||||||||||||||||||||||||||||||||||
| 188 | # here, but... just no. -- rjbs, 2014-10-04 | ||||||||||||||||||||||||||||||||||||||||||||||||
| 189 | 22 | (my $p = "$c2") =~ s/\v/ /g; | |||||||||||||||||||||||||||||||||||||||||||||||
| 190 | 22 | $p .= (' ' x (2 - $l)); | |||||||||||||||||||||||||||||||||||||||||||||||
| 191 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 192 | 22 | my $chr = ord($c); | |||||||||||||||||||||||||||||||||||||||||||||||
| 193 | 22 | my $name = charnames::viacode($chr); | |||||||||||||||||||||||||||||||||||||||||||||||
| 194 | my $utf8 = $opt->{utf8} | ||||||||||||||||||||||||||||||||||||||||||||||||
| 195 | ? (sprintf " - %${width}s", | ||||||||||||||||||||||||||||||||||||||||||||||||
| 196 | 0 | ▶ | join q{ }, map {; sprintf '%02X', ord } split //, $u) | ||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 197 | : ''; | ||||||||||||||||||||||||||||||||||||||||||||||||
| 198 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 199 | 22 | printf "%s- U+%05X%s - %s\n", $p, $chr, $utf8, $name; | |||||||||||||||||||||||||||||||||||||||||||||||
| 200 | } | ||||||||||||||||||||||||||||||||||||||||||||||||
| 201 | } | ||||||||||||||||||||||||||||||||||||||||||||||||
| 202 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 203 | 0 | ▶ | sub chars_by_u_numbers { | ||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
chars_by_u_numbers: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 204 | 0 | my ($points) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||
| 205 | 0 | my @chars = map {; /\A(?:u\+)?(.+)/; chr hex $1 } @$points; | |||||||||||||||||||||||||||||||||||||||||||||||
| 206 | 0 | return \@chars; | |||||||||||||||||||||||||||||||||||||||||||||||
| 207 | } | ||||||||||||||||||||||||||||||||||||||||||||||||
| 208 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 209 | 0 | ▶ | sub do_names { | ||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
do_names: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 210 | 0 | my ($terms, $opt) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||
| 211 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 212 | 0 | print_chars( chars_by_name( $terms ), $opt ); | |||||||||||||||||||||||||||||||||||||||||||||||
| 213 | } | ||||||||||||||||||||||||||||||||||||||||||||||||
| 214 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 215 | 1 | ▶ | sub chars_by_name { | ||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
chars_by_name: called CC=17 SCAR=32.6
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 216 | 1 | my ($input_terms, $arg) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||
| 217 | 1 | ▶ | my @terms = map {; { pattern => s{\A/(.+)/\z}{$1} ? qr/$_/i : qr/\b$_\b/i } } | ||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 218 | @$input_terms; | ||||||||||||||||||||||||||||||||||||||||||||||||
| 219 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 220 | 1 | ▶ | if ($arg && $arg->{match_codepoints}) { | ||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$arg and $arg->{"match_codepoints"}
MC/DC0%0/2
$arg and $arg->{"match_codepoints"}
$arg
$arg->{"match_codepoints"}
Truth table33%1/3
A and B
A= $argB= $arg->{"match_codepoints"}
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 221 | 1 | for (0 .. $#terms) { | |||||||||||||||||||||||||||||||||||||||||||||||
| 222 | 2 | ▶ | $terms[$_]{ord} = hex $input_terms->[$_] | ||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 223 | if $input_terms->[$_] =~ /\A[0-9A-Fa-f]+\z/; | ||||||||||||||||||||||||||||||||||||||||||||||||
| 224 | } | ||||||||||||||||||||||||||||||||||||||||||||||||
| 225 | } | ||||||||||||||||||||||||||||||||||||||||||||||||
| 226 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 227 | 1 | state $corpus = do 'unicore/Name.pl'; | |||||||||||||||||||||||||||||||||||||||||||||||
| 228 | 1 | ▶ | unless (defined $corpus) { | ||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 229 | 0 | ▶ | die "couldn't parse unicore/Name.pl: $@" if $@; | ||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 230 | 0 | ▶ | die "couldn't read unicore/Name.pl: $!" if $!; | ||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 231 | 0 | die "unicore/Name.pl returned undef"; | |||||||||||||||||||||||||||||||||||||||||||||||
| 232 | } | ||||||||||||||||||||||||||||||||||||||||||||||||
| 233 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 234 | # https://github.com/perl/perl5/commit/b555069b72f93a232deba173dc7bf7892cfa5868 | ||||||||||||||||||||||||||||||||||||||||||||||||
| 235 | 1 | ▶ | my ($entry_sep, $field_sep) = "$]" >= 5.031010 ? ("\n\n", "\n") : ("\n", "\t"); | ||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 236 | 1 | my @entries = split $entry_sep, $corpus; | |||||||||||||||||||||||||||||||||||||||||||||||
| 237 | 1 | my @chars; | |||||||||||||||||||||||||||||||||||||||||||||||
| 238 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 239 | my %seen; | ||||||||||||||||||||||||||||||||||||||||||||||||
| 240 | 1 | ENTRY: for my $entry (@entries) { | |||||||||||||||||||||||||||||||||||||||||||||||
| 241 | 35540 | my $i = index($entry, $field_sep); | |||||||||||||||||||||||||||||||||||||||||||||||
| 242 | 35540 | ▶ | next if rindex($entry, " ", $i) >= 0; # no sequences | ||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 243 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 244 | 35079 | my $name = substr($entry, $i+1); | |||||||||||||||||||||||||||||||||||||||||||||||
| 245 | 35079 | my $ord = hex substr($entry, 0, $i); | |||||||||||||||||||||||||||||||||||||||||||||||
| 246 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 247 | 35079 | for (@terms) { | |||||||||||||||||||||||||||||||||||||||||||||||
| 248 | next ENTRY unless $name =~ $_->{pattern} | ||||||||||||||||||||||||||||||||||||||||||||||||
| 249 | 35101 | ▶ | or defined $_->{ord} && $_->{ord} == $ord; | ||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition50%3/6
$name =~ /$_->{"pattern"}/i or defined $_->{"ord"} and $_->{"ord"} == $ord
defined $_->{"ord"} and $_->{"ord"} == $ord
MC/DC33%1/3
$name =~ /$_->{"pattern"}/i or defined $_->{"ord"} and $_->{"ord"} == $ord
$name =~ /$_->{"pattern"}/i
defined $_->{"ord"}
$_->{"ord"} == $ord
Truth table50%2/4
A or B and C
A= $name =~ /$_->{"pattern"}/iB= defined $_->{"ord"}C= $_->{"ord"} == $ord
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 250 | } | ||||||||||||||||||||||||||||||||||||||||||||||||
| 251 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 252 | 22 | my $c = chr hex substr $entry, 0, $i; | |||||||||||||||||||||||||||||||||||||||||||||||
| 253 | 22 | ▶ | next if $seen{$c}++; | ||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 254 | 22 | push @chars, chr hex substr $entry, 0, $i; | |||||||||||||||||||||||||||||||||||||||||||||||
| 255 | } | ||||||||||||||||||||||||||||||||||||||||||||||||
| 256 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 257 | 1 | return \@chars; | |||||||||||||||||||||||||||||||||||||||||||||||
| 258 | } | ||||||||||||||||||||||||||||||||||||||||||||||||
| 259 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 260 | 0 | ▶ | sub smerge { | ||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
smerge: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 261 | 0 | my %splat = map {; $_ => 1 } map { @$_ } @_; | |||||||||||||||||||||||||||||||||||||||||||||||
| 262 | 0 | return [ sort keys %splat ]; | |||||||||||||||||||||||||||||||||||||||||||||||
| 263 | } | ||||||||||||||||||||||||||||||||||||||||||||||||
| 264 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 265 | 1 | ▶ | sub do_dwim { | ||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
do_dwim: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 266 | 1 | my ($argv, $opt) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||
| 267 | 1 | my $chars = chars_by_name($argv, { match_codepoints => 1 }); | |||||||||||||||||||||||||||||||||||||||||||||||
| 268 | 1 | print_chars($chars, $opt); | |||||||||||||||||||||||||||||||||||||||||||||||
| 269 | } | ||||||||||||||||||||||||||||||||||||||||||||||||
| 270 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 271 | 1 | 1; | |||||||||||||||||||||||||||||||||||||||||||||||
| 272 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 273 | __END__ | ||||||||||||||||||||||||||||||||||||||||||||||||