]> gitweb.factorcode.org Git - factor.git/blob - extra/html/parser/state/state.factor
Merge branch 'master' into experimental
[factor.git] / extra / html / parser / state / state.factor
1 ! Copyright (C) 2005, 2009 Daniel Ehrenberg
2 ! See http://factorcode.org/license.txt for BSD license.
3 USING: namespaces math kernel sequences accessors fry circular ;
4 IN: html.parser.state
5
6 TUPLE: state string i ;
7
8 : get-i ( -- i ) state get i>> ;
9
10 : get-char ( -- char )
11     state get [ i>> ] [ string>> ] bi ?nth ;
12
13 : get-next ( -- char )
14     state get [ i>> 1+ ] [ string>> ] bi ?nth ;
15
16 : next ( -- )
17     state get [ 1+ ] change-i drop ;
18
19 : string-parse ( string quot -- )
20     [ 0 state boa state ] dip with-variable ;
21
22 : short* ( n seq -- n' seq )
23     over [ nip dup length swap ] unless ;
24
25 : skip-until ( quot: ( -- ? ) -- )
26     get-char [
27         [ call ] keep swap
28         [ drop ] [ next skip-until ] if
29     ] [ drop ] if ; inline recursive
30
31 : take-until ( quot: ( -- ? ) -- )
32     [ get-i ] dip skip-until get-i
33     state get string>> subseq ;
34
35 : string-matches? ( string circular -- ? )
36     get-char over push-circular sequence= ;
37
38 : take-string ( match -- string )
39     dup length <circular-string>
40     [ 2dup string-matches? ] take-until nip
41     dup length rot length 1- - head next ;