ShiftJIS::CP932::MapUTF - Conversion between CP-932 and Unicode
use ShiftJIS::CP932::MapUTF; $utf8_string = cp932_to_utf8($cp932_string);
The Microsoft CodePage 932 (CP-932) table comprises 7915 characters:
JIS X 0201-1976 single-byte characters (191 characters), JIS X 0208-1990 double-byte characters (6879 characters), NEC special characters (83 characters from SJIS row 13), NEC-selected IBM extended characters (374 characters from SJIS row 89 to 92), and IBM extended characters (388 characters from SJIS row 115 to 119).
It contains duplicates that do not round trip map. These duplicates are due to the characters defined by vendors, NEC and IBM.
For example, there are two characters that are mapped to U+2252, namely, 0x81e0 (JIS X 0208) and 0x8790 (NEC special character).
This module provides some functions to maps from CP-932 to Unicode, and vice versa.
cp932_to_utf8(STRING)
cp932_to_utf8(CODEREF, STRING)
Converts CP-932 to UTF-8.
For example, converts \x81\xe0 or \x87\x90 to U+2252 in the UTF-8 encoding.
\x81\xe0
\x87\x90
U+2252
If CODEREF is not specified, characters that aren't mapped to Unicode are deleted. If CODEREF is specified, characters that aren't mapped to Unicode are converted using CODEREF from the CP-932 character string.
CODEREF
For example, converts \x82\xf2 to U+3094, HIRAGANA LETTER VU, in the UTF-8 encoding.
\x82\xf2
U+3094
cp932_to_utf8( sub { $_[0] eq "\x82\xf2" ? "\xe3\x82\x94" : "" }, $cp932_string);
cp932_to_utf16(STRING)
cp932_to_utf16(CODEREF, STRING)
Converts CP-932 to UTF-16LE.
For example, converts \x81\xe0 or \x87\x90 to U+2252 in the UTF-16LE encoding.
For example, converts \x82\xf2 to U+3094, HIRAGANA LETTER VU, in the UTF-16LE encoding.
cp932_to_utf16( sub { $_[0] eq "\x82\xf2" ? "\x94\x30" : "" }, $cp932_string);
utf8_to_cp932(STRING)
utf8_to_cp932(CODEREF, STRING)
Converts UTF-8 to CP-932 (normalized).
For example, U+2252 in the UTF-8 encoding is converted to \x81\xe0, not to \x87\x90.
If CODEREF is not specified, characters that aren't mapped to CP-932 are deleted. If CODEREF is specified, characters that aren't mapped to CP-932 are converted using CODEREF from its Unicode code point (integer).
For example, characters that aren't mapped to CP-932 are converted to numerical character references for HTML 4.01.
utf8_to_cp932(sub {sprintf "&#x%04x;", shift}, $utf8_string);
utf16_to_cp932(STRING)
utf16_to_cp932(CODEREF, STRING)
Converts UTF-16LE to CP-932 (normalized).
UTF-16LE
CP-932
For example, U+2252 in the UTF-16LE encoding is converted to \x81\xe0, not to \x87\x90.
utf16_to_cp932(sub {sprintf "&#x%04x;", shift}, $utf16LE_string);
This module doesn't understand any logically wide characters (see perlunicode). Use utf8::decode/utf8::encode (see utf8) on Perl 5.7 or later if necessary.
Tomoyuki SADAHIRO
bqw10602@nifty.com http://homepage1.nifty.com/nomenclator/perl/ Copyright(C) 2001, SADAHIRO Tomoyuki. Japan. All rights reserved.
This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
Microsoft PRB: Conversion Problem Between Shift-JIS and Unicode (Article ID: Q170559)
Unicode.org
ftp://ftp.unicode.org/Public/MAPPINGS/VENDORS/MICSFT/WINDOWS/CP932.TXT
ShiftJIS::CP932::Correct
To install ShiftJIS::CP932::MapUTF, copy and paste the appropriate command in to your terminal.
cpanm
cpanm ShiftJIS::CP932::MapUTF
CPAN shell
perl -MCPAN -e shell install ShiftJIS::CP932::MapUTF
For more information on module installation, please visit the detailed CPAN module installation guide.