]> gitweb.factorcode.org Git - factor.git/blob - basis/html/parser/utils/utils.factor
Merge branch 'master' of git://factorcode.org/git/factor
[factor.git] / basis / html / parser / utils / utils.factor
1 USING: assocs circular combinators continuations hashtables
2 hashtables.private io kernel math
3 namespaces prettyprint quotations sequences splitting
4 state-parser strings sequences.lib ;
5 IN: html.parser.utils
6
7 : string-parse-end? ( -- ? ) get-next not ;
8
9 : take-string* ( match -- string )
10     dup length <circular-string>
11     [ 2dup string-matches? ] take-until nip
12     dup length rot length 1- - head next* ;
13
14 : trim1 ( seq ch -- newseq )
15     [ ?head drop ] [ ?tail drop ] bi ;
16
17 : single-quote ( str -- newstr )
18     "'" swap "'" 3append ;
19
20 : double-quote ( str -- newstr )
21     "\"" swap "\"" 3append ;
22
23 : quote ( str -- newstr )
24     CHAR: ' over member?
25     [ double-quote ] [ single-quote ] if ;
26
27 : quoted? ( str -- ? )
28     [ f ]
29     [ [ first ] [ peek ] bi [ = ] keep "'\"" member? and ] if-empty ;
30
31 : ?quote ( str -- newstr )
32     dup quoted? [ quote ] unless ;
33
34 : unquote ( str -- newstr )
35     dup quoted? [ but-last-slice rest-slice >string ] when ;
36
37 : quote? ( ch -- ? ) "'\"" member? ;