From 3a2182326cea438b339d72fd08fb076fce42328f Mon Sep 17 00:00:00 2001 From: Neil Brown Date: Tue, 14 Apr 2009 16:58:38 +0000 Subject: [PATCH] Added a new function in Utils for splitting a file into its extension, and the rest of it --- common/Utils.hs | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/common/Utils.hs b/common/Utils.hs index 632af8d..1ac65dc 100644 --- a/common/Utils.hs +++ b/common/Utils.hs @@ -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 ()