38 lines
992 B
Factor
38 lines
992 B
Factor
USING: assocs circular combinators continuations hashtables
|
|
hashtables.private io kernel math
|
|
namespaces prettyprint quotations sequences splitting
|
|
state-parser strings sequences.lib ;
|
|
IN: html.parser.utils
|
|
|
|
: string-parse-end? ( -- ? ) get-next not ;
|
|
|
|
: 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 )
|
|
[ ?head drop ] [ ?tail drop ] bi ;
|
|
|
|
: single-quote ( str -- newstr )
|
|
"'" swap "'" 3append ;
|
|
|
|
: double-quote ( str -- newstr )
|
|
"\"" swap "\"" 3append ;
|
|
|
|
: quote ( str -- newstr )
|
|
CHAR: ' over member?
|
|
[ double-quote ] [ single-quote ] if ;
|
|
|
|
: quoted? ( str -- ? )
|
|
[ f ]
|
|
[ [ first ] [ peek ] bi [ = ] keep "'\"" member? and ] if-empty ;
|
|
|
|
: ?quote ( str -- newstr )
|
|
dup quoted? [ quote ] unless ;
|
|
|
|
: unquote ( str -- newstr )
|
|
dup quoted? [ but-last-slice rest-slice >string ] when ;
|
|
|
|
: quote? ( ch -- ? ) "'\"" member? ;
|