blob: 801467ab69b80e39daf18a39b0b0b351eacbd3f5 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
|
#
# $Id: ucs2utf.pl,v 1.1 2000/10/30 10:40:30 ishii Exp $
# convert UCS-2 to UTF-8
#
sub ucs2utf {
local($ucs) = @_;
local $utf;
if ($ucs <= 0x007f) {
$utf = $ucs;
} elsif ($ucs > 0x007f && $ucs <= 0x07ff) {
$utf = (($ucs & 0x003f) | 0x80) | ((($ucs >> 6) | 0xc0) << 8);
} else {
$utf = ((($ucs >> 12) | 0xe0) << 16) |
(((($ucs & 0x0fc0) >> 6) | 0x80) << 8) |
(($ucs & 0x003f) | 0x80);
}
return($utf);
}
1;
|