factor/extra/html/parser/utils/utils.factor

35 lines
977 B
Factor
Raw Normal View History

2008-09-25 03:02:47 -04:00
! Copyright (C) 2008 Doug Coleman.
! See http://factorcode.org/license.txt for BSD license.
2007-09-20 18:09:08 -04:00
USING: assocs circular combinators continuations hashtables
2008-09-25 03:02:47 -04:00
hashtables.private io kernel math namespaces prettyprint
2009-01-21 22:57:44 -05:00
quotations sequences splitting html.parser.state strings
2009-01-04 12:38:25 -05:00
combinators.short-circuit ;
2007-12-04 15:14:33 -05:00
IN: html.parser.utils
2007-09-20 18:09:08 -04:00
2008-08-17 11:38:34 -04:00
: string-parse-end? ( -- ? ) get-next not ;
2007-09-20 18:09:08 -04:00
: trim1 ( seq ch -- newseq )
2009-01-04 12:38:25 -05:00
[ [ ?head-slice drop ] [ ?tail-slice drop ] bi ] 2keep drop like ;
2007-09-20 18:09:08 -04:00
2009-01-04 12:38:25 -05:00
: quote? ( ch -- ? ) "'\"" member? ;
: single-quote ( str -- newstr ) "'" dup surround ;
2007-09-20 18:09:08 -04:00
2009-01-04 12:38:25 -05:00
: double-quote ( str -- newstr ) "\"" dup surround ;
2007-09-20 18:09:08 -04:00
: quote ( str -- newstr )
CHAR: ' over member?
[ double-quote ] [ single-quote ] if ;
: quoted? ( str -- ? )
2009-01-04 12:38:25 -05:00
{
[ length 1 > ]
[ first quote? ]
[ [ first ] [ peek ] bi = ]
} 1&& ;
2007-09-20 18:09:08 -04:00
2009-01-04 12:38:25 -05:00
: ?quote ( str -- newstr ) dup quoted? [ quote ] unless ;
2007-09-20 18:09:08 -04:00
: unquote ( str -- newstr )
2008-05-07 02:38:34 -04:00
dup quoted? [ but-last-slice rest-slice >string ] when ;