| The Modular DocBook Stylesheets | ||
|---|---|---|
| Prev | DSSSL Library | Next |
(find-first-char string skipchars findchars #!optional (pos 0))
Finds first character in string that is in findchars, skipping all occurances of characters in skipchars. Search begins at pos. If no such characters are found, returns -1.
If skipchars is empty, skip anything not in findchars If skipchars is #f, skip nothing If findchars is empty, the first character not in skipchars is matched It is an error if findchars is not a string. It is an error if findchars is empty and skipchars is not a non-empty string.
Norman Walsh, <norm@berkshire.net>
(define (find-first-char string skipchars findchars #!optional (pos 0))
;; Find the first occurance of a character in a string
(let ((skiplist (if (string? skipchars)
(string->list skipchars)
'()))
(findlist (string->list findchars)))
(if (and (null? skiplist) (null? findlist))
;; this is an error
-2
(if (or (>= pos (string-length string)) (< pos 0))
-1
(let ((ch (string-ref string pos)))
(if (null? skiplist)
;; try to find first
(if (member ch findlist)
pos
(if (string? skipchars)
(find-first-char string
skipchars findchars (+ 1 pos))
-1))
;; try to skip first
(if (member ch skiplist)
(find-first-char string skipchars findchars (+ 1 pos))
(if (or (member ch findlist) (null? findlist))
pos
-1))))))))| Prev | Home | Next |
| file-extension | Up | has-ancestor-member? |
Copyright © 1997, 1998 Norman Walsh