File tree Expand file tree Collapse file tree 2 files changed +33
-32
lines changed Expand file tree Collapse file tree 2 files changed +33
-32
lines changed Original file line number Diff line number Diff line change @@ -324,6 +324,39 @@ 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+ 
327360  @ doc  """ 
328361  Appends a path to the Erlang VM code path list. 
329362
Original file line number Diff line number Diff line change @@ -574,38 +574,6 @@ defmodule String do
574574    end 
575575  end 
576576
577-   @ doc  ~S"""  
578-   Returns the list of lines in a string, preserving their line endings. 
579- 
580-   If you would like the lines without their line endings, use 
581-   `String.split(string, ["\r\n", "\n"])`. 
582- 
583-   ## Examples 
584- 
585-       iex> String.lines("foo\r\nbar\r\nbaz") 
586-       ["foo\r\n", "bar\r\n", "baz"] 
587- 
588-       iex> String.lines("foo\nbar\nbaz") 
589-       ["foo\n", "bar\n", "baz"] 
590- 
591-       iex> String.lines("") 
592-       [""] 
593- 
594-   """  
595-   @ doc  since:  "1.19.0" 
596-   def  lines ( string )  do 
597-     lines ( string ,  << >> ) 
598-   end 
599- 
600-   defp  lines ( << ?\n ,  rest :: binary >> ,  acc ) , 
601-     do:  [ << acc :: binary ,  ?\n >>  |  lines ( rest ,  << >> ) ] 
602- 
603-   defp  lines ( << char ,  rest :: binary >> ,  acc ) , 
604-     do:  lines ( rest ,  << acc :: binary ,  char >> ) 
605- 
606-   defp  lines ( << >> ,  acc ) , 
607-     do:  [ acc ] 
608- 
609577  @ doc  """ 
610578  Returns an enumerable that splits a string on demand. 
611579
    
 
   
 
     
   
   
          
     
  
    
     
 
    
      
     
 
     
    You can’t perform that action at this time.
  
 
    
  
     
    
      
        
     
 
       
      
     
   
 
    
    
  
 
  
 
     
    
0 commit comments