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

32 lines
812 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.
USING: assocs kernel quoting sequences splitting ;
2007-12-04 15:14:33 -05:00
IN: html.parser.utils
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
: 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 ;
2009-01-04 12:38:25 -05:00
: ?quote ( str -- newstr ) dup quoted? [ quote ] unless ;
CONSTANT: html-entities H{
{ """ "\"" }
{ "&lt;" "<" }
{ "&gt;" ">" }
{ "&amp;" "&" }
{ "&#39;" "'" }
}
: html-unescape ( str -- str' )
html-entities [ replace ] assoc-each ;
: html-escape ( str -- str' )
html-entities [ swap replace ] assoc-each ;