(char-attribute-name<): Add DOC-string.
[chise/xemacs-chise.git-] / lisp / utf-2000 / chise-subr.el
1 ;;; chise-subr.el --- basic lisp subroutines for XEmacs CHISE
2
3 ;; Copyright (C) 1999, 2001, 2002, 2003, 2004, 2005, 2008, 2009, 2010
4 ;;   MORIOKA Tomohiko.
5
6 ;; Author: MORIOKA Tomohiko <tomo@kanji.zinbun.kyoto-u.ac.jp>
7 ;; Keywords: CHISE, Character Database, ISO/IEC 10646, UCS, Unicode, MULE.
8
9 ;; This file is part of XEmacs CHISE.
10
11 ;; XEmacs CHISE is free software; you can redistribute it and/or
12 ;; modify it under the terms of the GNU General Public License as
13 ;; published by the Free Software Foundation; either version 2, or (at
14 ;; your option) any later version.
15
16 ;; XEmacs CHISE 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 GNU
19 ;; General Public License for more details.
20
21 ;; You should have received a copy of the GNU General Public License
22 ;; along with XEmacs CHISE; see the file COPYING.  If not, write to
23 ;; the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
24 ;; Boston, MA 02111-1307, USA.
25
26 ;;; Code:
27
28 ;;; @ feature name
29 ;;;
30
31 ;;;###autoload
32 (defun expand-char-feature-name (feature domain)
33   (if domain
34       (intern (format "%s@%s" feature domain))
35     feature))
36
37 ;;;###autoload
38 (defun char-attribute-name< (ka kb)
39   "Return t if symbol KA is less than KB in feature-name sorting order."
40   (cond
41    ((eq '->denotational kb)
42     t)
43    ((eq '->subsumptive kb)
44     (not (eq '->denotational ka)))
45    ((eq '->denotational ka)
46     nil)
47    ((eq '->subsumptive ka)
48     nil)
49    ((and (symbolp ka)
50          (string-match "^->" (symbol-name ka)))
51     (cond ((and (symbolp kb)
52                 (string-match "^->" (symbol-name kb)))
53            (string< (symbol-name ka)
54                     (symbol-name kb))
55            ))
56     )
57    ((and (symbolp kb)
58          (string-match "^->" (symbol-name kb)))
59     t)
60    ((and (symbolp ka)
61          (string-match "^<-" (symbol-name ka)))
62     (cond ((symbolp kb)
63            (cond ((string-match "^<-" (symbol-name kb))
64                   (string< (symbol-name ka)
65                            (symbol-name kb))
66                   )
67                  ;; ((string-match "^->" (symbol-name kb))
68                  ;;  t)
69                  )))
70     )
71    ((and (symbolp kb)
72          (string-match "^<-" (symbol-name kb)))
73     t
74     ;; (not (string-match "^->" (symbol-name ka)))
75     )
76    ((find-charset ka)
77     (if (find-charset kb)
78         (let (a-ir b-ir)
79           (if (setq a-ir (charset-property ka 'iso-ir))
80               (if (setq b-ir (charset-property kb 'iso-ir))
81                   (cond
82                    ((= a-ir b-ir)
83                     (< (charset-id ka)(charset-id kb))
84                     )
85                    ((= a-ir 177)
86                     t)
87                    ((= b-ir 177)
88                     nil)
89                    ((< a-ir
90                        b-ir)
91                     ))
92                 t)
93             (if (charset-property kb 'iso-ir)
94                 nil
95               (< (charset-id ka)(charset-id kb)))))
96       nil)
97     )
98    ((find-charset kb))
99    ((symbolp ka)
100     (cond ((symbolp kb)
101            (string< (symbol-name ka)
102                     (symbol-name kb)))
103           (t)))
104    ((symbolp kb)
105     nil)))
106
107
108 ;;; @ char feature
109 ;;;
110
111 ;;;###autoload
112 (defun char-ucs (char)
113   "Return code-point of UCS."
114   (or (encode-char char '=ucs 'defined-only)
115       (char-feature char '=>ucs)))
116
117 ;;;###autoload
118 (defun char-id (char)
119   (logand (char-int char) #x3FFFFFFF))
120
121
122 ;;; @ char hierarchy
123 ;;;
124
125 ;;;###autoload
126 (defun map-char-family (function char &optional ignore-sisters)
127   (let ((rest (list char))
128         ret checked)
129     (catch 'tag
130       (while rest
131         (unless (memq (car rest) checked)
132           (if (setq ret (funcall function (car rest)))
133               (throw 'tag ret))
134           (setq checked (cons (car rest) checked)
135                 rest (append rest
136                              (get-char-attribute (car rest) '->subsumptive)
137                              (get-char-attribute (car rest) '->denotational)
138                              (get-char-attribute (car rest) '->identical)))
139           (unless ignore-sisters
140             (setq rest (append rest
141                                (get-char-attribute (car rest) '<-subsumptive)
142                                (get-char-attribute (car rest) '<-denotational)))))
143         (setq rest (cdr rest))))))
144
145
146 ;;; @ string
147 ;;;
148
149 ;;;###autoload
150 (defun chise-string< (string1 string2 accessors)
151   (let ((len1 (length string1))
152         (len2 (length string2))
153         len
154         (i 0)
155         c1 c2
156         rest func
157         v1 v2)
158     (setq len (min len1 len2))
159     (catch 'tag
160       (while (< i len)
161         (setq c1 (aref string1 i)
162               c2 (aref string2 i))
163         (setq rest accessors)
164         (while (and rest
165                     (setq func (car rest))
166                     (setq v1 (funcall func c1)
167                           v2 (funcall func c2))
168                     (eq v1 v2))
169           (setq rest (cdr rest)))
170         (if v1
171             (if v2
172                 (cond ((< v1 v2)
173                        (throw 'tag t))
174                       ((> v1 v2)
175                        (throw 'tag nil)))
176               (throw 'tag nil))
177           (if v2
178               (throw 'tag t)))
179         (setq i (1+ i)))
180       (< len1 len2))))
181
182
183 ;;; @ end
184 ;;;
185
186 (provide 'chise-subr)
187
188 ;;; chise-subr.el ends here