| 1 |
|
| 2 |
=head1 NAME |
| 3 |
|
| 4 |
Encode::Restore::ISO2022JPnoESC --- Decoder of broken ISO-2022-JP |
| 5 |
data that has been removed ESCs. |
| 6 |
|
| 7 |
=head1 DESCRIPTION |
| 8 |
|
| 9 |
In some ISO/IEC 2022 based encodings such as ISO-2022-JP, |
| 10 |
control character ESC (01/11 = \x1B) has important role. |
| 11 |
But very very old softwares (mainly server software of |
| 12 |
transparents) does not recogenize this character so data |
| 13 |
come through such implemention are broken. |
| 14 |
|
| 15 |
This module provides some coding system that try to restore |
| 16 |
such broken ISO-2022-JP data. |
| 17 |
|
| 18 |
=head1 ENCODINGS |
| 19 |
|
| 20 |
=over 4 |
| 21 |
|
| 22 |
=cut |
| 23 |
|
| 24 |
package Encode::Restore::ISO2022JPnoESC; |
| 25 |
use strict; |
| 26 |
our $VERSION = do{my @r=(q$Revision: 1.10 $=~/\d+/g);sprintf "%d."."%02d" x $#r,@r}; |
| 27 |
use base qw(Encode::Encoding); |
| 28 |
__PACKAGE__->Define (qw!iso-2022-jp-no-esc!); |
| 29 |
|
| 30 |
=item iso-2022-jp-no-esc |
| 31 |
|
| 32 |
Broken ISO-2022-JP data that has been removed ESCs. |
| 33 |
|
| 34 |
=cut |
| 35 |
|
| 36 |
sub encode ($$;$) { |
| 37 |
my ($obj, $str, $chk) = @_; |
| 38 |
warn "encode: encode of iso-2022-jp-no-esc is not supported!"; |
| 39 |
$_[1] = '' if $chk; |
| 40 |
return Encode::encode ('iso-2022-jp', $str); |
| 41 |
} |
| 42 |
|
| 43 |
sub decode ($$;$) { |
| 44 |
my ($obj, $str, $chk) = @_; |
| 45 |
$_[1] = '' if $chk; |
| 46 |
$str =~ s/(\x24[\x40\x42](?:[\x21-\x7E][\x21-\x7E])+)(\x28[BHJ])/\x1B$1\x1B$2/g; |
| 47 |
return Encode::decode ('iso-2022-jp', $str); |
| 48 |
} |
| 49 |
|
| 50 |
package Encode::Restore::ISO2022JPnoESC::ISO2022JPescsp; |
| 51 |
use base qw(Encode::Encoding); |
| 52 |
__PACKAGE__->Define (qw!iso-2022-jp-esc-sp!); |
| 53 |
|
| 54 |
=item iso-2022-jp-esc-sp |
| 55 |
|
| 56 |
Broken ISO-2022-JP data that has been inserted SPs |
| 57 |
instead of ESCs. |
| 58 |
|
| 59 |
Note that old Japanese articles of Google Groups |
| 60 |
<http://groups.google.com/> are encoded in this scheme. |
| 61 |
|
| 62 |
=cut |
| 63 |
|
| 64 |
sub encode ($$;$) { |
| 65 |
my ($obj, $str, $chk) = @_; |
| 66 |
warn "encode: encode of iso-2022-jp-esc-sp is not supported!"; |
| 67 |
$_[1] = '' if $chk; |
| 68 |
return Encode::encode ('iso-2022-jp', $str); |
| 69 |
} |
| 70 |
|
| 71 |
sub decode ($$;$) { |
| 72 |
my ($obj, $str, $chk) = @_; |
| 73 |
$_[1] = '' if $chk; |
| 74 |
$str =~ s/\x20(\x24[\x40\x42](?:[\x21-\x7E][\x21-\x7E])+)\x20(\x28[BHJ])/\x1B$1\x1B$2/g; |
| 75 |
return Encode::decode ('iso-2022-jp', $str); |
| 76 |
} |
| 77 |
|
| 78 |
1; |
| 79 |
__END__ |
| 80 |
|
| 81 |
=back |
| 82 |
|
| 83 |
=head1 LICENSE |
| 84 |
|
| 85 |
Copyright 2002 Nanashi-san <nanashi@san.invalid> |
| 86 |
|
| 87 |
This library is free software; you can redistribute it |
| 88 |
and/or modify it under the same terms as Perl itself. |
| 89 |
|
| 90 |
=cut |
| 91 |
|
| 92 |
# $Date: 2002/10/16 10:39:35 $ |