-- | Match a 'FilePattern' against a 'FilePath', There are three special forms:
--
-- * @*@ matches an entire path component, excluding any separators.
--
-- * @\/\/@ matches an arbitrary number of path components, including absolute path
--   prefixes.
--
-- * @**@ as a path component matches an arbitrary number of path components, but not
--   absolute path prefixes.
--   Currently considered experimental.
--
--   Some examples:
--
-- * @test.c@ matches @test.c@ and nothing else.
--
-- * @*.c@ matches all @.c@ files in the current directory, so @file.c@ matches,
--   but @file.h@ and @dir\/file.c@ don't.
--
-- * @\/\/*.c@ matches all @.c@ files anywhere on the filesystem,
--   so @file.c@, @dir\/file.c@, @dir1\/dir2\/file.c@ and @\/path\/to\/file.c@ all match,
--   but @file.h@ and @dir\/file.h@ don't.
--
-- * @dir\/*\/*@ matches all files one level below @dir@, so @dir\/one\/file.c@ and
--   @dir\/two\/file.h@ match, but @file.c@, @one\/dir\/file.c@, @dir\/file.h@
--   and @dir\/one\/two\/file.c@ don't.
--
--   Patterns with constructs such as @foo\/..\/bar@ will never match
--   normalised 'FilePath' values, so are unlikely to be correct.
(?==) :: FilePattern -> FilePath -> Bool
(?==) p = case optimise $ parse p of
    [x] | x == Skip || x == Skip1 -> if rp then isRelativePath else const True
    p -> let f = not . null . match p . split isPathSeparator
         in if rp then (\x -> isRelativePath x && f x) else f
    where rp = isRelativePattern p
(?==) :: FilePattern -> FilePath -> Bool
(?==) p = case optimise $ parse p of
    [x] | x == Skip || x == Skip1 -> if rp then isRelativePath else const True
    p -> let f = not . null . match p . split isPathSeparator
         in if rp then (\x -> isRelativePath x && f x) else f
    where rp = isRelativePattern p
(?==) p = case optimise $ parse p of
    [x] | x == Skip || x == Skip1 -> if rp then isRelativePath else const True
    p -> let f = not . null . match p . split isPathSeparator
         in if rp then (\x -> isRelativePath x && f x) else f
    where rp = isRelativePattern p