Mercurial > emacs
annotate lisp/international/utf-16.el @ 58327:a360835c5032
*** empty log message ***
author | Richard M. Stallman <rms@gnu.org> |
---|---|
date | Fri, 19 Nov 2004 19:40:32 +0000 |
parents | b7fe21511efe |
children | a878c25f56db |
rev | line source |
---|---|
46677 | 1 ;;; utf-16.el --- UTF-16 encoding/decoding |
2 | |
55437
6e677a935fe9
Fix references to utf-translate-cjk into utf-translate-cjk-mode.
Andreas Schwab <schwab@suse.de>
parents:
52401
diff
changeset
|
3 ;; Copyright (C) 2001, 2002, 2003, 2004 Free Software Foundation, Inc. |
46677 | 4 |
5 ;; Author: Dave Love <fx@gnu.org> | |
6 ;; Keywords: Unicode, UTF-16, i18n | |
7 | |
8 ;; This file is part of GNU Emacs. | |
9 | |
10 ;; GNU Emacs is free software; you can redistribute it and/or modify | |
11 ;; it under the terms of the GNU General Public License as published by | |
12 ;; the Free Software Foundation; either version 2, or (at your option) | |
13 ;; any later version. | |
14 | |
15 ;; GNU Emacs is distributed in the hope that it will be useful, | |
16 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of | |
17 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
18 ;; GNU General Public License for more details. | |
19 | |
20 ;; You should have received a copy of the GNU General Public License | |
21 ;; along with GNU Emacs; see the file COPYING. If not, write to the | |
22 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330, | |
23 ;; Boston, MA 02111-1307, USA. | |
24 | |
25 ;;; Commentary: | |
26 | |
27 ;; Support for UTF-16, which is a two-byte encoding (modulo | |
52285
6c91b4a8b9af
Add mime-text-unsuitable coding system
Dave Love <fx@gnu.org>
parents:
51631
diff
changeset
|
28 ;; surrogates) of Unicode, defined in RFC 2781. It is written either |
6c91b4a8b9af
Add mime-text-unsuitable coding system
Dave Love <fx@gnu.org>
parents:
51631
diff
changeset
|
29 ;; in little or big endian order and either with or without the |
6c91b4a8b9af
Add mime-text-unsuitable coding system
Dave Love <fx@gnu.org>
parents:
51631
diff
changeset
|
30 ;; leading BOM (a two-byte signature which identifies their byte sex). |
51631
bc72d6855260
Many name changes: utf-16-{be,le} -> utf-16{be,le}.
Kenichi Handa <handa@m17n.org>
parents:
50483
diff
changeset
|
31 ;; |
52285
6c91b4a8b9af
Add mime-text-unsuitable coding system
Dave Love <fx@gnu.org>
parents:
51631
diff
changeset
|
32 ;; We provide these base coding systems. |
51631
bc72d6855260
Many name changes: utf-16-{be,le} -> utf-16{be,le}.
Kenichi Handa <handa@m17n.org>
parents:
50483
diff
changeset
|
33 ;; name endian BOM |
bc72d6855260
Many name changes: utf-16-{be,le} -> utf-16{be,le}.
Kenichi Handa <handa@m17n.org>
parents:
50483
diff
changeset
|
34 ;; ---- ------ --- |
bc72d6855260
Many name changes: utf-16-{be,le} -> utf-16{be,le}.
Kenichi Handa <handa@m17n.org>
parents:
50483
diff
changeset
|
35 ;; mule-utf-16le little no |
bc72d6855260
Many name changes: utf-16-{be,le} -> utf-16{be,le}.
Kenichi Handa <handa@m17n.org>
parents:
50483
diff
changeset
|
36 ;; mule-utf-16be big no |
bc72d6855260
Many name changes: utf-16-{be,le} -> utf-16{be,le}.
Kenichi Handa <handa@m17n.org>
parents:
50483
diff
changeset
|
37 ;; mule-utf-16le-with-signature little yes |
bc72d6855260
Many name changes: utf-16-{be,le} -> utf-16{be,le}.
Kenichi Handa <handa@m17n.org>
parents:
50483
diff
changeset
|
38 ;; mule-utf-16be-with-signature big yes |
bc72d6855260
Many name changes: utf-16-{be,le} -> utf-16{be,le}.
Kenichi Handa <handa@m17n.org>
parents:
50483
diff
changeset
|
39 ;; mule-utf-16 both yes |
bc72d6855260
Many name changes: utf-16-{be,le} -> utf-16{be,le}.
Kenichi Handa <handa@m17n.org>
parents:
50483
diff
changeset
|
40 ;; |
46677 | 41 ;; Note that un-decodable sequences aren't (yet?) preserved as raw |
42 ;; bytes, as they are with utf-8, so reading and writing as utf-16 can | |
43 ;; corrupt data. | |
44 | |
45 ;;; Code: | |
46 | |
47 ;; We end up with trivially different -le and -be versions of most | |
48 ;; things below, sometimes with commonality abstracted into a let | |
49 ;; binding for maintenance convenience. | |
50 | |
51 ;; Needed in macro expansion, so can't be let-bound. Zapped after use. | |
52 (eval-and-compile | |
53 (defconst utf-16-decode-ucs | |
56038
b7fe21511efe
(utf-16-decode-ucs): Handle a surrogate
Kenichi Handa <handa@m17n.org>
parents:
55437
diff
changeset
|
54 ;; If r5 is negative, r1 is a Unicode chacter code. Otherise, r5 is |
b7fe21511efe
(utf-16-decode-ucs): Handle a surrogate
Kenichi Handa <handa@m17n.org>
parents:
55437
diff
changeset
|
55 ;; the first of a surrogate pair and r1 is the second of the pair. |
b7fe21511efe
(utf-16-decode-ucs): Handle a surrogate
Kenichi Handa <handa@m17n.org>
parents:
55437
diff
changeset
|
56 ;; Output is charset ID in r0, code point in r1. R0 may be set to |
b7fe21511efe
(utf-16-decode-ucs): Handle a surrogate
Kenichi Handa <handa@m17n.org>
parents:
55437
diff
changeset
|
57 ;; -1 in which case a caller should not write out r1. |
b7fe21511efe
(utf-16-decode-ucs): Handle a surrogate
Kenichi Handa <handa@m17n.org>
parents:
55437
diff
changeset
|
58 `((if (r5 >= 0) |
b7fe21511efe
(utf-16-decode-ucs): Handle a surrogate
Kenichi Handa <handa@m17n.org>
parents:
55437
diff
changeset
|
59 ((r0 = (r1 < #xDC00)) |
b7fe21511efe
(utf-16-decode-ucs): Handle a surrogate
Kenichi Handa <handa@m17n.org>
parents:
55437
diff
changeset
|
60 (if ((r1 >= #xE000) | r0) |
b7fe21511efe
(utf-16-decode-ucs): Handle a surrogate
Kenichi Handa <handa@m17n.org>
parents:
55437
diff
changeset
|
61 ;; Invalid second code of surrogate pair. |
b7fe21511efe
(utf-16-decode-ucs): Handle a surrogate
Kenichi Handa <handa@m17n.org>
parents:
55437
diff
changeset
|
62 ((r0 = r5) |
b7fe21511efe
(utf-16-decode-ucs): Handle a surrogate
Kenichi Handa <handa@m17n.org>
parents:
55437
diff
changeset
|
63 (call ccl-mule-utf-untrans)) |
b7fe21511efe
(utf-16-decode-ucs): Handle a surrogate
Kenichi Handa <handa@m17n.org>
parents:
55437
diff
changeset
|
64 ((r1 -= #xDC00) |
b7fe21511efe
(utf-16-decode-ucs): Handle a surrogate
Kenichi Handa <handa@m17n.org>
parents:
55437
diff
changeset
|
65 (r1 += (((r5 - #xD800) << 10) + #x10000)))) |
b7fe21511efe
(utf-16-decode-ucs): Handle a surrogate
Kenichi Handa <handa@m17n.org>
parents:
55437
diff
changeset
|
66 (r5 = -1))) |
b7fe21511efe
(utf-16-decode-ucs): Handle a surrogate
Kenichi Handa <handa@m17n.org>
parents:
55437
diff
changeset
|
67 (if (r1 < 128) |
b7fe21511efe
(utf-16-decode-ucs): Handle a surrogate
Kenichi Handa <handa@m17n.org>
parents:
55437
diff
changeset
|
68 (r0 = ,(charset-id 'ascii)) |
b7fe21511efe
(utf-16-decode-ucs): Handle a surrogate
Kenichi Handa <handa@m17n.org>
parents:
55437
diff
changeset
|
69 ((lookup-integer utf-subst-table-for-decode r1 r3) |
b7fe21511efe
(utf-16-decode-ucs): Handle a surrogate
Kenichi Handa <handa@m17n.org>
parents:
55437
diff
changeset
|
70 (if r7 ; got a translation |
b7fe21511efe
(utf-16-decode-ucs): Handle a surrogate
Kenichi Handa <handa@m17n.org>
parents:
55437
diff
changeset
|
71 ((r0 = r1) (r1 = r3)) |
b7fe21511efe
(utf-16-decode-ucs): Handle a surrogate
Kenichi Handa <handa@m17n.org>
parents:
55437
diff
changeset
|
72 (if (r1 < 160) |
b7fe21511efe
(utf-16-decode-ucs): Handle a surrogate
Kenichi Handa <handa@m17n.org>
parents:
55437
diff
changeset
|
73 (r0 = ,(charset-id 'eight-bit-control)) |
b7fe21511efe
(utf-16-decode-ucs): Handle a surrogate
Kenichi Handa <handa@m17n.org>
parents:
55437
diff
changeset
|
74 (if (r1 < 256) |
b7fe21511efe
(utf-16-decode-ucs): Handle a surrogate
Kenichi Handa <handa@m17n.org>
parents:
55437
diff
changeset
|
75 ((r0 = ,(charset-id 'latin-iso8859-1)) |
b7fe21511efe
(utf-16-decode-ucs): Handle a surrogate
Kenichi Handa <handa@m17n.org>
parents:
55437
diff
changeset
|
76 (r1 -= 128)) |
b7fe21511efe
(utf-16-decode-ucs): Handle a surrogate
Kenichi Handa <handa@m17n.org>
parents:
55437
diff
changeset
|
77 (if (r1 < #x2500) |
b7fe21511efe
(utf-16-decode-ucs): Handle a surrogate
Kenichi Handa <handa@m17n.org>
parents:
55437
diff
changeset
|
78 ((r0 = ,(charset-id 'mule-unicode-0100-24ff)) |
b7fe21511efe
(utf-16-decode-ucs): Handle a surrogate
Kenichi Handa <handa@m17n.org>
parents:
55437
diff
changeset
|
79 (r1 -= #x100) |
b7fe21511efe
(utf-16-decode-ucs): Handle a surrogate
Kenichi Handa <handa@m17n.org>
parents:
55437
diff
changeset
|
80 (r2 = (((r1 / 96) + 32) << 7)) |
b7fe21511efe
(utf-16-decode-ucs): Handle a surrogate
Kenichi Handa <handa@m17n.org>
parents:
55437
diff
changeset
|
81 (r1 %= 96) |
b7fe21511efe
(utf-16-decode-ucs): Handle a surrogate
Kenichi Handa <handa@m17n.org>
parents:
55437
diff
changeset
|
82 (r1 += (r2 + 32))) |
b7fe21511efe
(utf-16-decode-ucs): Handle a surrogate
Kenichi Handa <handa@m17n.org>
parents:
55437
diff
changeset
|
83 (if (r1 < #x3400) |
b7fe21511efe
(utf-16-decode-ucs): Handle a surrogate
Kenichi Handa <handa@m17n.org>
parents:
55437
diff
changeset
|
84 ((r0 = ,(charset-id 'mule-unicode-2500-33ff)) |
b7fe21511efe
(utf-16-decode-ucs): Handle a surrogate
Kenichi Handa <handa@m17n.org>
parents:
55437
diff
changeset
|
85 (r1 -= #x2500) |
b7fe21511efe
(utf-16-decode-ucs): Handle a surrogate
Kenichi Handa <handa@m17n.org>
parents:
55437
diff
changeset
|
86 (r2 = (((r1 / 96) + 32) << 7)) |
b7fe21511efe
(utf-16-decode-ucs): Handle a surrogate
Kenichi Handa <handa@m17n.org>
parents:
55437
diff
changeset
|
87 (r1 %= 96) |
b7fe21511efe
(utf-16-decode-ucs): Handle a surrogate
Kenichi Handa <handa@m17n.org>
parents:
55437
diff
changeset
|
88 (r1 += (r2 + 32))) |
b7fe21511efe
(utf-16-decode-ucs): Handle a surrogate
Kenichi Handa <handa@m17n.org>
parents:
55437
diff
changeset
|
89 (if (r1 < #xD800) |
b7fe21511efe
(utf-16-decode-ucs): Handle a surrogate
Kenichi Handa <handa@m17n.org>
parents:
55437
diff
changeset
|
90 ;; We can't have this character. |
b7fe21511efe
(utf-16-decode-ucs): Handle a surrogate
Kenichi Handa <handa@m17n.org>
parents:
55437
diff
changeset
|
91 ((r0 = r1) |
b7fe21511efe
(utf-16-decode-ucs): Handle a surrogate
Kenichi Handa <handa@m17n.org>
parents:
55437
diff
changeset
|
92 (call ccl-mule-utf-untrans) |
b7fe21511efe
(utf-16-decode-ucs): Handle a surrogate
Kenichi Handa <handa@m17n.org>
parents:
55437
diff
changeset
|
93 (r5 = -1) |
b7fe21511efe
(utf-16-decode-ucs): Handle a surrogate
Kenichi Handa <handa@m17n.org>
parents:
55437
diff
changeset
|
94 (r0 = -1)) |
b7fe21511efe
(utf-16-decode-ucs): Handle a surrogate
Kenichi Handa <handa@m17n.org>
parents:
55437
diff
changeset
|
95 (if (r1 < #xDC00) |
b7fe21511efe
(utf-16-decode-ucs): Handle a surrogate
Kenichi Handa <handa@m17n.org>
parents:
55437
diff
changeset
|
96 ;; The first code of a surrogate pair. |
b7fe21511efe
(utf-16-decode-ucs): Handle a surrogate
Kenichi Handa <handa@m17n.org>
parents:
55437
diff
changeset
|
97 ((r5 = r1) |
b7fe21511efe
(utf-16-decode-ucs): Handle a surrogate
Kenichi Handa <handa@m17n.org>
parents:
55437
diff
changeset
|
98 (r0 = -1)) |
b7fe21511efe
(utf-16-decode-ucs): Handle a surrogate
Kenichi Handa <handa@m17n.org>
parents:
55437
diff
changeset
|
99 (if (r1 < #xE000) |
b7fe21511efe
(utf-16-decode-ucs): Handle a surrogate
Kenichi Handa <handa@m17n.org>
parents:
55437
diff
changeset
|
100 ;; The second code of a surrogate pair, invalid. |
b7fe21511efe
(utf-16-decode-ucs): Handle a surrogate
Kenichi Handa <handa@m17n.org>
parents:
55437
diff
changeset
|
101 ((r0 = r1) |
b7fe21511efe
(utf-16-decode-ucs): Handle a surrogate
Kenichi Handa <handa@m17n.org>
parents:
55437
diff
changeset
|
102 (call ccl-mule-utf-untrans) |
b7fe21511efe
(utf-16-decode-ucs): Handle a surrogate
Kenichi Handa <handa@m17n.org>
parents:
55437
diff
changeset
|
103 (r5 = -1) |
b7fe21511efe
(utf-16-decode-ucs): Handle a surrogate
Kenichi Handa <handa@m17n.org>
parents:
55437
diff
changeset
|
104 (r0 = -1)) |
b7fe21511efe
(utf-16-decode-ucs): Handle a surrogate
Kenichi Handa <handa@m17n.org>
parents:
55437
diff
changeset
|
105 (if (r1 < #x10000) |
b7fe21511efe
(utf-16-decode-ucs): Handle a surrogate
Kenichi Handa <handa@m17n.org>
parents:
55437
diff
changeset
|
106 ((r0 = ,(charset-id 'mule-unicode-e000-ffff)) |
b7fe21511efe
(utf-16-decode-ucs): Handle a surrogate
Kenichi Handa <handa@m17n.org>
parents:
55437
diff
changeset
|
107 (r1 -= #xE000) |
b7fe21511efe
(utf-16-decode-ucs): Handle a surrogate
Kenichi Handa <handa@m17n.org>
parents:
55437
diff
changeset
|
108 (r2 = (((r1 / 96) + 32) << 7)) |
b7fe21511efe
(utf-16-decode-ucs): Handle a surrogate
Kenichi Handa <handa@m17n.org>
parents:
55437
diff
changeset
|
109 (r1 %= 96) |
b7fe21511efe
(utf-16-decode-ucs): Handle a surrogate
Kenichi Handa <handa@m17n.org>
parents:
55437
diff
changeset
|
110 (r1 += (r2 + 32))) |
b7fe21511efe
(utf-16-decode-ucs): Handle a surrogate
Kenichi Handa <handa@m17n.org>
parents:
55437
diff
changeset
|
111 ;; We can't have this character. |
b7fe21511efe
(utf-16-decode-ucs): Handle a surrogate
Kenichi Handa <handa@m17n.org>
parents:
55437
diff
changeset
|
112 ((r0 = r1) |
b7fe21511efe
(utf-16-decode-ucs): Handle a surrogate
Kenichi Handa <handa@m17n.org>
parents:
55437
diff
changeset
|
113 (call ccl-mule-utf-untrans) |
b7fe21511efe
(utf-16-decode-ucs): Handle a surrogate
Kenichi Handa <handa@m17n.org>
parents:
55437
diff
changeset
|
114 (r5 = -1) |
b7fe21511efe
(utf-16-decode-ucs): Handle a surrogate
Kenichi Handa <handa@m17n.org>
parents:
55437
diff
changeset
|
115 (r0 = -1))))))))))))))) |
50483 | 116 |
51631
bc72d6855260
Many name changes: utf-16-{be,le} -> utf-16{be,le}.
Kenichi Handa <handa@m17n.org>
parents:
50483
diff
changeset
|
117 (defconst utf-16le-decode-loop |
56038
b7fe21511efe
(utf-16-decode-ucs): Handle a surrogate
Kenichi Handa <handa@m17n.org>
parents:
55437
diff
changeset
|
118 `((r5 = -1) |
b7fe21511efe
(utf-16-decode-ucs): Handle a surrogate
Kenichi Handa <handa@m17n.org>
parents:
55437
diff
changeset
|
119 (loop |
b7fe21511efe
(utf-16-decode-ucs): Handle a surrogate
Kenichi Handa <handa@m17n.org>
parents:
55437
diff
changeset
|
120 (r3 = -1) |
b7fe21511efe
(utf-16-decode-ucs): Handle a surrogate
Kenichi Handa <handa@m17n.org>
parents:
55437
diff
changeset
|
121 (read r3 r4) |
b7fe21511efe
(utf-16-decode-ucs): Handle a surrogate
Kenichi Handa <handa@m17n.org>
parents:
55437
diff
changeset
|
122 (r1 = (r4 <8 r3)) |
b7fe21511efe
(utf-16-decode-ucs): Handle a surrogate
Kenichi Handa <handa@m17n.org>
parents:
55437
diff
changeset
|
123 ,@utf-16-decode-ucs |
b7fe21511efe
(utf-16-decode-ucs): Handle a surrogate
Kenichi Handa <handa@m17n.org>
parents:
55437
diff
changeset
|
124 (if (r0 >= 0) |
b7fe21511efe
(utf-16-decode-ucs): Handle a surrogate
Kenichi Handa <handa@m17n.org>
parents:
55437
diff
changeset
|
125 ((translate-character utf-translation-table-for-decode r0 r1) |
b7fe21511efe
(utf-16-decode-ucs): Handle a surrogate
Kenichi Handa <handa@m17n.org>
parents:
55437
diff
changeset
|
126 (write-multibyte-character r0 r1))) |
b7fe21511efe
(utf-16-decode-ucs): Handle a surrogate
Kenichi Handa <handa@m17n.org>
parents:
55437
diff
changeset
|
127 (repeat)))) |
50483 | 128 |
51631
bc72d6855260
Many name changes: utf-16-{be,le} -> utf-16{be,le}.
Kenichi Handa <handa@m17n.org>
parents:
50483
diff
changeset
|
129 (defconst utf-16be-decode-loop |
56038
b7fe21511efe
(utf-16-decode-ucs): Handle a surrogate
Kenichi Handa <handa@m17n.org>
parents:
55437
diff
changeset
|
130 `((r5 = -1) |
b7fe21511efe
(utf-16-decode-ucs): Handle a surrogate
Kenichi Handa <handa@m17n.org>
parents:
55437
diff
changeset
|
131 (loop |
b7fe21511efe
(utf-16-decode-ucs): Handle a surrogate
Kenichi Handa <handa@m17n.org>
parents:
55437
diff
changeset
|
132 (r3 = -1) |
b7fe21511efe
(utf-16-decode-ucs): Handle a surrogate
Kenichi Handa <handa@m17n.org>
parents:
55437
diff
changeset
|
133 (read r3 r4) |
b7fe21511efe
(utf-16-decode-ucs): Handle a surrogate
Kenichi Handa <handa@m17n.org>
parents:
55437
diff
changeset
|
134 (r1 = (r3 <8 r4)) |
b7fe21511efe
(utf-16-decode-ucs): Handle a surrogate
Kenichi Handa <handa@m17n.org>
parents:
55437
diff
changeset
|
135 ,@utf-16-decode-ucs |
b7fe21511efe
(utf-16-decode-ucs): Handle a surrogate
Kenichi Handa <handa@m17n.org>
parents:
55437
diff
changeset
|
136 (if (r0 >= 0) |
b7fe21511efe
(utf-16-decode-ucs): Handle a surrogate
Kenichi Handa <handa@m17n.org>
parents:
55437
diff
changeset
|
137 ((translate-character utf-translation-table-for-decode r0 r1) |
b7fe21511efe
(utf-16-decode-ucs): Handle a surrogate
Kenichi Handa <handa@m17n.org>
parents:
55437
diff
changeset
|
138 (write-multibyte-character r0 r1))) |
b7fe21511efe
(utf-16-decode-ucs): Handle a surrogate
Kenichi Handa <handa@m17n.org>
parents:
55437
diff
changeset
|
139 (repeat)))) |
50483 | 140 |
141 ) | |
46677 | 142 |
51631
bc72d6855260
Many name changes: utf-16-{be,le} -> utf-16{be,le}.
Kenichi Handa <handa@m17n.org>
parents:
50483
diff
changeset
|
143 (define-ccl-program ccl-decode-mule-utf-16le |
46677 | 144 `(2 ; 2 bytes -> 1 to 4 bytes |
56038
b7fe21511efe
(utf-16-decode-ucs): Handle a surrogate
Kenichi Handa <handa@m17n.org>
parents:
55437
diff
changeset
|
145 ,utf-16le-decode-loop |
b7fe21511efe
(utf-16-decode-ucs): Handle a surrogate
Kenichi Handa <handa@m17n.org>
parents:
55437
diff
changeset
|
146 ((if (r5 >= 0) |
b7fe21511efe
(utf-16-decode-ucs): Handle a surrogate
Kenichi Handa <handa@m17n.org>
parents:
55437
diff
changeset
|
147 ((r0 = r5) |
b7fe21511efe
(utf-16-decode-ucs): Handle a surrogate
Kenichi Handa <handa@m17n.org>
parents:
55437
diff
changeset
|
148 (call ccl-mule-utf-untrans))) |
b7fe21511efe
(utf-16-decode-ucs): Handle a surrogate
Kenichi Handa <handa@m17n.org>
parents:
55437
diff
changeset
|
149 (if (r3 < 0) |
b7fe21511efe
(utf-16-decode-ucs): Handle a surrogate
Kenichi Handa <handa@m17n.org>
parents:
55437
diff
changeset
|
150 nil |
b7fe21511efe
(utf-16-decode-ucs): Handle a surrogate
Kenichi Handa <handa@m17n.org>
parents:
55437
diff
changeset
|
151 ((if (r3 < #xA0) |
b7fe21511efe
(utf-16-decode-ucs): Handle a surrogate
Kenichi Handa <handa@m17n.org>
parents:
55437
diff
changeset
|
152 (r0 = ,(charset-id 'eight-bit-control)) |
b7fe21511efe
(utf-16-decode-ucs): Handle a surrogate
Kenichi Handa <handa@m17n.org>
parents:
55437
diff
changeset
|
153 (r0 = ,(charset-id 'eight-bit-graphic))) |
b7fe21511efe
(utf-16-decode-ucs): Handle a surrogate
Kenichi Handa <handa@m17n.org>
parents:
55437
diff
changeset
|
154 (write-multibyte-character r0 r3))))) |
50349
12444cb90785
(ccl-decode-mule-utf-16-le): Don't assume the signature bytes.
Kenichi Handa <handa@m17n.org>
parents:
49598
diff
changeset
|
155 "Decode UTF-16LE (little endian without signature bytes). |
46677 | 156 Basic decoding is done into the charsets ascii, latin-iso8859-1 and |
47705
797c350a7f8c
(utf-16-decode-ucs): Look up
Kenichi Handa <handa@m17n.org>
parents:
47384
diff
changeset
|
157 mule-unicode-*. Un-representable Unicode characters are decoded as |
797c350a7f8c
(utf-16-decode-ucs): Look up
Kenichi Handa <handa@m17n.org>
parents:
47384
diff
changeset
|
158 U+fffd. The result is run through the translation-table named |
797c350a7f8c
(utf-16-decode-ucs): Look up
Kenichi Handa <handa@m17n.org>
parents:
47384
diff
changeset
|
159 `utf-translation-table-for-decode'.") |
46677 | 160 |
51631
bc72d6855260
Many name changes: utf-16-{be,le} -> utf-16{be,le}.
Kenichi Handa <handa@m17n.org>
parents:
50483
diff
changeset
|
161 (define-ccl-program ccl-decode-mule-utf-16be |
46677 | 162 `(2 ; 2 bytes -> 1 to 4 bytes |
56038
b7fe21511efe
(utf-16-decode-ucs): Handle a surrogate
Kenichi Handa <handa@m17n.org>
parents:
55437
diff
changeset
|
163 ,utf-16be-decode-loop |
b7fe21511efe
(utf-16-decode-ucs): Handle a surrogate
Kenichi Handa <handa@m17n.org>
parents:
55437
diff
changeset
|
164 ((if (r5 >= 0) |
b7fe21511efe
(utf-16-decode-ucs): Handle a surrogate
Kenichi Handa <handa@m17n.org>
parents:
55437
diff
changeset
|
165 ((r0 = r5) |
b7fe21511efe
(utf-16-decode-ucs): Handle a surrogate
Kenichi Handa <handa@m17n.org>
parents:
55437
diff
changeset
|
166 (call ccl-mule-utf-untrans))) |
b7fe21511efe
(utf-16-decode-ucs): Handle a surrogate
Kenichi Handa <handa@m17n.org>
parents:
55437
diff
changeset
|
167 (if (r3 >= 0) |
b7fe21511efe
(utf-16-decode-ucs): Handle a surrogate
Kenichi Handa <handa@m17n.org>
parents:
55437
diff
changeset
|
168 ((r0 = r3) |
b7fe21511efe
(utf-16-decode-ucs): Handle a surrogate
Kenichi Handa <handa@m17n.org>
parents:
55437
diff
changeset
|
169 (call ccl-mule-utf-untrans))))) |
50349
12444cb90785
(ccl-decode-mule-utf-16-le): Don't assume the signature bytes.
Kenichi Handa <handa@m17n.org>
parents:
49598
diff
changeset
|
170 "Decode UTF-16BE (big endian without signature bytes). |
46677 | 171 Basic decoding is done into the charsets ascii, latin-iso8859-1 and |
172 mule-unicode-*. Un-representable Unicode characters are | |
47705
797c350a7f8c
(utf-16-decode-ucs): Look up
Kenichi Handa <handa@m17n.org>
parents:
47384
diff
changeset
|
173 decoded as U+fffd. The result is run through the translation-table of |
797c350a7f8c
(utf-16-decode-ucs): Look up
Kenichi Handa <handa@m17n.org>
parents:
47384
diff
changeset
|
174 name `utf-translation-table-for-decode'.") |
46677 | 175 |
51631
bc72d6855260
Many name changes: utf-16-{be,le} -> utf-16{be,le}.
Kenichi Handa <handa@m17n.org>
parents:
50483
diff
changeset
|
176 (define-ccl-program ccl-decode-mule-utf-16le-with-signature |
50483 | 177 `(2 |
56038
b7fe21511efe
(utf-16-decode-ucs): Handle a surrogate
Kenichi Handa <handa@m17n.org>
parents:
55437
diff
changeset
|
178 ((r3 = -1) |
b7fe21511efe
(utf-16-decode-ucs): Handle a surrogate
Kenichi Handa <handa@m17n.org>
parents:
55437
diff
changeset
|
179 (read r3 r4) |
b7fe21511efe
(utf-16-decode-ucs): Handle a surrogate
Kenichi Handa <handa@m17n.org>
parents:
55437
diff
changeset
|
180 ,@utf-16le-decode-loop) |
b7fe21511efe
(utf-16-decode-ucs): Handle a surrogate
Kenichi Handa <handa@m17n.org>
parents:
55437
diff
changeset
|
181 (if (r3 >= 0) |
b7fe21511efe
(utf-16-decode-ucs): Handle a surrogate
Kenichi Handa <handa@m17n.org>
parents:
55437
diff
changeset
|
182 ((r0 = r3) |
b7fe21511efe
(utf-16-decode-ucs): Handle a surrogate
Kenichi Handa <handa@m17n.org>
parents:
55437
diff
changeset
|
183 (call ccl-mule-utf-untrans)))) |
51631
bc72d6855260
Many name changes: utf-16-{be,le} -> utf-16{be,le}.
Kenichi Handa <handa@m17n.org>
parents:
50483
diff
changeset
|
184 "Like ccl-decode-utf-16le but skip the first 2-byte BOM.") |
50483 | 185 |
51631
bc72d6855260
Many name changes: utf-16-{be,le} -> utf-16{be,le}.
Kenichi Handa <handa@m17n.org>
parents:
50483
diff
changeset
|
186 (define-ccl-program ccl-decode-mule-utf-16be-with-signature |
50483 | 187 `(2 |
56038
b7fe21511efe
(utf-16-decode-ucs): Handle a surrogate
Kenichi Handa <handa@m17n.org>
parents:
55437
diff
changeset
|
188 ((r3 = -1) |
b7fe21511efe
(utf-16-decode-ucs): Handle a surrogate
Kenichi Handa <handa@m17n.org>
parents:
55437
diff
changeset
|
189 (read r3 r4) |
b7fe21511efe
(utf-16-decode-ucs): Handle a surrogate
Kenichi Handa <handa@m17n.org>
parents:
55437
diff
changeset
|
190 ,@utf-16be-decode-loop) |
b7fe21511efe
(utf-16-decode-ucs): Handle a surrogate
Kenichi Handa <handa@m17n.org>
parents:
55437
diff
changeset
|
191 (if (r3 >= 0) |
b7fe21511efe
(utf-16-decode-ucs): Handle a surrogate
Kenichi Handa <handa@m17n.org>
parents:
55437
diff
changeset
|
192 ((r0 = r3) |
b7fe21511efe
(utf-16-decode-ucs): Handle a surrogate
Kenichi Handa <handa@m17n.org>
parents:
55437
diff
changeset
|
193 (call ccl-mule-utf-untrans)))) |
51631
bc72d6855260
Many name changes: utf-16-{be,le} -> utf-16{be,le}.
Kenichi Handa <handa@m17n.org>
parents:
50483
diff
changeset
|
194 "Like ccl-decode-utf-16be but skip the first 2-byte BOM.") |
50483 | 195 |
196 (define-ccl-program ccl-decode-mule-utf-16 | |
197 `(2 | |
56038
b7fe21511efe
(utf-16-decode-ucs): Handle a surrogate
Kenichi Handa <handa@m17n.org>
parents:
55437
diff
changeset
|
198 ((r3 = -1) |
b7fe21511efe
(utf-16-decode-ucs): Handle a surrogate
Kenichi Handa <handa@m17n.org>
parents:
55437
diff
changeset
|
199 (read r3 r4) |
50483 | 200 (r1 = (r3 <8 r4)) |
56038
b7fe21511efe
(utf-16-decode-ucs): Handle a surrogate
Kenichi Handa <handa@m17n.org>
parents:
55437
diff
changeset
|
201 (r5 = -1) |
50483 | 202 (if (r1 == #xFFFE) |
203 ;; R1 is a BOM for little endian. We keep this character as | |
204 ;; is temporarily. It is removed by post-read-conversion | |
205 ;; function. | |
206 (,@utf-16-decode-ucs | |
207 (write-multibyte-character r0 r1) | |
56038
b7fe21511efe
(utf-16-decode-ucs): Handle a surrogate
Kenichi Handa <handa@m17n.org>
parents:
55437
diff
changeset
|
208 ,@utf-16le-decode-loop) |
50483 | 209 ((if (r1 == #xFEFF) |
210 ;; R1 is a BOM for big endian, but we can't keep that | |
211 ;; character in the output because it can't be | |
212 ;; distinguished with the normal U+FEFF. So, we keep | |
213 ;; #xFFFF instead. | |
214 ((r1 = #xFFFF) | |
56038
b7fe21511efe
(utf-16-decode-ucs): Handle a surrogate
Kenichi Handa <handa@m17n.org>
parents:
55437
diff
changeset
|
215 ,@utf-16-decode-ucs |
b7fe21511efe
(utf-16-decode-ucs): Handle a surrogate
Kenichi Handa <handa@m17n.org>
parents:
55437
diff
changeset
|
216 (write-multibyte-character r0 r1)) |
b7fe21511efe
(utf-16-decode-ucs): Handle a surrogate
Kenichi Handa <handa@m17n.org>
parents:
55437
diff
changeset
|
217 ;; R1 is a normal Unicode character. |
50483 | 218 (,@utf-16-decode-ucs |
56038
b7fe21511efe
(utf-16-decode-ucs): Handle a surrogate
Kenichi Handa <handa@m17n.org>
parents:
55437
diff
changeset
|
219 (if (r0 >= 0) |
b7fe21511efe
(utf-16-decode-ucs): Handle a surrogate
Kenichi Handa <handa@m17n.org>
parents:
55437
diff
changeset
|
220 ((translate-character utf-translation-table-for-decode r0 r1) |
b7fe21511efe
(utf-16-decode-ucs): Handle a surrogate
Kenichi Handa <handa@m17n.org>
parents:
55437
diff
changeset
|
221 (write-multibyte-character r0 r1))))) |
b7fe21511efe
(utf-16-decode-ucs): Handle a surrogate
Kenichi Handa <handa@m17n.org>
parents:
55437
diff
changeset
|
222 ,@utf-16be-decode-loop))) |
b7fe21511efe
(utf-16-decode-ucs): Handle a surrogate
Kenichi Handa <handa@m17n.org>
parents:
55437
diff
changeset
|
223 (if (r3 >= 0) |
b7fe21511efe
(utf-16-decode-ucs): Handle a surrogate
Kenichi Handa <handa@m17n.org>
parents:
55437
diff
changeset
|
224 ((r0 = r3) |
b7fe21511efe
(utf-16-decode-ucs): Handle a surrogate
Kenichi Handa <handa@m17n.org>
parents:
55437
diff
changeset
|
225 (call ccl-mule-utf-untrans)))) |
51631
bc72d6855260
Many name changes: utf-16-{be,le} -> utf-16{be,le}.
Kenichi Handa <handa@m17n.org>
parents:
50483
diff
changeset
|
226 "Like ccl-decode-utf-16be/le but check the first BOM.") |
50483 | 227 |
46677 | 228 (makunbound 'utf-16-decode-ucs) ; done with it |
51631
bc72d6855260
Many name changes: utf-16-{be,le} -> utf-16{be,le}.
Kenichi Handa <handa@m17n.org>
parents:
50483
diff
changeset
|
229 (makunbound 'utf-16le-decode-loop) |
bc72d6855260
Many name changes: utf-16-{be,le} -> utf-16{be,le}.
Kenichi Handa <handa@m17n.org>
parents:
50483
diff
changeset
|
230 (makunbound 'utf-16be-decode-loop) |
46677 | 231 |
56038
b7fe21511efe
(utf-16-decode-ucs): Handle a surrogate
Kenichi Handa <handa@m17n.org>
parents:
55437
diff
changeset
|
232 ;; UTF-16 decoder generates an UTF-8 sequence represented by a |
b7fe21511efe
(utf-16-decode-ucs): Handle a surrogate
Kenichi Handa <handa@m17n.org>
parents:
55437
diff
changeset
|
233 ;; sequence eight-bit-control/graphic chars for an invalid byte (the |
b7fe21511efe
(utf-16-decode-ucs): Handle a surrogate
Kenichi Handa <handa@m17n.org>
parents:
55437
diff
changeset
|
234 ;; last byte of an odd length source) and an untranslatable character |
b7fe21511efe
(utf-16-decode-ucs): Handle a surrogate
Kenichi Handa <handa@m17n.org>
parents:
55437
diff
changeset
|
235 ;; (including an invalid surrogate-pair code-point). |
b7fe21511efe
(utf-16-decode-ucs): Handle a surrogate
Kenichi Handa <handa@m17n.org>
parents:
55437
diff
changeset
|
236 ;; |
b7fe21511efe
(utf-16-decode-ucs): Handle a surrogate
Kenichi Handa <handa@m17n.org>
parents:
55437
diff
changeset
|
237 ;; This CCL parses that sequence (the first byte is already in r1), |
b7fe21511efe
(utf-16-decode-ucs): Handle a surrogate
Kenichi Handa <handa@m17n.org>
parents:
55437
diff
changeset
|
238 ;; and if the sequence represents an untranslatable character, it sets |
b7fe21511efe
(utf-16-decode-ucs): Handle a surrogate
Kenichi Handa <handa@m17n.org>
parents:
55437
diff
changeset
|
239 ;; r1 to the original invalid code or untranslated Unicode character |
b7fe21511efe
(utf-16-decode-ucs): Handle a surrogate
Kenichi Handa <handa@m17n.org>
parents:
55437
diff
changeset
|
240 ;; code, sets r2 to -1 (to prevent r2 and r3 are written), set2 r5 to |
b7fe21511efe
(utf-16-decode-ucs): Handle a surrogate
Kenichi Handa <handa@m17n.org>
parents:
55437
diff
changeset
|
241 ;; -1 (to tell the caller that there's no pre-read character). |
b7fe21511efe
(utf-16-decode-ucs): Handle a surrogate
Kenichi Handa <handa@m17n.org>
parents:
55437
diff
changeset
|
242 ;; |
b7fe21511efe
(utf-16-decode-ucs): Handle a surrogate
Kenichi Handa <handa@m17n.org>
parents:
55437
diff
changeset
|
243 ;; If the sequence represents an invalid byte, it sets r1 to -1, r2 to |
b7fe21511efe
(utf-16-decode-ucs): Handle a surrogate
Kenichi Handa <handa@m17n.org>
parents:
55437
diff
changeset
|
244 ;; the byte, sets r3 and r5 to -1. |
b7fe21511efe
(utf-16-decode-ucs): Handle a surrogate
Kenichi Handa <handa@m17n.org>
parents:
55437
diff
changeset
|
245 ;; |
b7fe21511efe
(utf-16-decode-ucs): Handle a surrogate
Kenichi Handa <handa@m17n.org>
parents:
55437
diff
changeset
|
246 ;; Otherwise, don't change r1, set r2 and r3 to already read |
b7fe21511efe
(utf-16-decode-ucs): Handle a surrogate
Kenichi Handa <handa@m17n.org>
parents:
55437
diff
changeset
|
247 ;; eight-bit-control/graphic characters (if any), set r5 and r6 to the |
b7fe21511efe
(utf-16-decode-ucs): Handle a surrogate
Kenichi Handa <handa@m17n.org>
parents:
55437
diff
changeset
|
248 ;; last character that invalidates the UTF-8 form. |
b7fe21511efe
(utf-16-decode-ucs): Handle a surrogate
Kenichi Handa <handa@m17n.org>
parents:
55437
diff
changeset
|
249 ;; |
b7fe21511efe
(utf-16-decode-ucs): Handle a surrogate
Kenichi Handa <handa@m17n.org>
parents:
55437
diff
changeset
|
250 ;; Note: For UTF-8 validation, we only check if a character is |
b7fe21511efe
(utf-16-decode-ucs): Handle a surrogate
Kenichi Handa <handa@m17n.org>
parents:
55437
diff
changeset
|
251 ;; eight-bit-control/graphic or not. It may result in incorrect |
b7fe21511efe
(utf-16-decode-ucs): Handle a surrogate
Kenichi Handa <handa@m17n.org>
parents:
55437
diff
changeset
|
252 ;; handling of random binary data, but such a data can't be encoded by |
b7fe21511efe
(utf-16-decode-ucs): Handle a surrogate
Kenichi Handa <handa@m17n.org>
parents:
55437
diff
changeset
|
253 ;; UTF-16 anyway. At least, UTF-16 decoder doesn't generate such a |
b7fe21511efe
(utf-16-decode-ucs): Handle a surrogate
Kenichi Handa <handa@m17n.org>
parents:
55437
diff
changeset
|
254 ;; sequence even if a source contains invalid byte-sequence. |
b7fe21511efe
(utf-16-decode-ucs): Handle a surrogate
Kenichi Handa <handa@m17n.org>
parents:
55437
diff
changeset
|
255 |
b7fe21511efe
(utf-16-decode-ucs): Handle a surrogate
Kenichi Handa <handa@m17n.org>
parents:
55437
diff
changeset
|
256 (define-ccl-program ccl-mule-utf-16-encode-untrans |
b7fe21511efe
(utf-16-decode-ucs): Handle a surrogate
Kenichi Handa <handa@m17n.org>
parents:
55437
diff
changeset
|
257 `(0 |
b7fe21511efe
(utf-16-decode-ucs): Handle a surrogate
Kenichi Handa <handa@m17n.org>
parents:
55437
diff
changeset
|
258 ((r2 = -1) |
b7fe21511efe
(utf-16-decode-ucs): Handle a surrogate
Kenichi Handa <handa@m17n.org>
parents:
55437
diff
changeset
|
259 ;; Read the 2nd byte. |
b7fe21511efe
(utf-16-decode-ucs): Handle a surrogate
Kenichi Handa <handa@m17n.org>
parents:
55437
diff
changeset
|
260 (read-multibyte-character r5 r6) |
b7fe21511efe
(utf-16-decode-ucs): Handle a surrogate
Kenichi Handa <handa@m17n.org>
parents:
55437
diff
changeset
|
261 (r0 = (r5 != ,(charset-id 'eight-bit-control))) |
b7fe21511efe
(utf-16-decode-ucs): Handle a surrogate
Kenichi Handa <handa@m17n.org>
parents:
55437
diff
changeset
|
262 (if ((r5 != ,(charset-id 'eight-bit-graphic)) & r0) |
b7fe21511efe
(utf-16-decode-ucs): Handle a surrogate
Kenichi Handa <handa@m17n.org>
parents:
55437
diff
changeset
|
263 ((r2 = r1) |
b7fe21511efe
(utf-16-decode-ucs): Handle a surrogate
Kenichi Handa <handa@m17n.org>
parents:
55437
diff
changeset
|
264 (r3 = -1) |
b7fe21511efe
(utf-16-decode-ucs): Handle a surrogate
Kenichi Handa <handa@m17n.org>
parents:
55437
diff
changeset
|
265 (r1 = -1) |
b7fe21511efe
(utf-16-decode-ucs): Handle a surrogate
Kenichi Handa <handa@m17n.org>
parents:
55437
diff
changeset
|
266 (end))) ; invalid UTF-8 |
b7fe21511efe
(utf-16-decode-ucs): Handle a surrogate
Kenichi Handa <handa@m17n.org>
parents:
55437
diff
changeset
|
267 |
b7fe21511efe
(utf-16-decode-ucs): Handle a surrogate
Kenichi Handa <handa@m17n.org>
parents:
55437
diff
changeset
|
268 (r3 = -1) |
b7fe21511efe
(utf-16-decode-ucs): Handle a surrogate
Kenichi Handa <handa@m17n.org>
parents:
55437
diff
changeset
|
269 (r2 = r6) |
b7fe21511efe
(utf-16-decode-ucs): Handle a surrogate
Kenichi Handa <handa@m17n.org>
parents:
55437
diff
changeset
|
270 (if (r1 <= #xE0) |
b7fe21511efe
(utf-16-decode-ucs): Handle a surrogate
Kenichi Handa <handa@m17n.org>
parents:
55437
diff
changeset
|
271 ;; 2-byte UTF-8, i.e. originally an invalid byte. |
b7fe21511efe
(utf-16-decode-ucs): Handle a surrogate
Kenichi Handa <handa@m17n.org>
parents:
55437
diff
changeset
|
272 ((r2 &= #x3F) |
b7fe21511efe
(utf-16-decode-ucs): Handle a surrogate
Kenichi Handa <handa@m17n.org>
parents:
55437
diff
changeset
|
273 (r2 |= ((r1 & #x1F) << 6)) |
b7fe21511efe
(utf-16-decode-ucs): Handle a surrogate
Kenichi Handa <handa@m17n.org>
parents:
55437
diff
changeset
|
274 (r1 = -1) |
b7fe21511efe
(utf-16-decode-ucs): Handle a surrogate
Kenichi Handa <handa@m17n.org>
parents:
55437
diff
changeset
|
275 (r5 = -1) |
b7fe21511efe
(utf-16-decode-ucs): Handle a surrogate
Kenichi Handa <handa@m17n.org>
parents:
55437
diff
changeset
|
276 (end))) |
b7fe21511efe
(utf-16-decode-ucs): Handle a surrogate
Kenichi Handa <handa@m17n.org>
parents:
55437
diff
changeset
|
277 |
b7fe21511efe
(utf-16-decode-ucs): Handle a surrogate
Kenichi Handa <handa@m17n.org>
parents:
55437
diff
changeset
|
278 ;; Read the 3rd byte. |
b7fe21511efe
(utf-16-decode-ucs): Handle a surrogate
Kenichi Handa <handa@m17n.org>
parents:
55437
diff
changeset
|
279 (read-multibyte-character r5 r6) |
b7fe21511efe
(utf-16-decode-ucs): Handle a surrogate
Kenichi Handa <handa@m17n.org>
parents:
55437
diff
changeset
|
280 (r0 = (r5 != ,(charset-id 'eight-bit-control))) |
b7fe21511efe
(utf-16-decode-ucs): Handle a surrogate
Kenichi Handa <handa@m17n.org>
parents:
55437
diff
changeset
|
281 (if ((r5 != ,(charset-id 'eight-bit-graphic)) & r0) |
b7fe21511efe
(utf-16-decode-ucs): Handle a surrogate
Kenichi Handa <handa@m17n.org>
parents:
55437
diff
changeset
|
282 ((end))) ; invalid UTF-8 |
b7fe21511efe
(utf-16-decode-ucs): Handle a surrogate
Kenichi Handa <handa@m17n.org>
parents:
55437
diff
changeset
|
283 |
b7fe21511efe
(utf-16-decode-ucs): Handle a surrogate
Kenichi Handa <handa@m17n.org>
parents:
55437
diff
changeset
|
284 (if (r1 < #xF0) ; valid 3-byte UTF-8 |
b7fe21511efe
(utf-16-decode-ucs): Handle a surrogate
Kenichi Handa <handa@m17n.org>
parents:
55437
diff
changeset
|
285 ((r1 = ((r1 & #x0F) << 12)) |
b7fe21511efe
(utf-16-decode-ucs): Handle a surrogate
Kenichi Handa <handa@m17n.org>
parents:
55437
diff
changeset
|
286 (r1 |= ((r2 & #x3F) << 6)) |
b7fe21511efe
(utf-16-decode-ucs): Handle a surrogate
Kenichi Handa <handa@m17n.org>
parents:
55437
diff
changeset
|
287 (r1 |= (r6 & #x3F)) |
b7fe21511efe
(utf-16-decode-ucs): Handle a surrogate
Kenichi Handa <handa@m17n.org>
parents:
55437
diff
changeset
|
288 (r2 = -1) |
b7fe21511efe
(utf-16-decode-ucs): Handle a surrogate
Kenichi Handa <handa@m17n.org>
parents:
55437
diff
changeset
|
289 (r5 = -1) |
b7fe21511efe
(utf-16-decode-ucs): Handle a surrogate
Kenichi Handa <handa@m17n.org>
parents:
55437
diff
changeset
|
290 (end))) |
b7fe21511efe
(utf-16-decode-ucs): Handle a surrogate
Kenichi Handa <handa@m17n.org>
parents:
55437
diff
changeset
|
291 |
b7fe21511efe
(utf-16-decode-ucs): Handle a surrogate
Kenichi Handa <handa@m17n.org>
parents:
55437
diff
changeset
|
292 (r3 = r6) |
b7fe21511efe
(utf-16-decode-ucs): Handle a surrogate
Kenichi Handa <handa@m17n.org>
parents:
55437
diff
changeset
|
293 ;; Read the 4th byte. |
b7fe21511efe
(utf-16-decode-ucs): Handle a surrogate
Kenichi Handa <handa@m17n.org>
parents:
55437
diff
changeset
|
294 (read-multibyte-character r5 r6) |
b7fe21511efe
(utf-16-decode-ucs): Handle a surrogate
Kenichi Handa <handa@m17n.org>
parents:
55437
diff
changeset
|
295 (r0 = (r5 != ,(charset-id 'eight-bit-control))) |
b7fe21511efe
(utf-16-decode-ucs): Handle a surrogate
Kenichi Handa <handa@m17n.org>
parents:
55437
diff
changeset
|
296 (if ((r5 != ,(charset-id 'eight-bit-graphic)) & r0) |
b7fe21511efe
(utf-16-decode-ucs): Handle a surrogate
Kenichi Handa <handa@m17n.org>
parents:
55437
diff
changeset
|
297 (end)) ; livalid UTF-8 |
b7fe21511efe
(utf-16-decode-ucs): Handle a surrogate
Kenichi Handa <handa@m17n.org>
parents:
55437
diff
changeset
|
298 |
b7fe21511efe
(utf-16-decode-ucs): Handle a surrogate
Kenichi Handa <handa@m17n.org>
parents:
55437
diff
changeset
|
299 ;; valid 4-byte UTF-8 |
b7fe21511efe
(utf-16-decode-ucs): Handle a surrogate
Kenichi Handa <handa@m17n.org>
parents:
55437
diff
changeset
|
300 (r1 = ((r1 & #x07) << 18)) |
b7fe21511efe
(utf-16-decode-ucs): Handle a surrogate
Kenichi Handa <handa@m17n.org>
parents:
55437
diff
changeset
|
301 (r1 |= ((r2 & #x3F) << 12)) |
b7fe21511efe
(utf-16-decode-ucs): Handle a surrogate
Kenichi Handa <handa@m17n.org>
parents:
55437
diff
changeset
|
302 (r1 |= ((r3 & #x3F) << 6)) |
b7fe21511efe
(utf-16-decode-ucs): Handle a surrogate
Kenichi Handa <handa@m17n.org>
parents:
55437
diff
changeset
|
303 (r1 |= (r6 & #x3F)) |
b7fe21511efe
(utf-16-decode-ucs): Handle a surrogate
Kenichi Handa <handa@m17n.org>
parents:
55437
diff
changeset
|
304 (r2 = -1) |
b7fe21511efe
(utf-16-decode-ucs): Handle a surrogate
Kenichi Handa <handa@m17n.org>
parents:
55437
diff
changeset
|
305 (r5 = -1) |
b7fe21511efe
(utf-16-decode-ucs): Handle a surrogate
Kenichi Handa <handa@m17n.org>
parents:
55437
diff
changeset
|
306 (end)) |
b7fe21511efe
(utf-16-decode-ucs): Handle a surrogate
Kenichi Handa <handa@m17n.org>
parents:
55437
diff
changeset
|
307 |
b7fe21511efe
(utf-16-decode-ucs): Handle a surrogate
Kenichi Handa <handa@m17n.org>
parents:
55437
diff
changeset
|
308 (if (r1 >= 0) |
b7fe21511efe
(utf-16-decode-ucs): Handle a surrogate
Kenichi Handa <handa@m17n.org>
parents:
55437
diff
changeset
|
309 ((write r1) |
b7fe21511efe
(utf-16-decode-ucs): Handle a surrogate
Kenichi Handa <handa@m17n.org>
parents:
55437
diff
changeset
|
310 (if (r2 >= 0) |
b7fe21511efe
(utf-16-decode-ucs): Handle a surrogate
Kenichi Handa <handa@m17n.org>
parents:
55437
diff
changeset
|
311 ((write r2) |
b7fe21511efe
(utf-16-decode-ucs): Handle a surrogate
Kenichi Handa <handa@m17n.org>
parents:
55437
diff
changeset
|
312 (if (r3 >= 0) |
b7fe21511efe
(utf-16-decode-ucs): Handle a surrogate
Kenichi Handa <handa@m17n.org>
parents:
55437
diff
changeset
|
313 (write r3)))))))) |
b7fe21511efe
(utf-16-decode-ucs): Handle a surrogate
Kenichi Handa <handa@m17n.org>
parents:
55437
diff
changeset
|
314 |
46677 | 315 (eval-and-compile |
316 (defconst utf-16-decode-to-ucs | |
56038
b7fe21511efe
(utf-16-decode-ucs): Handle a surrogate
Kenichi Handa <handa@m17n.org>
parents:
55437
diff
changeset
|
317 ;; Read a character and set r1 to the corresponding Unicode code. |
b7fe21511efe
(utf-16-decode-ucs): Handle a surrogate
Kenichi Handa <handa@m17n.org>
parents:
55437
diff
changeset
|
318 ;; If r5 is not negative, it means that we have already read a |
b7fe21511efe
(utf-16-decode-ucs): Handle a surrogate
Kenichi Handa <handa@m17n.org>
parents:
55437
diff
changeset
|
319 ;; character into r5 and r6. |
b7fe21511efe
(utf-16-decode-ucs): Handle a surrogate
Kenichi Handa <handa@m17n.org>
parents:
55437
diff
changeset
|
320 ;; If an invalid eight-bit-control/graphic sequence is found, r2 and |
b7fe21511efe
(utf-16-decode-ucs): Handle a surrogate
Kenichi Handa <handa@m17n.org>
parents:
55437
diff
changeset
|
321 ;; r3 may contain a byte to written out, r5 and r6 may contain a |
b7fe21511efe
(utf-16-decode-ucs): Handle a surrogate
Kenichi Handa <handa@m17n.org>
parents:
55437
diff
changeset
|
322 ;; pre-read character. Usually they are set to -1. |
b7fe21511efe
(utf-16-decode-ucs): Handle a surrogate
Kenichi Handa <handa@m17n.org>
parents:
55437
diff
changeset
|
323 `((if (r5 < 0) |
b7fe21511efe
(utf-16-decode-ucs): Handle a surrogate
Kenichi Handa <handa@m17n.org>
parents:
55437
diff
changeset
|
324 (read-multibyte-character r0 r1) |
b7fe21511efe
(utf-16-decode-ucs): Handle a surrogate
Kenichi Handa <handa@m17n.org>
parents:
55437
diff
changeset
|
325 ((r0 = r5) |
b7fe21511efe
(utf-16-decode-ucs): Handle a surrogate
Kenichi Handa <handa@m17n.org>
parents:
55437
diff
changeset
|
326 (r1 = r6) |
b7fe21511efe
(utf-16-decode-ucs): Handle a surrogate
Kenichi Handa <handa@m17n.org>
parents:
55437
diff
changeset
|
327 (r5 = -1))) |
b7fe21511efe
(utf-16-decode-ucs): Handle a surrogate
Kenichi Handa <handa@m17n.org>
parents:
55437
diff
changeset
|
328 (lookup-character utf-subst-table-for-encode r0 r1) |
b7fe21511efe
(utf-16-decode-ucs): Handle a surrogate
Kenichi Handa <handa@m17n.org>
parents:
55437
diff
changeset
|
329 (r2 = -1) |
b7fe21511efe
(utf-16-decode-ucs): Handle a surrogate
Kenichi Handa <handa@m17n.org>
parents:
55437
diff
changeset
|
330 (if (r7 > 0) |
b7fe21511efe
(utf-16-decode-ucs): Handle a surrogate
Kenichi Handa <handa@m17n.org>
parents:
55437
diff
changeset
|
331 (r1 = r0) |
b7fe21511efe
(utf-16-decode-ucs): Handle a surrogate
Kenichi Handa <handa@m17n.org>
parents:
55437
diff
changeset
|
332 ((translate-character utf-translation-table-for-encode r0 r1) |
b7fe21511efe
(utf-16-decode-ucs): Handle a surrogate
Kenichi Handa <handa@m17n.org>
parents:
55437
diff
changeset
|
333 (if (r0 == ,(charset-id 'ascii)) |
b7fe21511efe
(utf-16-decode-ucs): Handle a surrogate
Kenichi Handa <handa@m17n.org>
parents:
55437
diff
changeset
|
334 nil |
b7fe21511efe
(utf-16-decode-ucs): Handle a surrogate
Kenichi Handa <handa@m17n.org>
parents:
55437
diff
changeset
|
335 (if (r0 == ,(charset-id 'latin-iso8859-1)) |
b7fe21511efe
(utf-16-decode-ucs): Handle a surrogate
Kenichi Handa <handa@m17n.org>
parents:
55437
diff
changeset
|
336 (r1 += 128) |
b7fe21511efe
(utf-16-decode-ucs): Handle a surrogate
Kenichi Handa <handa@m17n.org>
parents:
55437
diff
changeset
|
337 (if (r0 == ,(charset-id 'eight-bit-control)) |
b7fe21511efe
(utf-16-decode-ucs): Handle a surrogate
Kenichi Handa <handa@m17n.org>
parents:
55437
diff
changeset
|
338 nil |
b7fe21511efe
(utf-16-decode-ucs): Handle a surrogate
Kenichi Handa <handa@m17n.org>
parents:
55437
diff
changeset
|
339 (if (r0 == ,(charset-id 'eight-bit-graphic)) |
b7fe21511efe
(utf-16-decode-ucs): Handle a surrogate
Kenichi Handa <handa@m17n.org>
parents:
55437
diff
changeset
|
340 (call ccl-mule-utf-16-encode-untrans) |
b7fe21511efe
(utf-16-decode-ucs): Handle a surrogate
Kenichi Handa <handa@m17n.org>
parents:
55437
diff
changeset
|
341 ((r2 = ((r1 & #x7f) - 32)) |
b7fe21511efe
(utf-16-decode-ucs): Handle a surrogate
Kenichi Handa <handa@m17n.org>
parents:
55437
diff
changeset
|
342 (r3 = ((((r1 >> 7) - 32) * 96) + r2)) |
b7fe21511efe
(utf-16-decode-ucs): Handle a surrogate
Kenichi Handa <handa@m17n.org>
parents:
55437
diff
changeset
|
343 (r2 = -1) |
b7fe21511efe
(utf-16-decode-ucs): Handle a surrogate
Kenichi Handa <handa@m17n.org>
parents:
55437
diff
changeset
|
344 (r5 = -1) |
b7fe21511efe
(utf-16-decode-ucs): Handle a surrogate
Kenichi Handa <handa@m17n.org>
parents:
55437
diff
changeset
|
345 (if (r0 == ,(charset-id 'mule-unicode-0100-24ff)) |
b7fe21511efe
(utf-16-decode-ucs): Handle a surrogate
Kenichi Handa <handa@m17n.org>
parents:
55437
diff
changeset
|
346 (r1 = (r3 + #x100)) |
b7fe21511efe
(utf-16-decode-ucs): Handle a surrogate
Kenichi Handa <handa@m17n.org>
parents:
55437
diff
changeset
|
347 (if (r0 == ,(charset-id 'mule-unicode-2500-33ff)) |
b7fe21511efe
(utf-16-decode-ucs): Handle a surrogate
Kenichi Handa <handa@m17n.org>
parents:
55437
diff
changeset
|
348 (r1 = (r3 + #x2500)) |
b7fe21511efe
(utf-16-decode-ucs): Handle a surrogate
Kenichi Handa <handa@m17n.org>
parents:
55437
diff
changeset
|
349 (if (r0 == ,(charset-id 'mule-unicode-e000-ffff)) |
b7fe21511efe
(utf-16-decode-ucs): Handle a surrogate
Kenichi Handa <handa@m17n.org>
parents:
55437
diff
changeset
|
350 (r1 = (r3 + #xe000)) |
b7fe21511efe
(utf-16-decode-ucs): Handle a surrogate
Kenichi Handa <handa@m17n.org>
parents:
55437
diff
changeset
|
351 (r1 = #xfffd))))))))))))) |
50483 | 352 |
51631
bc72d6855260
Many name changes: utf-16-{be,le} -> utf-16{be,le}.
Kenichi Handa <handa@m17n.org>
parents:
50483
diff
changeset
|
353 (defconst utf-16le-encode-loop |
56038
b7fe21511efe
(utf-16-decode-ucs): Handle a surrogate
Kenichi Handa <handa@m17n.org>
parents:
55437
diff
changeset
|
354 `((r5 = -1) |
b7fe21511efe
(utf-16-decode-ucs): Handle a surrogate
Kenichi Handa <handa@m17n.org>
parents:
55437
diff
changeset
|
355 (loop |
b7fe21511efe
(utf-16-decode-ucs): Handle a surrogate
Kenichi Handa <handa@m17n.org>
parents:
55437
diff
changeset
|
356 ,@utf-16-decode-to-ucs |
b7fe21511efe
(utf-16-decode-ucs): Handle a surrogate
Kenichi Handa <handa@m17n.org>
parents:
55437
diff
changeset
|
357 (if (r1 >= #x10000) |
b7fe21511efe
(utf-16-decode-ucs): Handle a surrogate
Kenichi Handa <handa@m17n.org>
parents:
55437
diff
changeset
|
358 ((r1 -= #x10000) |
b7fe21511efe
(utf-16-decode-ucs): Handle a surrogate
Kenichi Handa <handa@m17n.org>
parents:
55437
diff
changeset
|
359 (r0 = ((r1 >> 10) + #xD800)) |
b7fe21511efe
(utf-16-decode-ucs): Handle a surrogate
Kenichi Handa <handa@m17n.org>
parents:
55437
diff
changeset
|
360 (write (r0 & 255)) |
b7fe21511efe
(utf-16-decode-ucs): Handle a surrogate
Kenichi Handa <handa@m17n.org>
parents:
55437
diff
changeset
|
361 (write (r0 >> 8)) |
b7fe21511efe
(utf-16-decode-ucs): Handle a surrogate
Kenichi Handa <handa@m17n.org>
parents:
55437
diff
changeset
|
362 (r1 = ((r1 & #x3FF) + #xDC00)))) |
b7fe21511efe
(utf-16-decode-ucs): Handle a surrogate
Kenichi Handa <handa@m17n.org>
parents:
55437
diff
changeset
|
363 (if (r1 >= 0) |
b7fe21511efe
(utf-16-decode-ucs): Handle a surrogate
Kenichi Handa <handa@m17n.org>
parents:
55437
diff
changeset
|
364 ((write (r1 & 255)) |
b7fe21511efe
(utf-16-decode-ucs): Handle a surrogate
Kenichi Handa <handa@m17n.org>
parents:
55437
diff
changeset
|
365 (write (r1 >> 8)))) |
b7fe21511efe
(utf-16-decode-ucs): Handle a surrogate
Kenichi Handa <handa@m17n.org>
parents:
55437
diff
changeset
|
366 (if (r2 >= 0) |
b7fe21511efe
(utf-16-decode-ucs): Handle a surrogate
Kenichi Handa <handa@m17n.org>
parents:
55437
diff
changeset
|
367 ((write r2) |
b7fe21511efe
(utf-16-decode-ucs): Handle a surrogate
Kenichi Handa <handa@m17n.org>
parents:
55437
diff
changeset
|
368 (if (r3 >= 0) |
b7fe21511efe
(utf-16-decode-ucs): Handle a surrogate
Kenichi Handa <handa@m17n.org>
parents:
55437
diff
changeset
|
369 (write r3)))) |
b7fe21511efe
(utf-16-decode-ucs): Handle a surrogate
Kenichi Handa <handa@m17n.org>
parents:
55437
diff
changeset
|
370 (repeat)))) |
50483 | 371 |
51631
bc72d6855260
Many name changes: utf-16-{be,le} -> utf-16{be,le}.
Kenichi Handa <handa@m17n.org>
parents:
50483
diff
changeset
|
372 (defconst utf-16be-encode-loop |
56038
b7fe21511efe
(utf-16-decode-ucs): Handle a surrogate
Kenichi Handa <handa@m17n.org>
parents:
55437
diff
changeset
|
373 `((r5 = -1) |
b7fe21511efe
(utf-16-decode-ucs): Handle a surrogate
Kenichi Handa <handa@m17n.org>
parents:
55437
diff
changeset
|
374 (loop |
b7fe21511efe
(utf-16-decode-ucs): Handle a surrogate
Kenichi Handa <handa@m17n.org>
parents:
55437
diff
changeset
|
375 ,@utf-16-decode-to-ucs |
b7fe21511efe
(utf-16-decode-ucs): Handle a surrogate
Kenichi Handa <handa@m17n.org>
parents:
55437
diff
changeset
|
376 (if (r1 >= #x10000) |
b7fe21511efe
(utf-16-decode-ucs): Handle a surrogate
Kenichi Handa <handa@m17n.org>
parents:
55437
diff
changeset
|
377 ((r1 -= #x10000) |
b7fe21511efe
(utf-16-decode-ucs): Handle a surrogate
Kenichi Handa <handa@m17n.org>
parents:
55437
diff
changeset
|
378 (r0 = ((r1 >> 10) + #xD800)) |
b7fe21511efe
(utf-16-decode-ucs): Handle a surrogate
Kenichi Handa <handa@m17n.org>
parents:
55437
diff
changeset
|
379 (write (r0 >> 8)) |
b7fe21511efe
(utf-16-decode-ucs): Handle a surrogate
Kenichi Handa <handa@m17n.org>
parents:
55437
diff
changeset
|
380 (write (r0 & 255)) |
b7fe21511efe
(utf-16-decode-ucs): Handle a surrogate
Kenichi Handa <handa@m17n.org>
parents:
55437
diff
changeset
|
381 (r1 = ((r1 & #x3FF) + #xDC00)))) |
b7fe21511efe
(utf-16-decode-ucs): Handle a surrogate
Kenichi Handa <handa@m17n.org>
parents:
55437
diff
changeset
|
382 (if (r1 >= 0) |
b7fe21511efe
(utf-16-decode-ucs): Handle a surrogate
Kenichi Handa <handa@m17n.org>
parents:
55437
diff
changeset
|
383 ((write (r1 >> 8)) |
b7fe21511efe
(utf-16-decode-ucs): Handle a surrogate
Kenichi Handa <handa@m17n.org>
parents:
55437
diff
changeset
|
384 (write (r1 & 255)))) |
b7fe21511efe
(utf-16-decode-ucs): Handle a surrogate
Kenichi Handa <handa@m17n.org>
parents:
55437
diff
changeset
|
385 (if (r2 >= 0) |
b7fe21511efe
(utf-16-decode-ucs): Handle a surrogate
Kenichi Handa <handa@m17n.org>
parents:
55437
diff
changeset
|
386 ((write r2) |
b7fe21511efe
(utf-16-decode-ucs): Handle a surrogate
Kenichi Handa <handa@m17n.org>
parents:
55437
diff
changeset
|
387 (if (r3 >= 0) |
b7fe21511efe
(utf-16-decode-ucs): Handle a surrogate
Kenichi Handa <handa@m17n.org>
parents:
55437
diff
changeset
|
388 (write r3)))) |
b7fe21511efe
(utf-16-decode-ucs): Handle a surrogate
Kenichi Handa <handa@m17n.org>
parents:
55437
diff
changeset
|
389 (repeat)))) |
50483 | 390 ) |
46677 | 391 |
51631
bc72d6855260
Many name changes: utf-16-{be,le} -> utf-16{be,le}.
Kenichi Handa <handa@m17n.org>
parents:
50483
diff
changeset
|
392 |
bc72d6855260
Many name changes: utf-16-{be,le} -> utf-16{be,le}.
Kenichi Handa <handa@m17n.org>
parents:
50483
diff
changeset
|
393 (define-ccl-program ccl-encode-mule-utf-16le |
46677 | 394 `(1 |
51631
bc72d6855260
Many name changes: utf-16-{be,le} -> utf-16{be,le}.
Kenichi Handa <handa@m17n.org>
parents:
50483
diff
changeset
|
395 ,utf-16le-encode-loop) |
50349
12444cb90785
(ccl-decode-mule-utf-16-le): Don't assume the signature bytes.
Kenichi Handa <handa@m17n.org>
parents:
49598
diff
changeset
|
396 "Encode to UTF-16LE (little endian without signature). |
46677 | 397 Characters from the charsets ascii, eight-bit-control, |
398 eight-bit-graphic, latin-iso8859-1 and mule-unicode-* are encoded | |
47705
797c350a7f8c
(utf-16-decode-ucs): Look up
Kenichi Handa <handa@m17n.org>
parents:
47384
diff
changeset
|
399 after translation through the translation-table of name |
797c350a7f8c
(utf-16-decode-ucs): Look up
Kenichi Handa <handa@m17n.org>
parents:
47384
diff
changeset
|
400 `utf-translation-table-for-encode'. |
46677 | 401 Others are encoded as U+FFFD.") |
402 | |
51631
bc72d6855260
Many name changes: utf-16-{be,le} -> utf-16{be,le}.
Kenichi Handa <handa@m17n.org>
parents:
50483
diff
changeset
|
403 (define-ccl-program ccl-encode-mule-utf-16be |
46677 | 404 `(1 |
51631
bc72d6855260
Many name changes: utf-16-{be,le} -> utf-16{be,le}.
Kenichi Handa <handa@m17n.org>
parents:
50483
diff
changeset
|
405 ,utf-16be-encode-loop) |
50349
12444cb90785
(ccl-decode-mule-utf-16-le): Don't assume the signature bytes.
Kenichi Handa <handa@m17n.org>
parents:
49598
diff
changeset
|
406 "Encode to UTF-16BE (big endian without signature). |
46677 | 407 Characters from the charsets ascii, eight-bit-control, |
408 eight-bit-graphic, latin-iso8859-1 and mule-unicode-* are encoded | |
47705
797c350a7f8c
(utf-16-decode-ucs): Look up
Kenichi Handa <handa@m17n.org>
parents:
47384
diff
changeset
|
409 after translation through the translation-table named |
797c350a7f8c
(utf-16-decode-ucs): Look up
Kenichi Handa <handa@m17n.org>
parents:
47384
diff
changeset
|
410 `utf-translation-table-for-encode'. |
46677 | 411 Others are encoded as U+FFFD.") |
412 | |
51631
bc72d6855260
Many name changes: utf-16-{be,le} -> utf-16{be,le}.
Kenichi Handa <handa@m17n.org>
parents:
50483
diff
changeset
|
413 (define-ccl-program ccl-encode-mule-utf-16le-with-signature |
50483 | 414 `(1 |
415 ((write #xFF) | |
416 (write #xFE) | |
56038
b7fe21511efe
(utf-16-decode-ucs): Handle a surrogate
Kenichi Handa <handa@m17n.org>
parents:
55437
diff
changeset
|
417 ,@utf-16le-encode-loop)) |
50483 | 418 "Encode to UTF-16 (little endian with signature). |
419 Characters from the charsets ascii, eight-bit-control, | |
420 eight-bit-graphic, latin-iso8859-1 and mule-unicode-* are encoded | |
421 after translation through the translation-table of name | |
422 `utf-translation-table-for-encode'. | |
423 Others are encoded as U+FFFD.") | |
424 | |
51631
bc72d6855260
Many name changes: utf-16-{be,le} -> utf-16{be,le}.
Kenichi Handa <handa@m17n.org>
parents:
50483
diff
changeset
|
425 (define-ccl-program ccl-encode-mule-utf-16be-with-signature |
50483 | 426 `(1 |
427 ((write #xFE) | |
428 (write #xFF) | |
56038
b7fe21511efe
(utf-16-decode-ucs): Handle a surrogate
Kenichi Handa <handa@m17n.org>
parents:
55437
diff
changeset
|
429 ,@utf-16be-encode-loop)) |
50483 | 430 "Encode to UTF-16 (big endian with signature). |
431 Characters from the charsets ascii, eight-bit-control, | |
432 eight-bit-graphic, latin-iso8859-1 and mule-unicode-* are encoded | |
433 after translation through the translation-table named | |
434 `utf-translation-table-for-encode'. | |
435 Others are encoded as U+FFFD.") | |
436 | |
46677 | 437 (makunbound 'utf-16-decode-to-ucs) |
51631
bc72d6855260
Many name changes: utf-16-{be,le} -> utf-16{be,le}.
Kenichi Handa <handa@m17n.org>
parents:
50483
diff
changeset
|
438 (makunbound 'utf-16le-encode-loop) |
bc72d6855260
Many name changes: utf-16-{be,le} -> utf-16{be,le}.
Kenichi Handa <handa@m17n.org>
parents:
50483
diff
changeset
|
439 (makunbound 'utf-16be-encode-loop) |
50483 | 440 |
441 (defun mule-utf-16-post-read-conversion (length) | |
442 (when (> length 0) | |
56038
b7fe21511efe
(utf-16-decode-ucs): Handle a surrogate
Kenichi Handa <handa@m17n.org>
parents:
55437
diff
changeset
|
443 (setq length (utf-8-post-read-conversion length)) |
50483 | 444 (let ((char (following-char))) |
445 (cond ((= char (decode-char 'ucs #xFFFE)) | |
446 (delete-char 1) | |
447 (setq last-coding-system-used | |
448 (coding-system-change-text-conversion | |
449 last-coding-system-used | |
51631
bc72d6855260
Many name changes: utf-16-{be,le} -> utf-16{be,le}.
Kenichi Handa <handa@m17n.org>
parents:
50483
diff
changeset
|
450 'mule-utf-16le-with-signature)) |
50483 | 451 (setq length (1- length))) |
452 ((= char (decode-char 'ucs #xFFFF)) | |
453 (delete-char 1) | |
454 (setq last-coding-system-used | |
455 (coding-system-change-text-conversion | |
456 last-coding-system-used | |
51631
bc72d6855260
Many name changes: utf-16-{be,le} -> utf-16{be,le}.
Kenichi Handa <handa@m17n.org>
parents:
50483
diff
changeset
|
457 'mule-utf-16be-with-signature)) |
50483 | 458 (setq length (1- length))) |
459 (t | |
51631
bc72d6855260
Many name changes: utf-16-{be,le} -> utf-16{be,le}.
Kenichi Handa <handa@m17n.org>
parents:
50483
diff
changeset
|
460 (setq last-coding-system-used 'mule-utf-16be))))) |
50483 | 461 length) |
46677 | 462 |
463 (let ((doc " | |
464 | |
47705
797c350a7f8c
(utf-16-decode-ucs): Look up
Kenichi Handa <handa@m17n.org>
parents:
47384
diff
changeset
|
465 It supports Unicode characters of these ranges: |
797c350a7f8c
(utf-16-decode-ucs): Look up
Kenichi Handa <handa@m17n.org>
parents:
47384
diff
changeset
|
466 U+0000..U+33FF, U+E000..U+FFFF. |
797c350a7f8c
(utf-16-decode-ucs): Look up
Kenichi Handa <handa@m17n.org>
parents:
47384
diff
changeset
|
467 They correspond to these Emacs character sets: |
797c350a7f8c
(utf-16-decode-ucs): Look up
Kenichi Handa <handa@m17n.org>
parents:
47384
diff
changeset
|
468 ascii, latin-iso8859-1, mule-unicode-0100-24ff, |
797c350a7f8c
(utf-16-decode-ucs): Look up
Kenichi Handa <handa@m17n.org>
parents:
47384
diff
changeset
|
469 mule-unicode-2500-33ff, mule-unicode-e000-ffff |
46677 | 470 |
47705
797c350a7f8c
(utf-16-decode-ucs): Look up
Kenichi Handa <handa@m17n.org>
parents:
47384
diff
changeset
|
471 On decoding (e.g. reading a file), Unicode characters not in the above |
797c350a7f8c
(utf-16-decode-ucs): Look up
Kenichi Handa <handa@m17n.org>
parents:
47384
diff
changeset
|
472 ranges are decoded as U+FFFD, effectively corrupting the data |
49598
0d8b17d428b5
Trailing whitepace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
49203
diff
changeset
|
473 if they are re-encoded. |
47705
797c350a7f8c
(utf-16-decode-ucs): Look up
Kenichi Handa <handa@m17n.org>
parents:
47384
diff
changeset
|
474 |
797c350a7f8c
(utf-16-decode-ucs): Look up
Kenichi Handa <handa@m17n.org>
parents:
47384
diff
changeset
|
475 On encoding (e.g. writing a file), Emacs characters not belonging to |
797c350a7f8c
(utf-16-decode-ucs): Look up
Kenichi Handa <handa@m17n.org>
parents:
47384
diff
changeset
|
476 any of the character sets listed above are encoded into the byte |
56038
b7fe21511efe
(utf-16-decode-ucs): Handle a surrogate
Kenichi Handa <handa@m17n.org>
parents:
55437
diff
changeset
|
477 sequence representing U+FFFD (REPLACEMENT CHARACTER).") |
b7fe21511efe
(utf-16-decode-ucs): Handle a surrogate
Kenichi Handa <handa@m17n.org>
parents:
55437
diff
changeset
|
478 (props `((safe-charsets |
b7fe21511efe
(utf-16-decode-ucs): Handle a surrogate
Kenichi Handa <handa@m17n.org>
parents:
55437
diff
changeset
|
479 ascii |
b7fe21511efe
(utf-16-decode-ucs): Handle a surrogate
Kenichi Handa <handa@m17n.org>
parents:
55437
diff
changeset
|
480 eight-bit-control |
b7fe21511efe
(utf-16-decode-ucs): Handle a surrogate
Kenichi Handa <handa@m17n.org>
parents:
55437
diff
changeset
|
481 eight-bit-graphic |
b7fe21511efe
(utf-16-decode-ucs): Handle a surrogate
Kenichi Handa <handa@m17n.org>
parents:
55437
diff
changeset
|
482 latin-iso8859-1 |
b7fe21511efe
(utf-16-decode-ucs): Handle a surrogate
Kenichi Handa <handa@m17n.org>
parents:
55437
diff
changeset
|
483 mule-unicode-0100-24ff |
b7fe21511efe
(utf-16-decode-ucs): Handle a surrogate
Kenichi Handa <handa@m17n.org>
parents:
55437
diff
changeset
|
484 mule-unicode-2500-33ff |
b7fe21511efe
(utf-16-decode-ucs): Handle a surrogate
Kenichi Handa <handa@m17n.org>
parents:
55437
diff
changeset
|
485 mule-unicode-e000-ffff |
b7fe21511efe
(utf-16-decode-ucs): Handle a surrogate
Kenichi Handa <handa@m17n.org>
parents:
55437
diff
changeset
|
486 ,@(if utf-translate-cjk-mode |
b7fe21511efe
(utf-16-decode-ucs): Handle a surrogate
Kenichi Handa <handa@m17n.org>
parents:
55437
diff
changeset
|
487 utf-translate-cjk-charsets)) |
b7fe21511efe
(utf-16-decode-ucs): Handle a surrogate
Kenichi Handa <handa@m17n.org>
parents:
55437
diff
changeset
|
488 (valid-codes (0 . 255)) |
b7fe21511efe
(utf-16-decode-ucs): Handle a surrogate
Kenichi Handa <handa@m17n.org>
parents:
55437
diff
changeset
|
489 (mime-text-unsuitable . t) |
b7fe21511efe
(utf-16-decode-ucs): Handle a surrogate
Kenichi Handa <handa@m17n.org>
parents:
55437
diff
changeset
|
490 (pre-write-conversion . utf-8-pre-write-conversion) |
b7fe21511efe
(utf-16-decode-ucs): Handle a surrogate
Kenichi Handa <handa@m17n.org>
parents:
55437
diff
changeset
|
491 (dependency unify-8859-on-encoding-mode |
b7fe21511efe
(utf-16-decode-ucs): Handle a surrogate
Kenichi Handa <handa@m17n.org>
parents:
55437
diff
changeset
|
492 unify-8859-on-decoding-mode |
b7fe21511efe
(utf-16-decode-ucs): Handle a surrogate
Kenichi Handa <handa@m17n.org>
parents:
55437
diff
changeset
|
493 utf-fragment-on-decoding |
b7fe21511efe
(utf-16-decode-ucs): Handle a surrogate
Kenichi Handa <handa@m17n.org>
parents:
55437
diff
changeset
|
494 utf-translate-cjk-mode)))) |
46677 | 495 (make-coding-system |
51631
bc72d6855260
Many name changes: utf-16-{be,le} -> utf-16{be,le}.
Kenichi Handa <handa@m17n.org>
parents:
50483
diff
changeset
|
496 'mule-utf-16le 4 |
46677 | 497 ?u ; Mule-UCS uses ?U, but code-pages uses that for koi8-u. |
498 (concat | |
51631
bc72d6855260
Many name changes: utf-16-{be,le} -> utf-16{be,le}.
Kenichi Handa <handa@m17n.org>
parents:
50483
diff
changeset
|
499 "UTF-16LE encoding for Emacs-supported Unicode characters." |
46677 | 500 doc) |
51631
bc72d6855260
Many name changes: utf-16-{be,le} -> utf-16{be,le}.
Kenichi Handa <handa@m17n.org>
parents:
50483
diff
changeset
|
501 '(ccl-decode-mule-utf-16le . ccl-encode-mule-utf-16le) |
56038
b7fe21511efe
(utf-16-decode-ucs): Handle a surrogate
Kenichi Handa <handa@m17n.org>
parents:
55437
diff
changeset
|
502 `(,@props |
b7fe21511efe
(utf-16-decode-ucs): Handle a surrogate
Kenichi Handa <handa@m17n.org>
parents:
55437
diff
changeset
|
503 (post-read-conversion . utf-8-post-read-conversion) |
b7fe21511efe
(utf-16-decode-ucs): Handle a surrogate
Kenichi Handa <handa@m17n.org>
parents:
55437
diff
changeset
|
504 (mime-charset . utf-16le))) |
46677 | 505 |
506 (make-coding-system | |
51631
bc72d6855260
Many name changes: utf-16-{be,le} -> utf-16{be,le}.
Kenichi Handa <handa@m17n.org>
parents:
50483
diff
changeset
|
507 'mule-utf-16be 4 ?u |
46677 | 508 (concat |
51631
bc72d6855260
Many name changes: utf-16-{be,le} -> utf-16{be,le}.
Kenichi Handa <handa@m17n.org>
parents:
50483
diff
changeset
|
509 "UTF-16BE encoding for Emacs-supported Unicode characters." |
46677 | 510 doc) |
511 | |
51631
bc72d6855260
Many name changes: utf-16-{be,le} -> utf-16{be,le}.
Kenichi Handa <handa@m17n.org>
parents:
50483
diff
changeset
|
512 '(ccl-decode-mule-utf-16be . ccl-encode-mule-utf-16be) |
56038
b7fe21511efe
(utf-16-decode-ucs): Handle a surrogate
Kenichi Handa <handa@m17n.org>
parents:
55437
diff
changeset
|
513 `(,@props |
b7fe21511efe
(utf-16-decode-ucs): Handle a surrogate
Kenichi Handa <handa@m17n.org>
parents:
55437
diff
changeset
|
514 (post-read-conversion . utf-8-post-read-conversion) |
b7fe21511efe
(utf-16-decode-ucs): Handle a surrogate
Kenichi Handa <handa@m17n.org>
parents:
55437
diff
changeset
|
515 (mime-charset . utf-16be))) |
50483 | 516 |
517 (make-coding-system | |
51631
bc72d6855260
Many name changes: utf-16-{be,le} -> utf-16{be,le}.
Kenichi Handa <handa@m17n.org>
parents:
50483
diff
changeset
|
518 'mule-utf-16le-with-signature 4 ?u |
50483 | 519 (concat |
520 "Little endian UTF-16 (with BOM) for Emacs-supported Unicode characters." | |
521 doc) | |
522 | |
51631
bc72d6855260
Many name changes: utf-16-{be,le} -> utf-16{be,le}.
Kenichi Handa <handa@m17n.org>
parents:
50483
diff
changeset
|
523 '(ccl-decode-mule-utf-16le-with-signature |
bc72d6855260
Many name changes: utf-16-{be,le} -> utf-16{be,le}.
Kenichi Handa <handa@m17n.org>
parents:
50483
diff
changeset
|
524 . ccl-encode-mule-utf-16le-with-signature) |
56038
b7fe21511efe
(utf-16-decode-ucs): Handle a surrogate
Kenichi Handa <handa@m17n.org>
parents:
55437
diff
changeset
|
525 `(,@props |
b7fe21511efe
(utf-16-decode-ucs): Handle a surrogate
Kenichi Handa <handa@m17n.org>
parents:
55437
diff
changeset
|
526 (post-read-conversion . utf-8-post-read-conversion) |
50483 | 527 (coding-category . coding-category-utf-16-le) |
56038
b7fe21511efe
(utf-16-decode-ucs): Handle a surrogate
Kenichi Handa <handa@m17n.org>
parents:
55437
diff
changeset
|
528 (mime-charset . utf-16))) |
50483 | 529 |
530 (make-coding-system | |
51631
bc72d6855260
Many name changes: utf-16-{be,le} -> utf-16{be,le}.
Kenichi Handa <handa@m17n.org>
parents:
50483
diff
changeset
|
531 'mule-utf-16be-with-signature 4 ?u |
50483 | 532 (concat |
533 "Big endian UTF-16 (with BOM) for Emacs-supported Unicode characters." | |
534 doc) | |
535 | |
51631
bc72d6855260
Many name changes: utf-16-{be,le} -> utf-16{be,le}.
Kenichi Handa <handa@m17n.org>
parents:
50483
diff
changeset
|
536 '(ccl-decode-mule-utf-16be-with-signature |
bc72d6855260
Many name changes: utf-16-{be,le} -> utf-16{be,le}.
Kenichi Handa <handa@m17n.org>
parents:
50483
diff
changeset
|
537 . ccl-encode-mule-utf-16be-with-signature) |
56038
b7fe21511efe
(utf-16-decode-ucs): Handle a surrogate
Kenichi Handa <handa@m17n.org>
parents:
55437
diff
changeset
|
538 `(,@props |
b7fe21511efe
(utf-16-decode-ucs): Handle a surrogate
Kenichi Handa <handa@m17n.org>
parents:
55437
diff
changeset
|
539 (post-read-conversion . utf-8-post-read-conversion) |
50483 | 540 (coding-category . coding-category-utf-16-be) |
56038
b7fe21511efe
(utf-16-decode-ucs): Handle a surrogate
Kenichi Handa <handa@m17n.org>
parents:
55437
diff
changeset
|
541 (mime-charset . utf-16))) |
50483 | 542 |
543 (make-coding-system | |
544 'mule-utf-16 4 ?u | |
545 (concat | |
546 "UTF-16 (with or without BOM) for Emacs-supported Unicode characters." | |
547 doc) | |
548 | |
51631
bc72d6855260
Many name changes: utf-16-{be,le} -> utf-16{be,le}.
Kenichi Handa <handa@m17n.org>
parents:
50483
diff
changeset
|
549 '(ccl-decode-mule-utf-16 . ccl-encode-mule-utf-16be-with-signature) |
56038
b7fe21511efe
(utf-16-decode-ucs): Handle a surrogate
Kenichi Handa <handa@m17n.org>
parents:
55437
diff
changeset
|
550 `(,@props |
b7fe21511efe
(utf-16-decode-ucs): Handle a surrogate
Kenichi Handa <handa@m17n.org>
parents:
55437
diff
changeset
|
551 (post-read-conversion . mule-utf-16-post-read-conversion) |
50483 | 552 (coding-category . coding-category-utf-16-be) |
56038
b7fe21511efe
(utf-16-decode-ucs): Handle a surrogate
Kenichi Handa <handa@m17n.org>
parents:
55437
diff
changeset
|
553 (mime-charset . utf-16))) |
50483 | 554 ) |
46677 | 555 |
51631
bc72d6855260
Many name changes: utf-16-{be,le} -> utf-16{be,le}.
Kenichi Handa <handa@m17n.org>
parents:
50483
diff
changeset
|
556 (define-coding-system-alias 'utf-16le 'mule-utf-16le) |
bc72d6855260
Many name changes: utf-16-{be,le} -> utf-16{be,le}.
Kenichi Handa <handa@m17n.org>
parents:
50483
diff
changeset
|
557 (define-coding-system-alias 'utf-16be 'mule-utf-16be) |
bc72d6855260
Many name changes: utf-16-{be,le} -> utf-16{be,le}.
Kenichi Handa <handa@m17n.org>
parents:
50483
diff
changeset
|
558 (define-coding-system-alias 'utf-16le-with-signature |
bc72d6855260
Many name changes: utf-16-{be,le} -> utf-16{be,le}.
Kenichi Handa <handa@m17n.org>
parents:
50483
diff
changeset
|
559 'mule-utf-16le-with-signature) |
bc72d6855260
Many name changes: utf-16-{be,le} -> utf-16{be,le}.
Kenichi Handa <handa@m17n.org>
parents:
50483
diff
changeset
|
560 (define-coding-system-alias 'utf-16be-with-signature |
bc72d6855260
Many name changes: utf-16-{be,le} -> utf-16{be,le}.
Kenichi Handa <handa@m17n.org>
parents:
50483
diff
changeset
|
561 'mule-utf-16be-with-signature) |
50483 | 562 (define-coding-system-alias 'utf-16 'mule-utf-16) |
46677 | 563 |
51631
bc72d6855260
Many name changes: utf-16-{be,le} -> utf-16{be,le}.
Kenichi Handa <handa@m17n.org>
parents:
50483
diff
changeset
|
564 ;; For backward compatibility. |
bc72d6855260
Many name changes: utf-16-{be,le} -> utf-16{be,le}.
Kenichi Handa <handa@m17n.org>
parents:
50483
diff
changeset
|
565 (define-coding-system-alias 'mule-utf-16-le 'mule-utf-16le-with-signature) |
bc72d6855260
Many name changes: utf-16-{be,le} -> utf-16{be,le}.
Kenichi Handa <handa@m17n.org>
parents:
50483
diff
changeset
|
566 (define-coding-system-alias 'utf-16-le 'mule-utf-16le-with-signature) |
bc72d6855260
Many name changes: utf-16-{be,le} -> utf-16{be,le}.
Kenichi Handa <handa@m17n.org>
parents:
50483
diff
changeset
|
567 (define-coding-system-alias 'mule-utf-16-be 'mule-utf-16be-with-signature) |
bc72d6855260
Many name changes: utf-16-{be,le} -> utf-16{be,le}.
Kenichi Handa <handa@m17n.org>
parents:
50483
diff
changeset
|
568 (define-coding-system-alias 'utf-16-be 'mule-utf-16be-with-signature) |
bc72d6855260
Many name changes: utf-16-{be,le} -> utf-16{be,le}.
Kenichi Handa <handa@m17n.org>
parents:
50483
diff
changeset
|
569 |
52401 | 570 ;;; arch-tag: 85455d46-d9c9-466d-a6f3-c3582a7367c4 |
46677 | 571 ;;; utf-16.el ends here |