changeset 22548:b054cd9f66df

Introduce new character code property `composition'. Add property `jisx0208' to Japanese hankaku characters. (japanese-kana-table): Add more data. (japanese-symbol-table): Change the order of elements. (japanese-katakana-region): Adjusted for the above changes. Check character code properties directly here. (japanese-hiragana-region): Likewise. (japanese-hankaku-region): Likewise. (japanese-zenkaku-region): Likewise.
author Kenichi Handa <handa@m17n.org>
date Tue, 23 Jun 1998 00:30:05 +0000
parents 1cf8123f4c67
children bb42066bb94a
files lisp/language/japan-util.el
diffstat 1 files changed, 61 insertions(+), 30 deletions(-) [+]
line wrap: on
line diff
--- a/lisp/language/japan-util.el	Tue Jun 23 00:29:51 1998 +0000
+++ b/lisp/language/japan-util.el	Tue Jun 23 00:30:05 1998 +0000
@@ -52,7 +52,7 @@
     (?$B$^(B ?$B%^(B ?(IO(B) (?$B$_(B ?$B%_(B ?(IP(B) (?$B$`(B ?$B%`(B ?(IQ(B) (?$B$a(B ?$B%a(B ?(IR(B) (?$B$b(B ?$B%b(B ?(IS(B)
     (?$B$d(B ?$B%d(B ?(IT(B) (?$B$f(B ?$B%f(B ?(IU(B) (?$B$h(B ?$B%h(B ?(IV(B)
     (?$B$i(B ?$B%i(B ?(IW(B) (?$B$j(B ?$B%j(B ?(IX(B) (?$B$k(B ?$B%k(B ?(IY(B) (?$B$l(B ?$B%l(B ?(IZ(B) (?$B$m(B ?$B%m(B ?(I[(B)
-    (?$B$o(B ?$B%o(B ?(I\(B) (?$B$p(B ?$B%p(B nil) (?$B$q(B ?$B%q(B nil) (?$B$r(B ?$B%r(B ?(I&(B)
+    (?$B$o(B ?$B%o(B ?(I\(B) (?$B$p(B ?$B%p(B "(I2(B") (?$B$q(B ?$B%q(B "(I4(B") (?$B$r(B ?$B%r(B ?(I&(B)
     (?$B$s(B ?$B%s(B ?(I](B)
     (?$B$,(B ?$B%,(B "(I6^(B") (?$B$.(B ?$B%.(B "(I7^(B") (?$B$0(B ?$B%0(B "(I8^(B") (?$B$2(B ?$B%2(B "(I9^(B") (?$B$4(B ?$B%4(B "(I:^(B")
     (?$B$6(B ?$B%6(B "(I;^(B") (?$B$8(B ?$B%8(B "(I<^(B") (?$B$:(B ?$B%:(B "(I=^(B") (?$B$<(B ?$B%<(B "(I>^(B") (?$B$>(B ?$B%>(B "(I?^(B")
@@ -62,8 +62,8 @@
     (?$B$!(B ?$B%!(B ?(I'(B) (?$B$#(B ?$B%#(B ?(I((B) (?$B$%(B ?$B%%(B ?(I)(B) (?$B$'(B ?$B%'(B ?(I*(B) (?$B$)(B ?$B%)(B ?(I+(B)
     (?$B$C(B ?$B%C(B ?(I/(B)
     (?$B$c(B ?$B%c(B ?(I,(B) (?$B$e(B ?$B%e(B ?(I-(B) (?$B$g(B ?$B%g(B ?(I.(B)
-    (?$B$n(B ?$B%n(B nil)
-    (nil ?$B%t(B "(I3^(B") (nil ?$B%u(B nil) (nil ?$B%v(B nil))
+    (?$B$n(B ?$B%n(B "(I\(B")
+    ("$B$&!+(B" ?$B%t(B "(I3^(B") (nil ?$B%u(B "(I6(B") (nil ?$B%v(B "(I9(B"))
   "Japanese JISX0208 Kana character table.
 Each element is of the form (HIRAGANA KATAKANA HANKAKU-KATAKANA), where
 HIRAGANA and KATAKANA belong to `japanese-jisx0208',
@@ -78,22 +78,32 @@
 	  hiragana (car slot) katakana (nth 1 slot) jisx0201 (nth 2 slot)
 	  l (cdr l))
     (if hiragana
-	(progn
+	(if (stringp hiragana)
+	    (if (> (length hiragana) 1)
+		(let ((hira (aref hiragana 0)))
+		  (put-char-code-property
+		   hira 'composition
+		   (cons (cons (aref hiragana 1) katakana)
+			 (get-char-code-property hira 'composition)))))
 	  (put-char-code-property hiragana 'katakana katakana)
-	  (put-char-code-property katakana 'hiragana hiragana)
-	  (if jisx0201
-	      (progn
-		(put-char-code-property hiragana 'jisx0201 jisx0201)
-		(if (integerp jisx0201)
-		    (put-char-code-property jisx0201 'hiragana hiragana))))))
+	  (put-char-code-property hiragana 'jisx0201 jisx0201)))
+    (when (integerp katakana)
+      (put-char-code-property katakana 'hiragana hiragana)
+      (put-char-code-property katakana 'jisx0201 jisx0201))
     (if jisx0201
-	(progn
-	  (put-char-code-property katakana 'jisx0201 jisx0201)
-	  (if (integerp jisx0201)
-	      (put-char-code-property jisx0201 'katakana katakana))))))
+	(if (stringp jisx0201)
+	    (if (> (length jisx0201) 1)
+		(let ((kana (aref jisx0201 0)))
+		  (put-char-code-property
+		   kana 'composition
+		   (cons (cons (aref jisx0201 1) katakana)
+			 (get-char-code-property kana 'composition)))))
+	  (put-char-code-property jisx0201 'hiragana hiragana)
+	  (put-char-code-property jisx0201 'katakana katakana)
+	  (put-char-code-property jisx0201 'jisx0208 katakana)))))
 
 (defconst japanese-symbol-table
-  '((?\$B!!(B ?\ ) (?$B!"(B ?, ?(I$(B) (?$B!#(B ?. ?(I!(B) (?$B!$(B ?, ?(I$(B) (?$B!%(B ?. ?(I!(B) (?$B!&(B nil ?(I%(B)
+  '((?\$B!!(B ?\ ) (?$B!$(B ?, ?(I$(B) (?$B!%(B ?. ?(I!(B) (?$B!"(B ?, ?(I$(B) (?$B!#(B ?. ?(I!(B) (?$B!&(B nil ?(I%(B)
     (?$B!'(B ?:) (?$B!((B ?\;) (?$B!)(B ??) (?$B!*(B ?!) (?$B!+(B nil ?(I^(B) (?$B!,(B nil ?(I_(B)
     (?$B!-(B ?') (?$B!.(B ?`) (?$B!0(B ?^) (?$B!2(B ?_) (?$B!<(B ?-) (?$B!=(B ?-) (?$B!>(B ?-)
     (?$B!?(B ?/) (?$B!@(B ?\\) (?$B!A(B ?~)  (?$B!C(B ?|) (?$B!F(B ?`) (?$B!G(B ?') (?$B!H(B ?\") (?$B!I(B ?\")
@@ -218,27 +228,40 @@
     (narrow-to-region from to)
     (goto-char (point-min))
     (while (re-search-forward "\\cH\\|\\cK" nil t)
-      (let* ((hira (preceding-char))
-	     (kata (japanese-katakana hira hankaku)))
-	(if kata
+      (let* ((kana (preceding-char))
+	     (composition (get-char-code-property kana 'composition))
+	     next slot)
+	(if (and composition (setq slot (assq (following-char) composition)))
 	    (progn
-	      (delete-region (match-beginning 0) (match-end 0))
-	      (insert kata)))))))
+	      (delete-region (match-beginning 0) (1+ (point)))
+	      (insert (cdr slot)))
+	  (let ((kata (get-char-code-property
+		       kana (if hankaku 'jisx0201 'katakana))))
+	    (if kata
+		(progn
+		  (delete-region (match-beginning 0) (match-end 0))
+		  (insert kata)))))))))
 
 ;;;###autoload
 (defun japanese-hiragana-region (from to)
-  "Convert Japanese `katakana' chars in the region to `hiragana'  chars."
+  "Convert Japanese `katakana' chars in the region to `hiragana' chars."
   (interactive "r")
   (save-restriction
     (narrow-to-region from to)
     (goto-char (point-min))
     (while (re-search-forward "\\cK\\|\\ck" nil t)
       (let* ((kata (preceding-char))
-	     (hira (japanese-hiragana kata)))
-	(if hira
+	     (composition (get-char-code-property kata 'composition))
+	     next slot)
+	(if (and composition (setq slot (assq (following-char) composition)))
 	    (progn
-	      (delete-region (match-beginning 0) (match-end 0))
-	      (insert hira)))))))
+	      (delete-region (match-beginning 0) (1+ (point)))
+	      (insert (get-char-code-property (cdr slot) 'hiragana)))
+	  (let ((hira (get-char-code-property kata 'hiragana)))
+	    (if hira
+		(progn
+		  (delete-region (match-beginning 0) (match-end 0))
+		  (insert hira)))))))))
 
 ;;;###autoload
 (defun japanese-hankaku-region (from to &optional ascii-only)
@@ -252,7 +275,9 @@
     (goto-char (point-min))
     (while (re-search-forward "\\cj" nil t)
       (let* ((zenkaku (preceding-char))
-	     (hankaku (japanese-hankaku zenkaku ascii-only)))
+	     (hankaku (or (get-char-code-property zenkaku 'ascii)
+			  (and (not ascii-only)
+			       (get-char-code-property zenkaku 'jisx0201)))))
 	(if hankaku
 	    (progn
 	      (delete-region (match-beginning 0) (match-end 0))
@@ -269,11 +294,17 @@
     (goto-char (point-min))
     (while (re-search-forward "\\ca\\|\\ck" nil t)
       (let* ((hankaku (preceding-char))
-	     (zenkaku (japanese-zenkaku hankaku)))
-	(if zenkaku
+	     (composition (get-char-code-property hankaku 'composition))
+	     next slot)
+	(if (and composition (setq slot (assq (following-char) composition)))
 	    (progn
-	      (delete-region (match-beginning 0) (match-end 0))
-	      (insert zenkaku)))))))
+	      (delete-region (match-beginning 0) (1+ (point)))
+	      (insert (cdr slot)))
+	  (let ((zenkaku (japanese-zenkaku hankaku)))
+	    (if zenkaku
+		(progn
+		  (delete-region (match-beginning 0) (match-end 0))
+		  (insert zenkaku)))))))))
 
 ;;;###autoload
 (defun read-hiragana-string (prompt &optional initial-input)