(loop (fix:+ index 1)))
(%regexp-match regexp string index end))))
+(define (regexp-search-all re string #!optional start end)
+ (guarantee nfc-string? string 'regexp-search)
+ (let* ((end (fix:end-index end (string-length string) 'regexp-search))
+ (start (fix:start-index start end 'regexp-search)))
+ (%regexp-search-all (regexp re) string start end)))
+
+(define (%regexp-search-all regexp string start end)
+ (let loop ((index start))
+ (let ((match (%regexp-search regexp string index end)))
+ (if match
+ (cons match (loop (regexp-match-submatch-start match 0)))
+ '()))))
+\f
(define-record-type <regexp-match>
(make-regexp-match group0 groups)
regexp-match?
(start (fix:start-index start end 'regexp-replace-all))
(regexp (regexp re)))
- (define (find-matches index)
- (let ((match (%regexp-search regexp string index end)))
- (if match
- (cons match
- (find-matches (regexp-match-submatch-start match 0)))
- '())))
-
(define (subst-matches matches start)
(if (pair? matches)
(let ((match (car matches))
(subst-matches matches (regexp-match-submatch-end match 0))))
'()))
- (let ((matches (find-matches start)))
+ (let ((matches (%regexp-search regexp string start end)))
(if (pair? matches)
(string-append* (subst-matches matches start))
(substring string start end)))))
((eq? 'pre subst)
(string-slice string start (regexp-match-submatch-start match 0)))
((eq? 'post subst)
- (string-slice starting (regexp-match-submatch-end match 0) end))
+ (string-slice string (regexp-match-submatch-end match 0) end))
(else
(or (regexp-match-submatch match subst) ""))))
(or (string? object)
(regexp-match-key? object)
(and (list? object)
- (every subst-template? object))))
+ (every regexp-match-replace-template? object))))
(register-predicate! regexp-match-replace-template?
'regexp-match-replace-template)