summaryrefslogtreecommitdiff
path: root/lib/irc/parser/mode.ex
diff options
context:
space:
mode:
Diffstat (limited to 'lib/irc/parser/mode.ex')
-rw-r--r--lib/irc/parser/mode.ex32
1 files changed, 32 insertions, 0 deletions
diff --git a/lib/irc/parser/mode.ex b/lib/irc/parser/mode.ex
new file mode 100644
index 0000000..d4c0a16
--- /dev/null
+++ b/lib/irc/parser/mode.ex
@@ -0,0 +1,32 @@
+defmodule Irc.Parser.Mode do
+ @moduledoc """
+ Mode change parser
+ """
+
+ def changes(string, previous) do
+ list = to_charlist(string)
+ acc_changes(list, nil, previous)
+ end
+
+ defp acc_changes([?+ | rest], _, acc) do
+ acc_changes(rest, true, acc)
+ end
+
+ defp acc_changes([?- | rest], _, acc) do
+ acc_changes(rest, false, acc)
+ end
+
+ defp acc_changes([0x20 | _], _, acc), do: acc
+
+ defp acc_changes([char | rest], action, acc) do
+ acc = if action do
+ [char | acc]
+ else
+ List.delete(acc, char)
+ end
+ acc_changes(rest, action, acc)
+ end
+
+ defp acc_changes([], _, acc), do: acc
+
+end