Handbook
Glossary
file-line-endings ( contents -- lines endings )
Vocabulary
io
.
files
.
private
Inputs
contents
an
object
Outputs
lines
an
object
endings
an
object
Definition
USING:
arrays
kernel
math
sequences
strings
;
IN:
io.files.private
::
file-line-endings
( contents -- lines endings )
V{
}
clone
:>
lines
V{
}
clone
:>
endings contents
string?
"\r\n"
"\n"
?
:>
separators 0
:>
start!
[
start contents
length
<
]
[
start contents
[
separators
member?
]
find-from
drop
:>
eol eol
[
eol contents
nth
13
=
eol 1
+
contents
?nth
10
=
and
2 1
?
eol
+
]
[
contents
length
]
if
:>
end start eol contents
length
or
contents
subseq
lines
push
eol contents
length
or
end contents
subseq
endings
push
end start!
]
while
lines
>array
endings
>array
;