1 ! Copyright (C) 2008 Doug Coleman.
2 ! See http://factorcode.org/license.txt for BSD license.
3 USING: accessors arrays assocs io kernel math math.order
4 namespaces regexp.backend sequences unicode.categories
5 math.ranges fry combinators.short-circuit vectors ;
8 : (while-changes) ( obj quot: ( obj -- obj' ) pred: ( obj -- <=> ) pred-ret -- obj )
9 [ [ dup slip ] dip pick over call ] dip dupd =
10 [ 3drop ] [ (while-changes) ] if ; inline recursive
12 : while-changes ( obj quot pred -- obj' )
13 pick over call (while-changes) ; inline
15 : assoc-with ( param assoc quot -- assoc curry )
16 swapd [ [ -rot ] dip call ] 2curry ; inline
18 : insert-at ( value key hash -- )
23 [ dup vector? [ 1vector ] unless ] 2dip set-at
26 : ?insert-at ( value key hash/f -- hash )
27 [ H{ } clone ] unless* [ insert-at ] keep ;
29 ERROR: bad-octal number ;
30 ERROR: bad-hex number ;
31 : check-octal ( octal -- octal ) dup 255 > [ bad-octal ] when ;
32 : check-hex ( hex -- hex ) dup number? [ bad-hex ] unless ;
34 : ascii? ( n -- ? ) 0 HEX: 7f between? ;
35 : octal-digit? ( n -- ? ) CHAR: 0 CHAR: 7 between? ;
36 : decimal-digit? ( n -- ? ) CHAR: 0 CHAR: 9 between? ;
38 : hex-digit? ( n -- ? )
41 [ CHAR: a CHAR: f between? ]
42 [ CHAR: A CHAR: F between? ]
45 : control-char? ( n -- ? )
47 [ 0 HEX: 1f between? ]
52 "!\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~" member? ;
54 : c-identifier-char? ( ch -- ? )
55 [ [ alpha? ] [ CHAR: _ = ] ] 1|| ;
57 : java-blank? ( n -- ? )
59 CHAR: \s CHAR: \t CHAR: \n
60 HEX: b HEX: 7 CHAR: \r
63 : java-printable? ( n -- ? )
64 [ [ alpha? ] [ punct? ] ] 1|| ;