| 
									
										
										
										
											2008-09-25 03:02:47 -04:00
										 |  |  | ! Copyright (C) 2008 Doug Coleman. | 
					
						
							|  |  |  | ! See http://factorcode.org/license.txt for BSD license. | 
					
						
							| 
									
										
										
										
											2007-09-20 18:09:08 -04:00
										 |  |  | USING: assocs circular combinators continuations hashtables | 
					
						
							| 
									
										
										
										
											2008-09-25 03:02:47 -04:00
										 |  |  | hashtables.private io kernel math namespaces prettyprint | 
					
						
							|  |  |  | quotations sequences splitting state-parser strings ;
 | 
					
						
							| 
									
										
										
										
											2007-12-04 15:14:33 -05:00
										 |  |  | IN: html.parser.utils | 
					
						
							| 
									
										
										
										
											2007-09-20 18:09:08 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-08-17 11:38:34 -04:00
										 |  |  | : string-parse-end? ( -- ? ) get-next not ;
 | 
					
						
							| 
									
										
										
										
											2007-09-20 18:09:08 -04:00
										 |  |  | 
 | 
					
						
							|  |  |  | : take-string* ( match -- string )
 | 
					
						
							|  |  |  |     dup length <circular-string> | 
					
						
							|  |  |  |     [ 2dup string-matches? ] take-until nip
 | 
					
						
							|  |  |  |     dup length rot length 1- - head next* ;
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | : trim1 ( seq ch -- newseq )
 | 
					
						
							| 
									
										
										
										
											2008-06-08 17:33:07 -04:00
										 |  |  |     [ ?head drop ] [ ?tail drop ] bi ;
 | 
					
						
							| 
									
										
										
										
											2007-09-20 18:09:08 -04:00
										 |  |  | 
 | 
					
						
							|  |  |  | : single-quote ( str -- newstr )
 | 
					
						
							| 
									
										
										
										
											2008-12-06 19:58:05 -05:00
										 |  |  |     "'" dup surround ;
 | 
					
						
							| 
									
										
										
										
											2007-09-20 18:09:08 -04:00
										 |  |  | 
 | 
					
						
							|  |  |  | : double-quote ( str -- newstr )
 | 
					
						
							| 
									
										
										
										
											2008-12-06 19:58:05 -05:00
										 |  |  |     "\"" dup surround ;
 | 
					
						
							| 
									
										
										
										
											2007-09-20 18:09:08 -04:00
										 |  |  | 
 | 
					
						
							|  |  |  | : quote ( str -- newstr )
 | 
					
						
							|  |  |  |     CHAR: ' over member?
 | 
					
						
							|  |  |  |     [ double-quote ] [ single-quote ] if ;
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | : quoted? ( str -- ? )
 | 
					
						
							| 
									
										
										
										
											2008-08-17 11:38:34 -04:00
										 |  |  |     [ f ] | 
					
						
							|  |  |  |     [ [ first ] [ peek ] bi [ = ] keep "'\"" member? and ] if-empty ;
 | 
					
						
							| 
									
										
										
										
											2007-09-20 18:09:08 -04:00
										 |  |  | 
 | 
					
						
							|  |  |  | : ?quote ( str -- newstr )
 | 
					
						
							|  |  |  |     dup quoted? [ quote ] unless ;
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | : unquote ( str -- newstr )
 | 
					
						
							| 
									
										
										
										
											2008-05-07 02:38:34 -04:00
										 |  |  |     dup quoted? [ but-last-slice rest-slice >string ] when ;
 | 
					
						
							| 
									
										
										
										
											2007-09-20 18:09:08 -04:00
										 |  |  | 
 | 
					
						
							|  |  |  | : quote? ( ch -- ? ) "'\"" member? ;
 |