-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathunicode-style
73 lines (64 loc) · 2.51 KB
/
unicode-style
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
#!perl
use 5.14.1;
use charnames ':full';
binmode(STDOUT, 'encoding(utf-8)');
binmode(STDIN, 'encoding(utf-8)');
my $i = 0;
my %digit = map { $i++ => $_ }
qw(ZERO ONE TWO THREE FOUR FIVE SIX SEVEN EIGHT NINE);
my $wonk = $ARGV[0] || die "usage: wonk \$type 'string to bold-ify'\n";
my @lines = $ARGV[1]
? $ARGV[1]
: <STDIN>;
#my $str = $ARGV[1] || die "usage: wonk \$type 'string to bold-ify'\n";
my $type = $wonk eq 'bold' ? 'MATHEMATICAL BOLD'
: $wonk eq 'script' ? 'MATHEMATICAL BOLD SCRIPT'
: $wonk eq 'fraktur' ? 'MATHEMATICAL FRAKTUR'
: $wonk eq 'italic' ? 'MATHEMATICAL ITALIC'
: $wonk eq 'ss' ? 'MATHEMATICAL SANS-SERIF'
: $wonk eq 'sc' ? 'LATIN LETTER SMALL'
: $wonk eq 'ssb' ? 'MATHEMATICAL SANS-SERIF BOLD'
: $wonk eq 'ssi' ? 'MATHEMATICAL SANS-SERIF ITALIC'
: $wonk eq 'ssbi' ? 'MATHEMATICAL SANS-SERIF BOLD ITALIC'
: $wonk eq 'fw' ? 'FULLWIDTH LATIN'
: $wonk eq 'sub' ? 'LATIN SUBSCRIPT'
: $wonk eq 'sup' ? 'LATIN SUPERSCRIPT'
: $wonk eq 'mono' ? 'MATHEMATICAL MONOSPACE'
: $wonk eq 'dbl' ? 'MATHEMATICAL DOUBLE-STRUCK'
: die "unknown type: $wonk";
# FULLWIDTH LATIN SMALL LETTER W
for my $str (@lines) {
chomp $str;
if ($wonk eq 'sc') {
$str =~ s<([a-z])><
my $name = $1 ge 'a' && $1 le 'z' ? "$type CAPITAL \U$1" : undef;
$name ? charnames::string_vianame($name) // $1 : $1;
>ge;
} elsif ($wonk eq 'fw') {
$str =~ s<(.)><
my $name = charnames::viacode(ord $1);
$name eq 'SPACE'
? ' '
: (charnames::string_vianame("FULLWIDTH $name") // $1);
>gei;
} elsif ($wonk eq 'sub' or $wonk eq 'sup') {
$str =~ s<([a-z0-9])><
my $name = $1 ge 'a' && $1 le 'z' ? "$type SMALL LETTER \U$1"
: $1 ge 'A' && $1 le 'Z' ? "$type CAPITAL LETTER $1"
: $1 ge '0' && $1 le '9' ? "MATHEMATICAL BOLD DIGIT $digit{$1}"
: undef;
$name =~ s/ (.)$/ LETTER $1/ if $wonk eq 'fw';
$name ? charnames::string_vianame($name) // $1 : $1;
>gei;
} else {
$str =~ s<([a-z0-9])><
my $name = $1 ge 'a' && $1 le 'z' ? "$type SMALL \U$1"
: $1 ge 'A' && $1 le 'Z' ? "$type CAPITAL $1"
: $1 ge '0' && $1 le '9' ? "MATHEMATICAL BOLD DIGIT $digit{$1}"
: undef;
$name =~ s/ (.)$/ LETTER $1/ if $wonk eq 'fw';
$name ? charnames::string_vianame($name) // $1 : $1;
>gei;
}
say $str;
}