summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorTatsuo Ishii <ishii@postgresql.org>2007-03-23 13:51:30 +0000
committerTatsuo Ishii <ishii@postgresql.org>2007-03-23 13:51:30 +0000
commit4c35ec53a9e8e9c5496b2e33c6b568c0cfbdb7e3 (patch)
tree3bcdf4900e558f79f276e1e29008bc60c57ce4c3 /src
parent6b77e3a8cc881b92f899aeca9e028479fe3b97b8 (diff)
downloadpostgresql-4c35ec53a9e8e9c5496b2e33c6b568c0cfbdb7e3.tar.gz
Allow 4 bytes UTF-8 (UCS-4 range 00010000-001FFFFF)
This is necessary to support JIS X 0213 <--> UTF-8 conversion.
Diffstat (limited to 'src')
-rw-r--r--src/backend/utils/mb/Unicode/ucs2utf.pl15
1 files changed, 11 insertions, 4 deletions
diff --git a/src/backend/utils/mb/Unicode/ucs2utf.pl b/src/backend/utils/mb/Unicode/ucs2utf.pl
index c2201ae663..0c31619329 100644
--- a/src/backend/utils/mb/Unicode/ucs2utf.pl
+++ b/src/backend/utils/mb/Unicode/ucs2utf.pl
@@ -1,6 +1,8 @@
#
-# $PostgreSQL: pgsql/src/backend/utils/mb/Unicode/ucs2utf.pl,v 1.2 2003/11/29 22:40:01 pgsql Exp $
-# convert UCS-2 to UTF-8
+# Copyright (c) 2001-2007, PostgreSQL Global Development Group
+#
+# $PostgreSQL: pgsql/src/backend/utils/mb/Unicode/ucs2utf.pl,v 1.3 2007/03/23 13:51:30 ishii Exp $
+# convert UCS-4 to UTF-8
#
sub ucs2utf {
local($ucs) = @_;
@@ -10,11 +12,16 @@ sub ucs2utf {
$utf = $ucs;
} elsif ($ucs > 0x007f && $ucs <= 0x07ff) {
$utf = (($ucs & 0x003f) | 0x80) | ((($ucs >> 6) | 0xc0) << 8);
- } else {
+ } elsif ($ucs > 0x07ff && $ucs <= 0xffff) {
$utf = ((($ucs >> 12) | 0xe0) << 16) |
(((($ucs & 0x0fc0) >> 6) | 0x80) << 8) |
(($ucs & 0x003f) | 0x80);
- }
+ } else {
+ $utf = ((($ucs >> 18) | 0xf0) << 24) |
+ (((($ucs & 0x3ffff) >> 12) | 0x80) << 16) |
+ (((($ucs & 0x0fc0) >> 6) | 0x80) << 8) |
+ (($ucs & 0x003f) | 0x80);
+ }
return($utf);
}
1;