Simplify and improve extension handling
The functions should be safe now and all known corner cases seem to work.
This commit is contained in:
parent
0ee52c5bdd
commit
69026edf83
21
Util.hs
21
Util.hs
@ -14,20 +14,25 @@ inRange (xlD, xuD) (ylD, yuD) (x,y)
|
|||||||
|
|
||||||
-- |Compare the extension of a file with the given String.
|
-- |Compare the extension of a file with the given String.
|
||||||
cmpExt :: String -> FilePath -> Bool
|
cmpExt :: String -> FilePath -> Bool
|
||||||
cmpExt _ [] = False
|
cmpExt checkExt = (==) checkExt . getExt
|
||||||
cmpExt checkExt fp
|
|
||||||
| actualExt == fp = False
|
|
||||||
| otherwise = checkExt == actualExt
|
|
||||||
where
|
|
||||||
actualExt = getExt fp
|
|
||||||
|
|
||||||
|
|
||||||
-- |Get the extension of a file.
|
-- |Get the extension of a file.
|
||||||
getExt :: FilePath -> String
|
getExt :: FilePath -> String
|
||||||
getExt = last .
|
getExt fp
|
||||||
|
| hasExt fp = last .
|
||||||
splitBy (== '.') .
|
splitBy (== '.') .
|
||||||
last .
|
last .
|
||||||
splitBy (== '/')
|
splitBy (== '/') $
|
||||||
|
fp
|
||||||
|
| otherwise = ""
|
||||||
|
|
||||||
|
|
||||||
|
-- |Check if the file has an extension.
|
||||||
|
hasExt :: FilePath -> Bool
|
||||||
|
hasExt fp
|
||||||
|
| (<= 1) . length . splitBy (== '.') $ fp = False
|
||||||
|
| otherwise = True
|
||||||
|
|
||||||
|
|
||||||
-- |Split an array into subarrays depending on a given condition.
|
-- |Split an array into subarrays depending on a given condition.
|
||||||
|
Loading…
Reference in New Issue
Block a user