1 ;;; ids.el --- Parser and utility for Ideographic Description Sequence.
3 ;; Copyright (C) 2001, 2002, 2003, 2005, 2020 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 CHISE-IDS.
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)
35 (defun ideographic-structure-find-char (structure)
36 (car (ideographic-structure-find-chars structure))
37 ;; (dolist (product (char-feature (nth 1 structure) 'ideographic-products))
38 ;; (if (equal structure
39 ;; (char-feature product 'ideographic-structure))
43 (defun ids-parse-terminal (string)
44 (if (>= (length string) 1)
45 (let* ((chr (aref string 0))
46 (ucs (encode-char chr '=ucs 'defined-only))
48 (unless (and ucs (<= #x2FF0 ucs)(<= ucs #x2FFF))
49 (if (and ucs (<= #xE000 ucs)(<= ucs #xF8FF)
50 (setq big5 (encode-char chr 'chinese-big5)))
51 (setq chr (decode-char '=big5-cdp big5)))
53 (substring string 1))))))
55 (defun ids-parse-op-2 (string)
56 (if (>= (length string) 1)
57 (let* ((chr (aref string 0))
58 (ucs (encode-char chr '=ucs 'defined-only)))
59 (if (or (eq ucs #x2FF0)
61 (and (<= #x2FF4 ucs)(<= ucs #x2FFB)))
63 (substring string 1))))))
65 (defun ids-parse-op-3 (string)
66 (if (>= (length string) 1)
67 (let ((chr (aref string 0)))
68 (if (memq chr '(?\u2FF2 ?\u2FF3))
70 (substring string 1))))))
72 (defun ids-parse-component (string simplify)
73 (let ((ret (ids-parse-element string simplify))
78 (setq rret (ideographic-structure-find-char
79 (cdr (assq 'ideographic-structure (car ret))))))
83 (defun ids-parse-element (string simplify)
84 (let (ret op arg1 arg2 arg3)
85 (cond ((ids-parse-terminal string))
86 ((setq ret (ids-parse-op-2 string))
88 (when (setq ret (ids-parse-component (cdr ret) simplify))
90 (when (setq ret (ids-parse-component (cdr ret) simplify))
92 (cons (list (list 'ideographic-structure op arg1 arg2))
94 ((setq ret (ids-parse-op-3 string))
96 (when (setq ret (ids-parse-component (cdr ret) simplify))
98 (when (setq ret (ids-parse-component (cdr ret) simplify))
100 (when (setq ret (ids-parse-component (cdr ret) simplify))
101 (setq arg3 (car ret))
102 (cons (list (list 'ideographic-structure op arg1 arg2 arg3))
106 (defun ids-parse-string (ids-string &optional simplify)
107 "Parse IDS-STRING and return the result."
108 (let ((ret (ids-parse-element ids-string simplify)))
109 (if (= (length (cdr ret)) 0)
112 ;; (defun ids-format-unit (ids-char)
114 ;; (cond ((characterp ids-char)
115 ;; (char-to-string ids-char))
116 ;; ((integerp ids-char)
117 ;; (char-to-string (decode-char 'ucs ids-char)))
118 ;; ((setq ret (find-char ids-char))
119 ;; (char-to-string ret))
120 ;; ((setq ret (assq 'ideographic-structure ids-char))
121 ;; (ids-format-list (cdr ret))))))
124 ;; (defun ids-format-list (ids-list)
125 ;; "Format ideographic-structure IDS-LIST as an IDS-string."
126 ;; (mapconcat (lambda (cell)
128 ;; (if (char-ref-p cell)
129 ;; (plist-get cell :char)
133 (define-obsolete-function-alias
134 'ids-format-list 'ideographic-structure-to-ids)