From: Chris Hanson Date: Sat, 4 Mar 2017 08:32:57 +0000 (-0800) Subject: Redefine the string-find-X procedures to take substring indices. X-Git-Tag: mit-scheme-pucked-9.2.12~196^2~15 X-Git-Url: https://birchwood-abbey.net/git?a=commitdiff_plain;h=e192523087eac98e1c94497898f81bff34b039d6;p=mit-scheme.git Redefine the string-find-X procedures to take substring indices. --- diff --git a/src/runtime/ustring.scm b/src/runtime/ustring.scm index 85e3aba56..ede4d7175 100644 --- a/src/runtime/ustring.scm +++ b/src/runtime/ustring.scm @@ -1430,30 +1430,36 @@ USA. ;;;;Backwards compatibility -(define (string-find-next-char string char) - (string-find-first-index (char=-predicate char) string)) +(define-integrable (string-find-maker finder key->predicate) + (lambda (string key #!optional start end) + (let* ((start (if (default-object? start) 0 start)) + (index + (finder (key->predicate key) + (string-slice string start end)))) + (and index + (fix:+ start index))))) + +(define string-find-next-char + (string-find-maker string-find-first-index char=-predicate)) -(define (string-find-next-char-ci string char) - (string-find-first-index (char-ci=-predicate char) string)) +(define string-find-next-char-ci + (string-find-maker string-find-first-index char-ci=-predicate)) -(define (string-find-next-char-in-set string char-set) - (string-find-first-index (char-set-predicate char-set) string)) +(define string-find-next-char-in-set + (string-find-maker string-find-first-index char-set-predicate)) -(define (string-find-previous-char string char) - (string-find-last-index (char=-predicate char) string)) +(define string-find-previous-char + (string-find-maker string-find-last-index char=-predicate)) -(define (string-find-previous-char-ci string char) - (string-find-last-index (char-ci=-predicate char) string)) +(define string-find-previous-char-ci + (string-find-maker string-find-last-index char-ci=-predicate)) -(define (string-find-previous-char-in-set string char-set) - (string-find-last-index (char-set-predicate char-set) string)) +(define string-find-previous-char-in-set + (string-find-maker string-find-last-index char-set-predicate)) (define-integrable (substring-find-maker string-find) (lambda (string start end key) - (let* ((slice (string-slice string start end)) - (index (string-find slice key))) - (and index - (fix:+ start index))))) + (string-find string key start end))) (define substring-find-next-char (substring-find-maker string-find-next-char))