Mercurial > emacs
annotate lisp/international/utf-16.el @ 50739:fbec4e6f73c8
(ada-stmt-add-to-ada-menu): Moved to ada-mode.el.
(ada-template-map): Merged with the keymap handling in ada-mode.el.
author | Juanma Barranquero <lekktu@gmail.com> |
---|---|
date | Tue, 29 Apr 2003 23:44:43 +0000 |
parents | 15382232cf57 |
children | bc72d6855260 |
rev | line source |
---|---|
46677 | 1 ;;; utf-16.el --- UTF-16 encoding/decoding |
2 | |
3 ;; Copyright (C) 2001, 2002 Free Software Foundation, Inc. | |
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 | |
28 ;; surrogates) of Unicode, written either in little or big endian | |
29 ;; order: coding-systems `mule-utf-16-le' and `mule-utf-16-be'. | |
30 ;; (utf-16-le is used by the DozeN'T clipboard, for instance.) The | |
31 ;; data are preceeded by a two-byte signature which identifies their | |
32 ;; byte sex. These are used by the coding-category-utf-16-{b,l}e code | |
33 ;; to identify the coding, but ignored on decoding. | |
34 | |
35 ;; Note that un-decodable sequences aren't (yet?) preserved as raw | |
36 ;; bytes, as they are with utf-8, so reading and writing as utf-16 can | |
37 ;; corrupt data. | |
38 | |
39 ;;; Code: | |
40 | |
41 ;; We end up with trivially different -le and -be versions of most | |
42 ;; things below, sometimes with commonality abstracted into a let | |
43 ;; binding for maintenance convenience. | |
44 | |
45 ;; We'd need new charsets distinct from ascii and eight-bit-control to | |
46 ;; deal with untranslated sequences, since we can't otherwise | |
47 ;; distinguish the bytes, as we can with utf-8. | |
48 | |
49 ;; ;; Do a multibyte write for bytes in r3 and r4. | |
50 ;; ;; Intended for untranslatable utf-16 sequences. | |
51 ;; (define-ccl-program ccl-mule-utf-16-untrans | |
52 ;; `(0 | |
53 ;; (if (r3 < 128) | |
54 ;; (r0 = ,(charset-id 'ascii)) | |
55 ;; (if (r3 < 160) | |
56 ;; (r0 = ,(charset-id 'eight-bit-control)) | |
57 ;; (r0 = ,(charset-id 'eight-bit-graphic)))) | |
58 ;; (if (r4 < 128) | |
59 ;; (r0 = ,(charset-id 'ascii)) | |
60 ;; (if (r4 < 160) | |
61 ;; (r0 = ,(charset-id 'eight-bit-control)) | |
62 ;; (r0 = ,(charset-id 'eight-bit-graphic)))) | |
63 ;; (r1 = r4))) | |
64 ;; "Do a multibyte write for bytes in r3 and r4. | |
65 ;; First swap them if we're big endian, indicated by r5==0. | |
66 ;; Intended for untranslatable utf-16 sequences.") | |
67 | |
68 ;; Needed in macro expansion, so can't be let-bound. Zapped after use. | |
69 (eval-and-compile | |
70 (defconst utf-16-decode-ucs | |
50349
12444cb90785
(ccl-decode-mule-utf-16-le): Don't assume the signature bytes.
Kenichi Handa <handa@m17n.org>
parents:
49598
diff
changeset
|
71 ;; We have the unicode in r1. Output is charset ID in r0, code |
50483 | 72 ;; point in r1. |
47705
797c350a7f8c
(utf-16-decode-ucs): Look up
Kenichi Handa <handa@m17n.org>
parents:
47384
diff
changeset
|
73 `((lookup-integer utf-subst-table-for-decode r1 r3) |
797c350a7f8c
(utf-16-decode-ucs): Look up
Kenichi Handa <handa@m17n.org>
parents:
47384
diff
changeset
|
74 (if r7 ; got a translation |
797c350a7f8c
(utf-16-decode-ucs): Look up
Kenichi Handa <handa@m17n.org>
parents:
47384
diff
changeset
|
75 ((r0 = r1) (r1 = r3)) |
797c350a7f8c
(utf-16-decode-ucs): Look up
Kenichi Handa <handa@m17n.org>
parents:
47384
diff
changeset
|
76 (if (r1 < 128) |
797c350a7f8c
(utf-16-decode-ucs): Look up
Kenichi Handa <handa@m17n.org>
parents:
47384
diff
changeset
|
77 (r0 = ,(charset-id 'ascii)) |
797c350a7f8c
(utf-16-decode-ucs): Look up
Kenichi Handa <handa@m17n.org>
parents:
47384
diff
changeset
|
78 (if (r1 < 160) |
797c350a7f8c
(utf-16-decode-ucs): Look up
Kenichi Handa <handa@m17n.org>
parents:
47384
diff
changeset
|
79 (r0 = ,(charset-id 'eight-bit-control)) |
797c350a7f8c
(utf-16-decode-ucs): Look up
Kenichi Handa <handa@m17n.org>
parents:
47384
diff
changeset
|
80 (if (r1 < 256) |
797c350a7f8c
(utf-16-decode-ucs): Look up
Kenichi Handa <handa@m17n.org>
parents:
47384
diff
changeset
|
81 ((r0 = ,(charset-id 'latin-iso8859-1)) |
797c350a7f8c
(utf-16-decode-ucs): Look up
Kenichi Handa <handa@m17n.org>
parents:
47384
diff
changeset
|
82 (r1 -= 128)) |
797c350a7f8c
(utf-16-decode-ucs): Look up
Kenichi Handa <handa@m17n.org>
parents:
47384
diff
changeset
|
83 (if (r1 < #x2500) |
797c350a7f8c
(utf-16-decode-ucs): Look up
Kenichi Handa <handa@m17n.org>
parents:
47384
diff
changeset
|
84 ((r0 = ,(charset-id 'mule-unicode-0100-24ff)) |
797c350a7f8c
(utf-16-decode-ucs): Look up
Kenichi Handa <handa@m17n.org>
parents:
47384
diff
changeset
|
85 (r1 -= #x100) |
797c350a7f8c
(utf-16-decode-ucs): Look up
Kenichi Handa <handa@m17n.org>
parents:
47384
diff
changeset
|
86 (r2 = (((r1 / 96) + 32) << 7)) |
797c350a7f8c
(utf-16-decode-ucs): Look up
Kenichi Handa <handa@m17n.org>
parents:
47384
diff
changeset
|
87 (r1 %= 96) |
797c350a7f8c
(utf-16-decode-ucs): Look up
Kenichi Handa <handa@m17n.org>
parents:
47384
diff
changeset
|
88 (r1 += (r2 + 32))) |
797c350a7f8c
(utf-16-decode-ucs): Look up
Kenichi Handa <handa@m17n.org>
parents:
47384
diff
changeset
|
89 (if (r1 < #x3400) |
797c350a7f8c
(utf-16-decode-ucs): Look up
Kenichi Handa <handa@m17n.org>
parents:
47384
diff
changeset
|
90 ((r0 = ,(charset-id 'mule-unicode-2500-33ff)) |
797c350a7f8c
(utf-16-decode-ucs): Look up
Kenichi Handa <handa@m17n.org>
parents:
47384
diff
changeset
|
91 (r1 -= #x2500) |
797c350a7f8c
(utf-16-decode-ucs): Look up
Kenichi Handa <handa@m17n.org>
parents:
47384
diff
changeset
|
92 (r2 = (((r1 / 96) + 32) << 7)) |
797c350a7f8c
(utf-16-decode-ucs): Look up
Kenichi Handa <handa@m17n.org>
parents:
47384
diff
changeset
|
93 (r1 %= 96) |
797c350a7f8c
(utf-16-decode-ucs): Look up
Kenichi Handa <handa@m17n.org>
parents:
47384
diff
changeset
|
94 (r1 += (r2 + 32))) |
797c350a7f8c
(utf-16-decode-ucs): Look up
Kenichi Handa <handa@m17n.org>
parents:
47384
diff
changeset
|
95 (if (r1 < #xd800) ; 2 untranslated bytes |
797c350a7f8c
(utf-16-decode-ucs): Look up
Kenichi Handa <handa@m17n.org>
parents:
47384
diff
changeset
|
96 ;; ;; Assume this is rare, so don't worry about the |
797c350a7f8c
(utf-16-decode-ucs): Look up
Kenichi Handa <handa@m17n.org>
parents:
47384
diff
changeset
|
97 ;; ;; overhead of the call. |
797c350a7f8c
(utf-16-decode-ucs): Look up
Kenichi Handa <handa@m17n.org>
parents:
47384
diff
changeset
|
98 ;; (call mule-utf-16-untrans) |
797c350a7f8c
(utf-16-decode-ucs): Look up
Kenichi Handa <handa@m17n.org>
parents:
47384
diff
changeset
|
99 ((r0 = ,(charset-id 'mule-unicode-e000-ffff)) |
797c350a7f8c
(utf-16-decode-ucs): Look up
Kenichi Handa <handa@m17n.org>
parents:
47384
diff
changeset
|
100 (r1 = 15037)) ; U+fffd |
797c350a7f8c
(utf-16-decode-ucs): Look up
Kenichi Handa <handa@m17n.org>
parents:
47384
diff
changeset
|
101 (if (r1 < #xe000) ; surrogate |
797c350a7f8c
(utf-16-decode-ucs): Look up
Kenichi Handa <handa@m17n.org>
parents:
47384
diff
changeset
|
102 ;; ((call mule-utf-16-untrans) |
797c350a7f8c
(utf-16-decode-ucs): Look up
Kenichi Handa <handa@m17n.org>
parents:
47384
diff
changeset
|
103 ;; (write-multibyte-character r0 r1) |
797c350a7f8c
(utf-16-decode-ucs): Look up
Kenichi Handa <handa@m17n.org>
parents:
47384
diff
changeset
|
104 ;; (read r3 r4) |
797c350a7f8c
(utf-16-decode-ucs): Look up
Kenichi Handa <handa@m17n.org>
parents:
47384
diff
changeset
|
105 ;; (call mule-utf-16-untrans)) |
797c350a7f8c
(utf-16-decode-ucs): Look up
Kenichi Handa <handa@m17n.org>
parents:
47384
diff
changeset
|
106 ((read r3 r4) |
797c350a7f8c
(utf-16-decode-ucs): Look up
Kenichi Handa <handa@m17n.org>
parents:
47384
diff
changeset
|
107 (r0 = ,(charset-id 'mule-unicode-e000-ffff)) |
797c350a7f8c
(utf-16-decode-ucs): Look up
Kenichi Handa <handa@m17n.org>
parents:
47384
diff
changeset
|
108 (r1 = 15037)) |
797c350a7f8c
(utf-16-decode-ucs): Look up
Kenichi Handa <handa@m17n.org>
parents:
47384
diff
changeset
|
109 ((r0 = ,(charset-id 'mule-unicode-e000-ffff)) |
797c350a7f8c
(utf-16-decode-ucs): Look up
Kenichi Handa <handa@m17n.org>
parents:
47384
diff
changeset
|
110 (r1 -= #xe000) |
797c350a7f8c
(utf-16-decode-ucs): Look up
Kenichi Handa <handa@m17n.org>
parents:
47384
diff
changeset
|
111 (r2 = (((r1 / 96) + 32) << 7)) |
797c350a7f8c
(utf-16-decode-ucs): Look up
Kenichi Handa <handa@m17n.org>
parents:
47384
diff
changeset
|
112 (r1 %= 96) |
50483 | 113 (r1 += (r2 + 32))))))))))))) |
114 | |
115 (defconst utf-16-le-decode-loop | |
116 `(loop | |
117 (read r3 r4) | |
118 (r1 = (r4 <8 r3)) | |
119 ,utf-16-decode-ucs | |
120 (translate-character utf-translation-table-for-decode r0 r1) | |
121 (write-multibyte-character r0 r1) | |
122 (repeat))) | |
123 | |
124 (defconst utf-16-be-decode-loop | |
125 `(loop | |
126 (read r3 r4) | |
127 (r1 = (r3 <8 r4)) | |
128 ,@utf-16-decode-ucs | |
129 (translate-character utf-translation-table-for-decode r0 r1) | |
130 (write-multibyte-character r0 r1) | |
131 (repeat))) | |
132 | |
133 ) | |
46677 | 134 |
135 (define-ccl-program ccl-decode-mule-utf-16-le | |
136 `(2 ; 2 bytes -> 1 to 4 bytes | |
50483 | 137 ,utf-16-le-decode-loop) |
50349
12444cb90785
(ccl-decode-mule-utf-16-le): Don't assume the signature bytes.
Kenichi Handa <handa@m17n.org>
parents:
49598
diff
changeset
|
138 "Decode UTF-16LE (little endian without signature bytes). |
46677 | 139 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
|
140 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
|
141 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
|
142 `utf-translation-table-for-decode'.") |
46677 | 143 |
144 (define-ccl-program ccl-decode-mule-utf-16-be | |
145 `(2 ; 2 bytes -> 1 to 4 bytes | |
50483 | 146 ,utf-16-be-decode-loop) |
50349
12444cb90785
(ccl-decode-mule-utf-16-le): Don't assume the signature bytes.
Kenichi Handa <handa@m17n.org>
parents:
49598
diff
changeset
|
147 "Decode UTF-16BE (big endian without signature bytes). |
46677 | 148 Basic decoding is done into the charsets ascii, latin-iso8859-1 and |
149 mule-unicode-*. Un-representable Unicode characters are | |
47705
797c350a7f8c
(utf-16-decode-ucs): Look up
Kenichi Handa <handa@m17n.org>
parents:
47384
diff
changeset
|
150 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
|
151 name `utf-translation-table-for-decode'.") |
46677 | 152 |
50483 | 153 (define-ccl-program ccl-decode-mule-utf-16-le-with-signature |
154 `(2 | |
155 ((read r3 r4) | |
156 ,utf-16-le-decode-loop)) | |
157 "Like ccl-decode-utf-16-le but skip the first 2-byte BOM.") | |
158 | |
159 (define-ccl-program ccl-decode-mule-utf-16-be-with-signature | |
160 `(2 | |
161 ((read r3 r4) | |
162 ,utf-16-be-decode-loop)) | |
163 "Like ccl-decode-utf-16-be but skip the first 2-byte BOM.") | |
164 | |
165 (define-ccl-program ccl-decode-mule-utf-16 | |
166 `(2 | |
167 ((read r3 r4) | |
168 (r1 = (r3 <8 r4)) | |
169 (if (r1 == #xFFFE) | |
170 ;; R1 is a BOM for little endian. We keep this character as | |
171 ;; is temporarily. It is removed by post-read-conversion | |
172 ;; function. | |
173 (,@utf-16-decode-ucs | |
174 (write-multibyte-character r0 r1) | |
175 ,utf-16-le-decode-loop) | |
176 ((if (r1 == #xFEFF) | |
177 ;; R1 is a BOM for big endian, but we can't keep that | |
178 ;; character in the output because it can't be | |
179 ;; distinguished with the normal U+FEFF. So, we keep | |
180 ;; #xFFFF instead. | |
181 ((r1 = #xFFFF) | |
182 ,@utf-16-decode-ucs) | |
183 ;; R1 a normal Unicode character. | |
184 (,@utf-16-decode-ucs | |
185 (translate-character utf-translation-table-for-decode r0 r1))) | |
186 (write-multibyte-character r0 r1) | |
187 ,utf-16-be-decode-loop)))) | |
188 "Like ccl-decode-utf-16-be/le but check the first BOM.") | |
189 | |
46677 | 190 (makunbound 'utf-16-decode-ucs) ; done with it |
50483 | 191 (makunbound 'utf-16-le-decode-loop) |
192 (makunbound 'utf-16-be-decode-loop) | |
46677 | 193 |
194 (eval-and-compile | |
195 (defconst utf-16-decode-to-ucs | |
196 ;; CCL which, given the result of a multibyte read in r0 and r1, | |
197 ;; sets r0 to the character's Unicode if the charset is one of the | |
198 ;; basic utf-8 coding system ones. Otherwise set to U+fffd. | |
199 `(if (r0 == ,(charset-id 'ascii)) | |
200 (r0 = r1) | |
201 (if (r0 == ,(charset-id 'latin-iso8859-1)) | |
202 (r0 = (r1 + 128)) | |
203 (if (r0 == ,(charset-id 'eight-bit-control)) | |
204 (r0 = r1) | |
205 (if (r0 == ,(charset-id 'eight-bit-graphic)) | |
206 (r0 = r1) | |
207 ((r2 = (r1 & #x7f)) | |
208 (r1 >>= 7) | |
209 (r3 = ((r1 - 32) * 96)) | |
210 (r3 += (r2 - 32)) | |
211 (if (r0 == ,(charset-id 'mule-unicode-0100-24ff)) | |
212 (r0 = (r3 + #x100)) | |
213 (if (r0 == ,(charset-id 'mule-unicode-2500-33ff)) | |
214 (r0 = (r3 + #x2500)) | |
215 (if (r0 == ,(charset-id 'mule-unicode-e000-ffff)) | |
216 (r0 = (r3 + #xe000)) | |
50483 | 217 (r0 = #xfffd)))))))))) |
218 | |
219 (defconst utf-16-le-encode-loop | |
220 `(loop | |
221 (read-multibyte-character r0 r1) | |
222 (lookup-character utf-subst-table-for-encode r0 r1) | |
223 (if (r7 == 0) | |
224 ((translate-character utf-translation-table-for-encode r0 r1) | |
225 ,utf-16-decode-to-ucs)) | |
226 (write (r0 & 255)) | |
227 (write (r0 >> 8)) | |
228 (repeat))) | |
229 | |
230 (defconst utf-16-be-encode-loop | |
231 `(loop | |
232 (read-multibyte-character r0 r1) | |
233 (lookup-character utf-subst-table-for-encode r0 r1) | |
234 (if (r7 == 0) | |
235 ((translate-character utf-translation-table-for-encode r0 r1) | |
236 ,utf-16-decode-to-ucs)) | |
237 (write (r0 >> 8)) | |
238 (write (r0 & 255)) | |
239 (repeat))) | |
240 ) | |
46677 | 241 |
242 (define-ccl-program ccl-encode-mule-utf-16-le | |
243 `(1 | |
50483 | 244 ,utf-16-le-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
|
245 "Encode to UTF-16LE (little endian without signature). |
46677 | 246 Characters from the charsets ascii, eight-bit-control, |
247 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
|
248 after translation through the translation-table of name |
797c350a7f8c
(utf-16-decode-ucs): Look up
Kenichi Handa <handa@m17n.org>
parents:
47384
diff
changeset
|
249 `utf-translation-table-for-encode'. |
46677 | 250 Others are encoded as U+FFFD.") |
251 | |
252 (define-ccl-program ccl-encode-mule-utf-16-be | |
253 `(1 | |
50483 | 254 ,utf-16-be-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
|
255 "Encode to UTF-16BE (big endian without signature). |
46677 | 256 Characters from the charsets ascii, eight-bit-control, |
257 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
|
258 after translation through the translation-table named |
797c350a7f8c
(utf-16-decode-ucs): Look up
Kenichi Handa <handa@m17n.org>
parents:
47384
diff
changeset
|
259 `utf-translation-table-for-encode'. |
46677 | 260 Others are encoded as U+FFFD.") |
261 | |
50483 | 262 (define-ccl-program ccl-encode-mule-utf-16-le-with-signature |
263 `(1 | |
264 ((write #xFF) | |
265 (write #xFE) | |
266 ,utf-16-le-encode-loop)) | |
267 "Encode to UTF-16 (little endian with signature). | |
268 Characters from the charsets ascii, eight-bit-control, | |
269 eight-bit-graphic, latin-iso8859-1 and mule-unicode-* are encoded | |
270 after translation through the translation-table of name | |
271 `utf-translation-table-for-encode'. | |
272 Others are encoded as U+FFFD.") | |
273 | |
274 (define-ccl-program ccl-encode-mule-utf-16-be-with-signature | |
275 `(1 | |
276 ((write #xFE) | |
277 (write #xFF) | |
278 ,utf-16-be-encode-loop)) | |
279 "Encode to UTF-16 (big endian with signature). | |
280 Characters from the charsets ascii, eight-bit-control, | |
281 eight-bit-graphic, latin-iso8859-1 and mule-unicode-* are encoded | |
282 after translation through the translation-table named | |
283 `utf-translation-table-for-encode'. | |
284 Others are encoded as U+FFFD.") | |
285 | |
46677 | 286 (makunbound 'utf-16-decode-to-ucs) |
50483 | 287 (makunbound 'utf-16-le-encode-loop) |
288 (makunbound 'utf-16-be-encode-loop) | |
289 | |
290 (defun mule-utf-16-post-read-conversion (length) | |
291 (when (> length 0) | |
292 (let ((char (following-char))) | |
293 (cond ((= char (decode-char 'ucs #xFFFE)) | |
294 (delete-char 1) | |
295 (setq last-coding-system-used | |
296 (coding-system-change-text-conversion | |
297 last-coding-system-used | |
298 'mule-utf-16-le-with-signature)) | |
299 (setq length (1- length))) | |
300 ((= char (decode-char 'ucs #xFFFF)) | |
301 (delete-char 1) | |
302 (setq last-coding-system-used | |
303 (coding-system-change-text-conversion | |
304 last-coding-system-used | |
305 'mule-utf-16-be-with-signature)) | |
306 (setq length (1- length))) | |
307 (t | |
308 (setq last-coding-system-used 'mule-utf-16-be))))) | |
309 length) | |
46677 | 310 |
311 (let ((doc " | |
312 | |
47705
797c350a7f8c
(utf-16-decode-ucs): Look up
Kenichi Handa <handa@m17n.org>
parents:
47384
diff
changeset
|
313 It supports Unicode characters of these ranges: |
797c350a7f8c
(utf-16-decode-ucs): Look up
Kenichi Handa <handa@m17n.org>
parents:
47384
diff
changeset
|
314 U+0000..U+33FF, U+E000..U+FFFF. |
797c350a7f8c
(utf-16-decode-ucs): Look up
Kenichi Handa <handa@m17n.org>
parents:
47384
diff
changeset
|
315 They correspond to these Emacs character sets: |
797c350a7f8c
(utf-16-decode-ucs): Look up
Kenichi Handa <handa@m17n.org>
parents:
47384
diff
changeset
|
316 ascii, latin-iso8859-1, mule-unicode-0100-24ff, |
797c350a7f8c
(utf-16-decode-ucs): Look up
Kenichi Handa <handa@m17n.org>
parents:
47384
diff
changeset
|
317 mule-unicode-2500-33ff, mule-unicode-e000-ffff |
46677 | 318 |
47705
797c350a7f8c
(utf-16-decode-ucs): Look up
Kenichi Handa <handa@m17n.org>
parents:
47384
diff
changeset
|
319 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
|
320 ranges are decoded as U+FFFD, effectively corrupting the data |
49598
0d8b17d428b5
Trailing whitepace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
49203
diff
changeset
|
321 if they are re-encoded. |
47705
797c350a7f8c
(utf-16-decode-ucs): Look up
Kenichi Handa <handa@m17n.org>
parents:
47384
diff
changeset
|
322 |
797c350a7f8c
(utf-16-decode-ucs): Look up
Kenichi Handa <handa@m17n.org>
parents:
47384
diff
changeset
|
323 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
|
324 any of the character sets listed above are encoded into the byte |
797c350a7f8c
(utf-16-decode-ucs): Look up
Kenichi Handa <handa@m17n.org>
parents:
47384
diff
changeset
|
325 sequence representing U+FFFD (REPLACEMENT CHARACTER).")) |
46677 | 326 (make-coding-system |
327 'mule-utf-16-le 4 | |
328 ?u ; Mule-UCS uses ?U, but code-pages uses that for koi8-u. | |
329 (concat | |
330 "Little endian UTF-16 encoding for Emacs-supported Unicode characters." | |
331 doc) | |
332 | |
333 '(ccl-decode-mule-utf-16-le . ccl-encode-mule-utf-16-le) | |
334 '((safe-charsets | |
335 ascii | |
336 eight-bit-control | |
337 latin-iso8859-1 | |
338 mule-unicode-0100-24ff | |
339 mule-unicode-2500-33ff | |
340 mule-unicode-e000-ffff) | |
341 (mime-charset . utf-16le) | |
342 (valid-codes (0 . 255)) | |
47705
797c350a7f8c
(utf-16-decode-ucs): Look up
Kenichi Handa <handa@m17n.org>
parents:
47384
diff
changeset
|
343 (dependency unify-8859-on-encoding-mode |
797c350a7f8c
(utf-16-decode-ucs): Look up
Kenichi Handa <handa@m17n.org>
parents:
47384
diff
changeset
|
344 unify-8859-on-decoding-mode |
797c350a7f8c
(utf-16-decode-ucs): Look up
Kenichi Handa <handa@m17n.org>
parents:
47384
diff
changeset
|
345 utf-fragment-on-decoding |
797c350a7f8c
(utf-16-decode-ucs): Look up
Kenichi Handa <handa@m17n.org>
parents:
47384
diff
changeset
|
346 utf-translate-cjk))) |
46677 | 347 |
348 (make-coding-system | |
349 'mule-utf-16-be 4 ?u | |
350 (concat | |
351 "Big endian UTF-16 encoding for Emacs-supported Unicode characters." | |
352 doc) | |
353 | |
354 '(ccl-decode-mule-utf-16-be . ccl-encode-mule-utf-16-be) | |
355 '((safe-charsets | |
356 ascii | |
357 eight-bit-control | |
358 latin-iso8859-1 | |
359 mule-unicode-0100-24ff | |
360 mule-unicode-2500-33ff | |
361 mule-unicode-e000-ffff) | |
362 (mime-charset . utf-16be) | |
50483 | 363 (valid-codes (0 . 255)) |
364 (dependency unify-8859-on-encoding-mode | |
365 unify-8859-on-decoding-mode | |
366 utf-fragment-on-decoding | |
367 utf-translate-cjk))) | |
368 | |
369 (make-coding-system | |
370 'mule-utf-16-le-with-signature 4 ?u | |
371 (concat | |
372 "Little endian UTF-16 (with BOM) for Emacs-supported Unicode characters." | |
373 doc) | |
374 | |
375 '(ccl-decode-mule-utf-16-le-with-signature | |
376 . ccl-encode-mule-utf-16-le-with-signature) | |
377 '((safe-charsets | |
378 ascii | |
379 eight-bit-control | |
380 latin-iso8859-1 | |
381 mule-unicode-0100-24ff | |
382 mule-unicode-2500-33ff | |
383 mule-unicode-e000-ffff) | |
384 (coding-category . coding-category-utf-16-le) | |
385 (mime-charset . utf-16) | |
46677 | 386 (valid-codes (0 . 255)) |
47705
797c350a7f8c
(utf-16-decode-ucs): Look up
Kenichi Handa <handa@m17n.org>
parents:
47384
diff
changeset
|
387 (dependency unify-8859-on-encoding-mode |
797c350a7f8c
(utf-16-decode-ucs): Look up
Kenichi Handa <handa@m17n.org>
parents:
47384
diff
changeset
|
388 unify-8859-on-decoding-mode |
797c350a7f8c
(utf-16-decode-ucs): Look up
Kenichi Handa <handa@m17n.org>
parents:
47384
diff
changeset
|
389 utf-fragment-on-decoding |
50483 | 390 utf-translate-cjk))) |
391 | |
392 (make-coding-system | |
393 'mule-utf-16-be-with-signature 4 ?u | |
394 (concat | |
395 "Big endian UTF-16 (with BOM) for Emacs-supported Unicode characters." | |
396 doc) | |
397 | |
398 '(ccl-decode-mule-utf-16-be-with-signature | |
399 . ccl-encode-mule-utf-16-be-with-signature) | |
400 '((safe-charsets | |
401 ascii | |
402 eight-bit-control | |
403 latin-iso8859-1 | |
404 mule-unicode-0100-24ff | |
405 mule-unicode-2500-33ff | |
406 mule-unicode-e000-ffff) | |
407 (coding-category . coding-category-utf-16-be) | |
408 (mime-charset . utf-16) | |
409 (valid-codes (0 . 255)) | |
410 (dependency unify-8859-on-encoding-mode | |
411 unify-8859-on-decoding-mode | |
412 utf-fragment-on-decoding | |
413 utf-translate-cjk))) | |
414 | |
415 (make-coding-system | |
416 'mule-utf-16 4 ?u | |
417 (concat | |
418 "UTF-16 (with or without BOM) for Emacs-supported Unicode characters." | |
419 doc) | |
420 | |
421 '(ccl-decode-mule-utf-16 . ccl-encode-mule-utf-16-be-with-signature) | |
422 '((safe-charsets | |
423 ascii | |
424 eight-bit-control | |
425 latin-iso8859-1 | |
426 mule-unicode-0100-24ff | |
427 mule-unicode-2500-33ff | |
428 mule-unicode-e000-ffff) | |
429 (coding-category . coding-category-utf-16-be) | |
430 (mime-charset . utf-16) | |
431 (valid-codes (0 . 255)) | |
432 (dependency unify-8859-on-encoding-mode | |
433 unify-8859-on-decoding-mode | |
434 utf-fragment-on-decoding | |
435 utf-translate-cjk) | |
436 (post-read-conversion . mule-utf-16-post-read-conversion))) | |
437 ) | |
46677 | 438 |
439 (define-coding-system-alias 'utf-16-le 'mule-utf-16-le) | |
440 (define-coding-system-alias 'utf-16-be 'mule-utf-16-be) | |
50483 | 441 (define-coding-system-alias 'utf-16-le-with-signature |
442 'mule-utf-16-le-with-signature) | |
443 (define-coding-system-alias 'utf-16-be-with-signature | |
444 'mule-utf-16-be-with-signature) | |
445 (define-coding-system-alias 'utf-16 'mule-utf-16) | |
46677 | 446 |
447 ;;; utf-16.el ends here |