Added a new function in Utils for splitting a file into its extension, and the rest of it

This commit is contained in:
Neil Brown 2009-04-14 16:58:38 +00:00
parent 5abf19a2a3
commit 3a2182326c

View File

@ -58,6 +58,14 @@ joinPath base new
"." -> new
dir -> dir ++ new
-- | Splits a file into its stem (whole path minus extension) and its extension
-- (without the dot):
splitExtension :: String -> (String, String)
splitExtension s
= case span (/= '.') (reverse s) of
(whole, []) -> (s, []) -- no extension
(revExt, _ : revRest) -> (reverse revRest, reverse revExt)
-- | Given a monadic action wrapped in a `Maybe`, run it if there's one there;
-- if it's `Nothing`, then do nothing.
doMaybe :: Monad m => Maybe (m ()) -> m ()