3 ;; JSCL is free software: you can redistribute it and/or
4 ;; modify it under the terms of the GNU General Public License as
5 ;; published by the Free Software Foundation, either version 3 of the
6 ;; License, or (at your option) any later version.
8 ;; JSCL is distributed in the hope that it will be useful, but
9 ;; WITHOUT ANY WARRANTY; without even the implied warranty of
10 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 ;; General Public License for more details.
13 ;; You should have received a copy of the GNU General Public License
14 ;; along with JSCL. If not, see <http://www.gnu.org/licenses/>.
19 (defun string-length (string)
20 (storage-vector-size string))
22 (defun make-string (n &key initial-element)
23 (make-array n :element-type 'character :initial-element initial-element))
25 (defun char (string index)
26 (unless (stringp string) (error "~S is not a string" string))
27 (storage-vector-ref string index))
31 ((symbolp x) (symbol-name x))
32 (t (make-string 1 :initial-element x))))
34 (defun string= (s1 s2)
35 (let* ((s1 (string s1))
38 (when (= (length s2) n)
40 (unless (char= (char s1 i) (char s2 i))
41 (return-from string= nil))))))
43 (defun string< (s1 s2)
44 (let ((len-1 (length s1))
46 (cond ((= len-2 0) nil)
48 (t (dotimes (i len-1 nil)
49 (when (char< (char s1 i) (char s2 i))
50 (return-from string< i))
51 (when (and (= i (1- len-1)) (> len-2 len-1))
52 (return-from string< (1+ i))))))))
54 (define-setf-expander char (string index)
55 (let ((g!string (gensym))
58 (values (list g!string g!index)
61 `(aset ,g!string ,g!index ,g!value)
62 `(char ,g!string ,g!index))))
65 (defun concat-two (string1 string2)
66 (let* ((len1 (length string1))
67 (len2 (length string2))
68 (string (make-array (+ len1 len2) :element-type 'character))
71 (aset string i (char string1 j))
74 (aset string i (char string2 j))
78 (defun concat (&rest strs)
79 (!reduce #'concat-two strs ""))
82 (defun string-upcase (string)
83 (let ((new (make-string (length string))))
84 (dotimes (i (length string) new)
85 (aset new i (char-upcase (char string i))))))
87 (defun string-downcase (string)
88 (let ((new (make-string (length string))))
89 (dotimes (i (length string) new)
90 (aset new i (char-downcase (char string i))))))