packages feed

MicroHs-0.17.4.0 / mhs / System / FilePath.hs

-- A few function copied from the filepath packagemodule System.FilePath(    FilePath,--    splitSearchPath,    pathSeparator,--    takeExtension,    dropExtension,    (<.>),    splitFileName,    takeDirectory,    (</>),  ) whereimport qualified Prelude(); import MHSPreludeimport Data.Listinfixr 7 <.>infixr 5 </>(</>) :: FilePath -> FilePath -> FilePath(</>) = combine{-hasLeadingPathSeparator :: FilePath -> BoolhasLeadingPathSeparator ('/':_) = TruehasLeadingPathSeparator _ = FalsehasTrailingPathSeparator :: FilePath -> BoolhasTrailingPathSeparator = hasLeadingPathSeparator . reverse-}joinPath :: [FilePath] -> FilePathjoinPath = foldr combine ""combine :: FilePath -> FilePath -> FilePathcombine a b {-x | hasLeadingPathSeparator b = b            | otherwise -} = combineAlways a bcombineAlways :: FilePath -> FilePath -> FilePathcombineAlways a b {-x | null a = b                  | null b = a                  | hasTrailingPathSeparator a = a ++ b                  | otherwise -} = a ++ pathSeparator : bpathSeparator :: CharpathSeparator = if _isWindows then '\\' else '/'isPathSeparator :: Char -> BoolisPathSeparator = (pathSeparator ==)---------{-splitSearchPath :: String -> [FilePath]splitSearchPath = f  where    f xs = case break (':' ==) xs of             (pre, []    ) -> g pre             (pre, _:post) -> g pre ++ f post    g "" = ["."]    g x = [x]-}---------splitFileName :: FilePath -> (String, String)splitFileName x = (if null dir then "./" else dir, name)    where        (dir, name) = splitFileName_ xsplitFileName_ :: FilePath -> (String, String)splitFileName_ = breakEnd isPathSeparatordropFileName :: FilePath -> FilePathdropFileName = fst . splitFileName{-replaceBaseName :: FilePath -> String -> FilePathreplaceBaseName pth nam = combineAlways a (nam <.> ext)    where        (a,b) = splitFileName_ pth        ext = takeExtension b-}takeDirectory :: FilePath -> FilePathtakeDirectory = dropTrailingPathSeparator . dropFileNamedropTrailingPathSeparator :: FilePath -> FilePathdropTrailingPathSeparator = dropWhileEnd isPathSeparator---------extSeparator :: CharextSeparator = '.'isExtSeparator :: Char -> BoolisExtSeparator = (extSeparator ==){-splitExtension :: FilePath -> (String, String)splitExtension x = case nameDot of                       "" -> (x,"")                       _  -> (dir ++ init nameDot, extSeparator : ext)    where        (dir, file) = splitFileName_ x        (nameDot, ext) = breakEnd isExtSeparator filetakeExtension :: FilePath -> StringtakeExtension = snd . splitExtension-}dropExtension :: FilePath -> FilePath--dropExtension = fst . splitExtensiondropExtension s =  case dropWhile (not . isExtSeparator) . reverse $ s of    "" -> s    s' -> reverse . drop 1 $ s'(<.>) :: FilePath -> String -> FilePath(<.>) = addExtensionaddExtension :: FilePath -> String -> FilePathaddExtension file "" = fileaddExtension file xs@(x:_) = res    where        res = if isExtSeparator x then file ++ xs              else file ++ extSeparator : xs