fix take-rest for out of bounds

db4
Doug Coleman 2009-04-01 22:39:20 -05:00
parent 4dbb2aa491
commit 9bee1fe004
2 changed files with 16 additions and 3 deletions

View File

@ -93,3 +93,9 @@ IN: html.parser.state.tests
[ "abcd e \\\"f g" ]
[ "\"abcd e \\\"f g\"" <state-parser> CHAR: \ CHAR: " take-token* ] unit-test
[ "" ]
[ "" <state-parser> take-rest ] unit-test
[ "" ]
[ "abc" <state-parser> dup "abc" take-sequence drop take-rest ] unit-test

View File

@ -1,8 +1,8 @@
! Copyright (C) 2005, 2009 Daniel Ehrenberg
! See http://factorcode.org/license.txt for BSD license.
USING: namespaces math kernel sequences accessors fry circular
unicode.case unicode.categories locals combinators.short-circuit
make combinators ;
unicode.case ascii locals combinators.short-circuit
make combinators io splitting ;
IN: html.parser.state
@ -74,8 +74,12 @@ TUPLE: state-parser sequence n ;
: skip-whitespace ( state-parser -- state-parser )
[ [ current blank? not ] take-until drop ] keep ;
: take-rest-slice ( state-parser -- sequence/f )
[ sequence>> ] [ n>> ] bi
2dup [ length ] dip < [ 2drop f ] [ tail-slice ] if ; inline
: take-rest ( state-parser -- sequence )
[ drop f ] take-until ; inline
[ take-rest-slice ] [ sequence>> like ] bi ;
: take-until-object ( state-parser obj -- sequence )
'[ current _ = ] take-until ;
@ -111,3 +115,6 @@ TUPLE: state-parser sequence n ;
: take-token ( state-parser -- string/f )
CHAR: \ CHAR: " take-token* ;
: write-full ( state-parser -- ) sequence>> write ;
: write-rest ( state-parser -- ) take-rest write ;