escape-strings: Instead of [[ [=[ [==[, [[ [0[ [1[ ...

modern-harvey3
Doug Coleman 2019-11-18 23:09:58 -06:00
parent c9684dbd14
commit 1cf3e1161d
1 changed files with 18 additions and 2 deletions

View File

@ -1,7 +1,8 @@
! Copyright (C) 2017 John Benediktsson, Doug Coleman.
! See http://factorcode.org/license.txt for BSD license.
USING: assocs assocs.extras combinators kernel math math.order
math.statistics sequences sequences.extras sets ;
USING: ascii assocs assocs.extras combinators kernel math
math.order math.statistics sequences sequences.extras sets
strings ;
IN: escape-strings
: find-escapes ( str -- set )
@ -14,6 +15,21 @@ IN: escape-strings
} case
] each 0 > [ over adjoin ] [ drop ] if ;
: find-number-escapes ( str -- set )
[ HS{ } clone sbuf"" clone 0 ] dip
[
{
{ [ dup char: \] = ] [
drop 1 + dup 2 = [
drop dup >string pick adjoin
0 over set-length 1
] when
] }
{ [ dup digit? ] [ [ dup 1 = ] dip '[ [ _ over push ] dip ] [ ] if ] }
[ 2drop 0 over set-length 0 ]
} cond
] each 0 > [ >string over adjoin ] [ drop ] if ;
: lowest-missing ( set -- min )
members dup [ = not ] find-index
[ nip ] [ drop length ] if ;