cover/Elixir.Glob.html

1 defmodule Glob do
2 import String, only: [contains?: 2]
3 import Path, only: [split: 1]
4
5 def hits?(path, pattern) do
6
:-(
match(split(path), split(pattern))
7 end
8
9 def wild?(pattern) do
10
:-(
contains?(pattern, ["*", "**"])
11 end
12
13
:-(
def match(_, []), do: true
14
:-(
def match([], ["**" | t]), do: match([], t)
15
:-(
def match([], _), do: false
16
:-(
def match(e, ["**" | t]), do: unwind(match(e, t), e, t)
17
:-(
def match([_ | et], ["*" | pt]), do: match(et, pt)
18
:-(
def match([eh | et], [eh | pt]), do: match(et, pt)
19
:-(
def match([_ | _], [_ | _]), do: false
20
21
:-(
def unwind(true, _e, _t), do: true
22
:-(
def unwind(false, [_ | et], t), do: match(et, ["**" | t])
23
:-(
def unwind(false, [], _t), do: false
24 end
Line Hits Source