| 
									
										
										
										
											2007-09-20 18:09:08 -04:00
										 |  |  | ! Copyright (C) 2005, 2006 Daniel Ehrenberg | 
					
						
							|  |  |  | ! See http://factorcode.org/license.txt for BSD license. | 
					
						
							| 
									
										
										
										
											2009-01-15 23:20:24 -05:00
										 |  |  | USING: namespaces make kernel assocs sequences fry values | 
					
						
							| 
									
										
										
										
											2009-01-23 16:29:28 -05:00
										 |  |  | io.files io.encodings.binary xml.state ;
 | 
					
						
							| 
									
										
										
										
											2007-09-20 18:09:08 -04:00
										 |  |  | IN: xml.entities | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-01-30 16:03:02 -05:00
										 |  |  | : entities-out | 
					
						
							|  |  |  |     H{ | 
					
						
							|  |  |  |         { CHAR: < "<"   } | 
					
						
							|  |  |  |         { CHAR: > ">"   } | 
					
						
							|  |  |  |         { CHAR: & "&"  } | 
					
						
							|  |  |  |     } ;
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | : quoted-entities-out | 
					
						
							|  |  |  |     H{ | 
					
						
							|  |  |  |         { CHAR: & "&"  } | 
					
						
							|  |  |  |         { CHAR: ' "'" } | 
					
						
							|  |  |  |         { CHAR: " """ } | 
					
						
							| 
									
										
										
										
											2009-01-26 22:39:08 -05:00
										 |  |  |         { CHAR: < "<"   } | 
					
						
							| 
									
										
										
										
											2008-01-30 16:03:02 -05:00
										 |  |  |     } ;
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | : escape-string-by ( str table -- escaped )
 | 
					
						
							|  |  |  |     #! Convert <, >, &, ' and " to HTML entities. | 
					
						
							| 
									
										
										
										
											2008-12-02 20:59:16 -05:00
										 |  |  |     [ '[ dup _ at [ % ] [ , ] ?if ] each ] "" make ;
 | 
					
						
							| 
									
										
										
										
											2008-01-30 16:03:02 -05:00
										 |  |  | 
 | 
					
						
							|  |  |  | : escape-string ( str -- newstr )
 | 
					
						
							|  |  |  |     entities-out escape-string-by ;
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | : escape-quoted-string ( str -- newstr )
 | 
					
						
							|  |  |  |     quoted-entities-out escape-string-by ;
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2007-09-20 18:09:08 -04:00
										 |  |  | : entities | 
					
						
							|  |  |  |     H{ | 
					
						
							|  |  |  |         { "lt"    CHAR: <  } | 
					
						
							|  |  |  |         { "gt"    CHAR: >  } | 
					
						
							|  |  |  |         { "amp"   CHAR: &  } | 
					
						
							|  |  |  |         { "apos"  CHAR: '  } | 
					
						
							|  |  |  |         { "quot"  CHAR: "  } | 
					
						
							|  |  |  |     } ;
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | : with-entities ( entities quot -- )
 | 
					
						
							|  |  |  |     [ swap extra-entities set call ] with-scope ; inline
 |