Mercurial > emacs
annotate lisp/language/lao-util.el @ 91314:9433091ab2b1
New file.
author | Kenichi Handa <handa@m17n.org> |
---|---|
date | Mon, 07 Jan 2008 12:30:34 +0000 |
parents | f55f9811f5d7 |
children | 606f2d163a64 |
rev | line source |
---|---|
36683
b82a6fbaae16
Add coding: iso-2022-7bit tag.
Kenichi Handa <handa@m17n.org>
parents:
29361
diff
changeset
|
1 ;;; lao-util.el --- utilities for Lao -*- coding: iso-2022-7bit; -*- |
17083 | 2 |
75347 | 3 ;; Copyright (C) 2001, 2002, 2003, 2004, 2005, 2006, 2007 |
74544 | 4 ;; Free Software Foundation, Inc. |
75347 | 5 ;; Copyright (C) 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007 |
62396 | 6 ;; National Institute of Advanced Industrial Science and Technology (AIST) |
7 ;; Registration Number H14PRO021 | |
89483 | 8 ;; Copyright (C) 2003 |
9 ;; National Institute of Advanced Industrial Science and Technology (AIST) | |
10 ;; Registration Number H13PRO009 | |
17083 | 11 |
88761 | 12 ;; Keywords: multilingual, Lao, i18n |
17083 | 13 |
14 ;; This file is part of GNU Emacs. | |
15 | |
16 ;; GNU Emacs is free software; you can redistribute it and/or modify | |
17 ;; it under the terms of the GNU General Public License as published by | |
78309
0938de05f510
Restore comma mistakenly removed in last change.
Glenn Morris <rgm@gnu.org>
parents:
78300
diff
changeset
|
18 ;; the Free Software Foundation; either version 3, or (at your option) |
17083 | 19 ;; any later version. |
20 | |
21 ;; GNU Emacs is distributed in the hope that it will be useful, | |
22 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of | |
23 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
24 ;; GNU General Public License for more details. | |
25 | |
26 ;; You should have received a copy of the GNU General Public License | |
27 ;; along with GNU Emacs; see the file COPYING. If not, write to the | |
64085 | 28 ;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, |
29 ;; Boston, MA 02110-1301, USA. | |
17083 | 30 |
38414
67b464da13ec
Some fixes to follow coding conventions.
Pavel Janík <Pavel@Janik.cz>
parents:
36683
diff
changeset
|
31 ;;; Commentary: |
67b464da13ec
Some fixes to follow coding conventions.
Pavel Janík <Pavel@Janik.cz>
parents:
36683
diff
changeset
|
32 |
17083 | 33 ;;; Code: |
34 | |
26894 | 35 ;; Setting information of Thai characters. |
36 | |
37 (defconst lao-category-table (make-category-table)) | |
38 (define-category ?c "Lao consonant" lao-category-table) | |
39 (define-category ?s "Lao semi-vowel" lao-category-table) | |
40 (define-category ?v "Lao upper/lower vowel" lao-category-table) | |
41 (define-category ?t "Lao tone" lao-category-table) | |
42 | |
17083 | 43 (let ((l '((?(1!(B consonant "LETTER KOR KAI'" "CHICKEN") |
44 (?(1"(B consonant "LETTER KHOR KHAI'" "EGG") | |
45 (?(1#(B invalid nil) | |
46 (?(1$(B consonant "LETTER QHOR QHWARGN" "BUFFALO") | |
47 (?(1%(B invalid nil) | |
48 (? invalid nil) | |
49 (?(1'(B consonant "LETTER NGOR NGUU" "SNAKE") | |
50 (?(1((B consonant "LETTER JOR JUA" "BUDDHIST NOVICE") | |
51 (?(1)(B invalid nil) | |
52 (?(1*(B consonant "LETTER XOR X\"ARNG" "ELEPHANT") | |
53 (?(1+(B invalid nil) | |
54 (?(1,(B invalid nil) | |
55 (?(1-(B consonant "LETTER YOR YUNG" "MOSQUITO") | |
56 (?(1.(B invalid nil) | |
57 (?(1.(B invalid nil) | |
58 (?(1.(B invalid nil) | |
59 (?(1.(B invalid nil) | |
60 (?(1.(B invalid nil) | |
61 (?(1.(B invalid nil) | |
62 (?(14(B consonant "LETTER DOR DANG" "NOSE") | |
63 (?(15(B consonant "LETTER TOR TAR" "EYE") | |
19271
0caaca9020bc
Set t for Rao-SEMIVOWEL-SIGN-LO in
Kenichi Handa <handa@m17n.org>
parents:
18550
diff
changeset
|
64 (?(16(B consonant "LETTER THOR THUNG" "TO ASK,QUESTION") |
0caaca9020bc
Set t for Rao-SEMIVOWEL-SIGN-LO in
Kenichi Handa <handa@m17n.org>
parents:
18550
diff
changeset
|
65 (?(17(B consonant "LETTER DHOR DHARM" "FLAG") |
17083 | 66 (?(18(B invalid nil) |
67 (?(19(B consonant "LETTER NOR NOK" "BIRD") | |
68 (?(1:(B consonant "LETTER BOR BED" "FISHHOOK") | |
69 (?(1;(B consonant "LETTER POR PAR" "FISH") | |
70 (?(1<(B consonant "LETTER HPOR HPER\"" "BEE") | |
71 (?(1=(B consonant "LETTER FHOR FHAR" "WALL") | |
72 (?(1>(B consonant "LETTER PHOR PHUU" "MOUNTAIN") | |
73 (?(1?(B consonant "LETTER FOR FAI" "FIRE") | |
74 (?(1@(B invalid nil) | |
75 (?(1A(B consonant "LETTER MOR MAR\"" "HORSE") | |
76 (?(1B(B consonant "LETTER GNOR GNAR" "MEDICINE") | |
77 (?(1C(B consonant "LETTER ROR ROD" "CAR") | |
78 (?(1D(B invalid nil) | |
79 (?(1E(B consonant "LETTER LOR LIING" "MONKEY") | |
80 (?(1F(B invalid nil) | |
81 (?(1G(B consonant "LETTER WOR WII" "HAND FAN") | |
82 (?(1H(B invalid nil) | |
83 (?(1I(B invalid nil) | |
84 (?(1J(B consonant "LETTER SOR SEA" "TIGER") | |
85 (?(1K(B consonant "LETTER HHOR HHAI" "JAR") | |
86 (?(1L(B invalid nil) | |
87 (?(1M(B consonant "LETTER OR OOW" "TAKE") | |
88 (?(1N(B consonant "LETTER HOR HEA" "BOAT") | |
89 (?(1O(B special "ELLIPSIS") | |
90 (?(1P(B vowel-base "VOWEL SIGN SARA A") | |
91 (?(1Q(B vowel-upper "VOWEL SIGN MAI KAN") | |
92 (?(1R(B vowel-base "VOWEL SIGN SARA AR") | |
93 (?(1S(B vowel-base "VOWEL SIGN SARA AM") | |
49598
0d8b17d428b5
Trailing whitepace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
48042
diff
changeset
|
94 (?(1T(B vowel-upper "VOWEL SIGN SARA I") |
17083 | 95 (?(1U(B vowel-upper "VOWEL SIGN SARA II") |
96 (?(1V(B vowel-upper "VOWEL SIGN SARA EU") | |
97 (?(1W(B vowel-upper "VOWEL SIGN SARA UR") | |
98 (?(1X(B vowel-lower "VOWEL SIGN SARA U") | |
99 (?(1Y(B vowel-lower "VOWEL SIGN SARA UU") | |
100 (?(1Z(B invalid nil) | |
101 (?(1[(B vowel-upper "VOWEL SIGN MAI KONG") | |
102 (?(1\(B semivowel-lower "SEMIVOWEL SIGN LO") | |
103 (?(1](B vowel-base "SEMIVOWEL SIGN SARA IA") | |
104 (?(1^(B invalid nil) | |
105 (?(1_(B invalid nil) | |
106 (?(1`(B vowel-base "VOWEL SIGN SARA EE") | |
107 (?(1a(B vowel-base "VOWEL SIGN SARA AA") | |
108 (?(1b(B vowel-base "VOWEL SIGN SARA OO") | |
109 (?(1c(B vowel-base "VOWEL SIGN SARA EI MAI MUAN\"") | |
110 (?(1d(B vowel-base "VOWEL SIGN SARA AI MAI MAY") | |
111 (?(1e(B invalid nil) | |
49598
0d8b17d428b5
Trailing whitepace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
48042
diff
changeset
|
112 (?(1f(B special "KO LA (REPETITION)") |
17083 | 113 (?(1g(B invalid nil) |
114 (?(1h(B tone "TONE MAI EK") | |
115 (?(1i(B tone "TONE MAI THO") | |
116 (?(1j(B tone "TONE MAI TI") | |
117 (?(1k(B tone "TONE MAI JADTAWAR") | |
118 (?(1l(B tone "CANCELLATION MARK") | |
119 (?(1m(B vowel-upper "VOWEL SIGN SARA OR") | |
120 (?(1n(B invalid nil) | |
121 (?(1o(B invalid nil) | |
122 (?(1p(B special "DIGIT ZERO") | |
123 (?(1q(B special "DIGIT ONE") | |
124 (?(1r(B special "DIGIT TWO") | |
125 (?(1s(B special "DIGIT THREE") | |
126 (?(1t(B special "DIGIT FOUR") | |
127 (?(1u(B special "DIGIT FIVE") | |
128 (?(1v(B special "DIGIT SIX") | |
129 (?(1w(B special "DIGIT SEVEN") | |
130 (?(1x(B special "DIGIT EIGHT") | |
131 (?(1y(B special "DIGIT NINE") | |
132 (?(1z(B invalid nil) | |
133 (?(1{(B invalid nil) | |
134 (?(1|(B consonant "LETTER NHOR NHUU" "MOUSE") | |
135 (?(1}(B consonant "LETTER MHOR MHAR" "DOG") | |
88761 | 136 (?(1~(B invalid nil))) |
17083 | 137 elm) |
138 (while l | |
26894 | 139 (setq elm (car l) l (cdr l)) |
140 (let ((char (car elm)) | |
141 (ptype (nth 1 elm))) | |
142 (cond ((eq ptype 'consonant) | |
143 (modify-category-entry char ?c lao-category-table)) | |
144 ((memq ptype '(vowel-upper vowel-lower)) | |
145 (modify-category-entry char ?v lao-category-table)) | |
146 ((eq ptype 'semivowel-lower) | |
147 (modify-category-entry char ?s lao-category-table)) | |
148 ((eq ptype 'tone) | |
149 (modify-category-entry char ?t lao-category-table))) | |
150 (put-char-code-property char 'phonetic-type ptype) | |
151 (put-char-code-property char 'name (nth 2 elm)) | |
152 (put-char-code-property char 'meaning (nth 3 elm))))) | |
153 | |
154 ;; The general composing rules are as follows: | |
155 ;; | |
156 ;; T | |
157 ;; V T V T | |
158 ;; CV -> C, CT -> C, CVT -> C, Cv -> C, CvT -> C | |
159 ;; v v | |
160 ;; T | |
89300
6a0cc62928b5
(lao-post-read-conversion): Delete this
Kenichi Handa <handa@m17n.org>
parents:
88761
diff
changeset
|
161 ;; V T V T |
6a0cc62928b5
(lao-post-read-conversion): Delete this
Kenichi Handa <handa@m17n.org>
parents:
88761
diff
changeset
|
162 ;; CsV -> C, CsT -> C, CsVT -> C, Csv -> C, CsvT -> C |
6a0cc62928b5
(lao-post-read-conversion): Delete this
Kenichi Handa <handa@m17n.org>
parents:
88761
diff
changeset
|
163 ;; s s s s s |
6a0cc62928b5
(lao-post-read-conversion): Delete this
Kenichi Handa <handa@m17n.org>
parents:
88761
diff
changeset
|
164 ;; v v |
26894 | 165 |
166 | |
167 ;; where C: consonant, V: vowel upper, v: vowel lower, | |
168 ;; T: tone mark, s: semivowel lower | |
169 | |
170 (defvar lao-composition-pattern | |
171 "\\cc\\(\\ct\\|\\cv\\ct?\\|\\cs\\(\\ct\\|\\cv\\ct?\\)?\\)" | |
172 "Regular expression matching a Lao composite sequence.") | |
173 | |
174 ;;;###autoload | |
175 (defun lao-compose-string (str) | |
176 (with-category-table lao-category-table | |
177 (let ((idx 0)) | |
178 (while (setq idx (string-match lao-composition-pattern str idx)) | |
179 (compose-string str idx (match-end 0)) | |
180 (setq idx (match-end 0)))) | |
181 str)) | |
182 | |
183 ;;; LRT: Lao <-> Roman Transcription | |
184 | |
185 ;; Upper vowels and tone-marks are put on the letter. | |
186 ;; Semi-vowel-sign-lo and lower vowels are put under the letter. | |
187 | |
188 (defconst lao-transcription-consonant-alist | |
189 (sort '(;; single consonants | |
190 ("k" . "(1!(B") | |
191 ("kh" . "(1"(B") | |
192 ("qh" . "(1$(B") | |
193 ("ng" . "(1'(B") | |
194 ("j" . "(1((B") | |
195 ("s" . "(1J(B") | |
196 ("x" . "(1*(B") | |
197 ("y" . "(1-(B") | |
198 ("d" . "(14(B") | |
199 ("t" . "(15(B") | |
200 ("th" . "(16(B") | |
201 ("dh" . "(17(B") | |
202 ("n" . "(19(B") | |
203 ("b" . "(1:(B") | |
204 ("p" . "(1;(B") | |
205 ("hp" . "(1<(B") | |
206 ("fh" . "(1=(B") | |
207 ("ph" . "(1>(B") | |
208 ("f" . "(1?(B") | |
209 ("m" . "(1A(B") | |
210 ("gn" . "(1B(B") | |
211 ("l" . "(1E(B") | |
212 ("r" . "(1C(B") | |
213 ("v" . "(1G(B") | |
214 ("w" . "(1G(B") | |
215 ("hh" . "(1K(B") | |
216 ("O" . "(1M(B") | |
217 ("h" . "(1N(B") | |
218 ("nh" . "(1|(B") | |
219 ("mh" . "(1}(B") | |
220 ("lh" . ["(1K\(B"]) | |
221 ;; double consonants | |
222 ("ngh" . ["(1K'(B"]) | |
223 ("yh" . ["(1K](B"]) | |
224 ("wh" . ["(1KG(B"]) | |
225 ("hl" . ["(1KE(B"]) | |
226 ("hy" . ["(1K-(B"]) | |
227 ("hn" . ["(1K9(B"]) | |
228 ("hm" . ["(1KA(B"]) | |
229 ) | |
230 (function (lambda (x y) (> (length (car x)) (length (car y))))))) | |
231 | |
232 (defconst lao-transcription-semi-vowel-alist | |
233 '(("r" . "(1\(B"))) | |
234 | |
235 (defconst lao-transcription-vowel-alist | |
236 (sort '(("a" . "(1P(B") | |
237 ("ar" . "(1R(B") | |
238 ("i" . "(1T(B") | |
239 ("ii" . "(1U(B") | |
240 ("eu" . "(1V(B") | |
241 ("ur" . "(1W(B") | |
242 ("u" . "(1X(B") | |
243 ("uu" . "(1Y(B") | |
244 ("e" . ["(1`P(B"]) | |
245 ("ee" . "(1`(B") | |
246 ("ae" . ["(1aP(B"]) | |
247 ("aa" . "(1a(B") | |
248 ("o" . ["(1bP(B"]) | |
249 ("oo" . "(1b(B") | |
250 ("oe" . ["(1`RP(B"]) | |
251 ("or" . "(1m(B") | |
252 ("er" . ["(1`T(B"]) | |
253 ("ir" . ["(1`U(B"]) | |
254 ("ua" . ["(1[GP(B"]) | |
255 ("uaa" . ["(1[G(B"]) | |
256 ("ie" . ["(1`Q]P(B"]) | |
257 ("ia" . ["(1`Q](B"]) | |
258 ("ea" . ["(1`VM(B"]) | |
259 ("eaa" . ["(1`WM(B"]) | |
260 ("ai" . "(1d(B") | |
261 ("ei" . "(1c(B") | |
262 ("ao" . ["(1`[R(B"]) | |
263 ("aM" . "(1S(B")) | |
264 (function (lambda (x y) (> (length (car x)) (length (car y))))))) | |
265 | |
266 ;; Maa-sakod is put at the tail. | |
267 (defconst lao-transcription-maa-sakod-alist | |
268 '(("k" . "(1!(B") | |
269 ("g" . "(1'(B") | |
270 ("y" . "(1-(B") | |
271 ("d" . "(14(B") | |
272 ("n" . "(19(B") | |
273 ("b" . "(1:(B") | |
274 ("m" . "(1A(B") | |
275 ("v" . "(1G(B") | |
276 ("w" . "(1G(B") | |
277 )) | |
278 | |
279 (defconst lao-transcription-tone-alist | |
280 '(("'" . "(1h(B") | |
281 ("\"" . "(1i(B") | |
282 ("^" . "(1j(B") | |
283 ("+" . "(1k(B") | |
284 ("~" . "(1l(B"))) | |
285 | |
286 (defconst lao-transcription-punctuation-alist | |
287 '(("\\0" . "(1p(B") | |
288 ("\\1" . "(1q(B") | |
289 ("\\2" . "(1r(B") | |
290 ("\\3" . "(1s(B") | |
291 ("\\4" . "(1t(B") | |
292 ("\\5" . "(1u(B") | |
293 ("\\6" . "(1v(B") | |
294 ("\\7" . "(1w(B") | |
295 ("\\8" . "(1x(B") | |
296 ("\\9" . "(1y(B") | |
297 ("\\\\" . "(1f(B") | |
298 ("\\$" . "(1O(B"))) | |
299 | |
300 (defconst lao-transcription-pattern | |
301 (concat | |
302 "\\(" | |
303 (mapconcat 'car lao-transcription-consonant-alist "\\|") | |
304 "\\)\\(" | |
305 (mapconcat 'car lao-transcription-semi-vowel-alist "\\|") | |
306 "\\)?\\(\\(" | |
307 (mapconcat 'car lao-transcription-vowel-alist "\\|") | |
308 "\\)\\(" | |
309 (mapconcat 'car lao-transcription-maa-sakod-alist "\\|") | |
310 "\\)?\\(" | |
311 (mapconcat (lambda (x) (regexp-quote (car x))) | |
312 lao-transcription-tone-alist "\\|") | |
313 "\\)?\\)?\\|" | |
314 (mapconcat (lambda (x) (regexp-quote (car x))) | |
315 lao-transcription-punctuation-alist "\\|") | |
316 ) | |
317 "Regexp of Roman transcription pattern for one Lao syllable.") | |
318 | |
319 (defconst lao-transcription-pattern | |
320 (concat | |
321 "\\(" | |
322 (regexp-opt (mapcar 'car lao-transcription-consonant-alist)) | |
323 "\\)\\(" | |
324 (regexp-opt (mapcar 'car lao-transcription-semi-vowel-alist)) | |
325 "\\)?\\(\\(" | |
326 (regexp-opt (mapcar 'car lao-transcription-vowel-alist)) | |
327 "\\)\\(" | |
328 (regexp-opt (mapcar 'car lao-transcription-maa-sakod-alist)) | |
329 "\\)?\\(" | |
330 (regexp-opt (mapcar 'car lao-transcription-tone-alist)) | |
331 "\\)?\\)?\\|" | |
332 (regexp-opt (mapcar 'car lao-transcription-punctuation-alist)) | |
333 ) | |
334 "Regexp of Roman transcription pattern for one Lao syllable.") | |
335 | |
336 (defconst lao-vowel-reordering-rule | |
337 '(("(1P(B" (0 ?(1P(B) (0 ?(1Q(B)) | |
338 ("(1R(B" (0 ?(1R(B)) | |
339 ("(1T(B" (0 ?(1U(B)) | |
340 ("(1U(B" (0 ?(1U(B)) | |
341 ("(1V(B" (0 ?(1V(B)) | |
342 ("(1W(B" (0 ?(1W(B)) | |
343 ("(1X(B" (0 ?(1X(B)) | |
344 ("(1Y(B" (0 ?(1Y(B)) | |
345 ("(1`P(B" (?(1`(B 0 ?(1P(B) (?(1`(B 0 ?(1Q(B)) | |
346 ("(1`(B" (?(1`(B 0)) | |
347 ("(1aP(B" (?(1a(B 0 ?(1P(B) (?(1a(B 0 ?(1Q(B)) | |
348 ("(1a(B" (?(1a(B 0)) | |
349 ("(1bP(B" (?(1b(B 0 ?(1P(B) (0 ?(1[(B) (?(1-(B ?(1b(B 0 ?(1Q(B) (?(1G(B ?(1b(B 0 ?(1Q(B)) | |
350 ("(1b(B" (?(1b(B 0)) | |
351 ("(1`RP(B" (?(1`(B 0 ?(1R(B ?(1P(B) (0 ?(1Q(B ?(1M(B)) | |
352 ("(1m(B" (0 ?(1m(B) (0 ?(1M(B)) | |
353 ("(1`T(B" (?(1`(B 0 ?(1T(B)) | |
354 ("(1`U(B" (?(1`(B 0 ?(1U(B)) | |
355 ("(1[GP(B" (0 ?(1[(B ?(1G(B ?(1P(B) (0 ?(1Q(B ?(1G(B)) | |
356 ("(1[G(B" (0 ?(1[(B ?(1G(B) (0 ?(1G(B)) | |
357 ("(1`Q]P(B" (?(1`(B 0 ?(1Q(B ?(1](B ?(1P(B) (0 ?(1Q(B ?(1](B)) | |
358 ("(1`Q](B" (?(1`(B 0 ?(1Q(B ?(1](B) (0 ?(1](B)) | |
359 ("(1`VM(B" (?(1`(B 0 ?(1V(B ?(1M(B)) | |
360 ("(1`WM(B" (?(1`(B 0 ?(1W(B ?(1M(B)) | |
361 ("(1d(B" (?(1d(B 0)) | |
362 ("(1c(B" (?(1c(B 0)) | |
363 ("(1`[R(B" (?(1`(B 0 ?(1[(B ?(1R(B)) | |
88761 | 364 ("(1S(B" (0 ?(1S(B))) |
26894 | 365 "Alist of Lao vowel string vs the corresponding re-ordering rule. |
366 Each element has this form: | |
367 (VOWEL NO-MAA-SAKOD-RULE WITH-MAA-SAKOD-RULE (MAA-SAKOD-0 RULE-0) ...) | |
368 | |
369 VOWEL is a vowel string (e.g. \"(1`Q]P(B\"). | |
370 | |
371 NO-MAA-SAKOD-RULE is a rule to re-order and modify VOWEL following a | |
372 consonant. It is a list vowel characters or 0. The element 0 | |
373 indicate the place to embed a consonant. | |
374 | |
375 Optional WITH-MAA-SAKOD-RULE is a rule to re-order and modify VOWEL | |
376 follwoing a consonant and preceding a maa-sakod character. If it is | |
377 nil, NO-MAA-SAKOD-RULE is used. The maa-sakod character is alwasy | |
378 appended at the tail. | |
379 | |
380 For instance, rule `(\"(1`WM(B\" (?(1`(B t ?(1W(B ?(1M(B))' tells that this vowel | |
381 string following a consonant `(1!(B' should be re-ordered as \"(1`!WM(B\". | |
382 | |
383 Optional (MAA-SAKOD-n RULE-n) are rules specially applied to maa-sakod | |
384 character MAA-SAKOD-n.") | |
385 | |
386 ;;;###autoload | |
387 (defun lao-transcribe-single-roman-syllable-to-lao (from to &optional str) | |
388 "Transcribe a Romanized Lao syllable in the region FROM and TO to Lao string. | |
389 Only the first syllable is transcribed. | |
390 The value has the form: (START END LAO-STRING), where | |
391 START and END are the beggining and end positions of the Roman Lao syllable, | |
392 LAO-STRING is the Lao character transcription of it. | |
393 | |
394 Optional 3rd arg STR, if non-nil, is a string to search for Roman Lao | |
395 syllable. In that case, FROM and TO are indexes to STR." | |
396 (if str | |
397 (if (setq from (string-match lao-transcription-pattern str from)) | |
398 (progn | |
399 (if (>= from to) | |
400 (setq from nil) | |
401 (setq to (match-end 0))))) | |
402 (save-excursion | |
403 (goto-char from) | |
404 (if (setq to (re-search-forward lao-transcription-pattern to t)) | |
405 (setq from (match-beginning 0)) | |
406 (setq from nil)))) | |
407 (if from | |
408 (let* ((consonant (match-string 1 str)) | |
409 (semivowel (match-string 3 str)) | |
410 (vowel (match-string 5 str)) | |
411 (maa-sakod (match-string 8 str)) | |
412 (tone (match-string 9 str)) | |
413 lao-consonant lao-semivowel lao-vowel lao-maa-sakod lao-tone | |
414 clen cidx) | |
415 (setq to (match-end 0)) | |
416 (if (not consonant) | |
417 (setq str (cdr (assoc (match-string 0 str) | |
418 lao-transcription-punctuation-alist))) | |
419 (setq lao-consonant | |
420 (cdr (assoc consonant lao-transcription-consonant-alist))) | |
421 (if (vectorp lao-consonant) | |
422 (setq lao-consonant (aref lao-consonant 0))) | |
423 (setq clen (length lao-consonant)) | |
424 (if semivowel | |
425 ;; Include semivowel in STR. | |
426 (setq lao-semivowel | |
427 (cdr (assoc semivowel lao-transcription-semi-vowel-alist)) | |
428 str (if (= clen 1) | |
429 (concat lao-consonant lao-semivowel) | |
430 (concat (substring lao-consonant 0 1) lao-semivowel | |
431 (substring lao-consonant 1)))) | |
432 (setq str lao-consonant)) | |
433 (if vowel | |
434 (let (rule) | |
435 (setq lao-vowel | |
436 (cdr (assoc vowel lao-transcription-vowel-alist))) | |
437 (if (vectorp lao-vowel) | |
438 (setq lao-vowel (aref lao-vowel 0))) | |
439 (setq rule (assoc lao-vowel lao-vowel-reordering-rule)) | |
440 (if (null maa-sakod) | |
441 (setq rule (nth 1 rule)) | |
442 (setq lao-maa-sakod | |
443 (cdr (assoc maa-sakod lao-transcription-maa-sakod-alist)) | |
444 rule | |
445 (or (cdr (assq (aref lao-maa-sakod 0) (nthcdr 2 rule))) | |
446 (nth 2 rule) | |
447 (nth 1 rule)))) | |
448 (or rule | |
449 (error "Lao vowel %S has no re-ordering rule" lao-vowel)) | |
450 (setq lao-consonant str str "") | |
451 (while rule | |
452 (if (= (car rule) 0) | |
453 (setq str (concat str lao-consonant) | |
454 cidx (length str)) | |
455 (setq str (concat str (list (car rule))))) | |
456 (setq rule (cdr rule))) | |
457 (or cidx | |
458 (error "Lao vowel %S has malformed re-ordering rule" vowel)) | |
459 ;; Set CIDX to after upper or lower vowel if any. | |
460 (let ((len (length str))) | |
461 (while (and (< cidx len) | |
462 (memq (get-char-code-property (aref str cidx) | |
463 'phonetic-type) | |
464 '(vowel-lower vowel-upper))) | |
465 (setq cidx (1+ cidx)))) | |
466 (if lao-maa-sakod | |
467 (setq str (concat str lao-maa-sakod))) | |
468 (if tone | |
469 (setq lao-tone | |
470 (cdr (assoc tone lao-transcription-tone-alist)) | |
471 str (concat (substring str 0 cidx) lao-tone | |
472 (substring str cidx))))))) | |
473 (list from to (lao-compose-string str))))) | |
474 | |
475 ;;;###autoload | |
476 (defun lao-transcribe-roman-to-lao-string (str) | |
477 "Transcribe Romanized Lao string STR to Lao character string." | |
478 (let ((from 0) | |
479 (to (length str)) | |
480 (lao-str "") | |
481 val) | |
482 (while (setq val (lao-transcribe-single-roman-syllable-to-lao from to str)) | |
483 (let ((start (car val)) | |
484 (end (nth 1 val)) | |
485 (lao (nth 2 val))) | |
486 (if (> start from) | |
487 (setq lao-str (concat lao-str (substring str from start) lao)) | |
488 (setq lao-str (concat lao-str lao))) | |
489 (setq from end))) | |
490 (if (< from to) | |
491 (concat lao-str (substring str from to)) | |
492 lao-str))) | |
493 | |
494 ;;;###autoload | |
89300
6a0cc62928b5
(lao-post-read-conversion): Delete this
Kenichi Handa <handa@m17n.org>
parents:
88761
diff
changeset
|
495 (defun lao-composition-function (pos &optional string) |
6a0cc62928b5
(lao-post-read-conversion): Delete this
Kenichi Handa <handa@m17n.org>
parents:
88761
diff
changeset
|
496 (setq pos (1- pos)) |
6a0cc62928b5
(lao-post-read-conversion): Delete this
Kenichi Handa <handa@m17n.org>
parents:
88761
diff
changeset
|
497 (with-category-table lao-category-table |
6a0cc62928b5
(lao-post-read-conversion): Delete this
Kenichi Handa <handa@m17n.org>
parents:
88761
diff
changeset
|
498 (if string |
6a0cc62928b5
(lao-post-read-conversion): Delete this
Kenichi Handa <handa@m17n.org>
parents:
88761
diff
changeset
|
499 (if (and (>= pos 0) |
6a0cc62928b5
(lao-post-read-conversion): Delete this
Kenichi Handa <handa@m17n.org>
parents:
88761
diff
changeset
|
500 (eq (string-match lao-composition-pattern string pos) pos)) |
6a0cc62928b5
(lao-post-read-conversion): Delete this
Kenichi Handa <handa@m17n.org>
parents:
88761
diff
changeset
|
501 (prog1 (match-end 0) |
6a0cc62928b5
(lao-post-read-conversion): Delete this
Kenichi Handa <handa@m17n.org>
parents:
88761
diff
changeset
|
502 (compose-string string pos (match-end 0)))) |
6a0cc62928b5
(lao-post-read-conversion): Delete this
Kenichi Handa <handa@m17n.org>
parents:
88761
diff
changeset
|
503 (if (>= pos (point-min)) |
6a0cc62928b5
(lao-post-read-conversion): Delete this
Kenichi Handa <handa@m17n.org>
parents:
88761
diff
changeset
|
504 (save-excursion |
6a0cc62928b5
(lao-post-read-conversion): Delete this
Kenichi Handa <handa@m17n.org>
parents:
88761
diff
changeset
|
505 (goto-char pos) |
6a0cc62928b5
(lao-post-read-conversion): Delete this
Kenichi Handa <handa@m17n.org>
parents:
88761
diff
changeset
|
506 (if (looking-at lao-composition-pattern) |
6a0cc62928b5
(lao-post-read-conversion): Delete this
Kenichi Handa <handa@m17n.org>
parents:
88761
diff
changeset
|
507 (prog1 (match-end 0) |
6a0cc62928b5
(lao-post-read-conversion): Delete this
Kenichi Handa <handa@m17n.org>
parents:
88761
diff
changeset
|
508 (compose-region pos (match-end 0))))))))) |
17083 | 509 |
28791
bdf7581eb093
(lao-compose-region): New function.
Kenichi Handa <handa@m17n.org>
parents:
26894
diff
changeset
|
510 ;;;###autoload |
bdf7581eb093
(lao-compose-region): New function.
Kenichi Handa <handa@m17n.org>
parents:
26894
diff
changeset
|
511 (defun lao-compose-region (from to) |
bdf7581eb093
(lao-compose-region): New function.
Kenichi Handa <handa@m17n.org>
parents:
26894
diff
changeset
|
512 (interactive "r") |
bdf7581eb093
(lao-compose-region): New function.
Kenichi Handa <handa@m17n.org>
parents:
26894
diff
changeset
|
513 (save-restriction |
bdf7581eb093
(lao-compose-region): New function.
Kenichi Handa <handa@m17n.org>
parents:
26894
diff
changeset
|
514 (narrow-to-region from to) |
bdf7581eb093
(lao-compose-region): New function.
Kenichi Handa <handa@m17n.org>
parents:
26894
diff
changeset
|
515 (goto-char (point-min)) |
bdf7581eb093
(lao-compose-region): New function.
Kenichi Handa <handa@m17n.org>
parents:
26894
diff
changeset
|
516 (with-category-table lao-category-table |
bdf7581eb093
(lao-compose-region): New function.
Kenichi Handa <handa@m17n.org>
parents:
26894
diff
changeset
|
517 (while (re-search-forward lao-composition-pattern nil t) |
bdf7581eb093
(lao-compose-region): New function.
Kenichi Handa <handa@m17n.org>
parents:
26894
diff
changeset
|
518 (compose-region (match-beginning 0) (point)))))) |
bdf7581eb093
(lao-compose-region): New function.
Kenichi Handa <handa@m17n.org>
parents:
26894
diff
changeset
|
519 |
17083 | 520 ;; |
18309
bd8b521f5218
Provide XXX-util instead of
Kenichi Handa <handa@m17n.org>
parents:
18203
diff
changeset
|
521 (provide 'lao-util) |
17083 | 522 |
52401 | 523 ;;; arch-tag: 1f828781-3cb8-4695-88af-8f33222338ce |
17083 | 524 ;;; lao-util.el ends here |