Add utility functions for file handling

This commit is contained in:
hasufell 2014-10-01 20:18:45 +02:00
parent aec00c7e4d
commit d0f524167a
No known key found for this signature in database
GPG Key ID: 220CD1C5BDEED020
1 changed files with 17 additions and 0 deletions

17
Util.hs
View File

@ -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'