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