From e192523087eac98e1c94497898f81bff34b039d6 Mon Sep 17 00:00:00 2001 From: Chris Hanson Date: Sat, 4 Mar 2017 00:32:57 -0800 Subject: [PATCH] Redefine the string-find-X procedures to take substring indices. --- src/runtime/ustring.scm | 38 ++++++++++++++++++++++---------------- 1 file changed, 22 insertions(+), 16 deletions(-) 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)) -- 2.25.1