]> gitweb.factorcode.org Git - factor.git/commitdiff
matches? works as expected for reversed regexps
authorDaniel Ehrenberg <littledan@Macintosh-122.local>
Wed, 11 Mar 2009 00:17:25 +0000 (19:17 -0500)
committerDaniel Ehrenberg <littledan@Macintosh-122.local>
Wed, 11 Mar 2009 00:17:25 +0000 (19:17 -0500)
basis/regexp/regexp-tests.factor
basis/regexp/regexp.factor

index fa907011fd197e484f435ef0b4ea3497fca025db..f7d3dae3f3ffaccdd5b04ea33e74d924479d7296 100644 (file)
@@ -211,8 +211,8 @@ IN: regexp-tests
 [ f ] [ "aaaxb" "a+ab" <regexp> matches? ] unit-test
 [ t ] [ "aaacb" "a+cb" <regexp> matches? ] unit-test
 
-[ 3 ] [ "aaacb" "a*" <regexp> match-index-head ] unit-test
-[ 2 ] [ "aaacb" "aa?" <regexp> match-index-head ] unit-test
+[ "aaa" ] [ "aaacb" "a*" <regexp> match-head >string ] unit-test
+[ "aa" ] [ "aaacb" "aa?" <regexp> match-head >string ] unit-test
 
 [ t ] [ "aaa" R/ AAA/i matches? ] unit-test
 [ f ] [ "aax" R/ AAA/i matches? ] unit-test
@@ -310,8 +310,8 @@ IN: regexp-tests
 [ "a" ] [ "ba" "(?<=b)(?<=b)a" <regexp> match-head >string ] unit-test
 [ "a" ] [ "cab" "(?<=c)a(?=b)" <regexp> match-head >string ] unit-test
 
-[ 3 ] [ "foobar" "foo(?=bar)" <regexp> match-index-head ] unit-test
-[ f ] [ "foobxr" "foo(?=bar)" <regexp> match-index-head ] unit-test
+[ 3 ] [ "foobar" "foo(?=bar)" <regexp> match-head length ] unit-test
+[ f ] [ "foobxr" "foo(?=bar)" <regexp> match-head ] unit-test
 
 ! Bug in parsing word
 [ t ] [ "a" R' a' matches? ] unit-test
@@ -424,8 +424,8 @@ IN: regexp-tests
 [ 1 ] [ "a\r" R/ a$/m count-matches ] unit-test
 [ 1 ] [ "a\r\n" R/ a$/m count-matches ] unit-test
 
-[ f ] [ "foobxr" "foo\\z" <regexp> match-index-head ] unit-test
-[ 3 ] [ "foo" "foo\\z" <regexp> match-index-head ] unit-test
+[ f ] [ "foobxr" "foo\\z" <regexp> match-head ] unit-test
+[ 3 ] [ "foo" "foo\\z" <regexp> match-head length ] unit-test
 
 ! [ t ] [ "foo" "\\bfoo\\b" <regexp> matches? ] unit-test
 ! [ t ] [ "afoob" "\\Bfoo\\B" <regexp> matches? ] unit-test
index aacd888ccb37cab44bea212390dcac9f3c1b8a08..94bbc2af58cdc44bc824431b370e65392322bc39 100644 (file)
@@ -44,14 +44,17 @@ M: lookbehind question>quot ! Returns ( index string -- ? )
     ! and that string is a string.
     dup dfa>> execute( index string regexp -- i/f ) ;
 
-: match-index-head ( string regexp -- index/f )
-    [ 0 ] 2dip [ check-string ] dip match-index-from ;
+GENERIC: end/start ( string regexp -- end start )
+M: regexp end/start drop length 0 ;
+M: reverse-regexp end/start drop length 1- -1 swap ;
 
 PRIVATE>
 
 : matches? ( string regexp -- ? )
-    dupd match-index-head
-    [ swap length = ] [ drop f ] if* ;
+    [ end/start ] 2keep
+    [ check-string ] dip
+    match-index-from
+    [ swap = ] [ drop f ] if* ;
 
 <PRIVATE