now dirname and basename work well on Windows and other platform that can use backslash on path
This commit is contained in:
parent
5be5242113
commit
d07bb01b48
@ -244,15 +244,35 @@ a <> b = a ++ b
|
||||
--
|
||||
dirname :: FilePath -> FilePath
|
||||
dirname p =
|
||||
case reverse $ dropWhile (/= '/') $ reverse p of
|
||||
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
|
||||
[] -> "."
|
||||
p' -> p'
|
||||
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
|
||||
|
Loading…
x
Reference in New Issue
Block a user