1 ;;; ids.el --- Parser and utility for Ideographic Description Sequence.
3 ;; Copyright (C) 2001,2002,2003,2005 MORIOKA Tomohiko
5 ;; Author: MORIOKA Tomohiko <tomo@kanji.zinbun.kyoto-u.ac.jp>
6 ;; Keywords: IDS, IDC, Ideographs, UCS, Unicode
8 ;; This file is a part of Tomoyo-Tools.
10 ;; This program is free software; you can redistribute it and/or
11 ;; modify it under the terms of the GNU General Public License as
12 ;; published by the Free Software Foundation; either version 2, or (at
13 ;; your option) any later version.
15 ;; This program is distributed in the hope that it will be useful, but
16 ;; WITHOUT ANY WARRANTY; without even the implied warranty of
17 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 ;; General Public License for more details.
20 ;; You should have received a copy of the GNU General Public License
21 ;; along with this program; see the file COPYING. If not, write to
22 ;; the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
23 ;; Boston, MA 02111-1307, USA.
27 ;; Ideographic Description Sequence (IDS) is defined in ISO/IEC
28 ;; 10646-1:2000 Annex F.
32 (require 'ideograph-util)
34 (defun ideographic-structure-find-char (structure)
35 (dolist (product (char-feature (nth 1 structure) 'ideographic-products))
37 (char-feature product 'ideographic-structure))
40 (defun ids-parse-terminal (string)
41 (if (>= (length string) 1)
42 (let* ((chr (aref string 0))
43 (ucs (encode-char chr '=ucs 'defined-only))
45 (unless (and ucs (<= #x2FF0 ucs)(<= ucs #x2FFF))
46 (if (and ucs (<= #xE000 ucs)(<= ucs #xF8FF)
47 (setq big5 (encode-char chr 'chinese-big5)))
48 (setq chr (decode-char '=big5-cdp big5)))
50 (substring string 1))))))
52 (defun ids-parse-op-2 (string)
53 (if (>= (length string) 1)
54 (let* ((chr (aref string 0))
55 (ucs (encode-char chr '=ucs 'defined-only)))
56 (if (or (eq ucs #x2FF0)
58 (and (<= #x2FF4 ucs)(<= ucs #x2FFB)))
60 (substring string 1))))))
62 (defun ids-parse-op-3 (string)
63 (if (>= (length string) 1)
64 (let ((chr (aref string 0)))
65 (if (memq chr '(?\u2FF2 ?\u2FF3))
67 (substring string 1))))))
69 (defun ids-parse-component (string simplify)
70 (let ((ret (ids-parse-element string simplify))
75 (setq rret (ideographic-structure-find-char
76 (cdr (assq 'ideographic-structure (car ret))))))
80 (defun ids-parse-element (string simplify)
81 (let (ret op arg1 arg2 arg3)
82 (cond ((ids-parse-terminal string))
83 ((setq ret (ids-parse-op-2 string))
85 (when (setq ret (ids-parse-component (cdr ret) simplify))
87 (when (setq ret (ids-parse-component (cdr ret) simplify))
89 (cons (list (list 'ideographic-structure op arg1 arg2))
91 ((setq ret (ids-parse-op-3 string))
93 (when (setq ret (ids-parse-component (cdr ret) simplify))
95 (when (setq ret (ids-parse-component (cdr ret) simplify))
97 (when (setq ret (ids-parse-component (cdr ret) simplify))
99 (cons (list (list 'ideographic-structure op arg1 arg2 arg3))
103 (defun ids-parse-string (ids-string &optional simplify)
104 "Parse IDS-STRING and return the result."
105 (let ((ret (ids-parse-element ids-string simplify)))
106 (if (= (length (cdr ret)) 0)
109 ;; (defun ids-format-unit (ids-char)
111 ;; (cond ((characterp ids-char)
112 ;; (char-to-string ids-char))
113 ;; ((integerp ids-char)
114 ;; (char-to-string (decode-char 'ucs ids-char)))
115 ;; ((setq ret (find-char ids-char))
116 ;; (char-to-string ret))
117 ;; ((setq ret (assq 'ideographic-structure ids-char))
118 ;; (ids-format-list (cdr ret))))))
121 ;; (defun ids-format-list (ids-list)
122 ;; "Format ideographic-structure IDS-LIST as an IDS-string."
123 ;; (mapconcat (lambda (cell)
125 ;; (if (char-ref-p cell)
126 ;; (plist-get cell :char)
130 (define-obsolete-function-alias
131 'ids-format-list 'ideographic-structure-to-ids)