-
Notifications
You must be signed in to change notification settings - Fork 4
/
make_l10n_cjk_uni_table.pl
executable file
·69 lines (60 loc) · 1.25 KB
/
make_l10n_cjk_uni_table.pl
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
#!/usr/bin/perl
use strict;
use FileHandle;
my %width = ( N => 1,
Na => 1, # Nallow
W => 2, # Wide
H => 1, # HalfWidth
F => 2, # FullWidth
A => 2, # Anbiguous
);
sub main {
print STDERR "Processing";
my $ifh = new FileHandle("EastAsianWidth.txt");
my $bit = new Bit;
while (<$ifh>) {
next if (/^\s*\#/);
my ($from, $to, $type) = /([\da-f]+)(?:\.\.([\da-f]+))?;(\w+)/i
or next;
$to = $from unless defined($to);
last if (length($to) > 4); # only in BMP
if ($width{$type} == 2) {
foreach my $code (hex($from)..hex($to)) {
$bit->set($code);
}
}
print STDERR ".";
}
$ifh->close;
print STDERR "Done\n";
my $cnt = 0;
print <<EOF;
#include "l10n_cjk_uni_table.h"
unsigned long cjk_width[CJK_WIDTH_LENGTH] = {
EOF
foreach my $word (@$bit) {
print " " unless $cnt;
printf("0x%08x", $word);
$cnt = ($cnt + 1) % 4;
if ($cnt) {
print ", ";
} else {
print ",\n";
}
}
print "};\n";
}
main;
package Bit;
sub new {
my $class = shift;
my $self = [];
@$self = 0x10000 / 32;
return bless($self, $class);
}
sub set {
my ($self, $code) = @_;
my $index = int($code / 32);
my $bit = $code % 32;
$self->[$index] |= (1 << $bit);
}