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