Mercurial > hg > xemacs-beta
annotate lisp/mule/viet-util.el @ 5379:a32a108ae815
#'cl-non-fixnum-number-p: return t for integers > #x3fffffff and < -#x40000000
2011-03-21 Aidan Kehoe <kehoea@parhasard.net>
* cl-macs.el (cl-non-fixnum-number-p):
This should return t under 64-bit builds for fixnums that would
be bignums on a 32-bit machine; make it so.
author | Aidan Kehoe <kehoea@parhasard.net> |
---|---|
date | Mon, 21 Mar 2011 12:19:25 +0000 |
parents | f00192e1cd49 |
children | ac37a5f7e5be |
rev | line source |
---|---|
778 | 1 ;;; viet-util.el --- utilities for Vietnamese -*- coding: iso-2022-7bit; -*- |
771 | 2 |
3 ;; Copyright (C) 1995 Electrotechnical Laboratory, JAPAN. | |
788 | 4 ;; Copyright (C) 2002 Ben Wing. |
771 | 5 ;; Licensed to the Free Software Foundation. |
6 | |
7 ;; Keywords: mule, multilingual, Vietnamese | |
8 | |
9 ;; This file is part of XEmacs. | |
10 | |
11 ;; XEmacs is free software; you can redistribute it and/or modify it | |
12 ;; under the terms of the GNU General Public License as published by | |
13 ;; the Free Software Foundation; either version 2, or (at your option) | |
14 ;; any later version. | |
15 | |
16 ;; XEmacs is distributed in the hope that it will be useful, but | |
17 ;; WITHOUT ANY WARRANTY; without even the implied warranty of | |
18 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
19 ;; General Public License for more details. | |
20 | |
21 ;; You should have received a copy of the GNU General Public License | |
22 ;; along with XEmacs; see the file COPYING. If not, write to the Free | |
23 ;; Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA | |
24 ;; 02111-1307, USA. | |
25 | |
778 | 26 ;;; Synched up with: Emacs 21.1 (language/viet-util.el). |
771 | 27 |
28 ;;; Commentary: | |
29 | |
30 ;; Vietnamese uses ASCII characters and additional 134 unique | |
31 ;; characters (these are Latin alphabets with various diacritical and | |
32 ;; tone marks). As far as I know, Vietnamese now has 4 different ways | |
33 ;; for representing these characters: VISCII, VSCII, VIQR, and | |
34 ;; Unicode. VISCII and VSCII are simple 1-byte code which assigns 134 | |
35 ;; unique characters in control-code area (0x00..0x1F) and right half | |
36 ;; area (0x80..0xFF). VIQR is a menmonic encoding specification | |
37 ;; representing diacritical marks by following ASCII characters. | |
38 | |
39 ;;; Code: | |
40 | |
41 ;;;###autoload | |
42 (defun viet-encode-viscii-char (char) | |
43 "Return VISCII character code of CHAR if appropriate." | |
4072 | 44 (check-argument-type #'characterp char) |
45 (if (eq char ?~) | |
46 char | |
47 (setq char (encode-coding-string char 'viscii)) | |
5366
f00192e1cd49
Examining the result of #'length: `eql', not `=', it's better style & cheaper
Aidan Kehoe <kehoea@parhasard.net>
parents:
4072
diff
changeset
|
48 (if (and (eql 1 (length char)) |
f00192e1cd49
Examining the result of #'length: `eql', not `=', it's better style & cheaper
Aidan Kehoe <kehoea@parhasard.net>
parents:
4072
diff
changeset
|
49 (not (eql (aref char 0) ?~))) |
4072 | 50 (aref char 0)))) |
771 | 51 |
52 ;; VIQR is a menmonic encoding specification for Vietnamese. | |
53 ;; It represents diacritical marks by ASCII characters as follows: | |
54 ;; ------------+----------+-------- | |
55 ;; mark | mnemonic | example | |
56 ;; ------------+----------+--------- | |
57 ;; breve | ( | a( -> ,1e(B | |
58 ;; circumflex | ^ | a^ -> ,1b(B | |
59 ;; horn | + | o+ -> ,1=(B | |
60 ;; ------------+----------+--------- | |
61 ;; acute | ' | a' -> ,1a(B | |
62 ;; grave | ` | a` -> ,1`(B | |
63 ;; hook above | ? | a? -> ,1d(B | |
64 ;; tilde | ~ | a~ -> ,1c(B | |
65 ;; dot below | . | a. -> ,1U(B | |
66 ;; ------------+----------+--------- | |
67 ;; d bar | dd | dd -> ,1p(B | |
68 ;; ------------+----------+--------- | |
69 | |
70 (defvar viet-viqr-alist | |
71 '(;; lowercase | |
72 (?,1!(B . "a('") ; 161 | |
73 (?,1"(B . "a(`") ; 162 | |
74 (?,1#(B . "a(.") ; 163 | |
75 (?,1$(B . "a^'") ; 164 | |
76 (?,1%(B . "a^`") ; 165 | |
77 (?,1&(B . "a^?") ; 166 | |
78 (?,1'(B . "a^.") ; 167 | |
79 (?,1((B . "e~") ; 168 | |
80 (?,1)(B . "e.") ; 169 | |
81 (?,1*(B . "e^'") ; 170 | |
82 (?,1+(B . "e^`") ; 171 | |
83 (?,1,(B . "e^?") ; 172 | |
84 (?,1-(B . "e^~") ; 173 | |
85 (?,1.(B . "e^.") ; 174 | |
86 (?,1/(B . "o^'") ; 175 | |
87 (?,10(B . "o^`") ; 176 | |
88 (?,11(B . "o^?") ; 177 | |
89 (?,12(B . "o^~") ; 178 | |
90 (?,15(B . "o^.") ; 181 | |
91 (?,16(B . "o+`") ; 182 | |
92 (?,17(B . "o+?") ; 183 | |
93 (?,18(B . "i.") ; 184 | |
94 (?,1=(B . "o+") ; 189 | |
95 (?,1>(B . "o+'") ; 190 | |
96 (?,1F(B . "a(?") ; 198 | |
97 (?,1G(B . "a(~") ; 199 | |
98 (?,1O(B . "y`") ; 207 | |
99 (?,1Q(B . "u+'") ; 209 | |
100 (?,1U(B . "a.") ; 213 | |
101 (?,1V(B . "y?") ; 214 | |
102 (?,1W(B . "u+`") ; 215 | |
103 (?,1X(B . "u+?") ; 216 | |
104 (?,1[(B . "y~") ; 219 | |
105 (?,1\(B . "y.") ; 220 | |
106 (?,1^(B . "o+~") ; 222 | |
107 (?,1_(B . "u+") ; 223 | |
108 (?,1`(B . "a`") ; 224 | |
109 (?,1a(B . "a'") ; 225 | |
110 (?,1b(B . "a^") ; 226 | |
111 (?,1c(B . "a~") ; 227 | |
112 (?,1d(B . "a?") ; 228 | |
113 (?,1e(B . "a(") ; 229 | |
114 (?,1f(B . "u+~") ; 230 | |
115 (?,1g(B . "a^~") ; 231 | |
116 (?,1h(B . "e`") ; 232 | |
117 (?,1i(B . "e'") ; 233 | |
118 (?,1j(B . "e^") ; 234 | |
119 (?,1k(B . "e?") ; 235 | |
120 (?,1l(B . "i`") ; 236 | |
121 (?,1m(B . "i'") ; 237 | |
122 (?,1n(B . "i~") ; 238 | |
123 (?,1o(B . "i?") ; 239 | |
124 (?,1p(B . "dd") ; 240 | |
125 (?,1q(B . "u+.") ; 241 | |
126 (?,1r(B . "o`") ; 242 | |
127 (?,1s(B . "o'") ; 243 | |
128 (?,1t(B . "o^") ; 244 | |
129 (?,1u(B . "o~") ; 245 | |
130 (?,1v(B . "o?") ; 246 | |
131 (?,1w(B . "o.") ; 247 | |
132 (?,1x(B . "u.") ; 248 | |
133 (?,1y(B . "u`") ; 249 | |
134 (?,1z(B . "u'") ; 250 | |
135 (?,1{(B . "u~") ; 251 | |
136 (?,1|(B . "u?") ; 252 | |
137 (?,1}(B . "y'") ; 253 | |
138 (?,1~(B . "o+.") ; 254 | |
139 | |
140 ;; upper case | |
141 (?,2!(B . "A('") ; 161 | |
142 (?,2"(B . "A(`") ; 162 | |
143 (?,2#(B . "A(.") ; 163 | |
144 (?,2$(B . "A^'") ; 164 | |
145 (?,2%(B . "A^`") ; 165 | |
146 (?,2&(B . "A^?") ; 166 | |
147 (?,2'(B . "A^.") ; 167 | |
148 (?,2((B . "E~") ; 168 | |
149 (?,2)(B . "E.") ; 169 | |
150 (?,2*(B . "E^'") ; 170 | |
151 (?,2+(B . "E^`") ; 171 | |
152 (?,2,(B . "E^?") ; 172 | |
153 (?,2-(B . "E^~") ; 173 | |
154 (?,2.(B . "E^.") ; 174 | |
155 (?,2/(B . "O^'") ; 175 | |
156 (?,20(B . "O^`") ; 176 | |
157 (?,21(B . "O^?") ; 177 | |
158 (?,22(B . "O^~") ; 178 | |
159 (?,25(B . "O^.") ; 181 | |
160 (?,26(B . "O+`") ; 182 | |
161 (?,27(B . "O+?") ; 183 | |
162 (?,28(B . "I.") ; 184 | |
163 (?,2=(B . "O+") ; 189 | |
164 (?,2>(B . "O+'") ; 190 | |
165 (?,2F(B . "A(?") ; 198 | |
166 (?,2G(B . "A(~") ; 199 | |
167 (?,2O(B . "Y`") ; 207 | |
168 (?,2Q(B . "U+'") ; 209 | |
169 (?,2U(B . "A.") ; 213 | |
170 (?,2V(B . "Y?") ; 214 | |
171 (?,2W(B . "U+`") ; 215 | |
172 (?,2X(B . "U+?") ; 216 | |
173 (?,2[(B . "Y~") ; 219 | |
174 (?,2\(B . "Y.") ; 220 | |
175 (?,2^(B . "O+~") ; 222 | |
176 (?,2_(B . "U+") ; 223 | |
177 (?,2`(B . "A`") ; 224 | |
178 (?,2a(B . "A'") ; 225 | |
179 (?,2b(B . "A^") ; 226 | |
180 (?,2c(B . "A~") ; 227 | |
181 (?,2d(B . "A?") ; 228 | |
182 (?,2e(B . "A(") ; 229 | |
183 (?,2f(B . "U+~") ; 230 | |
184 (?,2g(B . "A^~") ; 231 | |
185 (?,2h(B . "E`") ; 232 | |
186 (?,2i(B . "E'") ; 233 | |
187 (?,2j(B . "E^") ; 234 | |
188 (?,2k(B . "E?") ; 235 | |
189 (?,2l(B . "I`") ; 236 | |
190 (?,2m(B . "I'") ; 237 | |
191 (?,2n(B . "I~") ; 238 | |
192 (?,2o(B . "I?") ; 239 | |
193 (?,2p(B . "DD") ; 240 | |
194 (?,2p(B . "dD") ; 240 | |
195 (?,2p(B . "Dd") ; 240 | |
196 (?,2q(B . "U+.") ; 241 | |
197 (?,2r(B . "O`") ; 242 | |
198 (?,2s(B . "O'") ; 243 | |
199 (?,2t(B . "O^") ; 244 | |
200 (?,2u(B . "O~") ; 245 | |
201 (?,2v(B . "O?") ; 246 | |
202 (?,2w(B . "O.") ; 247 | |
203 (?,2x(B . "U.") ; 248 | |
204 (?,2y(B . "U`") ; 249 | |
205 (?,2z(B . "U'") ; 250 | |
206 (?,2{(B . "U~") ; 251 | |
207 (?,2|(B . "U?") ; 252 | |
208 (?,2}(B . "Y'") ; 253 | |
209 (?,2~(B . "O+.") ; 254 | |
210 | |
211 ;; escape from composition | |
212 (?\( . "\\(") ; breve (left parenthesis) | |
213 (?^ . "\\^") ; circumflex (caret) | |
214 (?+ . "\\+") ; horn (plus sign) | |
215 (?' . "\\'") ; acute (apostrophe) | |
216 (?` . "\\`") ; grave (backquote) | |
217 (?? . "\\?") ; hook above (question mark) | |
218 (?~ . "\\~") ; tilde (tilde) | |
219 (?. . "\\.") ; dot below (period) | |
220 (?d . "\\d") ; d-bar (d) | |
221 (?\\ . "\\\\") ; literal backslash | |
222 ) | |
223 "Alist of Vietnamese characters vs corresponding `VIQR' string.") | |
224 | |
225 ;; Regular expression matching single Vietnamese character represented | |
226 ;; by VIQR. | |
227 (defconst viqr-regexp | |
228 "[aeiouyAEIOUY]\\([(^+]?['`?~.]\\|[(^+]\\)\\|[Dd][Dd]") | |
229 | |
230 ;;;###autoload | |
231 (defun viet-decode-viqr-region (from to) | |
1196 | 232 "Convert `VIQR' mnemonics of the current region to Vietnamese characters. |
771 | 233 When called from a program, expects two arguments, |
234 positions (integers or markers) specifying the stretch of the region." | |
235 (interactive "r") | |
236 (save-restriction | |
237 (narrow-to-region from to) | |
238 (goto-char (point-min)) | |
239 (while (re-search-forward viqr-regexp nil t) | |
240 (let* ((viqr (buffer-substring (match-beginning 0) (match-end 0))) | |
241 (ch (car (rassoc viqr viet-viqr-alist)))) | |
242 (if ch | |
243 (progn | |
244 (delete-region (match-beginning 0) (match-end 0)) | |
245 (insert ch))))))) | |
246 | |
247 ;;;###autoload | |
248 (defun viet-decode-viqr-buffer () | |
1196 | 249 "Convert `VIQR' mnemonics of the current buffer to Vietnamese characters." |
771 | 250 (interactive) |
251 (viet-decode-viqr-region (point-min) (point-max))) | |
252 | |
253 ;;;###autoload | |
254 (defun viet-encode-viqr-region (from to) | |
1196 | 255 "Convert Vietnamese characters of the current region to `VIQR' mnemonics. |
771 | 256 When called from a program, expects two arguments, |
257 positions (integers or markers) specifying the stretch of the region." | |
258 (interactive "r") | |
259 (save-restriction | |
260 (narrow-to-region from to) | |
261 (goto-char (point-min)) | |
262 (while (re-search-forward "\\cv" nil t) | |
263 (let* ((ch (preceding-char)) | |
264 (viqr (cdr (assq ch viet-viqr-alist)))) | |
265 (if viqr | |
266 (progn | |
267 (delete-char -1) | |
268 (insert viqr))))))) | |
269 | |
270 ;;;###autoload | |
271 (defun viet-encode-viqr-buffer () | |
1196 | 272 "Convert Vietnamese characters of the current buffer to `VIQR' mnemonics." |
771 | 273 (interactive) |
274 (viet-encode-viqr-region (point-min) (point-max))) | |
275 | |
276 ;;;###autoload | |
277 (defun viqr-post-read-conversion (len) | |
278 (save-excursion | |
279 (save-restriction | |
280 (narrow-to-region (point) (+ (point) len)) | |
281 (let ((buffer-modified-p (buffer-modified-p))) | |
282 (viet-decode-viqr-region (point-min) (point-max)) | |
283 (set-buffer-modified-p buffer-modified-p) | |
284 (- (point-max) (point-min)))))) | |
285 | |
286 ;;;###autoload | |
287 (defun viqr-pre-write-conversion (from to) | |
288 (let ((old-buf (current-buffer))) | |
289 (set-buffer (generate-new-buffer " *temp*")) | |
290 (if (stringp from) | |
291 (insert from) | |
292 (insert-buffer-substring old-buf from to)) | |
293 (viet-encode-viqr-region (point-min) (point-max)) | |
294 ;; Should return nil as annotations. | |
295 nil)) | |
296 | |
297 ;;; | |
298 (provide 'viet-util) | |
299 | |
300 ;;; viet-util.el ends here |