From eec5aaa0b45ed65da19383a3d83bbb0d8d1258b3 Mon Sep 17 00:00:00 2001 From: Alex Shinn Date: Mon, 15 Jul 2013 07:20:17 +0900 Subject: [PATCH] Adding optional start/end params to string-find[-right]. --- lib/chibi/string.scm | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/lib/chibi/string.scm b/lib/chibi/string.scm index 5ee2bd1b..f21c4ba8 100644 --- a/lib/chibi/string.scm +++ b/lib/chibi/string.scm @@ -29,7 +29,9 @@ (define (string-find str x . o) (let ((pred (make-char-predicate x)) - (end (string-cursor-end str))) + (end (if (and (pair? o) (pair? (cdr o))) + (cadr o) + (string-cursor-end str)))) (let lp ((i (if (pair? o) (car o) (string-cursor-start str)))) (cond ((string-cursor>=? i end) end) ((pred (string-cursor-ref str i)) i) @@ -37,10 +39,12 @@ (define (string-find-right str x . o) (let ((pred (make-char-predicate x)) - (end (string-cursor-start str))) - (let lp ((i (if (pair? o) (car o) (string-cursor-end str)))) + (start (if (pair? o) (car o) (string-cursor-start str)))) + (let lp ((i (if (and (pair? o) (pair? (cdr o))) + (cadr o) + (string-cursor-end str)))) (let ((i2 (string-cursor-prev str i))) - (cond ((string-cursor