Initial Commit

This commit is contained in:
Riley Schneider
2025-12-03 16:38:10 +01:00
parent c5e26bf594
commit b732d8d4b5
17680 changed files with 5977495 additions and 2 deletions

View File

@@ -0,0 +1,176 @@
#
# $Id: H2Z.pm,v 2.2 2006/06/03 20:28:48 dankogai Exp $
#
package Encode::JP::H2Z;
use strict;
use warnings;
our $RCSID = q$Id: H2Z.pm,v 2.2 2006/06/03 20:28:48 dankogai Exp $;
our $VERSION = do { my @r = ( q$Revision: 2.2 $ =~ /\d+/g ); sprintf "%d." . "%02d" x $#r, @r };
use Encode::CJKConstants qw(:all);
use vars qw(%_D2Z $_PAT_D2Z
%_Z2D $_PAT_Z2D
%_H2Z $_PAT_H2Z
%_Z2H $_PAT_Z2H);
%_H2Z = (
"\x8e\xa1" => "\xa1\xa3", #<23><>
"\x8e\xa2" => "\xa1\xd6", #<23><>
"\x8e\xa3" => "\xa1\xd7", #<23><>
"\x8e\xa4" => "\xa1\xa2", #<23><>
"\x8e\xa5" => "\xa1\xa6", #<23><>
"\x8e\xa6" => "\xa5\xf2", #<23><>
"\x8e\xa7" => "\xa5\xa1", #<23><>
"\x8e\xa8" => "\xa5\xa3", #<23><>
"\x8e\xa9" => "\xa5\xa5", #<23><>
"\x8e\xaa" => "\xa5\xa7", #<23><>
"\x8e\xab" => "\xa5\xa9", #<23><>
"\x8e\xac" => "\xa5\xe3", #<23><>
"\x8e\xad" => "\xa5\xe5", #<23><>
"\x8e\xae" => "\xa5\xe7", #<23><>
"\x8e\xaf" => "\xa5\xc3", #<23><>
"\x8e\xb0" => "\xa1\xbc", #<23><>
"\x8e\xb1" => "\xa5\xa2", #<23><>
"\x8e\xb2" => "\xa5\xa4", #<23><>
"\x8e\xb3" => "\xa5\xa6", #<23><>
"\x8e\xb4" => "\xa5\xa8", #<23><>
"\x8e\xb5" => "\xa5\xaa", #<23><>
"\x8e\xb6" => "\xa5\xab", #<23><>
"\x8e\xb7" => "\xa5\xad", #<23><>
"\x8e\xb8" => "\xa5\xaf", #<23><>
"\x8e\xb9" => "\xa5\xb1", #<23><>
"\x8e\xba" => "\xa5\xb3", #<23><>
"\x8e\xbb" => "\xa5\xb5", #<23><>
"\x8e\xbc" => "\xa5\xb7", #<23><>
"\x8e\xbd" => "\xa5\xb9", #<23><>
"\x8e\xbe" => "\xa5\xbb", #<23><>
"\x8e\xbf" => "\xa5\xbd", #<23><>
"\x8e\xc0" => "\xa5\xbf", #<23><>
"\x8e\xc1" => "\xa5\xc1", #<23><>
"\x8e\xc2" => "\xa5\xc4", #<23><>
"\x8e\xc3" => "\xa5\xc6", #<23><>
"\x8e\xc4" => "\xa5\xc8", #<23><>
"\x8e\xc5" => "\xa5\xca", #<23><>
"\x8e\xc6" => "\xa5\xcb", #<23><>
"\x8e\xc7" => "\xa5\xcc", #<23><>
"\x8e\xc8" => "\xa5\xcd", #<23><>
"\x8e\xc9" => "\xa5\xce", #<23><>
"\x8e\xca" => "\xa5\xcf", #<23><>
"\x8e\xcb" => "\xa5\xd2", #<23><>
"\x8e\xcc" => "\xa5\xd5", #<23><>
"\x8e\xcd" => "\xa5\xd8", #<23><>
"\x8e\xce" => "\xa5\xdb", #<23><>
"\x8e\xcf" => "\xa5\xde", #<23><>
"\x8e\xd0" => "\xa5\xdf", #<23><>
"\x8e\xd1" => "\xa5\xe0", #<23><>
"\x8e\xd2" => "\xa5\xe1", #<23><>
"\x8e\xd3" => "\xa5\xe2", #<23><>
"\x8e\xd4" => "\xa5\xe4", #<23><>
"\x8e\xd5" => "\xa5\xe6", #<23><>
"\x8e\xd6" => "\xa5\xe8", #<23><>
"\x8e\xd7" => "\xa5\xe9", #<23><>
"\x8e\xd8" => "\xa5\xea", #<23><>
"\x8e\xd9" => "\xa5\xeb", #<23><>
"\x8e\xda" => "\xa5\xec", #<23><>
"\x8e\xdb" => "\xa5\xed", #<23><>
"\x8e\xdc" => "\xa5\xef", #<23><>
"\x8e\xdd" => "\xa5\xf3", #<23><>
"\x8e\xde" => "\xa1\xab", #<23><>
"\x8e\xdf" => "\xa1\xac", #<23><>
);
%_D2Z = (
"\x8e\xb6\x8e\xde" => "\xa5\xac", #<23><>
"\x8e\xb7\x8e\xde" => "\xa5\xae", #<23><>
"\x8e\xb8\x8e\xde" => "\xa5\xb0", #<23><>
"\x8e\xb9\x8e\xde" => "\xa5\xb2", #<23><>
"\x8e\xba\x8e\xde" => "\xa5\xb4", #<23><>
"\x8e\xbb\x8e\xde" => "\xa5\xb6", #<23><>
"\x8e\xbc\x8e\xde" => "\xa5\xb8", #<23><>
"\x8e\xbd\x8e\xde" => "\xa5\xba", #<23><>
"\x8e\xbe\x8e\xde" => "\xa5\xbc", #<23><>
"\x8e\xbf\x8e\xde" => "\xa5\xbe", #<23><>
"\x8e\xc0\x8e\xde" => "\xa5\xc0", #<23><>
"\x8e\xc1\x8e\xde" => "\xa5\xc2", #<23><>
"\x8e\xc2\x8e\xde" => "\xa5\xc5", #<23><>
"\x8e\xc3\x8e\xde" => "\xa5\xc7", #<23><>
"\x8e\xc4\x8e\xde" => "\xa5\xc9", #<23><>
"\x8e\xca\x8e\xde" => "\xa5\xd0", #<23><>
"\x8e\xcb\x8e\xde" => "\xa5\xd3", #<23><>
"\x8e\xcc\x8e\xde" => "\xa5\xd6", #<23><>
"\x8e\xcd\x8e\xde" => "\xa5\xd9", #<23><>
"\x8e\xce\x8e\xde" => "\xa5\xdc", #<23><>
"\x8e\xca\x8e\xdf" => "\xa5\xd1", #<23><>
"\x8e\xcb\x8e\xdf" => "\xa5\xd4", #<23><>
"\x8e\xcc\x8e\xdf" => "\xa5\xd7", #<23><>
"\x8e\xcd\x8e\xdf" => "\xa5\xda", #<23><>
"\x8e\xce\x8e\xdf" => "\xa5\xdd", #<23><>
"\x8e\xb3\x8e\xde" => "\xa5\xf4", #<23><>
);
# init only once;
#$_PAT_D2Z = join("|", keys %_D2Z);
#$_PAT_H2Z = join("|", keys %_H2Z);
%_Z2H = reverse %_H2Z;
%_Z2D = reverse %_D2Z;
#$_PAT_Z2H = join("|", keys %_Z2H);
#$_PAT_Z2D = join("|", keys %_Z2D);
sub h2z {
no warnings qw(uninitialized);
my $r_str = shift;
my ($keep_dakuten) = @_;
my $n = 0;
unless ($keep_dakuten) {
$n = (
$$r_str =~ s(
($RE{EUC_KANA}
(?:\x8e[\xde\xdf])?)
){
my $str = $1;
$_D2Z{$str} || $_H2Z{$str} ||
# in case dakuten and handakuten are side-by-side!
$_H2Z{substr($str,0,2)} . $_H2Z{substr($str,2,2)};
}eogx
);
}
else {
$n = (
$$r_str =~ s(
($RE{EUC_KANA})
){
$_H2Z{$1};
}eogx
);
}
$n;
}
sub z2h {
my $r_str = shift;
my $n = (
$$r_str =~ s(
($RE{EUC_C}|$RE{EUC_0212}|$RE{EUC_KANA})
){
$_Z2D{$1} || $_Z2H{$1} || $1;
}eogx
);
$n;
}
1;
__END__
=head1 NAME
Encode::JP::H2Z -- internally used by Encode::JP::2022_JP*
=cut

View File

@@ -0,0 +1,168 @@
package Encode::JP::JIS7;
use strict;
use warnings;
our $VERSION = do { my @r = ( q$Revision: 2.8 $ =~ /\d+/g ); sprintf "%d." . "%02d" x $#r, @r };
use Encode qw(:fallbacks);
for my $name ( '7bit-jis', 'iso-2022-jp', 'iso-2022-jp-1' ) {
my $h2z = ( $name eq '7bit-jis' ) ? 0 : 1;
my $jis0212 = ( $name eq 'iso-2022-jp' ) ? 0 : 1;
my $obj = bless {
Name => $name,
h2z => $h2z,
jis0212 => $jis0212,
} => __PACKAGE__;
Encode::define_encoding($obj, $name);
}
use parent qw(Encode::Encoding);
# we override this to 1 so PerlIO works
sub needs_lines { 1 }
use Encode::CJKConstants qw(:all);
#
# decode is identical for all 2022 variants
#
sub decode($$;$) {
my ( $obj, $str, $chk ) = @_;
return undef unless defined $str;
my $residue = '';
if ($chk) {
$str =~ s/([^\x00-\x7f].*)$//so and $residue = $1;
}
$residue .= jis_euc( \$str );
$_[1] = $residue if $chk;
return Encode::decode( 'euc-jp', $str, FB_PERLQQ );
}
#
# encode is different
#
sub encode($$;$) {
require Encode::JP::H2Z;
my ( $obj, $utf8, $chk ) = @_;
return undef unless defined $utf8;
# empty the input string in the stack so perlio is ok
$_[1] = '' if $chk;
my ( $h2z, $jis0212 ) = @$obj{qw(h2z jis0212)};
my $octet = Encode::encode( 'euc-jp', $utf8, $chk || 0 );
$h2z and &Encode::JP::H2Z::h2z( \$octet );
euc_jis( \$octet, $jis0212 );
return $octet;
}
#
# cat_decode
#
my $re_scan_jis_g = qr{
\G ( ($RE{JIS_0212}) | $RE{JIS_0208} |
($RE{ISO_ASC}) | ($RE{JIS_KANA}) | )
([^\e]*)
}x;
sub cat_decode { # ($obj, $dst, $src, $pos, $trm, $chk)
my ( $obj, undef, undef, $pos, $trm ) = @_; # currently ignores $chk
my ( $rdst, $rsrc, $rpos ) = \@_[ 1, 2, 3 ];
local ${^ENCODING};
use bytes;
my $opos = pos($$rsrc);
pos($$rsrc) = $pos;
while ( $$rsrc =~ /$re_scan_jis_g/gc ) {
my ( $esc, $esc_0212, $esc_asc, $esc_kana, $chunk ) =
( $1, $2, $3, $4, $5 );
unless ($chunk) { $esc or last; next; }
if ( $esc && !$esc_asc ) {
$chunk =~ tr/\x21-\x7e/\xa1-\xfe/;
if ($esc_kana) {
$chunk =~ s/([\xa1-\xdf])/\x8e$1/og;
}
elsif ($esc_0212) {
$chunk =~ s/([\xa1-\xfe][\xa1-\xfe])/\x8f$1/og;
}
$chunk = Encode::decode( 'euc-jp', $chunk, 0 );
}
elsif ( ( my $npos = index( $chunk, $trm ) ) >= 0 ) {
$$rdst .= substr( $chunk, 0, $npos + length($trm) );
$$rpos += length($esc) + $npos + length($trm);
pos($$rsrc) = $opos;
return 1;
}
$$rdst .= $chunk;
$$rpos = pos($$rsrc);
}
$$rpos = pos($$rsrc);
pos($$rsrc) = $opos;
return '';
}
# JIS<->EUC
my $re_scan_jis = qr{
(?:($RE{JIS_0212})|$RE{JIS_0208}|($RE{ISO_ASC})|($RE{JIS_KANA}))([^\e]*)
}x;
sub jis_euc {
local ${^ENCODING};
my $r_str = shift;
$$r_str =~ s($re_scan_jis)
{
my ($esc_0212, $esc_asc, $esc_kana, $chunk) =
($1, $2, $3, $4);
if (!$esc_asc) {
$chunk =~ tr/\x21-\x7e/\xa1-\xfe/;
if ($esc_kana) {
$chunk =~ s/([\xa1-\xdf])/\x8e$1/og;
}
elsif ($esc_0212) {
$chunk =~ s/([\xa1-\xfe][\xa1-\xfe])/\x8f$1/og;
}
}
$chunk;
}geox;
my ($residue) = ( $$r_str =~ s/(\e.*)$//so );
return $residue;
}
sub euc_jis {
no warnings qw(uninitialized);
local ${^ENCODING};
my $r_str = shift;
my $jis0212 = shift;
$$r_str =~ s{
((?:$RE{EUC_C})+|(?:$RE{EUC_KANA})+|(?:$RE{EUC_0212})+)
}{
my $chunk = $1;
my $esc =
( $chunk =~ tr/\x8E//d ) ? $ESC{KANA} :
( $chunk =~ tr/\x8F//d ) ? $ESC{JIS_0212} :
$ESC{JIS_0208};
if ($esc eq $ESC{JIS_0212} && !$jis0212){
# fallback to '?'
$chunk =~ tr/\xA1-\xFE/\x3F/;
}else{
$chunk =~ tr/\xA1-\xFE/\x21-\x7E/;
}
$esc . $chunk . $ESC{ASC};
}geox;
$$r_str =~ s/\Q$ESC{ASC}\E
(\Q$ESC{KANA}\E|\Q$ESC{JIS_0212}\E|\Q$ESC{JIS_0208}\E)/$1/gox;
$$r_str;
}
1;
__END__
=head1 NAME
Encode::JP::JIS7 -- internally used by Encode::JP
=cut