Skip to content

Commit

Permalink
(maint) Update for Elixir 0.15.0
Browse files Browse the repository at this point in the history
Prior to this commit, ExIrc.Utils.parse_from/2 use Regex.split with
captures; however, this functionality has been removed from Elixir
0.15.0.

For example, `Regex.split(~r/(!@\.)/, "[email protected]")`
in Elixir 0.14.3 would yield
`["n", "!", "u", "@", "h", ".", "n", ".", "tld"]`
however, in Elixir 0.15.0, this yields
`["n", "u", "h", "n", "tld"]`

This commit works around this functionality by using explicit regular
expressions for each of the cases, pulling out each of the fields into a
named capture map and relying on the truthiness of the capture map to
trigger a condition match.
  • Loading branch information
jeffweiss committed Aug 6, 2014
1 parent 31ecdb5 commit c775f80
Showing 1 changed file with 12 additions and 9 deletions.
21 changes: 12 additions & 9 deletions lib/exirc/utils.ex
Original file line number Diff line number Diff line change
Expand Up @@ -26,16 +26,19 @@ defmodule ExIrc.Utils do
end

defp parse_from(from, msg) do
case Regex.split(~r/(!|@|\.)/, IO.iodata_to_binary(from)) do
[nick, "!", user, "@" | host] ->
%{msg | :nick => nick, :user => user, :host => Enum.join(host)}
[nick, "@" | host] ->
%{msg | :nick => nick, :host => Enum.join(host)}
[_, "." | _] ->
# from is probably a server name
binary_from = IO.iodata_to_binary(from)
fully_qualified_regex = ~r/(?<nick>.*)!(?<user>.*)@(?<host>.*)/
missing_user_regex = ~r/(?<nick>.*)@(?<host>.*)/
host_only_regex = ~r/.+\..+/
cond do
captures = Regex.named_captures fully_qualified_regex, binary_from ->
%{msg | :nick => captures[:nick], :user => captures[:user], :host => captures[:host]}
captures = Regex.named_captures missing_user_regex, binary_from ->
%{msg | :nick => captures[:nick], :host => captures[:host]}
Regex.match? host_only_regex, binary_from ->
%{msg | :server => to_string(from)}
[nick] ->
%{msg | :nick => nick}
true ->
%{msg | :nick => to_string(from)}
end
end

Expand Down

0 comments on commit c775f80

Please sign in to comment.