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
|
#! /usr/bin/perl
# USAGE: perl mkeastasianwidth.pl > charwidth.c
use IO::File;
my $fh=new IO::File "<EastAsianWidth.txt";
my $pb=-1;
my $pe=-1;
print "static const char32_t unicode_wcwidth_tab[][2]={\n";
sub full($$) {
my $b=hex(shift);
my $e=hex(shift);
if ($b == $pe+1)
{
$pe=$e;
return;
}
printf ("{0x%04x, 0x%04x},\n", $pb, $pe) unless $pb < 0;
$pb=$b;
$pe=$e;
}
while (defined($_=<$fh>))
{
chomp;
s/#.*//;
my @w=split(/;/);
grep {s/^\s*//; s/\s*$//; } @w;
next unless $w[1] eq "F" || $w[1] eq "W";
if ($w[0] =~ /(.*)\.\.(.*)/)
{
full($1, $2);
}
else
{
full($w[0], $w[0]);
}
}
printf ("{0x%04x, 0x%04x}\n};\n", $pb, $pe);
|