Skip to content
Merged
Show file tree
Hide file tree
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
12 changes: 6 additions & 6 deletions lib/elixir/lib/kernel.ex
Original file line number Diff line number Diff line change
Expand Up @@ -3659,15 +3659,15 @@ defmodule Kernel do
case is_binary(string) do
true ->
case mod do
?b -> String.split(string)
?a -> lc p inlist String.split(string), do: binary_to_atom(p)
?c -> lc p inlist String.split(string), do: String.to_char_list!(p)
?b -> lc p inlist String.split(string), p != "", do: p
?a -> lc p inlist String.split(string), p != "", do: binary_to_atom(p)
?c -> lc p inlist String.split(string), p != "", do: String.to_char_list!(p)
end
false ->
case mod do
?b -> quote do: String.split(unquote(string))
?a -> quote do: lc(p inlist String.split(unquote(string)), do: binary_to_atom(p))
?c -> quote do: lc(p inlist String.split(unquote(string)), do: String.to_char_list!(p))
?b -> quote do: lc(p inlist String.split(unquote(string)), p != "", do: p)
?a -> quote do: lc(p inlist String.split(unquote(string)), p != "", do: binary_to_atom(p))
?c -> quote do: lc(p inlist String.split(unquote(string)), p != "", do: String.to_char_list!(p))
end
end
end
Expand Down
4 changes: 2 additions & 2 deletions lib/elixir/lib/string.ex
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ defmodule String do

@doc """
Splits a string on substrings at each Unicode whitespace
occurrence with leading and trailing whitespace ignored.
occurrence.

## Examples

Expand All @@ -149,7 +149,7 @@ defmodule String do
iex> String.split("foo" <> <<194, 133>> <> "bar")
["foo", "bar"]
iex> String.split(" foo bar ")
["foo", "bar"]
["", "foo", "bar", ""]

"""
@spec split(t) :: [t]
Expand Down
12 changes: 2 additions & 10 deletions lib/elixir/priv/unicode.ex
Original file line number Diff line number Diff line change
Expand Up @@ -145,11 +145,7 @@ defmodule String.Unicode do

lc codepoint inlist whitespace do
defp do_split(unquote(codepoint) <> rest, buffer, acc) do
if buffer != "" do
do_split(rest, "", [buffer | acc])
else
do_split(rest, buffer, acc)
end
do_split(rest, "", [buffer | acc])
end
end

Expand All @@ -158,11 +154,7 @@ defmodule String.Unicode do
end

defp do_split(<<>>, buffer, acc) do
if buffer != "" do
[buffer | acc]
else
acc
end
[buffer | acc]
end

# Graphemes
Expand Down
8 changes: 4 additions & 4 deletions lib/elixir/test/elixir/string_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@ defmodule StringTest do
test :split do
assert String.split("") == [""]
assert String.split("foo bar") == ["foo", "bar"]
assert String.split(" foo bar") == ["foo", "bar"]
assert String.split("foo bar ") == ["foo", "bar"]
assert String.split(" foo bar ") == ["foo", "bar"]
assert String.split("foo\t\n\v\f\r\sbar\n") == ["foo", "bar"]
assert String.split(" foo bar") == ["", "foo", "bar"]
assert String.split("foo bar ") == ["foo", "bar", ""]
assert String.split(" foo bar ") == ["", "foo", "bar", ""]
assert String.split("foo\t\n\v\f\r\sbar\n") == ["foo", "", "", "", "", "", "bar", ""]
assert String.split("foo" <> <<31>> <> "bar") == ["foo", "bar"]
assert String.split("foo" <> <<194, 133>> <> "bar") == ["foo", "bar"]

Expand Down
2 changes: 1 addition & 1 deletion lib/iex/test/iex/helpers_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ defmodule IEx.HelpersTest do
assert ["ebin", "lib", "mix.exs", "test"]
= capture_io(fn -> ls end)
|> String.split
|> Enum.map(String.strip(&1))
|> Enum.filter(&(&1 != ""))
|> Enum.sort
assert capture_io(fn -> ls "~" end) == capture_io(fn -> ls System.user_home end)
end
Expand Down