anaphora.lisp: Rewrite `asetf' to use `with-places/gensyms'.
[lisp] / str.lisp
index 104c85a..a943bae 100644 (file)
--- a/str.lisp
+++ b/str.lisp
 ;;; it under the terms of the GNU General Public License as published by
 ;;; the Free Software Foundation; either version 2 of the License, or
 ;;; (at your option) any later version.
-;;; 
+;;;
 ;;; This program is distributed in the hope that it will be useful,
 ;;; but WITHOUT ANY WARRANTY; without even the implied warranty of
 ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 ;;; GNU General Public License for more details.
-;;; 
+;;;
 ;;; You should have received a copy of the GNU General Public License
 ;;; along with this program; if not, write to the Free Software Foundation,
 ;;; Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 
 (defpackage #:mdw.str
   (:use #:common-lisp #:mdw.base)
-  (:export #:join-strings #:str-next-word #:str-split-words))
+  (:export #:join-strings #:str-next-word #:str-split-words
+          #:str-beginsp #:str-endsp))
 (in-package #:mdw.str)
 
 (defun join-strings (del strs)
@@ -36,7 +37,7 @@
   (with-output-to-string (s)
     (when strs
       (loop
-        (princ (stringify (pop strs)) s)
+       (princ (stringify (pop strs)) s)
        (unless strs
          (return))
        (princ del s)))))
         (incf n)))
     (nreverse l)))
 
+(declaim (inline str-beginsp))
+(defun str-beginsp (string prefix &key (start1 0) end1 (start2 0) end2)
+  "Returns true if STRING (or the appropriate substring of it) begins with
+   PREFIX."
+  (setf-default end1 (length string)
+               end2 (length prefix))
+  (let ((strlen (- end1 start1))
+       (prelen (- end2 start2)))
+    (and (>= strlen prelen)
+        (string= string prefix
+                 :start1 start1 :end1 (+ start1 prelen)
+                 :start2 start2 :end2 end2))))
+
+(declaim (inline str-endsp))
+(defun str-endsp (string suffix &key (start1 0) end1 (start2 0) end2)
+  "Returns true if STRING (or the appropriate substring of it) ends with
+   SUFFIX."
+  (setf-default end1 (length string)
+               end2 (length suffix))
+  (let ((strlen (- end1 start1))
+       (suflen (- end2 start2)))
+    (and (>= strlen suflen)
+        (string= string suffix
+                 :start1 (- end1 suflen) :end1 end1
+                 :start2 start2 :end2 end2))))
+
 ;;;----- That's all, folks --------------------------------------------------