From ffd5745e2a0a38e1f63cd93a2f3c8394adaa907b Mon Sep 17 00:00:00 2001 From: tomo Date: Mon, 12 Mar 2012 19:45:52 +0000 Subject: [PATCH] (japanese-simplified-relation-features): New variable. (japanese-traditional-relation-features): New variable. (japanese-simplify-string): Refer `japanese-simplified-relation-features'. (japanese-traditionalize-string): Refer `japanese-traditional-relation-features'. (japanese-traditionalize-region): Refer `japanese-traditional-relation-features'. (japanese-simplify-region): Refer `japanese-simplified-relation-features'. --- ideo-trans.el | 85 +++++++++++++++++++++++++++++++++++++++++---------------- 1 file changed, 62 insertions(+), 23 deletions(-) diff --git a/ideo-trans.el b/ideo-trans.el index 3e9689a..7ab1783 100644 --- a/ideo-trans.el +++ b/ideo-trans.el @@ -1,6 +1,6 @@ ;;; ideo-trans.el --- Translation utility for Ideographic Strings -;; Copyright (C) 2003,2004,2005,2008 MORIOKA Tomohiko +;; Copyright (C) 2003,2004,2005,2008,2012 MORIOKA Tomohiko ;; Author: MORIOKA Tomohiko ;; Keywords: Ideographs, Character Database, Chaon, CHISE @@ -117,9 +117,47 @@ 'chinese-simplify-string) ;;;###autoload +(defvar japanese-simplified-relation-features + '(->simplified@JP/Jouyou + ->simplified@jp-jouyou + ->simplified@JP/extra + ->simplified@JP/extra/design + ->simplified@JP/jis + ->simplified@JP/jis/2004 + ->simplified@JP/jis/1978 + ->simplified@JP/misc + ->simplified@JP + ->simplified@jp + ->jp-simplified + ->simplified + ;; ->simplified@JP/old + ;; ->simplified@JP/buddhism + ) + "List of relation features to map traditional Kanji to simplified Kanji used in Japanese.") + +;;;###autoload +(defvar japanese-traditional-relation-features + '(<-simplified@JP/Jouyou + <-simplified@jp-jouyou + <-simplified@JP/extra + <-simplified@JP/extra/design + <-simplified@JP/jis + <-simplified@JP/jis/2004 + <-simplified@JP/jis/1978 + <-simplified@JP/misc + <-simplified@JP + <-simplified@jp + <-jp-simplified + <-simplified + ;; <-simplified@JP/old + ;; <-simplified@JP/buddhism + ) + "List of relation features to map simplified Kanji to traditional Kanji used in Japanese.") + +;;;###autoload (defun japanese-simplify-string (string) "Simplify traditional Kanji characters in STRING." - (let (ret) + (let (ret rest) (mapconcat (lambda (chr) (setq uchr @@ -131,9 +169,10 @@ (setq chr (decode-char '=ucs@jis ret)) chr)) (t chr))) - (setq ret (or (char-feature chr '->simplified@JP/Jouyou) - (char-feature chr '->simplified@JP) - (char-feature chr '->simplified))) + (setq rest japanese-simplified-relation-features) + (while (and rest + (null (setq ret (char-feature chr (car rest))))) + (setq rest (cdr rest))) (char-to-string (cond ((car ret)) ((setq ret (char-feature chr '=>ucs@jis)) @@ -205,13 +244,15 @@ (setq selector (lambda (chars) (ideo-trans-select-char chars (format "%c => " chr))))) - (let (ret) + (let (ret rest) (mapconcat (lambda (chr) + (setq rest japanese-traditional-relation-features) + (while (and rest + (null (setq ret (char-feature chr (car rest))))) + (setq rest (cdr rest))) (char-to-string - (cond ((setq ret (or (char-feature chr '<-simplified@JP/Jouyou) - (char-feature chr '<-simplified@JP) - (char-feature chr '<-simplified))) + (cond (ret (if (cdr ret) (funcall selector ret) (car ret))) @@ -246,16 +287,15 @@ (save-restriction (narrow-to-region start end) (goto-char start) - (let (chr ret rret) + (let (chr ret rret rest) (while (and (skip-chars-forward "\x00-\xFF") (not (eobp))) (setq chr (char-after)) - (if (setq ret (or (char-feature chr '<-simplified@JP/Jouyou) - (char-feature chr '<-simplified@jp-jouyou) - (char-feature chr '<-simplified@JP) - (char-feature chr '<-simplified@jp) - (char-feature chr '<-jp-simplified) - (char-feature chr '<-simplified))) + (setq rest japanese-traditional-relation-features) + (while (and rest + (null (setq ret (char-feature chr (car rest))))) + (setq rest (cdr rest))) + (if ret (progn (if (cdr ret) (progn @@ -274,16 +314,15 @@ (save-restriction (narrow-to-region start end) (goto-char start) - (let (chr ret rret) + (let (chr ret rret rest) (while (and (skip-chars-forward "\x00-\xFF") (not (eobp))) (setq chr (char-after)) - (if (setq ret (or (char-feature chr '->simplified@JP/Jouyou) - (char-feature chr '->simplified@jp-jouyou) - (char-feature chr '->simplified@JP) - (char-feature chr '->simplified@jp) - (char-feature chr '->jp-simplified) - (char-feature chr '->simplified))) + (setq rest japanese-simplified-relation-features) + (while (and rest + (null (setq ret (char-feature chr (car rest))))) + (setq rest (cdr rest))) + (if ret (progn (if (cdr ret) (progn -- 1.7.10.4