| 1 | ;;; strings.lisp | 
|---|
| 2 | ;;; | 
|---|
| 3 | ;;; Copyright (C) 2003-2005 Peter Graves | 
|---|
| 4 | ;;; $Id: strings.lisp 11391 2008-11-15 22:38:34Z vvoutilainen $ | 
|---|
| 5 | ;;; | 
|---|
| 6 | ;;; This program is free software; you can redistribute it and/or | 
|---|
| 7 | ;;; modify it under the terms of the GNU General Public License | 
|---|
| 8 | ;;; as published by the Free Software Foundation; either version 2 | 
|---|
| 9 | ;;; of the License, or (at your option) any later version. | 
|---|
| 10 | ;;; | 
|---|
| 11 | ;;; This program is distributed in the hope that it will be useful, | 
|---|
| 12 | ;;; but WITHOUT ANY WARRANTY; without even the implied warranty of | 
|---|
| 13 | ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the | 
|---|
| 14 | ;;; GNU General Public License for more details. | 
|---|
| 15 | ;;; | 
|---|
| 16 | ;;; You should have received a copy of the GNU General Public License | 
|---|
| 17 | ;;; along with this program; if not, write to the Free Software | 
|---|
| 18 | ;;; Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA. | 
|---|
| 19 | ;;; | 
|---|
| 20 | ;;; As a special exception, the copyright holders of this library give you | 
|---|
| 21 | ;;; permission to link this library with independent modules to produce an | 
|---|
| 22 | ;;; executable, regardless of the license terms of these independent | 
|---|
| 23 | ;;; modules, and to copy and distribute the resulting executable under | 
|---|
| 24 | ;;; terms of your choice, provided that you also meet, for each linked | 
|---|
| 25 | ;;; independent module, the terms and conditions of the license of that | 
|---|
| 26 | ;;; module.  An independent module is a module which is not derived from | 
|---|
| 27 | ;;; or based on this library.  If you modify this library, you may extend | 
|---|
| 28 | ;;; this exception to your version of the library, but you are not | 
|---|
| 29 | ;;; obligated to do so.  If you do not wish to do so, delete this | 
|---|
| 30 | ;;; exception statement from your version. | 
|---|
| 31 |  | 
|---|
| 32 | (in-package #:system) | 
|---|
| 33 |  | 
|---|
| 34 | (defun string-upcase (string &key (start 0) end) | 
|---|
| 35 |   (%string-upcase string start end)) | 
|---|
| 36 |  | 
|---|
| 37 | (defun string-downcase (string &key (start 0) end) | 
|---|
| 38 |   (%string-downcase string start end)) | 
|---|
| 39 |  | 
|---|
| 40 | (defun string-capitalize (string &key (start 0) end) | 
|---|
| 41 |   (%string-capitalize string start end)) | 
|---|
| 42 |  | 
|---|
| 43 | (defun nstring-upcase (string &key (start 0) end) | 
|---|
| 44 |   (%nstring-upcase string start end)) | 
|---|
| 45 |  | 
|---|
| 46 | (defun nstring-downcase (string &key (start 0) end) | 
|---|
| 47 |   (%nstring-downcase string start end)) | 
|---|
| 48 |  | 
|---|
| 49 | (defun nstring-capitalize (string &key (start 0) end) | 
|---|
| 50 |   (%nstring-capitalize string start end)) | 
|---|
| 51 |  | 
|---|
| 52 | (defun string= (string1 string2 &key (start1 0) end1 (start2 0) end2) | 
|---|
| 53 |   (%string= string1 string2 start1 end1 start2 end2)) | 
|---|
| 54 |  | 
|---|
| 55 | (defun string/= (string1 string2 &key (start1 0) end1 (start2 0) end2) | 
|---|
| 56 |   (let* ((string1 (string string1)) | 
|---|
| 57 |          (string2 (string string2)) | 
|---|
| 58 |          (end1 (or end1 (length string1))) | 
|---|
| 59 |          (end2 (or end2 (length string2)))) | 
|---|
| 60 |     (%string/= string1 string2 start1 end1 start2 end2))) | 
|---|
| 61 |  | 
|---|
| 62 | (defun string-equal (string1 string2 &key (start1 0) end1 (start2 0) end2) | 
|---|
| 63 |   (let* ((string1 (string string1)) | 
|---|
| 64 |          (string2 (string string2)) | 
|---|
| 65 |          (end1 (or end1 (length string1))) | 
|---|
| 66 |          (end2 (or end2 (length string2)))) | 
|---|
| 67 |     (%string-equal string1 string2 start1 end1 start2 end2))) | 
|---|
| 68 |  | 
|---|
| 69 | (defun string-not-equal (string1 string2 &key (start1 0) end1 (start2 0) end2) | 
|---|
| 70 |   (let* ((string1 (string string1)) | 
|---|
| 71 |          (string2 (string string2)) | 
|---|
| 72 |          (end1 (or end1 (length string1))) | 
|---|
| 73 |          (end2 (or end2 (length string2)))) | 
|---|
| 74 |     (%string-not-equal string1 string2 start1 end1 start2 end2))) | 
|---|
| 75 |  | 
|---|
| 76 | (defun string< (string1 string2 &key (start1 0) end1 (start2 0) end2) | 
|---|
| 77 |   (let* ((string1 (string string1)) | 
|---|
| 78 |          (string2 (string string2)) | 
|---|
| 79 |          (end1 (or end1 (length string1))) | 
|---|
| 80 |          (end2 (or end2 (length string2)))) | 
|---|
| 81 |     (%string< string1 string2 start1 end1 start2 end2))) | 
|---|
| 82 |  | 
|---|
| 83 | (defun string> (string1 string2 &key (start1 0) end1 (start2 0) end2) | 
|---|
| 84 |   (let* ((string1 (string string1)) | 
|---|
| 85 |          (string2 (string string2)) | 
|---|
| 86 |          (end1 (or end1 (length string1))) | 
|---|
| 87 |          (end2 (or end2 (length string2)))) | 
|---|
| 88 |     (%string> string1 string2 start1 end1 start2 end2))) | 
|---|
| 89 |  | 
|---|
| 90 | (defun string<= (string1 string2 &key (start1 0) end1 (start2 0) end2) | 
|---|
| 91 |   (let* ((string1 (string string1)) | 
|---|
| 92 |          (string2 (string string2)) | 
|---|
| 93 |          (end1 (or end1 (length string1))) | 
|---|
| 94 |          (end2 (or end2 (length string2)))) | 
|---|
| 95 |     (%string<= string1 string2 start1 end1 start2 end2))) | 
|---|
| 96 |  | 
|---|
| 97 | (defun string>= (string1 string2 &key (start1 0) end1 (start2 0) end2) | 
|---|
| 98 |   (let* ((string1 (string string1)) | 
|---|
| 99 |          (string2 (string string2)) | 
|---|
| 100 |          (end1 (or end1 (length string1))) | 
|---|
| 101 |          (end2 (or end2 (length string2)))) | 
|---|
| 102 |     (%string>= string1 string2 start1 end1 start2 end2))) | 
|---|
| 103 |  | 
|---|
| 104 | (defun string-lessp (string1 string2 &key (start1 0) end1 (start2 0) end2) | 
|---|
| 105 |   (let* ((string1 (string string1)) | 
|---|
| 106 |          (string2 (string string2)) | 
|---|
| 107 |          (end1 (or end1 (length string1))) | 
|---|
| 108 |          (end2 (or end2 (length string2)))) | 
|---|
| 109 |     (%string-lessp string1 string2 start1 end1 start2 end2))) | 
|---|
| 110 |  | 
|---|
| 111 | (defun string-greaterp (string1 string2 &key (start1 0) end1 (start2 0) end2) | 
|---|
| 112 |   (let* ((string1 (string string1)) | 
|---|
| 113 |          (string2 (string string2)) | 
|---|
| 114 |          (end1 (or end1 (length string1))) | 
|---|
| 115 |          (end2 (or end2 (length string2)))) | 
|---|
| 116 |     (%string-greaterp string1 string2 start1 end1 start2 end2))) | 
|---|
| 117 |  | 
|---|
| 118 | (defun string-not-lessp (string1 string2 &key (start1 0) end1 (start2 0) end2) | 
|---|
| 119 |   (let* ((string1 (string string1)) | 
|---|
| 120 |          (string2 (string string2)) | 
|---|
| 121 |          (end1 (or end1 (length string1))) | 
|---|
| 122 |          (end2 (or end2 (length string2)))) | 
|---|
| 123 |     (%string-not-lessp string1 string2 start1 end1 start2 end2))) | 
|---|
| 124 |  | 
|---|
| 125 | (defun string-not-greaterp (string1 string2 &key (start1 0) end1 (start2 0) end2) | 
|---|
| 126 |   (let* ((string1 (string string1)) | 
|---|
| 127 |          (string2 (string string2)) | 
|---|
| 128 |          (end1 (or end1 (length string1))) | 
|---|
| 129 |          (end2 (or end2 (length string2)))) | 
|---|
| 130 |     (%string-not-greaterp string1 string2 start1 end1 start2 end2))) | 
|---|
| 131 |  | 
|---|
| 132 |  | 
|---|
| 133 | ;;; STRING-LEFT-TRIM, STRING-RIGHT-TRIM, STRING-TRIM (from OpenMCL) | 
|---|
| 134 |  | 
|---|
| 135 | (defun string-left-trim (char-bag string &aux end) | 
|---|
| 136 |   "Given a set of characters (a list or string) and a string, returns | 
|---|
| 137 |    a copy of the string with the characters in the set removed from the | 
|---|
| 138 |    left end." | 
|---|
| 139 |   (setq string (string string)) | 
|---|
| 140 |   (setq end (length string)) | 
|---|
| 141 |   (do ((index 0 (+ index 1))) | 
|---|
| 142 |       ((or (= index end) (not (find (aref string index) char-bag))) | 
|---|
| 143 |        (subseq string index end)))) | 
|---|
| 144 |  | 
|---|
| 145 | (defun string-right-trim (char-bag string &aux end) | 
|---|
| 146 |   "Given a set of characters (a list or string) and a string, returns | 
|---|
| 147 |    a copy of the string with the characters in the set removed from the | 
|---|
| 148 |    right end." | 
|---|
| 149 |   (setq string (string string)) | 
|---|
| 150 |   (setq end (length string)) | 
|---|
| 151 |   (do ((index (- end 1) (- index 1))) | 
|---|
| 152 |       ((or (< index 0) (not (find (aref string index) char-bag))) | 
|---|
| 153 |        (subseq string 0 (+ index 1))))) | 
|---|
| 154 |  | 
|---|
| 155 | (defun string-trim (char-bag string &aux end) | 
|---|
| 156 |   "Given a set of characters (a list or string) and a string, returns a | 
|---|
| 157 |    copy of the string with the characters in the set removed from both | 
|---|
| 158 |    ends." | 
|---|
| 159 |   (setq string (string string)) | 
|---|
| 160 |   (setq end (length string)) | 
|---|
| 161 |   (let (left-end right-end) | 
|---|
| 162 |     (do ((index 0 (+ index 1))) | 
|---|
| 163 |         ((or (= index end) (not (find (aref string index) char-bag))) | 
|---|
| 164 |          (setq left-end index))) | 
|---|
| 165 |     (do ((index (- end 1) (- index 1))) | 
|---|
| 166 |         ((or (< index left-end) (not (find (aref string index) char-bag))) | 
|---|
| 167 |          (setq right-end index))) | 
|---|
| 168 |     (subseq string left-end (+ right-end 1)))) | 
|---|