Hippo2000 (2000/12/9)
Unicode系モジュールの1つUnicode::MapUTF8です。
作者はBenjamin Franzさんです。メールで許可をいただきました。
Unicode::MapUTF8 - 任意の文字セットから/へのUTF8の変換
use Unicode::MapUTF8 qw(to_utf8 from_utf8 utf8_supported_charset);
# 'ISO-8859-1'の文字列を 'UTF8'に変換する
my $output = to_utf8({ -string => 'An example', -charset => 'ISO-8859-1' });
# 'UTF8'エンコーディングの文字列をエンコーディング 'ISO-8859-1'へ変換する
my $other = from_utf8({ -string => 'Other text', -charset => 'ISO-8859-1' });
# 利用できる文字セットエンコーディングのリスト my @character_sets = utf8_supported_charset;
# 文字セット別名の追加
utf8_charset_alias({ 'ms-japanese' => 'sjis' });
# 2つの任意の(しかし大きく互換性のある)文字セットエンコーディングでの変換
# (SJIS to EUC-JP)
my $utf8_string = to_utf8({ -string =>$sjis_string, -charset => 'sjis'});
my $euc_jp_string = from_utf8({ -string => $utf8_string, -charset => 'euc-jp' })
# 特定の文字セットがサポートされているかを確認
if (utf8_supported_charset('ISO-8859-1') {
# Yes
}
UTF8とその他のエンコーディングから/への変換のための中核となるルーチンの間のアダプタ層を提供します。本質的には、複数存在するUnicodeモジュールへの1つの共通のインターフェース、下敷きになっている実装を知ることなく、簡単にUTF8から/へ他の文字セットエンコーディング変換を簡単におこないます。そのため、これはUnicode::String、Unicode::Map8、Unicode::Map、Jcodeモジュールを標準化された簡単なAPIの中に包みます。
またこれはUTF-8をベースに一般的な文字セット変換も提供します−これは2段階の変換つなげることにより、2つの互換性があり、サポートされている文字セットで可能です。
ほとんどのことがPerl的なので−かみ砕く対象として数多くの小さいなものの代わりに2、3の大きな固まりを与えると、1秒間により多くの文字を扱います。
設計では、登場するいかなる新しい文字セット・エンコーディング変換モジュールも取り込むように簡単に拡張することができます。
(原文のまま)
1.08 2000.11.06 - Added 'utf8_charset_alias' function to allow for runtime setting of character set aliases. Added several alternate names for 'sjis' (shiftjis, shift-jis, shift_jis, s-jis, and s_jis).
Corrected 'croak' messages for
'from_utf8' functions to appropriate
function name.
Tightened up initialization encapsulation
Corrected fatal problem in jcode from
unicode internals. Problem and fix
found by Brian Wisti <wbrian2@uswest.net>.
1.07 2000.11.01 - Added 'croak' to use Carp declaration to fix error messages. Problem and fix found by Brian Wisti <wbrian2@uswest.net>.
1.06 2000.10.30 - Fix to handle change in stringification of overloaded objects between Perl 5.005 and 5.6. Problem noticed by Brian Wisti <wbrian2@uswest.net>.
1.05 2000.10.23 - Error in conversions from UTF8 to multibyte encodings corrected
1.04 2000.10.23 - Additional diagnostic messages added for internal error conditions
1.03 2000.10.22 - Bug fix for load time autodetction of Unicode::Map8 encodings
1.02 2000.10.22 - Added load time autodetection of Unicode::Map8 supported character set encodings.
Fixed internal calling error for some
character sets with 'from_utf8'. Thanks
goes to Ilia Lobsanov
<ilia@lobsanov.com> for reporting this
problem.
1.01 2000.10.02 - Fixed handling of empty strings and added more identification for error messages.
1.00 2000.09.29 - Pre-release version
引数なしで呼ばれると、定義されている別名と、それにマップされる文字セットのハッシュを返します。
例::
my $aliases = utf8_charset_alias; my @alias_names = keys %$aliases;
1つのパラメータ付きで呼ばれると、もしその別名が定義されていれば、'本当の'文字セットの名前を返します。それが別名に見つからなければundefを返します。
例:
if (! utf8_charset_alias('VISCII')) {
# No alias for this
}
もし'alias' => 'charset'の組のリストで呼ばれれば、それらの別名が使えるように定義します。
例:
utf8_charset_alias({ 'japanese' => 'sjis', 'japan' => 'sjis' });
注意:渡された組が、予め定義されている文字セット・エンコーディングの集合に定義されている文字セットにマップされなければ、croakします。これは他の別名への別名を許してはいません。
複数の文字セットを1回の呼出しで設定することができます。
別名をクリーンするためには、undefの文字セットマッピングを渡します。
例:
utf8_charset_alias({ 'japanese' => undef });
別名が設定されている間、もし予め定義されている文字セットであれば、'utf8_supported_charset' 関数は別名を返します。
基本の定義された文字エンコーディングを別名でオーバーライドすると、標準エラー(STDERR)への警告メッセージを出します。
そうでなければfalseを返します。
例:
if (! utf8_supported_charset('VISCII')) {
# まだサポートされていません
}
パラメータなしで、リスト・コンテキストで呼ばれると、(ユーザが定義した別名も含めて)サポートされているすべての文字セット名のリストを返します。
例:
my @charsets = utf8_supported_charset;
1.08 2000.11.06
Copyright September, 2000 Benjamin Franz. All rights reserved.
This software is free software. You can redistribute it and/or modify it under the same terms as Perl itself.
Benjamin Franz <snowhare@nihongo.org>
Jcode、2バイト・エンコーディングそしてエンコーディング別名のための逆行テスト
Unicode::String Unicode::Map8 Unicode::Map Jcode
ご意見、ご質問はこちらの掲示板で受け付けています。
またメールは河馬屋(Nifty)にお願いします。