now dirname and basename work well on Windows and other platform that can use backslash on path

This commit is contained in:
shelarcy 2005-06-18 20:47:08 +00:00
parent 5be5242113
commit d07bb01b48

View File

@ -244,15 +244,35 @@ a <> b = a ++ b
--
dirname :: FilePath -> FilePath
dirname p =
case reverse $ dropWhile (/= '/') $ reverse p of
[] -> "."
p' -> p'
let x = findIndices (== '\\') p
y = findIndices (== '/') p
in
if not $ null x
then if not $ null y
then if (maximum x) > (maximum y) then dirname' '\\' p else dirname' '/' p
else dirname' '\\' p
else dirname' '/' p
where
dirname' chara pa =
case reverse $ dropWhile (/= chara) $ reverse pa of
[] -> "."
pa' -> pa'
--
-- | basename : return the filename portion of a path
--
basename :: FilePath -> FilePath
basename p = reverse $ takeWhile (/= '/') $ reverse p
basename p =
let x = findIndices (== '\\') p
y = findIndices (== '/') p
in
if not $ null x
then if not $ null y
then if (maximum x) > (maximum y) then basename' '\\' p else basename' '/' p
else basename' '\\' p
else basename' '/' p
where
basename' chara pa = reverse $ takeWhile (/= chara) $ reverse pa
--
-- drop suffix