From d0f524167a232a3ef8d0dd6dedfe6e4fbc83e793 Mon Sep 17 00:00:00 2001 From: hasufell Date: Wed, 1 Oct 2014 20:18:45 +0200 Subject: [PATCH] Add utility functions for file handling --- Util.hs | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/Util.hs b/Util.hs index bfc815a..4ffe212 100644 --- a/Util.hs +++ b/Util.hs @@ -11,3 +11,20 @@ inRange min' max' (x, y) | otherwise = False +cmpExt :: String -> FilePath -> Bool +cmpExt _ [] = False +cmpExt ext fp = ext == getExt fp + + +getExt :: FilePath -> String +getExt = last . + splitBy (== '.') . + last . + splitBy (== '/') + + +splitBy :: (a -> Bool) -> [a] -> [[a]] +splitBy f s = case dropWhile f s of + [] -> [] + s' -> w : splitBy f s'' + where (w, s'') = break f s'