summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLudovic Courtès <ludo@gnu.org>2008-09-25 21:07:06 +0200
committerLudovic Courtès <ludo@gnu.org>2008-09-25 21:07:06 +0200
commitc6333102655783c91b3ce733dde7ce79b362e1cf (patch)
treef48f71b0862b4928c2bde8eccd23edcaee1b98ce
parentfb2f8886c4d537b0c7d3e9e78a8d4e5e272a36f4 (diff)
downloadguile-c6333102655783c91b3ce733dde7ce79b362e1cf.tar.gz
Fix handling of the FLAGS argument in `fold-matches'.
* ice-9/regex.scm (fold-matches): If FLAGS is non-null, use `(car flags)', not `flags'. * test-suite/tests/regexp.test ("fold-matches"): New test prefix. * NEWS: Update.
-rw-r--r--NEWS1
-rw-r--r--ice-9/regex.scm4
-rw-r--r--test-suite/tests/regexp.test25
3 files changed, 27 insertions, 3 deletions
diff --git a/NEWS b/NEWS
index b55620075..baa176815 100644
--- a/NEWS
+++ b/NEWS
@@ -65,6 +65,7 @@ available: Guile is now always configured in "maintainer mode".
** `symbol->string' now returns a read-only string, as per R5RS
** Literal strings as returned by `read' are now read-only, as per R5RS
+** Fix incorrect handling of the FLAGS argument of `fold-matches'
** `guile-config link' now prints `-L$libdir' before `-lguile'
** Fix memory corruption involving GOOPS' `class-redefinition'
** Fix possible deadlock in `mutex-lock'
diff --git a/ice-9/regex.scm b/ice-9/regex.scm
index 21beb1665..61937d04f 100644
--- a/ice-9/regex.scm
+++ b/ice-9/regex.scm
@@ -1,4 +1,4 @@
-;;;; Copyright (C) 1997, 1999, 2001, 2004, 2005, 2006 Free Software Foundation, Inc.
+;;;; Copyright (C) 1997, 1999, 2001, 2004, 2005, 2006, 2008 Free Software Foundation, Inc.
;;;;
;;;; This library is free software; you can redistribute it and/or
;;;; modify it under the terms of the GNU Lesser General Public
@@ -178,7 +178,7 @@
(define (fold-matches regexp string init proc . flags)
(let ((regexp (if (regexp? regexp) regexp (make-regexp regexp)))
- (flags (if (null? flags) 0 flags)))
+ (flags (if (null? flags) 0 (car flags))))
(let loop ((start 0)
(value init)
(abuts #f)) ; True if start abuts a previous match.
diff --git a/test-suite/tests/regexp.test b/test-suite/tests/regexp.test
index 3050af39b..0ca0203b6 100644
--- a/test-suite/tests/regexp.test
+++ b/test-suite/tests/regexp.test
@@ -1,7 +1,7 @@
;;;; regexp.test --- test Guile's regular expression functions -*- scheme -*-
;;;; Jim Blandy <jimb@red-bean.com> --- September 1999
;;;;
-;;;; Copyright (C) 1999, 2004, 2006, 2007 Free Software Foundation, Inc.
+;;;; Copyright (C) 1999, 2004, 2006, 2007, 2008 Free Software Foundation, Inc.
;;;;
;;;; This program is free software; you can redistribute it and/or modify
;;;; it under the terms of the GNU General Public License as published by
@@ -103,6 +103,29 @@
(regexp-exec re "aaaabbbb" 0 'bogus-flags-arg))))
;;;
+;;; fold-matches
+;;;
+
+(with-test-prefix "fold-matches"
+
+ (pass-if "without flags"
+ (equal? '("hello")
+ (fold-matches "^[a-z]+$" "hello" '()
+ (lambda (match result)
+ (cons (match:substring match)
+ result)))))
+
+ (pass-if "with flags"
+ ;; Prior to 1.8.6, passing an additional flag would not work.
+ (null?
+ (fold-matches "^[a-z]+$" "hello" '()
+ (lambda (match result)
+ (cons (match:substring match)
+ result))
+ (logior regexp/notbol regexp/noteol)))))
+
+
+;;;
;;; regexp-quote
;;;