Update of /cvsroot/sbcl/sbcl/src/code
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv20664/src/code
Modified Files:
Tag: character_branch
cold-init.lisp target-char.lisp
Log Message:
0.8.13.77.character.16:
"What doesn't kill you makes you stronger"
Characters with codes 128-255 are now defined to be Latin-1 (or,
equivalently, the character set currently supported consists of
the first 256 characters of Unicode). Mostly from Teemu Kalvas.
... include character data (in binary form, added with -kb);
... make (simple-array (unsigned-byte 8) (*)) literals dumpable
by the cross-compiler;
... define names for (character-set '((#xa0 . #xbf)));
... test for char-name/graphic-char-p consistency.
Note: ucd.lisp is not used anywhere; it's included for interest
and because the method of generating the character database for
the core might change.
Index: cold-init.lisp
===================================================================
RCS file: /cvsroot/sbcl/sbcl/src/code/cold-init.lisp,v
retrieving revision 1.47
retrieving revision 1.47.4.1
diff -u -d -r1.47 -r1.47.4.1
--- cold-init.lisp 29 Jun 2004 08:50:58 -0000 1.47
+++ cold-init.lisp 13 Sep 2004 21:05:12 -0000 1.47.4.1
@@ -111,6 +111,8 @@
;; this to be initialized, so we initialize it right away.
(show-and-call !random-cold-init)
+ (show-and-call !character-database-cold-init)
+
(show-and-call !early-package-cold-init)
(show-and-call !package-cold-init)
Index: target-char.lisp
===================================================================
RCS file: /cvsroot/sbcl/sbcl/src/code/target-char.lisp,v
retrieving revision 1.6
retrieving revision 1.6.14.1
diff -u -d -r1.6 -r1.6.14.1
--- target-char.lisp 20 Jan 2004 18:10:23 -0000 1.6
+++ target-char.lisp 13 Sep 2004 21:05:12 -0000 1.6.14.1
@@ -32,6 +32,27 @@
(deftype char-code ()
`(integer 0 (,char-code-limit)))
+(defvar *character-database*)
+
+(macrolet ((frob ()
+ (with-open-file (stream (merge-pathnames
+ (make-pathname
+ :directory
+ '(:relative :up :up "tools-for-build")
+ :name "ucd"
+ :type "dat")
+ sb!xc:*compile-file-pathname*)
+ :direction :input
+ :element-type '(unsigned-byte 8))
+ (let* ((length (file-length stream))
+ (array (make-array length
+ :element-type '(unsigned-byte 8))))
+ (read-sequence array stream)
+ `(defun !character-database-cold-init ()
+ (setq *character-database* ',array))))))
+ (frob))
+#+sb-xc-host (!character-database-cold-init)
+
;;; This is the alist of (character-name . character) for characters
;;; with long names. The first name in this list for a given character
;;; is used on typeout and is the preferred form for input.
@@ -78,10 +99,68 @@
(#x1E ("Rs" "^^"))
(#x1F ("Us" "^_"))
(#x20 ("Space" "Sp")) ; *** See Note above.
- (#x7f ("Rubout" "Delete" "Del"))))) ; *** See Note above.
+ (#x7f ("Rubout" "Delete" "Del"))
+ (#x80 ("C80"))
+ (#x81 ("C81"))
+ (#x82 ("Break_permitted"))
+ (#x83 ("No_break_permitted"))
+ (#x84 ("C84"))
+ (#x85 ("Next_line"))
+ (#x86 ("Start_selected_area"))
+ (#x87 ("End_selected_area"))
+ (#x88 ("Character_tabulation_set"))
+ (#x89 ("Character_tabulation_with_justification"))
+ (#x8A ("Line_tabulation_set"))
+ (#x8B ("Partial_line_forward"))
+ (#x8C ("Partial_line_backward"))
+ (#x8D ("Reverse_linefeed"))
+ (#x8E ("Single_shift_two"))
+ (#x8F ("Single_shift_three"))
+ (#x90 ("Device_control_string"))
+ (#x91 ("Private_use_one"))
+ (#x92 ("Private_use_two"))
+ (#x93 ("Set_transmit_state"))
+ (#x94 ("Cancel_character"))
+ (#x95 ("Message_waiting"))
+ (#x96 ("Start_guarded_area"))
+ (#x97 ("End_guarded_area"))
+ (#x98 ("Start_string"))
+ (#x99 ("C99"))
+ (#x9A ("Single_character_introducer"))
+ (#x9B ("Control_sequence_introducer"))
+ (#x9C ("String_terminator"))
+ (#x9D ("Operating_system_command"))
+ (#x9E ("Privacy_message"))
+ (#x9F ("Application_program_command"))))) ; *** See Note above.
;;;; accessor functions
+(defun ucd-index (char)
+ (let* ((cp (char-code char))
+ (cp-high (ash cp -8))
+ (page (aref *character-database* (+ 1472 cp-high))))
+ (+ 5824 (ash page 10) (ash (ldb (byte 8 0) cp) 2))))
+
+(defun ucd-value-0 (char)
+ (aref *character-database* (ucd-index char)))
+
+(defun ucd-value-1 (char)
+ (let ((index (ucd-index char)))
+ (dpb (aref *character-database* (+ index 3))
+ (byte 8 16)
+ (dpb (aref *character-database* (+ index 2))
+ (byte 8 8)
+ (aref *character-database* (1+ index))))))
+
+(defun ucd-general-category (char)
+ (aref *character-database* (* 8 (ucd-value-0 char))))
+
+(defun ucd-decimal-digit (char)
+ (let ((decimal-digit (aref *character-database*
+ (+ 3 (* 8 (ucd-value-0 char))))))
+ (when (< decimal-digit 10)
+ decimal-digit)))
+
(defun char-code (char)
#!+sb-doc
"Return the integer code of CHAR."
@@ -156,41 +235,34 @@
"The argument must be a character object. GRAPHIC-CHAR-P returns T if the
argument is a printing character (space through ~ in ASCII), otherwise
returns NIL."
- (and (typep char 'base-char)
- (< 31
- (char-code (the base-char char))
- 127)))
+ (let ((n (char-code char)))
+ (or (< 31 n 127)
+ (< 159 n))))
(defun alpha-char-p (char)
#!+sb-doc
"The argument must be a character object. ALPHA-CHAR-P returns T if the
argument is an alphabetic character, A-Z or a-z; otherwise NIL."
- (let ((m (char-code char)))
- (or (< 64 m 91) (< 96 m 123))))
+ (< (ucd-general-category char) 5))
(defun upper-case-p (char)
#!+sb-doc
"The argument must be a character object; UPPER-CASE-P returns T if the
argument is an upper-case character, NIL otherwise."
- (< 64
- (char-code char)
- 91))
+ (= (ucd-value-0 char) 0))
(defun lower-case-p (char)
#!+sb-doc
"The argument must be a character object; LOWER-CASE-P returns T if the
argument is a lower-case character, NIL otherwise."
- (< 96
- (char-code char)
- 123))
+ (= (ucd-value-0 char) 1))
(defun both-case-p (char)
#!+sb-doc
"The argument must be a character object. BOTH-CASE-P returns T if the
argument is an alphabetic character and if the character exists in
both upper and lower case. For ASCII, this is the same as ALPHA-CHAR-P."
- (let ((m (char-code char)))
- (or (< 64 m 91) (< 96 m 123))))
+ (< (ucd-value-0 char) 3))
(defun digit-char-p (char &optional (radix 10.))
#!+sb-doc
@@ -208,14 +280,17 @@
;; Also check lower case a - z.
((and (>= (setq m (- m 32)) 10) (< m radix)) m)
;; Else, fail.
- (t nil))))
+ (t (let ((number (ucd-decimal-digit char)))
+ (when (and number (< number radix))
+ number))))))
(defun alphanumericp (char)
#!+sb-doc
"Given a character-object argument, ALPHANUMERICP returns T if the
argument is either numeric or alphabetic."
- (let ((m (char-code char)))
- (or (< 47 m 58) (< 64 m 91) (< 96 m 123))))
+ (let ((gc (ucd-general-category char)))
+ (or (< gc 5)
+ (= gc 12))))
(defun char= (character &rest more-characters)
#!+sb-doc
@@ -279,8 +354,11 @@
;;; which loses font, bits, and case info.
(defmacro equal-char-code (character)
- `(let ((ch (char-code ,character)))
- (if (< 96 ch 123) (- ch 32) ch)))
+ (let ((ch (gensym)))
+ `(let ((,ch ,character))
+ (if (= (ucd-value-0 ,ch) 0)
+ (ucd-value-1 ,ch)
+ (char-code ,ch)))))
(defun char-equal (character &rest more-characters)
#!+sb-doc
@@ -354,16 +432,17 @@
(defun char-upcase (char)
#!+sb-doc
- "Return CHAR converted to upper-case if that is possible."
- (if (lower-case-p char)
- (code-char (- (char-code char) 32))
+ "Return CHAR converted to upper-case if that is possible. Don't convert
+ lowercase eszet (U+DF)."
+ (if (= (ucd-value-0 char) 1)
+ (code-char (ucd-value-1 char))
char))
(defun char-downcase (char)
#!+sb-doc
"Return CHAR converted to lower-case if that is possible."
- (if (upper-case-p char)
- (code-char (+ (char-code char) 32))
+ (if (= (ucd-value-0 char) 0)
+ (code-char (ucd-value-1 char))
char))
(defun digit-char (weight &optional (radix 10))
|