Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 13 additions & 9 deletions lib/elixir/lib/string_io.ex
Original file line number Diff line number Diff line change
Expand Up @@ -365,7 +365,7 @@ defmodule StringIO do
## get_line

defp get_line(encoding, prompt, %{input: input} = state) do
case bytes_until_eol(input, encoding, 0) do
case bytes_until_eol(input, encoding, byte_size(input)) do
{:split, 0} ->
{:eof, state_after_read(state, "", prompt, 1)}

Expand Down Expand Up @@ -413,7 +413,7 @@ defmodule StringIO do
end

defp get_until(chars, encoding, mod, fun, args, continuation, count) do
case bytes_until_eol(chars, encoding, 0) do
case bytes_until_eol(chars, encoding, byte_size(chars)) do
{kind, size} when kind in [:split, :replace_split] ->
<<line::binary-size(^size), rest::binary>> = chars

Expand Down Expand Up @@ -466,16 +466,20 @@ defmodule StringIO do
%{state | input: remainder, output: output}
end

defp bytes_until_eol("", _, count), do: {:split, count}
defp bytes_until_eol(<<"\r\n"::binary, _::binary>>, _, count), do: {:replace_split, count + 2}
defp bytes_until_eol(<<"\n"::binary, _::binary>>, _, count), do: {:split, count + 1}
defp bytes_until_eol("", _, size), do: {:split, size}

defp bytes_until_eol(<<head::utf8, tail::binary>>, :unicode, count) do
bytes_until_eol(tail, :unicode, count + byte_size(<<head::utf8>>))
defp bytes_until_eol(<<"\r\n"::binary, rest::binary>>, _, size),
do: {:replace_split, size - byte_size(rest)}

defp bytes_until_eol(<<"\n"::binary, rest::binary>>, _, size),
do: {:split, size - byte_size(rest)}

defp bytes_until_eol(<<_::utf8, rest::binary>>, :unicode, size) do
bytes_until_eol(rest, :unicode, size)
end

defp bytes_until_eol(<<_, tail::binary>>, :latin1, count) do
bytes_until_eol(tail, :latin1, count + 1)
defp bytes_until_eol(<<_, rest::binary>>, :latin1, size) do
bytes_until_eol(rest, :latin1, size)
end

defp bytes_until_eol(<<_::binary>>, _, _), do: :error
Expand Down
Loading