1 ;;;; -*- Mode: Lisp; Syntax: ANSI-Common-Lisp; indent-tabs-mode: nil -*-
3 ;;; --- Surrogates of chars.
6 (in-package :iolib.base
)
8 ;;;-------------------------------------------------------------------------
10 ;;;-------------------------------------------------------------------------
12 (eval-when (:compile-toplevel
:load-toplevel
:execute
)
13 (defconstant uchar-code-limit
#x110000
))
16 ;;;-------------------------------------------------------------------------
18 ;;;-------------------------------------------------------------------------
21 '(mod #.uchar-code-limit
))
23 (deftype ustring
(&optional
(size '*))
24 `(simple-array uchar
(,size
)))
27 ;;;-------------------------------------------------------------------------
29 ;;;-------------------------------------------------------------------------
32 (defun code-uchar (code)
33 (check-type code
(mod #.uchar-code-limit
))
37 (defun uchar-code (uchar)
38 (check-type uchar uchar
)
41 (defun char-to-uchar (character)
42 (char-code character
))
44 (defun uchar-to-char (uchar)
47 (defun digit-uchar (digit &optional
(radix 10))
48 (check-type digit unsigned-byte
)
49 (check-type radix
(integer 2 36))
57 ((ustring 1) (aref thing
0))
59 (char-to-uchar (character thing
)))))
62 ;;;-------------------------------------------------------------------------
64 ;;;-------------------------------------------------------------------------
69 (defun unicode-uchar-p (uchar)
70 (check-type uchar uchar
)
74 (defun uchar/= (uchar &rest more-uchars
)
75 (check-type uchar uchar
)
76 (assert (every #'ucharp more-uchars
))
77 (= (1+ (length more-uchars
))
78 (length (remove-duplicates (list* uchar more-uchars
)
81 (defun uchar-not-equal (uchar &rest more-uchars
)
82 (check-type uchar uchar
)
83 (assert (every #'ucharp more-uchars
))
84 (= (1+ (length more-uchars
))
85 (length (remove-duplicates (list* uchar more-uchars
)
86 :test
#'= :key
#'uchar-downcase
))))
89 ((define-uchar-comparison (name test
&key
(key 'identity
))
90 `(defun ,name
(uchar &rest more-uchars
)
91 (check-type uchar uchar
)
92 (assert (every #'ucharp more-uchars
))
93 (do* ((r (,key uchar
) (,key
(car list
)))
94 (list more-uchars
(cdr list
)))
96 (unless (,test r
(,key
(car list
)))
98 (define-uchar-comparison uchar
= = )
99 (define-uchar-comparison uchar-equal
= :key uchar-downcase
)
100 (define-uchar-comparison uchar
< < )
101 (define-uchar-comparison uchar-lessp
< :key uchar-downcase
)
102 (define-uchar-comparison uchar
> > )
103 (define-uchar-comparison uchar-greaterp
> :key uchar-downcase
)
104 (define-uchar-comparison uchar
<= <= )
105 (define-uchar-comparison uchar-not-greaterp
<= :key uchar-downcase
)
106 (define-uchar-comparison uchar
>= >= )
107 (define-uchar-comparison uchar-not-lessp
>= :key uchar-downcase
))
109 (defun alpha-uchar-p (uchar)
110 (and (unicode-uchar-p uchar
)
111 (alpha-char-p (uchar-to-char uchar
))))
113 (defun alphanumeric-uchar-p (uchar)
114 (and (unicode-uchar-p uchar
)
115 (alphanumericp (uchar-to-char uchar
))))
117 (defun digit-uchar-p (uchar &optional
(radix 10))
118 (digit-char-p (uchar-to-char uchar
) radix
))
120 (defun graphic-uchar-p (uchar)
121 (and (unicode-uchar-p uchar
)
122 (graphic-char-p (uchar-to-char uchar
))))
124 (defun upper-case-uchar-p (uchar)
125 (and (unicode-uchar-p uchar
)
126 (upper-case-p (uchar-to-char uchar
))))
128 (defun lower-case-uchar-p (uchar)
129 (and (unicode-uchar-p uchar
)
130 (lower-case-p (uchar-to-char uchar
))))
132 (defun both-case-uchar-p (uchar)
133 (and (unicode-uchar-p uchar
)
134 (both-case-p (uchar-to-char uchar
))))
137 ;;;-------------------------------------------------------------------------
139 ;;;-------------------------------------------------------------------------
141 (defun uchar-upcase (uchar)
142 (if (unicode-uchar-p uchar
)
143 (char-to-uchar (char-upcase (uchar-to-char uchar
)))
146 (defun uchar-downcase (uchar)
147 (if (unicode-uchar-p uchar
)
148 (char-to-uchar (char-downcase (uchar-to-char uchar
)))