]> gitweb.factorcode.org Git - factor.git/blobdiff - extra/html/parser/utils/utils.factor
html.parser.utils: adding a simple html escape/unescape.
[factor.git] / extra / html / parser / utils / utils.factor
index afd63daf6bf241bca2c96f4f117501ca8fb42855..c12ba74585b3d6adfa9595ad0b752126387b2c83 100644 (file)
@@ -1,9 +1,6 @@
 ! 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 )
@@ -18,3 +15,17 @@ IN: html.parser.utils
     [ double-quote ] [ single-quote ] if ;
 
 : ?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 ;