Debian Codegraph @

src/backend/utils/mb/Unicode/UCS_to_SHIFT_JIS_2004.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_SHIFT_JIS_2004.pl
6 #
7 # Generate UTF-8 <--> SHIFT_JIS_2004 code conversion tables from
8 # "sjis-0213-2004-std.txt" (http://x0213.org)
9
10 use strict;
11 use warnings FATAL => 'all';
12
13 use convutils;
14
15 # first generate UTF-8 --> SHIFT_JIS_2004 table
16
17 my $this_script = 'src/backend/utils/mb/Unicode/UCS_to_SHIFT_JIS_2004.pl';
18
19 my $in_file = "sjis-0213-2004-std.txt";
20
21 open(my $in, '<', $in_file) || die("cannot open $in_file");
22
23 my @mapping;
24
25 while (my $line = <$in>)
26 {
27 if ($line =~ /^0x(\w+)\s*U\+(\w+)\+(\w+)\s*#\s*(\S.*)?\s*$/)
28 {
29
30 # combined characters
31 my ($c, $u1, $u2) = ($1, $2, $3);
32 # The "\t \t" below is just to avoid insubstantial diffs.
33 my $rest = "U+" . $u1 . "+" . $u2 . "\t \t" . $4;
34 my $code = hex($c);
35 my $ucs1 = hex($u1);
36 my $ucs2 = hex($u2);
37
38 push @mapping,
39 {
40 code => $code,
41 ucs => $ucs1,
42 ucs_second => $ucs2,
43 comment => $rest,
44 direction => BOTH,
45 f => $in_file,
46 l => $.
47 };
48 }
49 elsif ($line =~ /^0x(\w+)\s*U\+(\w+)\s*#\s*(\S.*)?\s*$/)
50 {
51
52 # non-combined characters
53 my ($c, $u, $rest) = ($1, $2, "U+" . $2 . $3);
54 my $ucs = hex($u);
55 my $code = hex($c);
56 my $direction;
57
58 if ($code < 0x80 && $ucs < 0x80)
59 {
60 next;
61 }
62 elsif ($code < 0x80)
63 {
64 $direction = FROM_UNICODE;
65 }
66 elsif ($ucs < 0x80)
67 {
68 $direction = TO_UNICODE;
69 }
70 else
71 {
72 $direction = BOTH;
73 }
74
75 push @mapping,
76 {
77 code => $code,
78 ucs => $ucs,
79 comment => $rest,
80 direction => $direction,
81 f => $in_file,
82 l => $.
83 };
84 }
85 }
86 close($in);
87
88 print_conversion_tables($this_script, "SHIFT_JIS_2004", \@mapping);