module Tools (fileName, fileExtension, splitOn, withFileContents) where import System.IO fileName :: String -> String fileName = reverse . takeWhile (/= '/') . reverse fileExtension :: String -> String fileExtension = reverse . takeWhile (/= '.') . reverse . fileName splitOn :: Char -> String -> [String] splitOn delim s = case dropWhile (== delim) s of "" -> [] s' -> w : splitOn delim s'' where (w, s'') = break (== delim) s' withFileContents :: FilePath -> (String -> IO a) -> IO a withFileContents filename handler = do h1 <- openBinaryFile filename ReadMode fileContent <- hGetContents h1 result <- handler fileContent hClose h1 return result