Skip to content

Commit 4c35ec5

Browse files
committed
Allow 4 bytes UTF-8 (UCS-4 range 00010000-001FFFFF)
This is necessary to support JIS X 0213 <--> UTF-8 conversion.
1 parent 6b77e3a commit 4c35ec5

File tree

1 file changed

+11
-4
lines changed

1 file changed

+11
-4
lines changed
Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
#
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
2+
# Copyright (c) 2001-2007, PostgreSQL Global Development Group
3+
#
4+
# $PostgreSQL: pgsql/src/backend/utils/mb/Unicode/ucs2utf.pl,v 1.3 2007/03/23 13:51:30 ishii Exp $
5+
# convert UCS-4 to UTF-8
46
#
57
sub ucs2utf {
68
local($ucs) = @_;
@@ -10,11 +12,16 @@ sub ucs2utf {
1012
$utf = $ucs;
1113
} elsif ($ucs > 0x007f && $ucs <= 0x07ff) {
1214
$utf = (($ucs & 0x003f) | 0x80) | ((($ucs >> 6) | 0xc0) << 8);
13-
} else {
15+
} elsif ($ucs > 0x07ff && $ucs <= 0xffff) {
1416
$utf = ((($ucs >> 12) | 0xe0) << 16) |
1517
(((($ucs & 0x0fc0) >> 6) | 0x80) << 8) |
1618
(($ucs & 0x003f) | 0x80);
17-
}
19+
} else {
20+
$utf = ((($ucs >> 18) | 0xf0) << 24) |
21+
(((($ucs & 0x3ffff) >> 12) | 0x80) << 16) |
22+
(((($ucs & 0x0fc0) >> 6) | 0x80) << 8) |
23+
(($ucs & 0x003f) | 0x80);
24+
}
1825
return($utf);
1926
}
2027
1;

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy