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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.1 - (show annotations) (download)
Fri Aug 16 09:19:18 2002 UTC (23 years, 5 months ago) by wakaba
Branch: MAIN
2002-08-16  Wakaba <w@suika.fam.cx>

	* ChangeLog: New file.

1 require 5.8.0;
2 package Encode::ISO2022::CP932;
3 use strict;
4 use vars qw(%DEFAULT $VERSION);
5 $VERSION=do{my @r=(q$Revision: 1.1 $=~/\d+/g);sprintf "%d."."%02d" x $#r,@r};
6 use base qw(Encode::Encoding);
7 __PACKAGE__->Define (qw/x-iso2022jp-cp932/);
8
9 sub encode ($$;$) {
10 my ($obj, $str, $chk) = @_;
11 $_[1] = '' if $chk;
12 ## TODO: implement this!
13 $str = Encode::encode ('iso-2022-jp', $str); ## temporary
14 return $str;
15 }
16
17 sub decode ($$;$) {
18 my ($obj, $str, $chk) = @_;
19 $_[1] = '' if $chk;
20 _jis7_to_sjis (\$str);
21 return Encode::decode ('cp932', $str);
22 }
23
24 my %_L2S;
25 sub _jis7_to_sjis (\$) {
26 my $s = shift;
27 $$s =~ s(
28 (\x1B\x24\x28?[\x40\x42]|\x1B\x28[BHIJ])
29 ([^\x00-\x20]*)
30 ){
31 my ($esc, $str) = ($1, $2);
32 if ($esc =~ /\x1B\x28I/o) {
33 $str =~ tr/\x21-\x7E/\xA1-\xDF???????????????????????????????/;
34 } elsif ($esc !~ /\x1B\x28/o) {
35 $str =~ s{ ([\x21-\xFF][\x21-\x7E]) }{
36 my $s = $1;
37 unless ($_L2S{$s}){
38 my ($c1, $c2) = unpack 'CC', $s;
39 $c2 += ($c1 & 1) ? ($c2 < 0x60 ? 0x1F : 0x20) : 0x7E;
40 $c1 = (($c1 - 1) >> 1) + ($c1 < 0x5F ? 0x71 : 0xB1);
41 $_L2S{$s} = pack 'CC', $c1, $c2;
42 }
43 $_L2S{$s};
44 }goex;
45 }
46 $str;
47 }goex;
48 $$s =~ s{ \x0E([\xA1-\xDF]+)\x0F }{
49 $1;
50 }goex;
51 }
52
53 1;
54 __END__
55
56 =head1 NAME
57
58 Encode::ISO2022::CP932 --- Encode module for ISO/IEC 2022 like
59 encoding of Microsoft CP932 (Shift JIS)
60
61 =head1 DESCRIPTION
62
63 Windows Code Page 932, Microsoft version of shift JIS,
64 is widely used in Japanese PC community. It is the combination
65 of JIS character set with non-standard extended characters (CCS)
66 and "shift JIS" encoding scheme (CES).
67
68 Non-PC communities such as un*x users' or Internet mail/news'
69 use standard JIS character set for CCS and EUC or 7bit
70 ISO/IEC 2022 for CES.
71
72 This situation makes such stupid converters that
73 output the charset consist of non-standard CCS and EUC
74 or 7bit ISO/IEC 2022 CES.
75
76 This module supports two such charsets. One is
77 C<x-iso2022jp-cp932>,
78
79 =head1 LICENSE
80
81 Copyright 2002 wakaba <w@suika.fam.cx>
82
83 This library is free software; you can redistribute it
84 and/or modify it under the same terms as Perl itself.
85
86 =head1 CHANGE
87
88 See F<ChangeLog>.
89 $Date: 2002/07/21 05:49:51 $
90
91 =cut

admin@suikawiki.org
ViewVC Help
Powered by ViewVC 1.1.24