Handbook
Glossary
split-lines ( seq -- seq' )
Factor handbook
»
The language
»
Collections
»
Sequence operations
»
Splitting sequences
Prev:
split-when-slice ( ... seq quot: ( ... elt -- ... ? ) -- ... pieces )
Next:
replace ( seq old new -- new-seq )
Vocabulary
splitting
Inputs
seq
a
sequence
Outputs
seq'
a
sequence
of
string
s
Word description
Splits a string along line breaks.
Examples
USING: prettyprint splitting ; "Hello\r\nworld\n" split-lines .
{ "Hello" "world" }
Definition
IN:
splitting
GENERIC:
split-lines
( seq -- seq' )
Methods
USING:
sbufs
sequences
splitting
;
M:
sbuf
split-lines
""
like
split-lines
;
USING:
kernel
math
sequences
splitting
strings
;
M:
string
split-lines
[
V{
}
clone
0
]
dip
[
2dup
bounds-check?
]
[
2dup
[
"\r\n"
member?
]
find-from
swapd
[
over
[
[
nip
length
]
keep
]
unless
[
""
subseq-as
suffix!
]
2keep
[
1
+
]
dip
]
dip
13
eq?
[
2dup
?nth
10
eq?
[
[
1
+
]
dip
]
when
]
when
]
while
2drop
{
}
like
;