! Copyright (C) 2008 Doug Coleman.
! See http://factorcode.org/license.txt for BSD license.
-USING: assocs circular combinators continuations hashtables
-hashtables.private io kernel math namespaces prettyprint
-quotations sequences splitting strings quoting
-combinators.short-circuit ;
+USING: assocs kernel quoting sequences splitting ;
IN: html.parser.utils
: trim1 ( seq ch -- newseq )
[ double-quote ] [ single-quote ] if ;
: ?quote ( str -- newstr ) dup quoted? [ quote ] unless ;
+
+CONSTANT: html-entities H{
+ { """ "\"" }
+ { "<" "<" }
+ { ">" ">" }
+ { "&" "&" }
+ { "'" "'" }
+}
+
+: html-unescape ( str -- str' )
+ html-entities [ replace ] assoc-each ;
+
+: html-escape ( str -- str' )
+ html-entities [ swap replace ] assoc-each ;