Mercurial > emacs
comparison lisp/language/viet-util.el @ 17052:d0d7b244b1d0
Initial revision
author | Karl Heuer <kwzh@gnu.org> |
---|---|
date | Thu, 20 Feb 1997 07:02:49 +0000 |
parents | |
children | 70194012fb3a |
comparison
equal
deleted
inserted
replaced
17051:fd0b17a79b07 | 17052:d0d7b244b1d0 |
---|---|
1 ;; viet-util.el -- utilities for Vietnamese | |
2 | |
3 ;; Copyright (C) 1995 Free Software Foundation, Inc. | |
4 ;; Copyright (C) 1995 Electrotechnical Laboratory, JAPAN. | |
5 | |
6 ;; Keywords: mule, multilingual, Vietnamese | |
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 | |
22 ;; the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. | |
23 | |
24 ;;; Commentary: | |
25 | |
26 ;; Vietnamese uses ASCII characters and additional 134 unique | |
27 ;; characters (these are Latin alphabets with various diacritical and | |
28 ;; tone marks). As far as I know, Vietnamese now has 4 different ways | |
29 ;; for representing these characters: VISCII, VSCII, VIQR, and | |
30 ;; Unicode. VISCII and VSCII are simple 1-byte code which assigns 134 | |
31 ;; unique characters in control-code area (0x00..0x1F) and right half | |
32 ;; area (0x80..0xFF). VIQR is a menmonic encoding specification | |
33 ;; representing diacritical marks by following ASCII characters. | |
34 | |
35 ;;; Code: | |
36 | |
37 ;; VIQR is a menmonic encoding specification for Vietnamese. | |
38 ;; It represents diacritical marks by ASCII characters as follows: | |
39 ;; ------------+----------+-------- | |
40 ;; mark | mnemonic | example | |
41 ;; ------------+----------+--------- | |
42 ;; breve | ( | a( -> ,1e(B | |
43 ;; circumflex | ^ | a^ -> ,1b(B | |
44 ;; horn | + | o+ -> ,1=(B | |
45 ;; ------------+----------+--------- | |
46 ;; acute | ' | a' -> ,1a(B | |
47 ;; grave | ` | a` -> ,1`(B | |
48 ;; hook above | ? | a? -> ,1d(B | |
49 ;; tilde | ~ | a~ -> ,1c(B | |
50 ;; dot below | . | a. -> ,1U(B | |
51 ;; ------------+----------+--------- | |
52 ;; d bar | dd | dd -> ,1p(B | |
53 ;; ------------+----------+--------- | |
54 | |
55 (defvar viet-viqr-alist | |
56 '(;; lowercase | |
57 (?,1!(B . "a('") ; 161 | |
58 (?,1"(B . "a(`") ; 162 | |
59 (?,1#(B . "a(.") ; 163 | |
60 (?,1$(B . "a^'") ; 164 | |
61 (?,1%(B . "a^`") ; 165 | |
62 (?,1&(B . "a^?") ; 166 | |
63 (?,1'(B . "a^.") ; 167 | |
64 (?,1((B . "e~") ; 168 | |
65 (?,1)(B . "e.") ; 169 | |
66 (?,1*(B . "e^'") ; 170 | |
67 (?,1+(B . "e^`") ; 171 | |
68 (?,1,(B . "e^?") ; 172 | |
69 (?,1-(B . "e^~") ; 173 | |
70 (?,1.(B . "e^.") ; 174 | |
71 (?,1/(B . "o^'") ; 175 | |
72 (?,10(B . "o^`") ; 176 | |
73 (?,11(B . "o^?") ; 177 | |
74 (?,12(B . "o^~") ; 178 | |
75 (?,15(B . "o^.") ; 181 | |
76 (?,16(B . "o+`") ; 182 | |
77 (?,17(B . "o+?") ; 183 | |
78 (?,18(B . "i.") ; 184 | |
79 (?,1=(B . "o+") ; 189 | |
80 (?,1>(B . "o+'") ; 190 | |
81 (?,1F(B . "a(?") ; 198 | |
82 (?,1G(B . "a(~") ; 199 | |
83 (?,1O(B . "y`") ; 207 | |
84 (?,1Q(B . "u+'") ; 209 | |
85 (?,1U(B . "a.") ; 213 | |
86 (?,1V(B . "y?") ; 214 | |
87 (?,1W(B . "u+`") ; 215 | |
88 (?,1X(B . "u+?") ; 216 | |
89 (?,1[(B . "y~") ; 219 | |
90 (?,1\(B . "y.") ; 220 | |
91 (?,1^(B . "o+~") ; 222 | |
92 (?,1_(B . "u+") ; 223 | |
93 (?,1`(B . "a`") ; 224 | |
94 (?,1a(B . "a'") ; 225 | |
95 (?,1b(B . "a^") ; 226 | |
96 (?,1c(B . "a~") ; 227 | |
97 (?,1d(B . "a?") ; 228 | |
98 (?,1e(B . "a(") ; 229 | |
99 (?,1f(B . "u+~") ; 230 | |
100 (?,1g(B . "a^~") ; 231 | |
101 (?,1h(B . "e`") ; 232 | |
102 (?,1i(B . "e'") ; 233 | |
103 (?,1j(B . "e^") ; 234 | |
104 (?,1k(B . "e?") ; 235 | |
105 (?,1l(B . "i`") ; 236 | |
106 (?,1m(B . "i'") ; 237 | |
107 (?,1n(B . "i~") ; 238 | |
108 (?,1o(B . "i?") ; 239 | |
109 (?,1p(B . "dd") ; 240 | |
110 (?,1q(B . "u+.") ; 241 | |
111 (?,1r(B . "o`") ; 242 | |
112 (?,1s(B . "o'") ; 243 | |
113 (?,1t(B . "o^") ; 244 | |
114 (?,1u(B . "o~") ; 245 | |
115 (?,1v(B . "o?") ; 246 | |
116 (?,1w(B . "o.") ; 247 | |
117 (?,1x(B . "u.") ; 248 | |
118 (?,1y(B . "u`") ; 249 | |
119 (?,1z(B . "u'") ; 250 | |
120 (?,1{(B . "u~") ; 251 | |
121 (?,1|(B . "u?") ; 252 | |
122 (?,1}(B . "y'") ; 253 | |
123 (?,1~(B . "o+.") ; 254 | |
124 | |
125 ;; upper case | |
126 (?,2!(B . "A('") ; 161 | |
127 (?,2"(B . "A(`") ; 162 | |
128 (?,2#(B . "A(.") ; 163 | |
129 (?,2$(B . "A^'") ; 164 | |
130 (?,2%(B . "A^`") ; 165 | |
131 (?,2&(B . "A^?") ; 166 | |
132 (?,2'(B . "A^.") ; 167 | |
133 (?,2((B . "E~") ; 168 | |
134 (?,2)(B . "E.") ; 169 | |
135 (?,2*(B . "E^'") ; 170 | |
136 (?,2+(B . "E^`") ; 171 | |
137 (?,2,(B . "E^?") ; 172 | |
138 (?,2-(B . "E^~") ; 173 | |
139 (?,2.(B . "E^.") ; 174 | |
140 (?,2/(B . "O^'") ; 175 | |
141 (?,20(B . "O^`") ; 176 | |
142 (?,21(B . "O^?") ; 177 | |
143 (?,22(B . "O^~") ; 178 | |
144 (?,25(B . "O^.") ; 181 | |
145 (?,26(B . "O+`") ; 182 | |
146 (?,27(B . "O+?") ; 183 | |
147 (?,28(B . "I.") ; 184 | |
148 (?,2=(B . "O+") ; 189 | |
149 (?,2>(B . "O+'") ; 190 | |
150 (?,2F(B . "A(?") ; 198 | |
151 (?,2G(B . "A(~") ; 199 | |
152 (?,2O(B . "Y`") ; 207 | |
153 (?,2Q(B . "U+'") ; 209 | |
154 (?,2U(B . "A.") ; 213 | |
155 (?,2V(B . "Y?") ; 214 | |
156 (?,2W(B . "U+`") ; 215 | |
157 (?,2X(B . "U+?") ; 216 | |
158 (?,2[(B . "Y~") ; 219 | |
159 (?,2\(B . "Y.") ; 220 | |
160 (?,2^(B . "O+~") ; 222 | |
161 (?,2_(B . "U+") ; 223 | |
162 (?,2`(B . "A`") ; 224 | |
163 (?,2a(B . "A'") ; 225 | |
164 (?,2b(B . "A^") ; 226 | |
165 (?,2c(B . "A~") ; 227 | |
166 (?,2d(B . "A?") ; 228 | |
167 (?,2e(B . "A(") ; 229 | |
168 (?,2f(B . "U+~") ; 230 | |
169 (?,2g(B . "A^~") ; 231 | |
170 (?,2h(B . "E`") ; 232 | |
171 (?,2i(B . "E'") ; 233 | |
172 (?,2j(B . "E^") ; 234 | |
173 (?,2k(B . "E?") ; 235 | |
174 (?,2l(B . "I`") ; 236 | |
175 (?,2m(B . "I'") ; 237 | |
176 (?,2n(B . "I~") ; 238 | |
177 (?,2o(B . "I?") ; 239 | |
178 (?,2p(B . "DD") ; 240 | |
179 (?,2p(B . "dD") ; 240 | |
180 (?,2p(B . "Dd") ; 240 | |
181 (?,2q(B . "U+.") ; 241 | |
182 (?,2r(B . "O`") ; 242 | |
183 (?,2s(B . "O'") ; 243 | |
184 (?,2t(B . "O^") ; 244 | |
185 (?,2u(B . "O~") ; 245 | |
186 (?,2v(B . "O?") ; 246 | |
187 (?,2w(B . "O.") ; 247 | |
188 (?,2x(B . "U.") ; 248 | |
189 (?,2y(B . "U`") ; 249 | |
190 (?,2z(B . "U'") ; 250 | |
191 (?,2{(B . "U~") ; 251 | |
192 (?,2|(B . "U?") ; 252 | |
193 (?,2}(B . "Y'") ; 253 | |
194 (?,2~(B . "O+.") ; 254 | |
195 | |
196 ;; escape from composition | |
197 (?\( . "\\(") ; breve (left parenthesis) | |
198 (?^ . "\\^") ; circumflex (caret) | |
199 (?+ . "\\+") ; horn (plus sign) | |
200 (?' . "\\'") ; acute (apostrophe) | |
201 (?` . "\\`") ; grave (backquote) | |
202 (?? . "\\?") ; hook above (question mark) | |
203 (?~ . "\\~") ; tilde (tilde) | |
204 (?. . "\\.") ; dot below (period) | |
205 (?d . "\\d") ; d-bar (d) | |
206 (?\\ . "\\\\") ; literal backslash | |
207 ) | |
208 "Alist of Vietnamese characters vs corresponding `VIQR' string.") | |
209 | |
210 ;; Regular expression matching single Vietnamese character represented | |
211 ;; by VIQR. | |
212 (defconst viqr-regexp | |
213 "[aeiouyAEIOUY]\\([(^+]?['`?~.]\\|[(^+]\\)\\|[Dd][Dd]") | |
214 | |
215 ;;;###autoload | |
216 (defun viet-decode-viqr-region (from to) | |
217 "Convert `VIQR' mnemonics of the current region to Vietnamese characaters. | |
218 When called from a program, expects two arguments, | |
219 positions (integers or markers) specifying the stretch of the region." | |
220 (interactive "r") | |
221 (save-restriction | |
222 (narrow-to-region from to) | |
223 (goto-char (point-min)) | |
224 (while (re-search-forward viqr-regexp nil t) | |
225 (let* ((viqr (buffer-substring (match-beginning 0) (match-end 0))) | |
226 (ch (car (rassoc viet-viqr-alist viqr)))) | |
227 (if ch | |
228 (progn | |
229 (delete-region (match-beginning 0) (match-end 0)) | |
230 (insert ch))))))) | |
231 | |
232 ;;;###autoload | |
233 (defun viet-decode-viqr-buffer () | |
234 "Convert `VIQR' mnemonics of the current buffer to Vietnamese characaters." | |
235 (interactive) | |
236 (viet-decode-viqr-region (point-min) (point-max))) | |
237 | |
238 ;;;###autoload | |
239 (defun viet-encode-viqr-region (from to) | |
240 "Convert Vietnamese characaters of the current region to `VIQR' mnemonics. | |
241 When called from a program, expects two arguments, | |
242 positions (integers or markers) specifying the stretch of the region." | |
243 (interactive "r") | |
244 (save-restriction | |
245 (narrow-to-region from to) | |
246 (goto-char (point-min)) | |
247 (while (re-search-forward "\\cv" nil t) | |
248 (let* ((ch (preceding-char)) | |
249 (viqr (cdr (assoc viet-viqr-alist ch)))) | |
250 (if viqr | |
251 (progn | |
252 (delete-char -1) | |
253 (insert viqr))))))) | |
254 | |
255 ;;;###autoload | |
256 (defun viet-encode-viqr-buffer () | |
257 "Convert Vietnamese characaters of the current buffer to `VIQR' mnemonics." | |
258 (interactive) | |
259 (viet-encode-viqr-region (point-min) (point-max))) | |
260 | |
261 ;;; | |
262 (provide 'language/viet-util) | |
263 | |
264 ;;; Local Variables: | |
265 ;;; generated-autoload-file: "../loaddefs.el" | |
266 ;;; End: | |
267 ;;; viet-util.el ends here |