New string-lines word

slava 2006-11-29 20:18:33 +00:00
parent 528e0e5d5d
commit 5d1f025e54
8 changed files with 23 additions and 8 deletions

View File

@ -76,7 +76,7 @@ M: ping handle-irc ( line -- )
: factorbot-loop [ factorbot ] try 30000 sleep factorbot-loop ; : factorbot-loop [ factorbot ] try 30000 sleep factorbot-loop ;
: multiline-respond ( string -- ) : multiline-respond ( string -- )
<string-reader> lines [ respond ] each ; string-lines [ respond ] each ;
: object-href : object-href
"http://factorcode.org" swap browser-link-href append ; "http://factorcode.org" swap browser-link-href append ;

View File

@ -1,4 +1,4 @@
! Copyright (C) 2004, 2005 Slava Pestov. ! Copyright (C) 2004, 2006 Slava Pestov.
! See http://factorcode.org/license.txt for BSD license. ! See http://factorcode.org/license.txt for BSD license.
IN: io IN: io
USING: errors generic io kernel math namespaces sequences USING: errors generic io kernel math namespaces sequences

View File

@ -53,3 +53,6 @@ M: sbuf stream-read
: contents ( stream -- str ) : contents ( stream -- str )
<string-writer> [ stream-copy ] keep >string ; <string-writer> [ stream-copy ] keep >string ;
: string-lines ( string -- seq )
CHAR: \n add <string-reader> lines ;

View File

@ -40,7 +40,7 @@ C: source-file ( path -- source-file )
: parse-lines ( lines -- quot ) : parse-lines ( lines -- quot )
[ f [ (parse) ] reduce >quotation ] with-parser ; [ f [ (parse) ] reduce >quotation ] with-parser ;
: parse ( str -- quot ) <string-reader> lines parse-lines ; : parse ( str -- quot ) string-lines parse-lines ;
: eval ( str -- ) parse call ; : eval ( str -- ) parse call ;

View File

@ -6,3 +6,15 @@ USE: generic
USE: kernel USE: kernel
[ "xyzzy" ] [ [ "xyzzy" write ] string-out ] unit-test [ "xyzzy" ] [ [ "xyzzy" write ] string-out ] unit-test
[ { "" } ] [ "" string-lines ] unit-test
[ { "" "" } ] [ "\n" string-lines ] unit-test
[ { "" "" } ] [ "\r" string-lines ] unit-test
[ { "" "" } ] [ "\r\n" string-lines ] unit-test
[ { "hello" } ] [ "hello" string-lines ] unit-test
[ { "hello" "" } ] [ "hello\n" string-lines ] unit-test
[ { "hello" "" } ] [ "hello\r" string-lines ] unit-test
[ { "hello" "" } ] [ "hello\r\n" string-lines ] unit-test
[ { "hello" "hi" } ] [ "hello\nhi" string-lines ] unit-test
[ { "hello" "hi" } ] [ "hello\rhi" string-lines ] unit-test
[ { "hello" "hi" } ] [ "hello\r\nhi" string-lines ] unit-test

View File

@ -13,7 +13,7 @@ TUPLE: label text font color ;
: set-label-string ( string label -- ) : set-label-string ( string label -- )
CHAR: \n pick memq? [ CHAR: \n pick memq? [
>r "\n" split r> set-label-text >r string-lines r> set-label-text
] [ ] [
set-label-text set-label-text
] if ; inline ] if ; inline

View File

@ -63,10 +63,10 @@ M: pane-stream stream-write1
[ pane-current stream-write1 ] do-pane-stream ; [ pane-current stream-write1 ] do-pane-stream ;
M: pane-stream stream-write M: pane-stream stream-write
[ swap "\n" split pane-write ] do-pane-stream ; [ swap string-lines pane-write ] do-pane-stream ;
M: pane-stream stream-format M: pane-stream stream-format
[ rot "\n" split pane-format ] do-pane-stream ; [ rot string-lines pane-format ] do-pane-stream ;
M: pane-stream stream-close drop ; M: pane-stream stream-close drop ;

View File

@ -90,7 +90,7 @@ C: document ( -- document )
: set-doc-range ( str startloc endloc document -- ) : set-doc-range ( str startloc endloc document -- )
[ [
>r >r >r "\n" split r> [ text+loc ] 2keep r> r> >r >r >r string-lines r> [ text+loc ] 2keep r> r>
[ (set-doc-range) ] change-model [ (set-doc-range) ] change-model
] keep update-locs ; ] keep update-locs ;
@ -123,7 +123,7 @@ C: document ( -- document )
[ set-model ] keep dup doc-end swap update-locs ; [ set-model ] keep dup doc-end swap update-locs ;
: set-doc-text ( string document -- ) : set-doc-text ( string document -- )
>r "\n" split r> set-doc-lines ; >r string-lines r> set-doc-lines ;
: clear-doc ( document -- ) : clear-doc ( document -- )
"" swap set-doc-text ; "" swap set-doc-text ;