Debian Codegraph @

src/backend/utils/mb/Unicode/UCS_to_GB18030.pl

raw
1 #! /usr/bin/perl
2 #
3 # Copyright (c) 2007-2025, PostgreSQL Global Development Group
4 #
5 # src/backend/utils/mb/Unicode/UCS_to_GB18030.pl
6 #
7 # Generate UTF-8 <--> GB18030 code conversion tables from
8 # "gb-18030-2000.xml", obtained from
9 # http://source.icu-project.org/repos/icu/data/trunk/charset/data/xml/
10 #
11 # The lines we care about in the source file look like
12 # <a u="009A" b="81 30 83 36"/>
13 # where the "u" field is the Unicode code point in hex,
14 # and the "b" field is the hex byte sequence for GB18030
15
16 use strict;
17 use warnings FATAL => 'all';
18
19 use convutils;
20
21 my $this_script = 'src/backend/utils/mb/Unicode/UCS_to_GB18030.pl';
22
23 # Read the input
24
25 my $in_file = "gb-18030-2000.xml";
26
27 open(my $in, '<', $in_file) || die("cannot open $in_file");
28
29 my @mapping;
30
31 while (<$in>)
32 {
33 next if (!m/<a u="([0-9A-F]+)" b="([0-9A-F ]+)"/);
34 my ($u, $c) = ($1, $2);
35 $c =~ s/ //g;
36 my $ucs = hex($u);
37 my $code = hex($c);
38 if ($code >= 0x80 && $ucs >= 0x0080)
39 {
40 push @mapping,
41 {
42 ucs => $ucs,
43 code => $code,
44 direction => BOTH,
45 f => $in_file,
46 l => $.
47 };
48 }
49 }
50 close($in);
51
52 print_conversion_tables($this_script, "GB18030", \@mapping);