Skip to content

Commit f70f2ad

Browse files
committed
Move to Code.Fragment
1 parent c7c21bf commit f70f2ad

File tree

2 files changed

+33
-33
lines changed

2 files changed

+33
-33
lines changed

lib/elixir/lib/code.ex

Lines changed: 0 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -324,39 +324,6 @@ defmodule Code do
324324
unrequire_files(files)
325325
end
326326

327-
@doc ~S"""
328-
Returns the list of lines in the given string, preserving their line endings.
329-
330-
Only the line endings recognized by the Elixir compiler are
331-
considered, namely `\r\n` and `\n`. If you would like the retrieve
332-
lines without their line endings, use `String.split(string, ["\r\n", "\n"])`.
333-
334-
## Examples
335-
336-
iex> Code.lines("foo\r\nbar\r\nbaz")
337-
["foo\r\n", "bar\r\n", "baz"]
338-
339-
iex> Code.lines("foo\nbar\nbaz")
340-
["foo\n", "bar\n", "baz"]
341-
342-
iex> Code.lines("")
343-
[""]
344-
345-
"""
346-
@doc since: "1.19.0"
347-
def lines(string) do
348-
lines(string, <<>>)
349-
end
350-
351-
defp lines(<<?\n, rest::binary>>, acc),
352-
do: [<<acc::binary, ?\n>> | lines(rest, <<>>)]
353-
354-
defp lines(<<char, rest::binary>>, acc),
355-
do: lines(rest, <<acc::binary, char>>)
356-
357-
defp lines(<<>>, acc),
358-
do: [acc]
359-
360327
@doc """
361328
Appends a path to the Erlang VM code path list.
362329

lib/elixir/lib/code/fragment.ex

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,39 @@ defmodule Code.Fragment do
1111

1212
@type position :: {line :: pos_integer(), column :: pos_integer()}
1313

14+
@doc ~S"""
15+
Returns the list of lines in the given string, preserving their line endings.
16+
17+
Only the line endings recognized by the Elixir compiler are
18+
considered, namely `\r\n` and `\n`. If you would like the retrieve
19+
lines without their line endings, use `String.split(string, ["\r\n", "\n"])`.
20+
21+
## Examples
22+
23+
iex> Code.Fragment.lines("foo\r\nbar\r\nbaz")
24+
["foo\r\n", "bar\r\n", "baz"]
25+
26+
iex> Code.Fragment.lines("foo\nbar\nbaz")
27+
["foo\n", "bar\n", "baz"]
28+
29+
iex> Code.Fragment.lines("")
30+
[""]
31+
32+
"""
33+
@doc since: "1.19.0"
34+
def lines(string) do
35+
lines(string, <<>>)
36+
end
37+
38+
defp lines(<<?\n, rest::binary>>, acc),
39+
do: [<<acc::binary, ?\n>> | lines(rest, <<>>)]
40+
41+
defp lines(<<char, rest::binary>>, acc),
42+
do: lines(rest, <<acc::binary, char>>)
43+
44+
defp lines(<<>>, acc),
45+
do: [acc]
46+
1447
@doc """
1548
Receives a string and returns the cursor context.
1649

0 commit comments

Comments
 (0)