Ignore:
Timestamp:
08/11/03 16:31:37 (18 years ago)
Author:
piso
Message:

STRING-LEFT-TRIM, STRING-RIGHT-TRIM, STRING-TRIM

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/j/src/org/armedbear/lisp/strings.lisp

    r2707 r3330  
    22;;;
    33;;; Copyright (C) 2003 Peter Graves
    4 ;;; $Id: strings.lisp,v 1.5 2003-07-02 15:27:43 piso Exp $
     4;;; $Id: strings.lisp,v 1.6 2003-08-11 16:31:37 piso Exp $
    55;;;
    66;;; This program is free software; you can redistribute it and/or
     
    121121         (end2 (or end2 (length string2))))
    122122    (%string-not-greaterp string1 string2 start1 end1 start2 end2)))
     123
     124
     125;;; STRING-LEFT-TRIM, STRING-RIGHT-TRIM, STRING-TRIM (from OpenMCL)
     126
     127(defun string-left-trim (char-bag string &aux end)
     128  "Given a set of characters (a list or string) and a string, returns
     129   a copy of the string with the characters in the set removed from the
     130   left end."
     131  (setq string (string string))
     132  (setq end (length string))
     133  (do ((index 0 (+ index 1)))
     134      ((or (= index end) (not (find (aref string index) char-bag)))
     135       (subseq string index end))))
     136
     137(defun string-right-trim (char-bag string &aux end)
     138  "Given a set of characters (a list or string) and a string, returns
     139   a copy of the string with the characters in the set removed from the
     140   right end."
     141  (setq string (string string))
     142  (setq end (length string))
     143  (do ((index (- end 1) (- index 1)))
     144      ((or (< index 0) (not (find (aref string index) char-bag)))
     145       (subseq string 0 (+ index 1)))))
     146
     147(defun string-trim (char-bag string &aux end)
     148  "Given a set of characters (a list or string) and a string, returns a
     149   copy of the string with the characters in the set removed from both
     150   ends."
     151  (setq string (string string))
     152  (setq end (length string))
     153  (let ((left-end) (right-end))
     154    (do ((index 0 (+ index 1)))
     155        ((or (= index end) (not (find (aref string index) char-bag)))
     156         (setq left-end index)))
     157    (do ((index (- end 1) (- index 1)))
     158        ((or (< index left-end) (not (find (aref string index) char-bag)))
     159         (setq right-end index)))
     160    (subseq string left-end (+ right-end 1))))
Note: See TracChangeset for help on using the changeset viewer.