]> granicus.if.org Git - postgresql/blob - src/backend/utils/mb/Unicode/ucs2utf.pl
make sure the $Id tags are converted to $PostgreSQL as well ...
[postgresql] / src / backend / utils / mb / Unicode / ucs2utf.pl
1 #
2 # $PostgreSQL: pgsql/src/backend/utils/mb/Unicode/ucs2utf.pl,v 1.2 2003/11/29 22:40:01 pgsql Exp $
3 # convert UCS-2 to UTF-8
4 #
5 sub ucs2utf {
6         local($ucs) = @_;
7         local $utf;
8
9         if ($ucs <= 0x007f) {
10                 $utf = $ucs;
11         } elsif ($ucs > 0x007f && $ucs <= 0x07ff) {
12                 $utf = (($ucs & 0x003f) | 0x80) | ((($ucs >> 6) | 0xc0) << 8);
13         } else {
14                 $utf = ((($ucs >> 12) | 0xe0) << 16) | 
15                         (((($ucs & 0x0fc0) >> 6) | 0x80) << 8) |
16                                 (($ucs & 0x003f) | 0x80);
17         }
18         return($utf);
19 }
20 1;