kommentaraenderungen
[closure-common.git] / characters.lisp
blob58674f5ca2768cff35e944b15c6e5f6d56834328
1 ;;; copyright (c) 2004 knowledgeTools Int. GmbH
2 ;;; Author of this version: David Lichteblau <david@knowledgetools.de>
3 ;;;
4 ;;; derived from runes.lisp, (c) copyright 1998,1999 by Gilbert Baumann
5 ;;;
6 ;;; License: LLGPL (See file COPYING for details).
7 ;;;
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
12 ;;; the file COPYING.
13 ;;;
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.
18 ;;;
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
25 (in-package :runes)
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)
32 (char 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)
44 (string-upcase rod))
46 (definline code-rune (x) (code-char x))
47 (definline rune-code (x) (char-code x))
49 (definline rune= (x y)
50 (char= x y))
52 (defun rune-downcase (rune)
53 (char-downcase rune))
55 (definline rune-upcase (rune)
56 (char-upcase rune))
58 (defun rune-upper-case-letter-p (rune)
59 (upper-case-p rune))
61 (defun rune-lower-case-letter-p (rune)
62 (lower-case-p rune))
64 (defun rune-equal (x y)
65 (char-equal x y))
67 (defun rod-downcase (rod)
68 (string-downcase rod))
70 (defun rod-upcase (rod)
71 (string-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))
82 (defun rod (x)
83 (cond
84 ((stringp x) x)
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))))
91 (defun runep (x)
92 (characterp x))
94 (defun sloopy-rod-p (x)
95 (stringp x))
97 (defun rod= (x y)
98 (string= x y))
100 (defun rod-equal (x y)
101 (string-equal x y))
103 (definline make-rod (size)
104 (make-string size :element-type 'rune))
106 (defun char-rune (char)
107 char)
109 (defun rune-char (rune &optional default)
110 (declare (ignore default))
111 rune)
113 (defun rod-string (rod &optional (default-char #\?))
114 (declare (ignore default-char))
115 rod)
117 (defun string-rod (string)
118 string)
120 ;;;;
122 (defun rune<= (rune &rest more-runes)
123 (loop
124 for (a b) on (cons rune more-runes)
125 while b
126 always (char<= a b)))
128 (defun rune>= (rune &rest more-runes)
129 (loop
130 for (a b) on (cons rune more-runes)
131 while b
132 always (char>= a b)))
134 (defun rodp (object)
135 (stringp object))
137 (defun rod-subseq (source start &optional (end (length source)))
138 (unless (stringp source)
139 (error "~S is not of type ~S." source 'rod))
140 (subseq source start end))
142 (defun rod-subseq* (source start &optional (end (length source)))
143 (rod-subseq source start end))
145 (defun rod< (rod1 rod2)
146 (string< rod1 rod2))