xref: /unit/src/nxt_unicode_lowcase.pl (revision 1008:84f2370bd642)
1#!/usr/bin/perl
2
3use warnings;
4use strict;
5
6# BLOCK_SIZE should be 128, 256, 512, etc.  The value 128 provides
7# the minimum memory footprint for both 32-bit and 64-bit platforms.
8use constant BLOCK_SIZE => 128;
9
10my %lowcase;
11my %blocks;
12my $max_block = 0;
13my $max_lowcase = 0;
14
15while (<>) {
16    if (/^(\w+); (C|S); (\w+);/) {
17        my ($symbol, $folding) = (hex $1, hex $3);
18        $lowcase{$symbol} = $folding;
19        $blocks{int($symbol / BLOCK_SIZE)} = 1;
20
21        if ($max_lowcase < $symbol) {
22            $max_lowcase = $symbol;
23        }
24    }
25}
26
27
28my $last_block_size = $max_lowcase % BLOCK_SIZE + 1;
29
30
31for my $block (sort { $a <=> $b } keys %blocks) {
32    if ($max_block < $block) {
33        $max_block = $block;
34    }
35}
36
37
38my $blocks = scalar keys %blocks;
39
40printf("\n/*\n" .
41       " * %d %s-bytes blocks, %d pointers.\n" .
42       " * %d bytes on 32-bit platforms, %d bytes on 64-bit platforms.\n" .
43       " */\n\n",
44       $blocks, BLOCK_SIZE, $max_block + 1,
45       ($blocks - 1) * BLOCK_SIZE * 4 + $last_block_size + $max_block * 4,
46       ($blocks - 1) * BLOCK_SIZE * 4 + $last_block_size+ $max_block * 8);
47
48printf("#define NXT_UNICODE_MAX_LOWCASE  0x%05x\n\n", $max_lowcase);
49printf("#define NXT_UNICODE_BLOCK_SIZE   %d\n\n\n", BLOCK_SIZE);
50
51
52for my $block (sort { $a <=> $b } keys %blocks) {
53    my $block_size = ($block != $max_block) ? BLOCK_SIZE : $last_block_size;
54
55    print "static const uint32_t  ";
56    printf("nxt_unicode_block_%03x[%d]  nxt_aligned(64) = {",
57           $block, $block_size);
58
59    for my $c (0 .. $block_size - 1) {
60        printf "\n   " if $c % 8 == 0;
61
62        my $n = $block * BLOCK_SIZE + $c;
63
64        if (exists $lowcase{$n}) {
65            printf(" 0x%05x,", $lowcase{$n});
66
67        } else {
68            #print " .......,";
69            printf(" 0x%05x,", $n);
70        }
71    }
72
73    print "\n};\n\n\n";
74}
75
76
77print "static const uint32_t  *nxt_unicode_blocks[]  nxt_aligned(64) = {\n";
78
79for my $block (0 .. $max_block) {
80    if (exists($blocks{$block})) {
81        printf("    nxt_unicode_block_%03x,\n", $block);
82
83    } else {
84        print  "    NULL,\n";
85    }
86}
87
88print "};\n";
89