1
Fork 0
mirror of https://git.savannah.gnu.org/git/guile.git synced 2025-04-30 03:40:34 +02:00

In fold-matches, set regexp/notbol unless matching string start.

* module/ice-9/regex.scm (fold-matches): Set regexp/notbol if the
  starting position is nonzero.
* test-suite/tests/regexp.test (fold-matches): Check that when
  matching /^foo/ against "foofoofoofoo", only one match results.

Signed-off-by: Ludovic Courtès <ludo@gnu.org>
This commit is contained in:
Chris K. Jester-Young 2012-09-16 02:27:19 -04:00 committed by Ludovic Courtès
parent b6aedd68bc
commit d6e1c8bfdb
2 changed files with 10 additions and 2 deletions

View file

@ -172,8 +172,9 @@
(let loop ((start 0)
(value init)
(abuts #f)) ; True if start abuts a previous match.
(define bol (if (zero? start) 0 regexp/notbol))
(let ((m (if (> start (string-length string)) #f
(regexp-exec regexp string start flags))))
(regexp-exec regexp string start (logior flags bol)))))
(cond
((not m) value)
((and (= (match:start m) (match:end m)) abuts)

View file

@ -132,7 +132,14 @@
(lambda (match result)
(cons (match:substring match)
result))
(logior regexp/notbol regexp/noteol)))))
(logior regexp/notbol regexp/noteol))))
(pass-if "regexp/notbol is set correctly"
(equal? '("foo")
(fold-matches "^foo" "foofoofoofoo" '()
(lambda (match result)
(cons (match:substring match)
result))))))
;;;