michael@0: #!/usr/bin/perl michael@0: # michael@0: # This Source Code Form is subject to the terms of the Mozilla Public michael@0: # License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: # file, You can obtain one at http://mozilla.org/MPL/2.0/. michael@0: michael@0: open ( TEXTFILE , "< NormalizationTest.txt") michael@0: || die "Cannot find NormalizationTest.txt. The latest version should be available from\n http://www.unicode.org/Public/UNIDATA/NormalizationTest.txt\n"; michael@0: michael@0: open ( OUT , "> NormalizationData.h") michael@0: #open ( OUT , "> test.txt") michael@0: || die "Cannot create output file NormalizationData.h\n"; michael@0: michael@0: $mpl = <) { michael@0: chop; michael@0: if (/^# NormalizationTest-(.+)\.txt/) { michael@0: print OUT "static char versionText[] = \"$1\";\n"; michael@0: } elsif (/^\@Part(.)/) { michael@0: if ($1 != "0") { michael@0: print OUT " {\n"; michael@0: print OUT " L\"\",\n"; michael@0: print OUT " L\"\",\n"; michael@0: print OUT " L\"\",\n"; michael@0: print OUT " L\"\",\n"; michael@0: print OUT " L\"\",\n"; michael@0: print OUT " \"\",\n"; michael@0: print OUT " },\n"; michael@0: print OUT "};\n"; michael@0: } michael@0: print OUT "\n"; michael@0: print OUT "static testcaseLine Part$1TestData[] = \n"; michael@0: print OUT "{\n"; michael@0: } else { michael@0: unless (/^\#/) { michael@0: @cases = split(/;/ , $_); michael@0: print OUT " {\n"; michael@0: for ($case = 0; $case < 5; ++$case) { michael@0: $c = $cases[$case]; michael@0: print OUT " L\""; michael@0: @codepoints = split(/ / , $c); michael@0: foreach (@codepoints) { michael@0: $cp = hex($_); michael@0: if ($cp < 0x10000) { michael@0: # BMP codepoint michael@0: printf OUT "\\x%04X", $cp; michael@0: } else { michael@0: # non-BMP codepoint, convert to surrogate pair michael@0: printf OUT "\\x%04X\\x%04X", michael@0: ($cp >> 10) + 0xD7C0, michael@0: ($cp & 0x03FF) | 0xDC00; michael@0: } michael@0: } michael@0: print OUT "\",\n"; michael@0: } michael@0: $description = $cases[10]; michael@0: $description =~ s/^ \) //; michael@0: print OUT " \"$description\"\n"; michael@0: print OUT " },\n"; michael@0: } michael@0: } michael@0: } michael@0: michael@0: print OUT " {\n"; michael@0: print OUT " L\"\",\n"; michael@0: print OUT " L\"\",\n"; michael@0: print OUT " L\"\",\n"; michael@0: print OUT " L\"\",\n"; michael@0: print OUT " L\"\",\n"; michael@0: print OUT " \"\",\n"; michael@0: print OUT " },\n"; michael@0: print OUT "};\n"; michael@0: close (OUT); michael@0: close (TEXTFILE);