From 91119d87f42c9740647f2234fc501c8dd174bda8 Mon Sep 17 00:00:00 2001 From: John Benediktsson Date: Mon, 21 Apr 2014 16:59:38 -0700 Subject: [PATCH] html.parser.utils: adding a simple html escape/unescape. --- extra/html/parser/utils/utils.factor | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/extra/html/parser/utils/utils.factor b/extra/html/parser/utils/utils.factor index afd63daf6b..c12ba74585 100644 --- a/extra/html/parser/utils/utils.factor +++ b/extra/html/parser/utils/utils.factor @@ -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{ + { """ "\"" } + { "<" "<" } + { ">" ">" } + { "&" "&" } + { "'" "'" } +} + +: html-unescape ( str -- str' ) + html-entities [ replace ] assoc-each ; + +: html-escape ( str -- str' ) + html-entities [ swap replace ] assoc-each ; -- 2.34.1