Add arch taglines
[bpt/emacs.git] / lisp / language / lao-util.el
CommitLineData
64fd2bb1 1;;; lao-util.el --- utilities for Lao -*- coding: iso-2022-7bit; -*-
d92d0128 2
d92d0128 3;; Copyright (C) 1997 Electrotechnical Laboratory, JAPAN.
fa526c4a 4;; Licensed to the Free Software Foundation.
a549727e 5;; Copyright (C) 2001 Free Software Foundation, Inc.
d92d0128
KH
6
7;; Keywords: multilingual, Lao
8
9;; This file is part of GNU Emacs.
10
11;; GNU Emacs is free software; you can redistribute it and/or modify
12;; it under the terms of the GNU General Public License as published by
13;; the Free Software Foundation; either version 2, or (at your option)
14;; any later version.
15
16;; GNU Emacs is distributed in the hope that it will be useful,
17;; but WITHOUT ANY WARRANTY; without even the implied warranty of
18;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19;; GNU General Public License for more details.
20
21;; You should have received a copy of the GNU General Public License
22;; along with GNU Emacs; see the file COPYING. If not, write to the
23;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
24;; Boston, MA 02111-1307, USA.
25
60370d40
PJ
26;;; Commentary:
27
d92d0128
KH
28;;; Code:
29
31ce7719
KH
30;; Setting information of Thai characters.
31
32(defconst lao-category-table (make-category-table))
33(define-category ?c "Lao consonant" lao-category-table)
34(define-category ?s "Lao semi-vowel" lao-category-table)
35(define-category ?v "Lao upper/lower vowel" lao-category-table)
36(define-category ?t "Lao tone" lao-category-table)
37
d92d0128
KH
38(let ((l '((?\e(1!\e(B consonant "LETTER KOR KAI'" "CHICKEN")
39 (?\e(1"\e(B consonant "LETTER KHOR KHAI'" "EGG")
40 (?\e(1#\e(B invalid nil)
41 (?\e(1$\e(B consonant "LETTER QHOR QHWARGN" "BUFFALO")
42 (?\e(1%\e(B invalid nil)
43 (? invalid nil)
44 (?\e(1'\e(B consonant "LETTER NGOR NGUU" "SNAKE")
45 (?\e(1(\e(B consonant "LETTER JOR JUA" "BUDDHIST NOVICE")
46 (?\e(1)\e(B invalid nil)
47 (?\e(1*\e(B consonant "LETTER XOR X\"ARNG" "ELEPHANT")
48 (?\e(1+\e(B invalid nil)
49 (?\e(1,\e(B invalid nil)
50 (?\e(1-\e(B consonant "LETTER YOR YUNG" "MOSQUITO")
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(1.\e(B invalid nil)
57 (?\e(14\e(B consonant "LETTER DOR DANG" "NOSE")
58 (?\e(15\e(B consonant "LETTER TOR TAR" "EYE")
3518ac16
KH
59 (?\e(16\e(B consonant "LETTER THOR THUNG" "TO ASK,QUESTION")
60 (?\e(17\e(B consonant "LETTER DHOR DHARM" "FLAG")
d92d0128
KH
61 (?\e(18\e(B invalid nil)
62 (?\e(19\e(B consonant "LETTER NOR NOK" "BIRD")
63 (?\e(1:\e(B consonant "LETTER BOR BED" "FISHHOOK")
64 (?\e(1;\e(B consonant "LETTER POR PAR" "FISH")
65 (?\e(1<\e(B consonant "LETTER HPOR HPER\"" "BEE")
66 (?\e(1=\e(B consonant "LETTER FHOR FHAR" "WALL")
67 (?\e(1>\e(B consonant "LETTER PHOR PHUU" "MOUNTAIN")
68 (?\e(1?\e(B consonant "LETTER FOR FAI" "FIRE")
69 (?\e(1@\e(B invalid nil)
70 (?\e(1A\e(B consonant "LETTER MOR MAR\"" "HORSE")
71 (?\e(1B\e(B consonant "LETTER GNOR GNAR" "MEDICINE")
72 (?\e(1C\e(B consonant "LETTER ROR ROD" "CAR")
73 (?\e(1D\e(B invalid nil)
74 (?\e(1E\e(B consonant "LETTER LOR LIING" "MONKEY")
75 (?\e(1F\e(B invalid nil)
76 (?\e(1G\e(B consonant "LETTER WOR WII" "HAND FAN")
77 (?\e(1H\e(B invalid nil)
78 (?\e(1I\e(B invalid nil)
79 (?\e(1J\e(B consonant "LETTER SOR SEA" "TIGER")
80 (?\e(1K\e(B consonant "LETTER HHOR HHAI" "JAR")
81 (?\e(1L\e(B invalid nil)
82 (?\e(1M\e(B consonant "LETTER OR OOW" "TAKE")
83 (?\e(1N\e(B consonant "LETTER HOR HEA" "BOAT")
84 (?\e(1O\e(B special "ELLIPSIS")
85 (?\e(1P\e(B vowel-base "VOWEL SIGN SARA A")
86 (?\e(1Q\e(B vowel-upper "VOWEL SIGN MAI KAN")
87 (?\e(1R\e(B vowel-base "VOWEL SIGN SARA AR")
88 (?\e(1S\e(B vowel-base "VOWEL SIGN SARA AM")
a1506d29 89 (?\e(1T\e(B vowel-upper "VOWEL SIGN SARA I")
d92d0128
KH
90 (?\e(1U\e(B vowel-upper "VOWEL SIGN SARA II")
91 (?\e(1V\e(B vowel-upper "VOWEL SIGN SARA EU")
92 (?\e(1W\e(B vowel-upper "VOWEL SIGN SARA UR")
93 (?\e(1X\e(B vowel-lower "VOWEL SIGN SARA U")
94 (?\e(1Y\e(B vowel-lower "VOWEL SIGN SARA UU")
95 (?\e(1Z\e(B invalid nil)
96 (?\e(1[\e(B vowel-upper "VOWEL SIGN MAI KONG")
97 (?\e(1\\e(B semivowel-lower "SEMIVOWEL SIGN LO")
98 (?\e(1]\e(B vowel-base "SEMIVOWEL SIGN SARA IA")
99 (?\e(1^\e(B invalid nil)
100 (?\e(1_\e(B invalid nil)
101 (?\e(1`\e(B vowel-base "VOWEL SIGN SARA EE")
102 (?\e(1a\e(B vowel-base "VOWEL SIGN SARA AA")
103 (?\e(1b\e(B vowel-base "VOWEL SIGN SARA OO")
104 (?\e(1c\e(B vowel-base "VOWEL SIGN SARA EI MAI MUAN\"")
105 (?\e(1d\e(B vowel-base "VOWEL SIGN SARA AI MAI MAY")
106 (?\e(1e\e(B invalid nil)
a1506d29 107 (?\e(1f\e(B special "KO LA (REPETITION)")
d92d0128
KH
108 (?\e(1g\e(B invalid nil)
109 (?\e(1h\e(B tone "TONE MAI EK")
110 (?\e(1i\e(B tone "TONE MAI THO")
111 (?\e(1j\e(B tone "TONE MAI TI")
112 (?\e(1k\e(B tone "TONE MAI JADTAWAR")
113 (?\e(1l\e(B tone "CANCELLATION MARK")
114 (?\e(1m\e(B vowel-upper "VOWEL SIGN SARA OR")
115 (?\e(1n\e(B invalid nil)
116 (?\e(1o\e(B invalid nil)
117 (?\e(1p\e(B special "DIGIT ZERO")
118 (?\e(1q\e(B special "DIGIT ONE")
119 (?\e(1r\e(B special "DIGIT TWO")
120 (?\e(1s\e(B special "DIGIT THREE")
121 (?\e(1t\e(B special "DIGIT FOUR")
122 (?\e(1u\e(B special "DIGIT FIVE")
123 (?\e(1v\e(B special "DIGIT SIX")
124 (?\e(1w\e(B special "DIGIT SEVEN")
125 (?\e(1x\e(B special "DIGIT EIGHT")
126 (?\e(1y\e(B special "DIGIT NINE")
127 (?\e(1z\e(B invalid nil)
128 (?\e(1{\e(B invalid nil)
129 (?\e(1|\e(B consonant "LETTER NHOR NHUU" "MOUSE")
130 (?\e(1}\e(B consonant "LETTER MHOR MHAR" "DOG")
131 (?\e(1~\e(B invalid nil)
a549727e
DL
132 ;; Unicode equivalents
133 (?\e$,1D!\e(B consonant "LETTER KOR KAI'" "CHICKEN")
134 (?\e$,1D"\e(B consonant "LETTER KHOR KHAI'" "EGG")
135 (?\e$,1D$\e(B consonant "LETTER QHOR QHWARGN" "BUFFALO")
136 (?\e$,1D'\e(B consonant "LETTER NGOR NGUU" "SNAKE")
137 (?\e$,1D(\e(B consonant "LETTER JOR JUA" "BUDDHIST NOVICE")
138 (?\e$,1D*\e(B consonant "LETTER XOR X\"ARNG" "ELEPHANT")
139 (?\e$,1D-\e(B consonant "LETTER YOR YUNG" "MOSQUITO")
140 (?\e$,1D4\e(B consonant "LETTER DOR DANG" "NOSE")
141 (?\e$,1D5\e(B consonant "LETTER TOR TAR" "EYE")
142 (?\e$,1D6\e(B consonant "LETTER THOR THUNG" "TO ASK,QUESTION")
143 (?\e$,1D7\e(B consonant "LETTER DHOR DHARM" "FLAG")
144 (?\e$,1D9\e(B consonant "LETTER NOR NOK" "BIRD")
145 (?\e$,1D:\e(B consonant "LETTER BOR BED" "FISHHOOK")
146 (?\e$,1D;\e(B consonant "LETTER POR PAR" "FISH")
147 (?\e$,1D<\e(B consonant "LETTER HPOR HPER\"" "BEE")
148 (?\e$,1D=\e(B consonant "LETTER FHOR FHAR" "WALL")
149 (?\e$,1D>\e(B consonant "LETTER PHOR PHUU" "MOUNTAIN")
150 (?\e$,1D?\e(B consonant "LETTER FOR FAI" "FIRE")
151 (?\e$,1DA\e(B consonant "LETTER MOR MAR\"" "HORSE")
152 (?\e$,1DB\e(B consonant "LETTER GNOR GNAR" "MEDICINE")
153 (?\e$,1DC\e(B consonant "LETTER ROR ROD" "CAR")
154 (?\e$,1DE\e(B consonant "LETTER LOR LIING" "MONKEY")
155 (?\e$,1DG\e(B consonant "LETTER WOR WII" "HAND FAN")
156 (?\e$,1DJ\e(B consonant "LETTER SOR SEA" "TIGER")
157 (?\e$,1DK\e(B consonant "LETTER HHOR HHAI" "JAR")
158 (?\e$,1DM\e(B consonant "LETTER OR OOW" "TAKE")
159 (?\e$,1DN\e(B consonant "LETTER HOR HEA" "BOAT")
160 (?\e$,1DO\e(B special "ELLIPSIS")
161 (?\e$,1DP\e(B vowel-base "VOWEL SIGN SARA A")
162 (?\e$,1DQ\e(B vowel-upper "VOWEL SIGN MAI KAN")
163 (?\e$,1DR\e(B vowel-base "VOWEL SIGN SARA AR")
164 (?\e$,1DS\e(B vowel-base "VOWEL SIGN SARA AM")
a1506d29 165 (?\e$,1DT\e(B vowel-upper "VOWEL SIGN SARA I")
a549727e
DL
166 (?\e$,1DU\e(B vowel-upper "VOWEL SIGN SARA II")
167 (?\e$,1DV\e(B vowel-upper "VOWEL SIGN SARA EU")
168 (?\e$,1DW\e(B vowel-upper "VOWEL SIGN SARA UR")
169 (?\e$,1DX\e(B vowel-lower "VOWEL SIGN SARA U")
170 (?\e$,1DY\e(B vowel-lower "VOWEL SIGN SARA UU")
171 (?\e$,1D[\e(B vowel-upper "VOWEL SIGN MAI KONG")
172 (?\e$,1D\\e(B semivowel-lower "SEMIVOWEL SIGN LO")
173 (?\e$,1D]\e(B vowel-base "SEMIVOWEL SIGN SARA IA")
174 (?\e$,1D`\e(B vowel-base "VOWEL SIGN SARA EE")
175 (?\e$,1Da\e(B vowel-base "VOWEL SIGN SARA AA")
176 (?\e$,1Db\e(B vowel-base "VOWEL SIGN SARA OO")
177 (?\e$,1Dc\e(B vowel-base "VOWEL SIGN SARA EI MAI MUAN\"")
178 (?\e$,1Dd\e(B vowel-base "VOWEL SIGN SARA AI MAI MAY")
179 (?\e$,1Df\e(B special "KO LA (REPETITION)")
180 (?\e$,1Dh\e(B tone "TONE MAI EK")
181 (?\e$,1Di\e(B tone "TONE MAI THO")
182 (?\e$,1Dj\e(B tone "TONE MAI TI")
183 (?\e$,1Dk\e(B tone "TONE MAI JADTAWAR")
184 (?\e$,1Dl\e(B tone "CANCELLATION MARK")
185 (?\e$,1Dm\e(B vowel-upper "VOWEL SIGN SARA OR")
186 (?\e$,1Dp\e(B special "DIGIT ZERO")
187 (?\e$,1Dq\e(B special "DIGIT ONE")
188 (?\e$,1Dr\e(B special "DIGIT TWO")
189 (?\e$,1Ds\e(B special "DIGIT THREE")
190 (?\e$,1Dt\e(B special "DIGIT FOUR")
191 (?\e$,1Du\e(B special "DIGIT FIVE")
192 (?\e$,1Dv\e(B special "DIGIT SIX")
193 (?\e$,1Dw\e(B special "DIGIT SEVEN")
194 (?\e$,1Dx\e(B special "DIGIT EIGHT")
195 (?\e$,1Dy\e(B special "DIGIT NINE")
196 (?\e$,1D|\e(B consonant "LETTER NHOR NHUU" "MOUSE")
197 (?\e$,1D}\e(B consonant "LETTER MHOR MHAR" "DOG")))
d92d0128
KH
198 elm)
199 (while l
31ce7719
KH
200 (setq elm (car l) l (cdr l))
201 (let ((char (car elm))
202 (ptype (nth 1 elm)))
203 (cond ((eq ptype 'consonant)
204 (modify-category-entry char ?c lao-category-table))
205 ((memq ptype '(vowel-upper vowel-lower))
206 (modify-category-entry char ?v lao-category-table))
207 ((eq ptype 'semivowel-lower)
208 (modify-category-entry char ?s lao-category-table))
209 ((eq ptype 'tone)
210 (modify-category-entry char ?t lao-category-table)))
211 (put-char-code-property char 'phonetic-type ptype)
212 (put-char-code-property char 'name (nth 2 elm))
213 (put-char-code-property char 'meaning (nth 3 elm)))))
214
215;; The general composing rules are as follows:
216;;
217;; T
218;; V T V T
219;; CV -> C, CT -> C, CVT -> C, Cv -> C, CvT -> C
220;; v v
221;; T
222;; V T V T
223;; CsV -> C, CsT -> C, CsVT -> C, Csv -> C, CvT -> C
224;; s s s s s
225;; v v
226
227
228;; where C: consonant, V: vowel upper, v: vowel lower,
229;; T: tone mark, s: semivowel lower
230
231(defvar lao-composition-pattern
232 "\\cc\\(\\ct\\|\\cv\\ct?\\|\\cs\\(\\ct\\|\\cv\\ct?\\)?\\)"
233 "Regular expression matching a Lao composite sequence.")
234
235;;;###autoload
236(defun lao-compose-string (str)
237 (with-category-table lao-category-table
238 (let ((idx 0))
239 (while (setq idx (string-match lao-composition-pattern str idx))
240 (compose-string str idx (match-end 0))
241 (setq idx (match-end 0))))
242 str))
243
244;;; LRT: Lao <-> Roman Transcription
245
246;; Upper vowels and tone-marks are put on the letter.
247;; Semi-vowel-sign-lo and lower vowels are put under the letter.
248
249(defconst lao-transcription-consonant-alist
250 (sort '(;; single consonants
251 ("k" . "\e(1!\e(B")
252 ("kh" . "\e(1"\e(B")
253 ("qh" . "\e(1$\e(B")
254 ("ng" . "\e(1'\e(B")
255 ("j" . "\e(1(\e(B")
256 ("s" . "\e(1J\e(B")
257 ("x" . "\e(1*\e(B")
258 ("y" . "\e(1-\e(B")
259 ("d" . "\e(14\e(B")
260 ("t" . "\e(15\e(B")
261 ("th" . "\e(16\e(B")
262 ("dh" . "\e(17\e(B")
263 ("n" . "\e(19\e(B")
264 ("b" . "\e(1:\e(B")
265 ("p" . "\e(1;\e(B")
266 ("hp" . "\e(1<\e(B")
267 ("fh" . "\e(1=\e(B")
268 ("ph" . "\e(1>\e(B")
269 ("f" . "\e(1?\e(B")
270 ("m" . "\e(1A\e(B")
271 ("gn" . "\e(1B\e(B")
272 ("l" . "\e(1E\e(B")
273 ("r" . "\e(1C\e(B")
274 ("v" . "\e(1G\e(B")
275 ("w" . "\e(1G\e(B")
276 ("hh" . "\e(1K\e(B")
277 ("O" . "\e(1M\e(B")
278 ("h" . "\e(1N\e(B")
279 ("nh" . "\e(1|\e(B")
280 ("mh" . "\e(1}\e(B")
281 ("lh" . ["\e(1K\\e(B"])
282 ;; double consonants
283 ("ngh" . ["\e(1K'\e(B"])
284 ("yh" . ["\e(1K]\e(B"])
285 ("wh" . ["\e(1KG\e(B"])
286 ("hl" . ["\e(1KE\e(B"])
287 ("hy" . ["\e(1K-\e(B"])
288 ("hn" . ["\e(1K9\e(B"])
289 ("hm" . ["\e(1KA\e(B"])
290 )
291 (function (lambda (x y) (> (length (car x)) (length (car y)))))))
292
293(defconst lao-transcription-semi-vowel-alist
294 '(("r" . "\e(1\\e(B")))
295
296(defconst lao-transcription-vowel-alist
297 (sort '(("a" . "\e(1P\e(B")
298 ("ar" . "\e(1R\e(B")
299 ("i" . "\e(1T\e(B")
300 ("ii" . "\e(1U\e(B")
301 ("eu" . "\e(1V\e(B")
302 ("ur" . "\e(1W\e(B")
303 ("u" . "\e(1X\e(B")
304 ("uu" . "\e(1Y\e(B")
305 ("e" . ["\e(1`P\e(B"])
306 ("ee" . "\e(1`\e(B")
307 ("ae" . ["\e(1aP\e(B"])
308 ("aa" . "\e(1a\e(B")
309 ("o" . ["\e(1bP\e(B"])
310 ("oo" . "\e(1b\e(B")
311 ("oe" . ["\e(1`RP\e(B"])
312 ("or" . "\e(1m\e(B")
313 ("er" . ["\e(1`T\e(B"])
314 ("ir" . ["\e(1`U\e(B"])
315 ("ua" . ["\e(1[GP\e(B"])
316 ("uaa" . ["\e(1[G\e(B"])
317 ("ie" . ["\e(1`Q]P\e(B"])
318 ("ia" . ["\e(1`Q]\e(B"])
319 ("ea" . ["\e(1`VM\e(B"])
320 ("eaa" . ["\e(1`WM\e(B"])
321 ("ai" . "\e(1d\e(B")
322 ("ei" . "\e(1c\e(B")
323 ("ao" . ["\e(1`[R\e(B"])
324 ("aM" . "\e(1S\e(B"))
325 (function (lambda (x y) (> (length (car x)) (length (car y)))))))
326
327;; Maa-sakod is put at the tail.
328(defconst lao-transcription-maa-sakod-alist
329 '(("k" . "\e(1!\e(B")
330 ("g" . "\e(1'\e(B")
331 ("y" . "\e(1-\e(B")
332 ("d" . "\e(14\e(B")
333 ("n" . "\e(19\e(B")
334 ("b" . "\e(1:\e(B")
335 ("m" . "\e(1A\e(B")
336 ("v" . "\e(1G\e(B")
337 ("w" . "\e(1G\e(B")
338 ))
339
340(defconst lao-transcription-tone-alist
341 '(("'" . "\e(1h\e(B")
342 ("\"" . "\e(1i\e(B")
343 ("^" . "\e(1j\e(B")
344 ("+" . "\e(1k\e(B")
345 ("~" . "\e(1l\e(B")))
346
347(defconst lao-transcription-punctuation-alist
348 '(("\\0" . "\e(1p\e(B")
349 ("\\1" . "\e(1q\e(B")
350 ("\\2" . "\e(1r\e(B")
351 ("\\3" . "\e(1s\e(B")
352 ("\\4" . "\e(1t\e(B")
353 ("\\5" . "\e(1u\e(B")
354 ("\\6" . "\e(1v\e(B")
355 ("\\7" . "\e(1w\e(B")
356 ("\\8" . "\e(1x\e(B")
357 ("\\9" . "\e(1y\e(B")
358 ("\\\\" . "\e(1f\e(B")
359 ("\\$" . "\e(1O\e(B")))
360
361(defconst lao-transcription-pattern
362 (concat
363 "\\("
364 (mapconcat 'car lao-transcription-consonant-alist "\\|")
365 "\\)\\("
366 (mapconcat 'car lao-transcription-semi-vowel-alist "\\|")
367 "\\)?\\(\\("
368 (mapconcat 'car lao-transcription-vowel-alist "\\|")
369 "\\)\\("
370 (mapconcat 'car lao-transcription-maa-sakod-alist "\\|")
371 "\\)?\\("
372 (mapconcat (lambda (x) (regexp-quote (car x)))
373 lao-transcription-tone-alist "\\|")
374 "\\)?\\)?\\|"
375 (mapconcat (lambda (x) (regexp-quote (car x)))
376 lao-transcription-punctuation-alist "\\|")
377 )
378 "Regexp of Roman transcription pattern for one Lao syllable.")
379
380(defconst lao-transcription-pattern
381 (concat
382 "\\("
383 (regexp-opt (mapcar 'car lao-transcription-consonant-alist))
384 "\\)\\("
385 (regexp-opt (mapcar 'car lao-transcription-semi-vowel-alist))
386 "\\)?\\(\\("
387 (regexp-opt (mapcar 'car lao-transcription-vowel-alist))
388 "\\)\\("
389 (regexp-opt (mapcar 'car lao-transcription-maa-sakod-alist))
390 "\\)?\\("
391 (regexp-opt (mapcar 'car lao-transcription-tone-alist))
392 "\\)?\\)?\\|"
393 (regexp-opt (mapcar 'car lao-transcription-punctuation-alist))
394 )
395 "Regexp of Roman transcription pattern for one Lao syllable.")
396
397(defconst lao-vowel-reordering-rule
398 '(("\e(1P\e(B" (0 ?\e(1P\e(B) (0 ?\e(1Q\e(B))
399 ("\e(1R\e(B" (0 ?\e(1R\e(B))
400 ("\e(1T\e(B" (0 ?\e(1U\e(B))
401 ("\e(1U\e(B" (0 ?\e(1U\e(B))
402 ("\e(1V\e(B" (0 ?\e(1V\e(B))
403 ("\e(1W\e(B" (0 ?\e(1W\e(B))
404 ("\e(1X\e(B" (0 ?\e(1X\e(B))
405 ("\e(1Y\e(B" (0 ?\e(1Y\e(B))
406 ("\e(1`P\e(B" (?\e(1`\e(B 0 ?\e(1P\e(B) (?\e(1`\e(B 0 ?\e(1Q\e(B))
407 ("\e(1`\e(B" (?\e(1`\e(B 0))
408 ("\e(1aP\e(B" (?\e(1a\e(B 0 ?\e(1P\e(B) (?\e(1a\e(B 0 ?\e(1Q\e(B))
409 ("\e(1a\e(B" (?\e(1a\e(B 0))
410 ("\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))
411 ("\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\e(B" (?\e$,1D`\e(B 0 ?\e$,1DQ\e(B ?\e$,1D]\e(B) (0 ?\e$,1D]\e(B))
450 ("\e$,1D`DVDM\e(B" (?\e$,1D`\e(B 0 ?\e$,1DV\e(B ?\e$,1DM\e(B))
451 ("\e$,1D`DWDM\e(B" (?\e$,1D`\e(B 0 ?\e$,1DW\e(B ?\e$,1DM\e(B))
452 ("\e$,1Dd\e(B" (?\e$,1Dd\e(B 0))
453 ("\e$,1Dc\e(B" (?\e$,1Dc\e(B 0))
454 ("\e$,1D`D[DR\e(B" (?\e$,1D`\e(B 0 ?\e$,1D[\e(B ?\e$,1DR\e(B))
455 ("\e$,1DS\e(B" (0 ?\e$,1DS\e(B)))
31ce7719
KH
456 "Alist of Lao vowel string vs the corresponding re-ordering rule.
457Each element has this form:
458 (VOWEL NO-MAA-SAKOD-RULE WITH-MAA-SAKOD-RULE (MAA-SAKOD-0 RULE-0) ...)
459
460VOWEL is a vowel string (e.g. \"\e(1`Q]P\e(B\").
461
462NO-MAA-SAKOD-RULE is a rule to re-order and modify VOWEL following a
463consonant. It is a list vowel characters or 0. The element 0
464indicate the place to embed a consonant.
465
466Optional WITH-MAA-SAKOD-RULE is a rule to re-order and modify VOWEL
467follwoing a consonant and preceding a maa-sakod character. If it is
468nil, NO-MAA-SAKOD-RULE is used. The maa-sakod character is alwasy
469appended at the tail.
470
471For instance, rule `(\"\e(1`WM\e(B\" (?\e(1`\e(B t ?\e(1W\e(B ?\e(1M\e(B))' tells that this vowel
472string following a consonant `\e(1!\e(B' should be re-ordered as \"\e(1`!WM\e(B\".
473
474Optional (MAA-SAKOD-n RULE-n) are rules specially applied to maa-sakod
475character MAA-SAKOD-n.")
476
477;;;###autoload
478(defun lao-transcribe-single-roman-syllable-to-lao (from to &optional str)
479 "Transcribe a Romanized Lao syllable in the region FROM and TO to Lao string.
480Only the first syllable is transcribed.
481The value has the form: (START END LAO-STRING), where
482START and END are the beggining and end positions of the Roman Lao syllable,
483LAO-STRING is the Lao character transcription of it.
484
485Optional 3rd arg STR, if non-nil, is a string to search for Roman Lao
486syllable. In that case, FROM and TO are indexes to STR."
487 (if str
488 (if (setq from (string-match lao-transcription-pattern str from))
489 (progn
490 (if (>= from to)
491 (setq from nil)
492 (setq to (match-end 0)))))
493 (save-excursion
494 (goto-char from)
495 (if (setq to (re-search-forward lao-transcription-pattern to t))
496 (setq from (match-beginning 0))
497 (setq from nil))))
498 (if from
499 (let* ((consonant (match-string 1 str))
500 (semivowel (match-string 3 str))
501 (vowel (match-string 5 str))
502 (maa-sakod (match-string 8 str))
503 (tone (match-string 9 str))
504 lao-consonant lao-semivowel lao-vowel lao-maa-sakod lao-tone
505 clen cidx)
506 (setq to (match-end 0))
507 (if (not consonant)
508 (setq str (cdr (assoc (match-string 0 str)
509 lao-transcription-punctuation-alist)))
510 (setq lao-consonant
511 (cdr (assoc consonant lao-transcription-consonant-alist)))
512 (if (vectorp lao-consonant)
513 (setq lao-consonant (aref lao-consonant 0)))
514 (setq clen (length lao-consonant))
515 (if semivowel
516 ;; Include semivowel in STR.
517 (setq lao-semivowel
518 (cdr (assoc semivowel lao-transcription-semi-vowel-alist))
519 str (if (= clen 1)
520 (concat lao-consonant lao-semivowel)
521 (concat (substring lao-consonant 0 1) lao-semivowel
522 (substring lao-consonant 1))))
523 (setq str lao-consonant))
524 (if vowel
525 (let (rule)
526 (setq lao-vowel
527 (cdr (assoc vowel lao-transcription-vowel-alist)))
528 (if (vectorp lao-vowel)
529 (setq lao-vowel (aref lao-vowel 0)))
530 (setq rule (assoc lao-vowel lao-vowel-reordering-rule))
531 (if (null maa-sakod)
532 (setq rule (nth 1 rule))
533 (setq lao-maa-sakod
534 (cdr (assoc maa-sakod lao-transcription-maa-sakod-alist))
535 rule
536 (or (cdr (assq (aref lao-maa-sakod 0) (nthcdr 2 rule)))
537 (nth 2 rule)
538 (nth 1 rule))))
539 (or rule
540 (error "Lao vowel %S has no re-ordering rule" lao-vowel))
541 (setq lao-consonant str str "")
542 (while rule
543 (if (= (car rule) 0)
544 (setq str (concat str lao-consonant)
545 cidx (length str))
546 (setq str (concat str (list (car rule)))))
547 (setq rule (cdr rule)))
548 (or cidx
549 (error "Lao vowel %S has malformed re-ordering rule" vowel))
550 ;; Set CIDX to after upper or lower vowel if any.
551 (let ((len (length str)))
552 (while (and (< cidx len)
553 (memq (get-char-code-property (aref str cidx)
554 'phonetic-type)
555 '(vowel-lower vowel-upper)))
556 (setq cidx (1+ cidx))))
557 (if lao-maa-sakod
558 (setq str (concat str lao-maa-sakod)))
559 (if tone
560 (setq lao-tone
561 (cdr (assoc tone lao-transcription-tone-alist))
562 str (concat (substring str 0 cidx) lao-tone
563 (substring str cidx)))))))
564 (list from to (lao-compose-string str)))))
565
566;;;###autoload
567(defun lao-transcribe-roman-to-lao-string (str)
568 "Transcribe Romanized Lao string STR to Lao character string."
569 (let ((from 0)
570 (to (length str))
571 (lao-str "")
572 val)
573 (while (setq val (lao-transcribe-single-roman-syllable-to-lao from to str))
574 (let ((start (car val))
575 (end (nth 1 val))
576 (lao (nth 2 val)))
577 (if (> start from)
578 (setq lao-str (concat lao-str (substring str from start) lao))
579 (setq lao-str (concat lao-str lao)))
580 (setq from end)))
581 (if (< from to)
582 (concat lao-str (substring str from to))
583 lao-str)))
584
a549727e
DL
585;;;###autoload
586(defun lao-post-read-conversion (len)
587 (lao-compose-region (point) (+ (point) len))
588 len)
589
31ce7719
KH
590;;;###autoload
591(defun lao-composition-function (from to pattern &optional string)
592 "Compose Lao text in the region FROM and TO.
593The text matches the regular expression PATTERN.
594Optional 4th argument STRING, if non-nil, is a string containing text
595to compose.
596
597The return value is number of composed characters."
598 (if (< (1+ from) to)
e10fd9a8 599 (progn
31ce7719 600 (if string
1513ad08 601 (compose-string string from to)
31ce7719
KH
602 (compose-region from to))
603 (- to from))))
d92d0128 604
9b21ecc2
KH
605;;;###autoload
606(defun lao-compose-region (from to)
607 (interactive "r")
608 (save-restriction
609 (narrow-to-region from to)
610 (goto-char (point-min))
611 (with-category-table lao-category-table
612 (while (re-search-forward lao-composition-pattern nil t)
613 (compose-region (match-beginning 0) (point))))))
614
d92d0128 615;;
650e8505 616(provide 'lao-util)
d92d0128 617
ab5796a9 618;;; arch-tag: 1f828781-3cb8-4695-88af-8f33222338ce
d92d0128 619;;; lao-util.el ends here