X-Git-Url: http://repo.macrolet.net/gitweb/?a=blobdiff_plain;f=src%2Fcode%2Ftarget-char.lisp;h=ad0f9ee0df697108ee81b981d8a53f08368f94d9;hb=d10b036b1d20e6cff820f72b69af2a06dc362327;hp=92d529bcdf6f1c713d34c2cdac207dc6d6f71083;hpb=acc978383105b5a2bfd970f8a34214fd5774bb2a;p=sbcl.git diff --git a/src/code/target-char.lisp b/src/code/target-char.lisp index 92d529b..ad0f9ee 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 @@ -419,16 +437,21 @@ (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." (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. @@ -438,11 +461,13 @@ ((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. @@ -450,10 +475,12 @@ (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. @@ -461,10 +488,12 @@ (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. @@ -472,10 +501,12 @@ (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. @@ -483,8 +514,7 @@ (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