/[pub]/test/oldencodeutils/lib/Encode/ISO2022/JIS.pm
Suika

Contents of /test/oldencodeutils/lib/Encode/ISO2022/JIS.pm

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.4 - (show annotations) (download)
Sun Sep 22 11:08:23 2002 UTC (23 years, 3 months ago) by wakaba
Branch: MAIN
Changes since 1.3: +11 -6 lines
2002-09-22  Wakaba <w@suika.fam.cx>

	* ISO646.pm, RFC1345.pm: New modules.

1 =head1 NAME
2
3 C<Encode::ISO2022::JIS> --- Encode and decode of ISO/IEC 2022
4 based encodings defined by JIS (Japan Industrial Standard),
5 other than RFC 1468 coded representation, C<ISO-2022-JP-3>
6 coded representations and C<EUC-JISX0213> coded representations
7
8 =head1 ENCODINGS
9
10 =over 4
11
12 =cut
13
14 require 5.7.3;
15 use strict;
16 package Encode::ISO2022::JIS;
17 use vars qw($VERSION);
18 $VERSION=do{my @r=(q$Revision: 1.3 $=~/\d+/g);sprintf "%d."."%02d" x $#r,@r};
19 use base qw(Encode::Encoding);
20 require Encode::ISO2022;
21
22 sub encode ($$;$) {
23 my ($obj, $str, $chk) = @_;
24 $_[1] = '' if $chk;
25 $str = &Encode::ISO2022::internal_to_iso2022 ($str, $obj->__2022_encode);
26 return $str;
27 }
28
29 sub decode ($$;$) {
30 my ($obj, $str, $chk) = @_;
31 $_[1] = '' if $chk;
32 return &Encode::ISO2022::iso2022_to_internal ($str, $obj->__2022_decode);
33 }
34
35 sub __2022__common ($) {
36 my $C = Encode::ISO2022->new_object;
37 $C->{option}->{designate_to}->{C0}->{default} = -1;
38 $C->{option}->{designate_to}->{C1}->{default} = -1;
39 $C->{option}->{designate_to}->{G94}->{default} = -1;
40 $C->{option}->{designate_to}->{G94}->{B} = -1;
41 $C->{option}->{designate_to}->{G94n}->{default} = -1;
42 $C->{option}->{designate_to}->{G96}->{default} = -1;
43 $C->{option}->{designate_to}->{G96n}->{default} = -1;
44 $C->{G1} = $Encode::ISO2022::CHARSET{G94}->{"\x7E"}; ## empty
45 $C->{option}->{reset}->{Gdesignation} = 0;
46 $C->{option}->{reset}->{Ginvoke} = 0;
47 $C->{option}->{undef_char} = ["\x22\x2E", ## GETA MARK
48 {type => 'G94n', charset => 'B', revision => '@'}];
49 $C;
50 }
51 sub __2022_encode ($) {
52 my $C = shift->__2022__common;
53 $C;
54 }
55 sub __2022_decode ($) {
56 my $C = shift->__2022__common;
57 $C;
58 }
59
60 package Encode::ISO2022::JIS::JISX0201Latin7;
61 use vars qw/@ISA/;
62 push @ISA, 'Encode::ISO2022::JIS';
63 __PACKAGE__->Define (qw/jisx0201-1997-latin-7bit JIS_C6220-1969-ro
64 iso-ir-14 ir14 jp ISO646-JP 646-jp csISO14JISC6220ro/);
65
66 =item jisx0201-1997-latin-7bit
67
68 JIS X 0201:1997 6.1 7-bit code for Latin.
69 (Alias: C<JIS_C6220-1969-ro> (RFC 1345), C<iso-ir-14> (RFC 1345),
70 C<ir14>, C<jp> (RFC 1345), C<ISO646-JP> (RFC 1345), C<646-jp>,
71 C<csISO14JISC6220ro> (IANA))
72
73 =cut
74
75 sub __2022__common ($) {
76 my $C = shift->SUPER::__2022__common;
77 $C->{bit} = 7;
78 $C->{G0} = $Encode::ISO2022::CHARSET{G94}->{J}; ## JIS X 0201:1997 Latin set
79 $C->{G1} = $C->{G0}; $C->{G2} = $C->{G1}; ## RFC 1345 (not in JIS)
80 $C->{G3} = $C->{G1};
81 $C->{option}->{undef_char} = ["\x3F", {type => 'G94', charset => 'J'}];
82 $C;
83 }
84
85 package Encode::ISO2022::JIS::JISX0201Katakana7;
86 use vars qw/@ISA/;
87 push @ISA, 'Encode::ISO2022::JIS';
88 __PACKAGE__->Define (qw/jisx0201-1997-katakana-7bit JIS_C6220-1969-jp JIS_C6220-1969
89 iso-ir-13 ir13 katakana x0201-7 csISO13JISC6220jp/);
90
91 =item jisx0201-1997-katakana-7bit
92
93 JIS X 0201:1997 6.2 7-bit code for Katakana
94 (Alias: JIS_C6220-1969-jp (RFC 1345), JIS_C6220-1969 (RFC 1345),
95 iso-ir-13 (RFC 1345), ir13, katakana (RFC 1345), x0201-7 (RFC 1345),
96 csISO13JISC6220jp (IANA))
97
98 =cut
99
100 sub __2022__common ($) {
101 my $C = shift->SUPER::__2022__common;
102 $C->{bit} = 7;
103 $C->{G0} = $Encode::ISO2022::CHARSET{G94}->{I}; ## JIS X 0201:1997 Katakana set
104 $C->{G1} = $C->{G0}; $C->{G2} = $C->{G1}; ## RFC 1345 (not in JIS)
105 $C->{G3} = $C->{G1};
106 $C->{option}->{undef_char} = ["\x25", {type => 'G94', charset => 'I'}];
107 $C;
108 }
109
110 package Encode::ISO2022::JIS::JISX0201LatinKatakana7;
111 use vars qw/@ISA/;
112 push @ISA, 'Encode::ISO2022::JIS';
113 __PACKAGE__->Define (qw/jisx0201-1997-latin-katakana-7bit
114 JIS_X0201 X0201 csHalfWidthKatakana/);
115
116 =item jisx0201-1997-latin-katakana-7bit
117
118 JIS X 0201:1997 6.3 7-bit code for Latin and Katakana
119 (Alias: JIS_X0201 (RFC 1345), X0201 (RFC 1345), csHalfWidthKatakana (IANA))
120
121 =cut
122
123 sub __2022__common ($) {
124 my $C = shift->SUPER::__2022__common;
125 $C->{bit} = 7;
126 $C->{G0} = $Encode::ISO2022::CHARSET{G94}->{J}; ## JIS X 0201:1997 Latin set
127 $C->{G1} = $Encode::ISO2022::CHARSET{G94}->{I}; ## JIS X 0201:1997 Katakana set
128 $C->{option}->{Ginvoke_to_left} = [1,1,1,1];
129 $C->{option}->{reset}->{Ginvoke} = 1;
130 ## JIS X 0201:1997 does not specify this limitation.
131 $C->{option}->{undef_char} = ["\x3F", {type => 'G94', charset => 'J'}];
132 $C;
133 }
134 sub __2022_encode ($) {
135 my $C = shift->__2022__common;
136 $C->{GR} = undef;
137 $C;
138 }
139
140 package Encode::ISO2022::JIS::JISX0201LatinKatakana8;
141 use vars qw/@ISA/;
142 push @ISA, 'Encode::ISO2022::JIS';
143 __PACKAGE__->Define (qw/jisx0201-1997-latin-latin-8bit/);
144
145 =item jisx0201-1997-latin-katakana-8bit
146
147 JIS X 0208:1997 7.4 8-bit code for Latin and Katakana
148
149 =cut
150
151 sub __2022__common ($) {
152 my $C = shift->SUPER::__2022__common;
153 $C->{bit} = 8;
154 $C->{G0} = $Encode::ISO2022::CHARSET{G94}->{J}; ## JIS X 0201:1997 Latin set
155 $C->{G1} = $Encode::ISO2022::CHARSET{G94}->{I}; ## JIS X 0201:1997 Katakana set
156 $C->{option}->{undef_char} = ["\x3F", {type => 'G94', charset => 'J'}];
157 $C->{option}->{C1invoke_to_right} = 1;
158 $C;
159 }
160
161 package Encode::ISO2022::JIS::JISX0208Kanji7;
162 use vars qw/@ISA/;
163 push @ISA, 'Encode::ISO2022::JIS';
164 __PACKAGE__->Define (qw/jisx0208-1997-kanji-7bit/);
165
166 =item jisx0208-1997-kanji-7bit
167
168 JIS X 0208:1997 7.1.1 7-bit code for Kanji
169
170 =cut
171
172 sub __2022__common ($) {
173 my $C = shift->SUPER::__2022__common;
174 $C->{bit} = 7;
175 $C->{G0} = $Encode::ISO2022::CHARSET{G94n}->{'B@'}; ## JIS X 0208:1997
176 $C;
177 }
178
179 package Encode::ISO2022::JIS::JISX0208Kanji8;
180 use vars qw/@ISA/;
181 push @ISA, 'Encode::ISO2022::JIS';
182 __PACKAGE__->Define (qw/jisx0208-1997-kanji-8bit/);
183
184 =item jisx0208-1997-kanji-8bit
185
186 JIS X 0208:1997 7.1.2 8-bit code for Kanji
187
188 =cut
189
190 sub __2022__common ($) {
191 my $C = shift->SUPER::__2022__common;
192 $C->{bit} = 8;
193 $C->{G0} = $Encode::ISO2022::CHARSET{G94n}->{'B@'}; ## JIS X 0208:1997
194 $C->{G1} = $Encode::ISO2022::CHARSET{G94}->{"\x7E"}; ## empty
195 $C->{option}->{C1invoke_to_right} = 1;
196 $C;
197 }
198
199 package Encode::ISO2022::JIS::JISX0208IRVKanji7;
200 use vars qw/@ISA/;
201 push @ISA, 'Encode::ISO2022::JIS';
202 __PACKAGE__->Define (qw/jisx0208-1997-irv-kanji-7bit/);
203
204 =item jisx0208-1997-irv-kanji-7bit
205
206 JIS X 0208:1997 7.2.1 7-bit code for IRV and Kanji
207
208 =cut
209
210 sub __2022__common ($) {
211 my $C = shift->SUPER::__2022__common;
212 $C->{bit} = 7;
213 $C->{G0} = $Encode::ISO2022::CHARSET{G94}->{B}; ## ISO/IEC 646 IRV
214 $C->{G1} = $Encode::ISO2022::CHARSET{G94n}->{'B@'}; ## JIS X 0208:1997
215 $C->{option}->{Ginvoke_to_left} = [1,1,1,1];
216 $C->{option}->{reset}->{Ginvoke} = 1;
217 ## JIS X 0208:1997 does not specify this limitation.
218 $C;
219 }
220 sub __2022_encode ($) {
221 my $C = shift->__2022__common;
222 $C->{GR} = undef;
223 $C;
224 }
225
226 package Encode::ISO2022::JIS::JISX0208IRVKanji8;
227 use vars qw/@ISA/;
228 push @ISA, 'Encode::ISO2022::JIS';
229 __PACKAGE__->Define (qw/jisx0208-1997-irv-kanji-8bit/);
230
231 =item jisx0208-1997-irv-kanji-8bit
232
233 JIS X 0208:1997 7.2.2 8-bit code for IRV and Kanji.
234 (A subset of EUC-japan)
235
236 =cut
237
238 sub __2022__common ($) {
239 my $C = shift->SUPER::__2022__common;
240 $C->{bit} = 8;
241 $C->{G0} = $Encode::ISO2022::CHARSET{G94}->{B}; ## ISO/IEC 646 IRV
242 $C->{G1} = $Encode::ISO2022::CHARSET{G94n}->{'B@'}; ## JIS X 0208:1997
243 $C->{option}->{C1invoke_to_right} = 1;
244 $C;
245 }
246
247 package Encode::ISO2022::JIS::JISX0208LatinKanji7;
248 use vars qw/@ISA/;
249 push @ISA, 'Encode::ISO2022::JIS';
250 __PACKAGE__->Define (qw/jisx0208-1997-latin-kanji-7bit/);
251
252 =item jisx0208-1997-latin-kanji-7bit
253
254 JIS X 0208:1997 7.3.1 7-bit code for Latin and Kanji
255
256 =cut
257
258 sub __2022__common ($) {
259 my $C = shift->SUPER::__2022__common;
260 $C->{bit} = 7;
261 $C->{G0} = $Encode::ISO2022::CHARSET{G94}->{J}; ## JIS X 0201:1997 Latin set
262 $C->{G1} = $Encode::ISO2022::CHARSET{G94n}->{'B@'}; ## JIS X 0208:1997
263 $C->{option}->{Ginvoke_to_left} = [1,1,1,1];
264 $C->{option}->{reset}->{Ginvoke} = 1;
265 ## JIS X 0208:1997 does not specify this limitation.
266 $C;
267 }
268 sub __2022_encode ($) {
269 my $C = shift->__2022__common;
270 $C->{GR} = undef;
271 $C;
272 }
273
274 package Encode::ISO2022::JIS::JISX0208LatinKanji8;
275 use vars qw/@ISA/;
276 push @ISA, 'Encode::ISO2022::JIS';
277 __PACKAGE__->Define (qw/jisx0208-1997-latin-kanji-8bit/);
278
279 =item jisx0208-1997-latin-kanji-8bit
280
281 JIS X 0208:1997 7.2.2 8-bit code for Latin and Kanji
282
283 =cut
284
285 sub __2022__common ($) {
286 my $C = shift->SUPER::__2022__common;
287 $C->{bit} = 8;
288 $C->{G0} = $Encode::ISO2022::CHARSET{G94}->{J}; ## JIS X 0201:1997 Latin set
289 $C->{G1} = $Encode::ISO2022::CHARSET{G94n}->{'B@'}; ## JIS X 0208:1997
290 $C->{option}->{C1invoke_to_right} = 1;
291 $C;
292 }
293
294 package Encode::ISO2022::JIS::JISX0213Kanji7;
295 use vars qw/@ISA/;
296 push @ISA, 'Encode::ISO2022::JIS';
297 __PACKAGE__->Define (qw/jisx0213-2000-kanji-7bit/);
298
299 =item jisx0213-2000-kanji-7bit
300
301 JIS X 0213:2000 7.1.1 7-bit code for Kanji
302
303 =cut
304
305 sub __2022__common ($) {
306 my $C = shift->SUPER::__2022__common;
307 $C->{bit} = 7;
308 $C->{G0} = $Encode::ISO2022::CHARSET{G94n}->{O}; ## plane 1
309 $C->{G1} = $Encode::ISO2022::CHARSET{G94n}->{P}; ## plane 2
310 $C->{option}->{Ginvoke_to_left} = [1,1,1,1];
311 $C->{option}->{reset}->{Ginvoke} = 1;
312 ## JIS X 0213:2000 does not specify this limitation.
313 $C->{option}->{undef_char} = ["\x22\x2E", {type => 'G94n', charset => 'O'}];
314 $C;
315 }
316 sub __2022_encode ($) {
317 my $C = shift->__2022__common;
318 $C->{GR} = undef;
319 $C;
320 }
321
322 package Encode::ISO2022::JIS::JISX0213Kanji8;
323 use vars qw/@ISA/;
324 push @ISA, 'Encode::ISO2022::JIS';
325 __PACKAGE__->Define (qw/jisx0213-2000-kanji-8bit/);
326
327 =item jisx0213-2000-kanji-8bit
328
329 JIS X 0213:2000 7.1.2 8-bit code for Kanji
330
331 =cut
332
333 sub __2022__common ($) {
334 my $C = shift->SUPER::__2022__common;
335 $C->{bit} = 7;
336 $C->{G0} = $Encode::ISO2022::CHARSET{G94n}->{O}; ## plane 1
337 $C->{G1} = $Encode::ISO2022::CHARSET{G94n}->{P}; ## plane 2
338 $C->{option}->{undef_char} = ["\x22\x2E", {type => 'G94n', charset => 'O'}];
339 $C->{option}->{C1invoke_to_right} = 1;
340 $C;
341 }
342
343 package Encode::ISO2022::JIS::JISX0213IRVKanji7;
344 use vars qw/@ISA/;
345 push @ISA, 'Encode::ISO2022::JIS';
346 __PACKAGE__->Define (qw/jisx0213-2000-irv-kanji-7bit/);
347
348 =item jisx0213-2000-irv-kanji-7bit
349
350 JIS X 0213:2000 7.2.1 7-bit code for IRV and Kanji
351
352 =cut
353
354 sub __2022__common ($) {
355 my $C = shift->SUPER::__2022__common;
356 $C->{bit} = 7;
357 $C->{G0} = $Encode::ISO2022::CHARSET{G94}->{B}; ## ISO/IEC 646 IRV
358 $C->{G1} = $Encode::ISO2022::CHARSET{G94n}->{O}; ## plane 1
359 $C->{G3} = $Encode::ISO2022::CHARSET{G94n}->{P}; ## plane 2
360 $C->{option}->{Ginvoke_by_single_shift}->[3] = 1;
361 $C->{option}->{Ginvoke_to_left} = [1,1,1,1];
362 $C->{option}->{reset}->{Ginvoke} = 1;
363 ## JIS X 0213:2000 does not specify this limitation.
364 $C->{option}->{undef_char} = ["\x22\x2E", {type => 'G94n', charset => 'O'}];
365 $C;
366 }
367 sub __2022_encode ($) {
368 my $C = shift->__2022__common;
369 $C->{GR} = undef;
370 $C;
371 }
372
373 package Encode::ISO2022::JIS::JISX0213IRVKanji8;
374 use vars qw/@ISA/;
375 push @ISA, 'Encode::ISO2022::JIS';
376 __PACKAGE__->Define (qw/jisx0213-2000-irv-kanji-8bit/);
377
378 =item jisx0213-2000-irv-kanji-8bit
379
380 JIS X 0213:2000 7.2.2 8-bit code for IRV and Kanji.
381 (A subset of EUC-JISX0213)
382
383 =cut
384
385 sub __2022__common ($) {
386 my $C = shift->SUPER::__2022__common;
387 $C->{bit} = 8;
388 $C->{G0} = $Encode::ISO2022::CHARSET{G94}->{B}; ## ISO/IEC 646 IRV
389 $C->{G1} = $Encode::ISO2022::CHARSET{G94n}->{O}; ## plane 1
390 $C->{G3} = $Encode::ISO2022::CHARSET{G94n}->{P}; ## plane 2
391 $C->{option}->{Ginvoke_by_single_shift}->[3] = 1;
392 $C->{option}->{Ginvoke_to_left} = [1,0,0,0];
393 $C->{option}->{undef_char} = ["\x22\x2E", {type => 'G94n', charset => 'O'}];
394 $C->{option}->{C1invoke_to_right} = 1;
395 $C;
396 }
397
398 package Encode::ISO2022::JIS::JISX0213LatinKanji7;
399 use vars qw/@ISA/;
400 push @ISA, 'Encode::ISO2022::JIS';
401 __PACKAGE__->Define (qw/jisx0213-2000-latin-kanji-7bit/);
402
403 =item jisx0213-2000-latin-kanji-7bit
404
405 JIS X 0213:2000 7.3.1 7-bit code for Latin and Kanji
406
407 =cut
408
409 sub __2022__common ($) {
410 my $C = shift->SUPER::__2022__common;
411 $C->{bit} = 7;
412 $C->{G0} = $Encode::ISO2022::CHARSET{G94}->{J}; ## JIS X 0201:1997 Latin set
413 $C->{G1} = $Encode::ISO2022::CHARSET{G94n}->{O}; ## plane 1
414 $C->{G3} = $Encode::ISO2022::CHARSET{G94n}->{P}; ## plane 2
415 $C->{option}->{Ginvoke_by_single_shift}->[3] = 1;
416 $C->{option}->{Ginvoke_to_left} = [1,1,1,1];
417 $C->{option}->{reset}->{Ginvoke} = 1;
418 ## JIS X 0213:2000 does not specify this limitation.
419 $C->{option}->{undef_char} = ["\x22\x2E", {type => 'G94n', charset => 'O'}];
420 $C;
421 }
422 sub __2022_encode ($) {
423 my $C = shift->__2022__common;
424 $C->{GR} = undef;
425 $C;
426 }
427
428 package Encode::ISO2022::JIS::JISX0213LatinKanji8;
429 use vars qw/@ISA/;
430 push @ISA, 'Encode::ISO2022::JIS';
431 __PACKAGE__->Define (qw/jisx0213-2000-latin-kanji-8bit/);
432
433 =item jisx0213-2000-latin-kanji-8bit
434
435 JIS X 0213:2000 7.2.2 8-bit code for Latin and Kanji
436
437 =cut
438
439 sub __2022__common ($) {
440 my $C = shift->SUPER::__2022__common;
441 $C->{bit} = 8;
442 $C->{G0} = $Encode::ISO2022::CHARSET{G94}->{J}; ## JIS X 0201:1997 Latin set
443 $C->{G1} = $Encode::ISO2022::CHARSET{G94n}->{O}; ## plane 1
444 $C->{G3} = $Encode::ISO2022::CHARSET{G94n}->{P}; ## plane 2
445 $C->{option}->{Ginvoke_by_single_shift}->[3] = 1;
446 $C->{option}->{Ginvoke_to_left} = [1,0,0,0];
447 $C->{option}->{undef_char} = ["\x22\x2E", {type => 'G94n', charset => 'O'}];
448 $C->{option}->{C1invoke_to_right} = 1;
449 $C;
450 }
451
452 package Encode::ISO2022::JIS::JISX4001Text7;
453 use vars qw/@ISA/;
454 push @ISA, 'Encode::ISO2022::JIS';
455 __PACKAGE__->Define (qw/jisx4001-text-7bit/);
456
457 =item jisx4001-text-7bit
458
459 JIS X 4001-1989 text (7-bit code)
460
461 =cut
462
463 sub __2022__common ($) {
464 my $C = shift->SUPER::__2022__common;
465 $C->{bit} = 7;
466 $C->{G0} = $Encode::ISO2022::CHARSET{G94n}->{B}; ## JIS X 0208-1983
467 $C->{option}->{designate_to}->{G94}->{J} = 0; ## JIS X 0201 Roman
468 $C->{option}->{designate_to}->{G94n}->{B} = 0; ## JIS X 0208-1983
469 $C;
470 }
471
472 package Encode::ISO2022::JIS::JISX4001Text8;
473 use vars qw/@ISA/;
474 push @ISA, 'Encode::ISO2022::JIS::JISX4001Text7';
475 __PACKAGE__->Define (qw/jisx4001-text-8bit/);
476
477 =item jisx4001-text-8bit
478
479 JIS X 4001-1989 text (8-bit code)
480
481 =cut
482
483 sub __2022__common ($) {
484 my $C = shift->SUPER::__2022__common;
485 $C->{bit} = 7;
486 $C->{option}->{C1invoke_to_right} = 1;
487 $C;
488 }
489
490 1;
491 __END__
492
493 =back
494
495 Note that although other JISes such as JIS X 0212 and JIS X 9010
496 define ISO/IEC 2022-comfprming coded character sets,
497 these standards do not define complete coding system (but define
498 as used on ISO/IEC 2022 environment), so this module
499 does not include those coded character sets. (IETF RFC 1345
500 and IANAREG give charset name to coded character sets
501 consist of such standards. But those are defined by RFC 1345,
502 not by JIS. Such coded character sets should be implemented
503 in Encode::ISO2022::RFC1345.)
504
505 =head1 LICENSE
506
507 Copyright 2002 Wakaba <w@suika.fam.cx>
508
509 This library is free software; you can redistribute it
510 and/or modify it under the same terms as Perl itself.
511
512 =cut
513
514 # $Date: 2002/09/20 14:01:45 $
515 ### JIS.pm ends here

admin@suikawiki.org
ViewVC Help
Powered by ViewVC 1.1.24