! Copyright (C) 2005, 2006 Daniel Ehrenberg
! See http://factorcode.org/license.txt for BSD license.
-USING: namespaces make kernel assocs sequences fry values
-io.files io.encodings.binary xml.state ;
+USING: assocs kernel make namespaces sequences xml.state ;
IN: xml.entities
-: entities-out
+CONSTANT: entities-out
H{
{ CHAR: < "<" }
{ CHAR: > ">" }
{ CHAR: & "&" }
- } ;
+ }
-: quoted-entities-out
+CONSTANT: quoted-entities-out
H{
{ CHAR: & "&" }
{ CHAR: ' "'" }
- { CHAR: " """ }
- } ;
+ { CHAR: \" """ }
+ { CHAR: < "<" }
+ }
: escape-string-by ( str table -- escaped )
- #! Convert <, >, &, ' and " to HTML entities.
+ ! Convert <, >, &, ' and " to HTML entities.
[ '[ dup _ at [ % ] [ , ] ?if ] each ] "" make ;
: escape-string ( str -- newstr )
: escape-quoted-string ( str -- newstr )
quoted-entities-out escape-string-by ;
-: entities
+CONSTANT: entities
H{
{ "lt" CHAR: < }
{ "gt" CHAR: > }
{ "amp" CHAR: & }
{ "apos" CHAR: ' }
- { "quot" CHAR: " }
- } ;
+ { "quot" CHAR: \" }
+ }
: with-entities ( entities quot -- )
- [ swap extra-entities set call ] with-scope ; inline
+ [ extra-entities ] dip with-variable ; inline