From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: "Chris K. Jester-Young" Newsgroups: gmane.lisp.guile.devel Subject: [PATCH] In fold-matches, set regexp/notbol unless matching string start. Date: Sun, 16 Sep 2012 02:27:19 -0400 Message-ID: <20120916062719.GA20685@yarrow> NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: ger.gmane.org 1347777726 7623 80.91.229.3 (16 Sep 2012 06:42:06 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Sun, 16 Sep 2012 06:42:06 +0000 (UTC) To: guile-devel@gnu.org Original-X-From: guile-devel-bounces+guile-devel=m.gmane.org@gnu.org Sun Sep 16 08:42:10 2012 Return-path: Envelope-to: guile-devel@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by plane.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1TD8YT-0001f2-Kf for guile-devel@m.gmane.org; Sun, 16 Sep 2012 08:42:09 +0200 Original-Received: from localhost ([::1]:36399 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TD8YP-0005Jf-Nn for guile-devel@m.gmane.org; Sun, 16 Sep 2012 02:42:05 -0400 Original-Received: from eggs.gnu.org ([208.118.235.92]:50382) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TD8YM-0005BA-NL for guile-devel@gnu.org; Sun, 16 Sep 2012 02:42:03 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1TD8Kj-0008UV-LR for guile-devel@gnu.org; Sun, 16 Sep 2012 02:27:58 -0400 Original-Received: from mail-qa0-f48.google.com ([209.85.216.48]:57346) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TD8Kj-0008UR-Hd for guile-devel@gnu.org; Sun, 16 Sep 2012 02:27:57 -0400 Original-Received: by qady1 with SMTP id y1so1075840qad.0 for ; Sat, 15 Sep 2012 23:27:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=date:from:to:subject:message-id:mail-followup-to:mime-version :content-type:content-disposition:user-agent; bh=VpUvpQG/OiVlGANfCZCremWepMDItuQSpB8rdiiE6/Y=; b=c3WV3IFEZP34B1EsIFj1x8htyxcMWTI+OCZrAPFHDet77IffX1K3ji15ZqmFRUoMzO V3YHyxfSBbiBQGAa2Iyq3G8OHbFot0Mv3+VlTS0bZmbuX0OwOVmL2t1vGp2L9f1cpvVj L99l0Z4mmtm8tiG+rHV9z0Bu5NEJde3XyeIcJBq2RCB7dycfwGnOBToI1QgiBELsMor6 7/JZpAdgW1WMgVn8RcFf1m4sxS3mpRmLgU3S3lDXT83BZAAnzasq+s0yS0mq52xhexTv BDd13JR9Kq69AvIVLo422qSwFwODoGat62yaa/2uBlOYzwKkzky4NaKObWNvafwrCL/t 8OzQ== Original-Received: by 10.229.135.149 with SMTP id n21mr5004087qct.131.1347776876775; Sat, 15 Sep 2012 23:27:56 -0700 (PDT) Original-Received: from yarrow (cpe-069-134-140-185.nc.res.rr.com. [69.134.140.185]) by mx.google.com with ESMTPS id k6sm9866237qac.0.2012.09.15.23.27.55 (version=SSLv3 cipher=OTHER); Sat, 15 Sep 2012 23:27:56 -0700 (PDT) Mail-Followup-To: guile-devel@gnu.org Content-Disposition: inline User-Agent: Mutt/1.5.21 (2010-09-15) X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 209.85.216.48 X-BeenThere: guile-devel@gnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: "Developers list for Guile, the GNU extensibility library" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: guile-devel-bounces+guile-devel=m.gmane.org@gnu.org Original-Sender: guile-devel-bounces+guile-devel=m.gmane.org@gnu.org Xref: news.gmane.org gmane.lisp.guile.devel:14888 Archived-At: * 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