Commit ba41dedc authored by Andrey Mokhov's avatar Andrey Mokhov
Browse files

Implement encodeModule -- the inverse for decodeModule.

parent bfe72a5f
......@@ -25,9 +25,8 @@ module Base (
module System.Console.ANSI,
-- * Miscellaneous utilities
bimap, minusOrd, intersectOrd,
removeFileIfExists,
replaceEq, replaceSeparators, decodeModule, unifyPath, (-/-), chunksOfSize,
bimap, minusOrd, intersectOrd, removeFileIfExists, replaceEq, chunksOfSize,
replaceSeparators, decodeModule, encodeModule, unifyPath, (-/-)
) where
import Control.Applicative
......@@ -78,12 +77,18 @@ replaceSeparators = replaceIf isPathSeparator
replaceIf :: (a -> Bool) -> a -> [a] -> [a]
replaceIf p to = map (\from -> if p from then to else from)
-- | Given a module name extract the directory and file names, e.g.:
-- | Given a module name extract the directory and file name, e.g.:
--
-- > decodeModule "Data.Functor.Identity" = ("Data/Functor/", "Identity")
decodeModule :: String -> (FilePath, String)
decodeModule = splitFileName . replaceEq '.' '/'
-- | Given the directory and file name find the corresponding module name, e.g.:
--
-- > encodeModule "Data/Functor/" "Identity.hs" = "Data.Functor.Identity"
encodeModule :: FilePath -> String -> String
encodeModule dir file = replaceEq '/' '.' $ dir -/- takeBaseName file
-- | Normalise a path and convert all path separators to @/@, even on Windows.
unifyPath :: FilePath -> FilePath
unifyPath = toStandard . normaliseEx
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment