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