aboutsummaryrefslogtreecommitdiffstats
path: root/vespalib/src/tests/text/lowercase/to-c-code.pl
diff options
context:
space:
mode:
authorJon Bratseth <bratseth@yahoo-inc.com>2016-06-15 23:09:44 +0200
committerJon Bratseth <bratseth@yahoo-inc.com>2016-06-15 23:09:44 +0200
commit72231250ed81e10d66bfe70701e64fa5fe50f712 (patch)
tree2728bba1131a6f6e5bdf95afec7d7ff9358dac50 /vespalib/src/tests/text/lowercase/to-c-code.pl
Publish
Diffstat (limited to 'vespalib/src/tests/text/lowercase/to-c-code.pl')
-rwxr-xr-xvespalib/src/tests/text/lowercase/to-c-code.pl74
1 files changed, 74 insertions, 0 deletions
diff --git a/vespalib/src/tests/text/lowercase/to-c-code.pl b/vespalib/src/tests/text/lowercase/to-c-code.pl
new file mode 100755
index 00000000000..63a87fb56ae
--- /dev/null
+++ b/vespalib/src/tests/text/lowercase/to-c-code.pl
@@ -0,0 +1,74 @@
+#!/usr/local/bin/perl
+# Copyright 2016 Yahoo Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
+
+# input looks like:
+# lowercase( 65 )= 97
+
+
+my %lowercase;
+
+my %blocks;
+
+while (<>) {
+ my ( $key, $value ) = m{lowercase. (\d+) .. (\d+)$} ;
+ $lowercase{$key} = $value;
+
+ my $b = ( $key >> 8 );
+ ++$blocks{$b};
+}
+
+@kl = keys %blocks;
+@nkl = sort {$a <=> $b} @kl;
+
+print STDERR "blocks: " . join(" ", @nkl) . "\n";
+
+
+foreach $b ( @nkl )
+{
+ if ( $b == 0 ) {
+ print "unsigned char\nLowerCase::lowercase_${b}_block[256] = {\n\t";
+ } else {
+ print "\nuint32_t\nLowerCase::lowercase_${b}_block[256] = {\n\t";
+ }
+ my $act = 0;
+ for ($i = 0; $i < 256; $i++) {
+ if ($act > 7) {
+ print ",\n\t";
+ $act = 0;
+ } elsif ($act) {
+ print ",";
+ }
+ $n = ($b << 8) + $i;
+ $v = $lowercase{$n};
+ if (defined $v) {
+ print "\t$v";
+ die "too big value in table 0: $v\n" if ($v > 255 && $b == 0);
+ } else {
+ print "\t$n";
+ }
+ ++$act;
+ }
+ print "\n\t};\n\n";
+}
+
+{
+ print "\nuint32_t\nLowerCase::lowercase_0_5_block[0x600] = {\n\t";
+ my $act = 0;
+ for ($i = 0; $i < 0x600; $i++) {
+ if ($act > 7) {
+ print ",\n\t";
+ $act = 0;
+ } elsif ($act) {
+ print ",";
+ }
+ $n = $i;
+ $v = $lowercase{$n};
+ if (defined $v) {
+ print "\t$v";
+ } else {
+ print "\t$n";
+ }
+ ++$act;
+ }
+ print "\n\t};\n\n";
+}