X-Git-Url: http://repo.macrolet.net/gitweb/?a=blobdiff_plain;f=src%2Fcode%2Ftarget-char.lisp;h=e4b87c355ccc3eef5ec5f95043883e1ea67fef60;hb=a160917364f85b38dc0826a5e3dcef87e3c4c62c;hp=92d529bcdf6f1c713d34c2cdac207dc6d6f71083;hpb=acc978383105b5a2bfd970f8a34214fd5774bb2a;p=sbcl.git diff --git a/src/code/target-char.lisp b/src/code/target-char.lisp index 92d529b..e4b87c3 100644 --- a/src/code/target-char.lisp +++ b/src/code/target-char.lisp @@ -67,8 +67,10 @@ for char-name = (string-upcase (read stream nil nil)) while code-point do (setf (gethash code-point names) char-name)) - (let ((tree (make-huffman-tree - (let (list) + (let ((tree + #!+sb-unicode + (make-huffman-tree + (let (list) (maphash (lambda (code name) (declare (ignore code)) (push name list)) @@ -248,8 +250,13 @@ (let ((h-code (cdr (binary-search char-code (car *unicode-character-name-database*) :key #'car)))) - (when h-code - (huffman-decode h-code *unicode-character-name-huffman-tree*)))))) + (cond + (h-code + (huffman-decode h-code *unicode-character-name-huffman-tree*)) + ((< char-code #x10000) + (format nil "U~4,'0X" char-code)) + (t + (format nil "U~8,'0X" char-code))))))) (defun name-char (name) #!+sb-doc @@ -264,12 +271,23 @@ (let ((encoding (huffman-encode (string-upcase name) *unicode-character-name-huffman-tree*))) (when encoding - (let ((char-code - (car (binary-search encoding - (cdr *unicode-character-name-database*) - :key #'cdr)))) - (when char-code - (code-char char-code))))))) + (let* ((char-code + (car (binary-search encoding + (cdr *unicode-character-name-database*) + :key #'cdr))) + (name-string (string name)) + (name-length (length name-string))) + (cond + (char-code + (code-char char-code)) + ((and (or (= name-length 9) + (= name-length 5)) + (char-equal (char name-string 0) #\U) + (loop for i from 1 below name-length + always (digit-char-p (char name-string i) 16))) + (code-char (parse-integer name-string :start 1 :radix 16))) + (t + nil))))))) ;;;; predicates @@ -354,6 +372,7 @@ (defun char= (character &rest more-characters) #!+sb-doc "Return T if all of the arguments are the same character." + (declare (truly-dynamic-extent more-characters)) (dolist (c more-characters t) (declare (type character c)) (unless (eq c character) (return nil)))) @@ -361,6 +380,7 @@ (defun char/= (character &rest more-characters) #!+sb-doc "Return T if no two of the arguments are the same character." + (declare (truly-dynamic-extent more-characters)) (do* ((head character (car list)) (list more-characters (cdr list))) ((null list) t) @@ -372,6 +392,7 @@ (defun char< (character &rest more-characters) #!+sb-doc "Return T if the arguments are in strictly increasing alphabetic order." + (declare (truly-dynamic-extent more-characters)) (do* ((c character (car list)) (list more-characters (cdr list))) ((null list) t) @@ -382,6 +403,7 @@ (defun char> (character &rest more-characters) #!+sb-doc "Return T if the arguments are in strictly decreasing alphabetic order." + (declare (truly-dynamic-extent more-characters)) (do* ((c character (car list)) (list more-characters (cdr list))) ((null list) t) @@ -392,6 +414,7 @@ (defun char<= (character &rest more-characters) #!+sb-doc "Return T if the arguments are in strictly non-decreasing alphabetic order." + (declare (truly-dynamic-extent more-characters)) (do* ((c character (car list)) (list more-characters (cdr list))) ((null list) t) @@ -402,6 +425,7 @@ (defun char>= (character &rest more-characters) #!+sb-doc "Return T if the arguments are in strictly non-increasing alphabetic order." + (declare (truly-dynamic-extent more-characters)) (do* ((c character (car list)) (list more-characters (cdr list))) ((null list) t) @@ -419,72 +443,90 @@ (ucd-value-1 ,ch) (char-code ,ch))))) +(defun two-arg-char-equal (c1 c2) + (= (equal-char-code c1) (equal-char-code c2))) + (defun char-equal (character &rest more-characters) #!+sb-doc "Return T if all of the arguments are the same character. Font, bits, and case are ignored." + (declare (truly-dynamic-extent more-characters)) (do ((clist more-characters (cdr clist))) ((null clist) t) - (unless (= (equal-char-code (car clist)) - (equal-char-code character)) + (unless (two-arg-char-equal (car clist) character) (return nil)))) +(defun two-arg-char-not-equal (c1 c2) + (/= (equal-char-code c1) (equal-char-code c2))) + (defun char-not-equal (character &rest more-characters) #!+sb-doc "Return T if no two of the arguments are the same character. Font, bits, and case are ignored." + (declare (truly-dynamic-extent more-characters)) (do* ((head character (car list)) (list more-characters (cdr list))) ((null list) t) (unless (do* ((l list (cdr l))) ((null l) t) - (if (= (equal-char-code head) - (equal-char-code (car l))) + (if (two-arg-char-equal head (car l)) (return nil))) (return nil)))) +(defun two-arg-char-lessp (c1 c2) + (< (equal-char-code c1) (equal-char-code c2))) + (defun char-lessp (character &rest more-characters) #!+sb-doc "Return T if the arguments are in strictly increasing alphabetic order. Font, bits, and case are ignored." + (declare (truly-dynamic-extent more-characters)) (do* ((c character (car list)) (list more-characters (cdr list))) ((null list) t) - (unless (< (equal-char-code c) - (equal-char-code (car list))) + (unless (two-arg-char-lessp c (car list)) (return nil)))) +(defun two-arg-char-greaterp (c1 c2) + (> (equal-char-code c1) (equal-char-code c2))) + (defun char-greaterp (character &rest more-characters) #!+sb-doc "Return T if the arguments are in strictly decreasing alphabetic order. Font, bits, and case are ignored." + (declare (truly-dynamic-extent more-characters)) (do* ((c character (car list)) (list more-characters (cdr list))) ((null list) t) - (unless (> (equal-char-code c) - (equal-char-code (car list))) + (unless (two-arg-char-greaterp c (car list)) (return nil)))) +(defun two-arg-char-not-greaterp (c1 c2) + (<= (equal-char-code c1) (equal-char-code c2))) + (defun char-not-greaterp (character &rest more-characters) #!+sb-doc "Return T if the arguments are in strictly non-decreasing alphabetic order. Font, bits, and case are ignored." + (declare (truly-dynamic-extent more-characters)) (do* ((c character (car list)) (list more-characters (cdr list))) ((null list) t) - (unless (<= (equal-char-code c) - (equal-char-code (car list))) + (unless (two-arg-char-not-greaterp c (car list)) (return nil)))) +(defun two-arg-char-not-lessp (c1 c2) + (>= (equal-char-code c1) (equal-char-code c2))) + (defun char-not-lessp (character &rest more-characters) #!+sb-doc "Return T if the arguments are in strictly non-increasing alphabetic order. Font, bits, and case are ignored." + (declare (truly-dynamic-extent more-characters)) (do* ((c character (car list)) (list more-characters (cdr list))) ((null list) t) - (unless (>= (equal-char-code c) - (equal-char-code (car list))) + (unless (two-arg-char-not-lessp c (car list)) (return nil)))) ;;;; miscellaneous functions