1 ;;; copyright (c) 2004 knowledgeTools Int. GmbH
2 ;;; Author of this version: David Lichteblau <david@knowledgetools.de>
4 ;;; derived from runes.lisp, (c) copyright 1998,1999 by Gilbert Baumann
6 ;;; License: Lisp-LGPL (See file COPYING for details).
8 ;;; This code is free software; you can redistribute it and/or modify it
9 ;;; under the terms of the version 2.1 of the GNU Lesser General Public
10 ;;; License as published by the Free Software Foundation, as clarified
11 ;;; by the "Preamble to the Gnu Lesser General Public License" found in
14 ;;; This code is distributed in the hope that it will be useful,
15 ;;; but without any warranty; without even the implied warranty of
16 ;;; merchantability or fitness for a particular purpose. See the GNU
17 ;;; Lesser General Public License for more details.
19 ;;; Version 2.1 of the GNU Lesser General Public License is in the file
20 ;;; COPYING that was distributed with this file. If it is not present,
21 ;;; you can access it from http://www.gnu.org/copyleft/lesser.txt (until
22 ;;; superseded by a newer version) or write to the Free Software
23 ;;; Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
27 (deftype rune
() #-lispworks
'character
#+lispworks
'lw
:simple-char
)
28 (deftype rod
() '(vector rune
))
29 (deftype simple-rod
() '(simple-array rune
))
31 (definline rune
(rod index
)
34 (defun (setf rune
) (new rod index
)
35 (setf (char rod index
) new
))
37 (definline %rune
(rod index
)
38 (aref (the simple-string rod
) (the fixnum index
)))
40 (definline (setf %rune
) (new rod index
)
41 (setf (aref (the simple-string rod
) (the fixnum index
)) new
))
43 (defun rod-capitalize (rod)
46 (definline code-rune
(x) (code-char x
))
47 (definline rune-code
(x) (char-code x
))
49 (definline rune
= (x y
)
52 (defun rune-downcase (rune)
55 (definline rune-upcase
(rune)
58 (defun rune-upper-case-letter-p (rune)
61 (defun rune-lower-case-letter-p (rune)
64 (defun rune-equal (x y
)
67 (defun rod-downcase (rod)
68 (string-downcase rod
))
70 (defun rod-upcase (rod)
73 (definline white-space-rune-p
(char)
74 (or (char= char
#\tab
)
75 (char= char
#.
(code-char 10)) ;Linefeed
76 (char= char
#.
(code-char 13)) ;Carriage Return
77 (char= char
#\space
)))
79 (definline digit-rune-p
(char &optional
(radix 10))
80 (digit-char-p char radix
))
85 ((symbolp x
) (string x
))
86 ((characterp x
) (string x
))
87 ((vectorp x
) (coerce x
'string
))
88 ((integerp x
) (string (code-char x
)))
89 (t (error "Cannot convert ~S to a ~S" x
'rod
))))
94 (defun sloopy-rod-p (x)
98 (if (zerop (length x
))
100 (and (plusp (length y
)) (string= x y
))))
102 (defun rod-equal (x y
)
105 (definline make-rod
(size)
106 (make-string size
:element-type
'rune
))
108 (defun char-rune (char)
111 (defun rune-char (rune &optional default
)
112 (declare (ignore default
))
115 (defun rod-string (rod &optional
(default-char #\?))
116 (declare (ignore default-char
))
119 (defun string-rod (string)
124 (defun rune<= (rune &rest more-runes
)
126 for
(a b
) on
(cons rune more-runes
)
128 always
(char<= a b
)))
130 (defun rune>= (rune &rest more-runes
)
132 for
(a b
) on
(cons rune more-runes
)
134 always
(char>= a b
)))
139 (defun rod-subseq (source start
&optional
(end (length source
)))
140 (unless (stringp source
)
141 (error "~S is not of type ~S." source
'rod
))
142 (subseq source start end
))
144 (defun rod-subseq* (source start
&optional
(end (length source
)))
145 (rod-subseq source start end
))
147 (defun rod< (rod1 rod2
)