* [PATCH] In fold-matches, set regexp/notbol unless matching string start.
@ 2012-09-16 6:27 Chris K. Jester-Young
2012-09-26 21:46 ` Ludovic Courtès
0 siblings, 1 reply; 2+ messages in thread
From: Chris K. Jester-Young @ 2012-09-16 6:27 UTC (permalink / raw)
To: guile-devel
* 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.
---
module/ice-9/regex.scm | 3 ++-
test-suite/tests/regexp.test | 9 ++++++++-
2 files changed, 10 insertions(+), 2 deletions(-)
diff --git a/module/ice-9/regex.scm b/module/ice-9/regex.scm
index f7b94b7..08ae2c2 100644
--- a/module/ice-9/regex.scm
+++ b/module/ice-9/regex.scm
@@ -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)
diff --git a/test-suite/tests/regexp.test b/test-suite/tests/regexp.test
index ef59465..d549df2 100644
--- a/test-suite/tests/regexp.test
+++ b/test-suite/tests/regexp.test
@@ -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))))))
;;;
--
1.7.9.5
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH] In fold-matches, set regexp/notbol unless matching string start.
2012-09-16 6:27 [PATCH] In fold-matches, set regexp/notbol unless matching string start Chris K. Jester-Young
@ 2012-09-26 21:46 ` Ludovic Courtès
0 siblings, 0 replies; 2+ messages in thread
From: Ludovic Courtès @ 2012-09-26 21:46 UTC (permalink / raw)
To: guile-devel
"Chris K. Jester-Young" <cky944@gmail.com> skribis:
> * 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.
> ---
> module/ice-9/regex.scm | 3 ++-
> test-suite/tests/regexp.test | 9 ++++++++-
> 2 files changed, 10 insertions(+), 2 deletions(-)
Applied, thanks!
Ludo’.
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2012-09-26 21:46 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-09-16 6:27 [PATCH] In fold-matches, set regexp/notbol unless matching string start Chris K. Jester-Young
2012-09-26 21:46 ` Ludovic Courtès
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).