File tree Expand file tree Collapse file tree 2 files changed +33
-33
lines changed Expand file tree Collapse file tree 2 files changed +33
-33
lines changed Original file line number Diff line number Diff 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
Original file line number Diff line number Diff 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
You can’t perform that action at this time.
0 commit comments