Initial revision
[bpt/emacs.git] / lisp / language / viet-util.el
CommitLineData
4ed46869
KH
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( -> \e,1e\e(B
43;; circumflex | ^ | a^ -> \e,1b\e(B
44;; horn | + | o+ -> \e,1=\e(B
45;; ------------+----------+---------
46;; acute | ' | a' -> \e,1a\e(B
47;; grave | ` | a` -> \e,1`\e(B
48;; hook above | ? | a? -> \e,1d\e(B
49;; tilde | ~ | a~ -> \e,1c\e(B
50;; dot below | . | a. -> \e,1U\e(B
51;; ------------+----------+---------
52;; d bar | dd | dd -> \e,1p\e(B
53;; ------------+----------+---------
54
55(defvar viet-viqr-alist
56 '(;; lowercase
57 (?\e,1!\e(B . "a('") ; 161
58 (?\e,1"\e(B . "a(`") ; 162
59 (?\e,1#\e(B . "a(.") ; 163
60 (?\e,1$\e(B . "a^'") ; 164
61 (?\e,1%\e(B . "a^`") ; 165
62 (?\e,1&\e(B . "a^?") ; 166
63 (?\e,1'\e(B . "a^.") ; 167
64 (?\e,1(\e(B . "e~") ; 168
65 (?\e,1)\e(B . "e.") ; 169
66 (?\e,1*\e(B . "e^'") ; 170
67 (?\e,1+\e(B . "e^`") ; 171
68 (?\e,1,\e(B . "e^?") ; 172
69 (?\e,1-\e(B . "e^~") ; 173
70 (?\e,1.\e(B . "e^.") ; 174
71 (?\e,1/\e(B . "o^'") ; 175
72 (?\e,10\e(B . "o^`") ; 176
73 (?\e,11\e(B . "o^?") ; 177
74 (?\e,12\e(B . "o^~") ; 178
75 (?\e,15\e(B . "o^.") ; 181
76 (?\e,16\e(B . "o+`") ; 182
77 (?\e,17\e(B . "o+?") ; 183
78 (?\e,18\e(B . "i.") ; 184
79 (?\e,1=\e(B . "o+") ; 189
80 (?\e,1>\e(B . "o+'") ; 190
81 (?\e,1F\e(B . "a(?") ; 198
82 (?\e,1G\e(B . "a(~") ; 199
83 (?\e,1O\e(B . "y`") ; 207
84 (?\e,1Q\e(B . "u+'") ; 209
85 (?\e,1U\e(B . "a.") ; 213
86 (?\e,1V\e(B . "y?") ; 214
87 (?\e,1W\e(B . "u+`") ; 215
88 (?\e,1X\e(B . "u+?") ; 216
89 (?\e,1[\e(B . "y~") ; 219
90 (?\e,1\\e(B . "y.") ; 220
91 (?\e,1^\e(B . "o+~") ; 222
92 (?\e,1_\e(B . "u+") ; 223
93 (?\e,1`\e(B . "a`") ; 224
94 (?\e,1a\e(B . "a'") ; 225
95 (?\e,1b\e(B . "a^") ; 226
96 (?\e,1c\e(B . "a~") ; 227
97 (?\e,1d\e(B . "a?") ; 228
98 (?\e,1e\e(B . "a(") ; 229
99 (?\e,1f\e(B . "u+~") ; 230
100 (?\e,1g\e(B . "a^~") ; 231
101 (?\e,1h\e(B . "e`") ; 232
102 (?\e,1i\e(B . "e'") ; 233
103 (?\e,1j\e(B . "e^") ; 234
104 (?\e,1k\e(B . "e?") ; 235
105 (?\e,1l\e(B . "i`") ; 236
106 (?\e,1m\e(B . "i'") ; 237
107 (?\e,1n\e(B . "i~") ; 238
108 (?\e,1o\e(B . "i?") ; 239
109 (?\e,1p\e(B . "dd") ; 240
110 (?\e,1q\e(B . "u+.") ; 241
111 (?\e,1r\e(B . "o`") ; 242
112 (?\e,1s\e(B . "o'") ; 243
113 (?\e,1t\e(B . "o^") ; 244
114 (?\e,1u\e(B . "o~") ; 245
115 (?\e,1v\e(B . "o?") ; 246
116 (?\e,1w\e(B . "o.") ; 247
117 (?\e,1x\e(B . "u.") ; 248
118 (?\e,1y\e(B . "u`") ; 249
119 (?\e,1z\e(B . "u'") ; 250
120 (?\e,1{\e(B . "u~") ; 251
121 (?\e,1|\e(B . "u?") ; 252
122 (?\e,1}\e(B . "y'") ; 253
123 (?\e,1~\e(B . "o+.") ; 254
124
125 ;; upper case
126 (?\e,2!\e(B . "A('") ; 161
127 (?\e,2"\e(B . "A(`") ; 162
128 (?\e,2#\e(B . "A(.") ; 163
129 (?\e,2$\e(B . "A^'") ; 164
130 (?\e,2%\e(B . "A^`") ; 165
131 (?\e,2&\e(B . "A^?") ; 166
132 (?\e,2'\e(B . "A^.") ; 167
133 (?\e,2(\e(B . "E~") ; 168
134 (?\e,2)\e(B . "E.") ; 169
135 (?\e,2*\e(B . "E^'") ; 170
136 (?\e,2+\e(B . "E^`") ; 171
137 (?\e,2,\e(B . "E^?") ; 172
138 (?\e,2-\e(B . "E^~") ; 173
139 (?\e,2.\e(B . "E^.") ; 174
140 (?\e,2/\e(B . "O^'") ; 175
141 (?\e,20\e(B . "O^`") ; 176
142 (?\e,21\e(B . "O^?") ; 177
143 (?\e,22\e(B . "O^~") ; 178
144 (?\e,25\e(B . "O^.") ; 181
145 (?\e,26\e(B . "O+`") ; 182
146 (?\e,27\e(B . "O+?") ; 183
147 (?\e,28\e(B . "I.") ; 184
148 (?\e,2=\e(B . "O+") ; 189
149 (?\e,2>\e(B . "O+'") ; 190
150 (?\e,2F\e(B . "A(?") ; 198
151 (?\e,2G\e(B . "A(~") ; 199
152 (?\e,2O\e(B . "Y`") ; 207
153 (?\e,2Q\e(B . "U+'") ; 209
154 (?\e,2U\e(B . "A.") ; 213
155 (?\e,2V\e(B . "Y?") ; 214
156 (?\e,2W\e(B . "U+`") ; 215
157 (?\e,2X\e(B . "U+?") ; 216
158 (?\e,2[\e(B . "Y~") ; 219
159 (?\e,2\\e(B . "Y.") ; 220
160 (?\e,2^\e(B . "O+~") ; 222
161 (?\e,2_\e(B . "U+") ; 223
162 (?\e,2`\e(B . "A`") ; 224
163 (?\e,2a\e(B . "A'") ; 225
164 (?\e,2b\e(B . "A^") ; 226
165 (?\e,2c\e(B . "A~") ; 227
166 (?\e,2d\e(B . "A?") ; 228
167 (?\e,2e\e(B . "A(") ; 229
168 (?\e,2f\e(B . "U+~") ; 230
169 (?\e,2g\e(B . "A^~") ; 231
170 (?\e,2h\e(B . "E`") ; 232
171 (?\e,2i\e(B . "E'") ; 233
172 (?\e,2j\e(B . "E^") ; 234
173 (?\e,2k\e(B . "E?") ; 235
174 (?\e,2l\e(B . "I`") ; 236
175 (?\e,2m\e(B . "I'") ; 237
176 (?\e,2n\e(B . "I~") ; 238
177 (?\e,2o\e(B . "I?") ; 239
178 (?\e,2p\e(B . "DD") ; 240
179 (?\e,2p\e(B . "dD") ; 240
180 (?\e,2p\e(B . "Dd") ; 240
181 (?\e,2q\e(B . "U+.") ; 241
182 (?\e,2r\e(B . "O`") ; 242
183 (?\e,2s\e(B . "O'") ; 243
184 (?\e,2t\e(B . "O^") ; 244
185 (?\e,2u\e(B . "O~") ; 245
186 (?\e,2v\e(B . "O?") ; 246
187 (?\e,2w\e(B . "O.") ; 247
188 (?\e,2x\e(B . "U.") ; 248
189 (?\e,2y\e(B . "U`") ; 249
190 (?\e,2z\e(B . "U'") ; 250
191 (?\e,2{\e(B . "U~") ; 251
192 (?\e,2|\e(B . "U?") ; 252
193 (?\e,2}\e(B . "Y'") ; 253
194 (?\e,2~\e(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.
218When called from a program, expects two arguments,
219positions (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.
241When called from a program, expects two arguments,
242positions (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