Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 11 additions & 10 deletions core/src/Streamly/Internal/FileSystem/Path/Common.hs
Original file line number Diff line number Diff line change
Expand Up @@ -718,15 +718,15 @@ splitPath = splitPathUsing True
-- /Unimplemented/
{-# INLINE splitHead #-}
splitHead :: -- (Unbox a, Integral a) =>
OS -> Array a -> (Array a, Array a)
OS -> Array a -> (Array a, Maybe (Array a))
splitHead _os _arr = undefined

-- | Split the last non-empty path component.
--
-- /Unimplemented/
{-# INLINE splitTail #-}
splitTail :: -- (Unbox a, Integral a) =>
OS -> Array a -> (Array a, Array a)
OS -> Array a -> (Maybe (Array a), Array a)
splitTail _os _arr = undefined

------------------------------------------------------------------------------
Expand Down Expand Up @@ -764,7 +764,8 @@ validateFile os arr = do
Posix -> pure ()

{-# INLINE splitFile #-}
splitFile :: (Unbox a, Integral a) => OS -> Array a -> (Array a, Array a)
splitFile :: (Unbox a, Integral a) =>
OS -> Array a -> Maybe (Maybe (Array a), Array a)
splitFile os arr =
let p x =
if os == Windows
Expand All @@ -789,9 +790,9 @@ splitFile os arr =
&& fileSecond == charToWord '.')
then
if baseLen <= 0
then (Array.empty, arr)
else (Array.unsafeSliceOffLen 0 baseLen base, file) -- "/"
else (arr, Array.empty)
then Just (Nothing, arr)
else Just (Just $ Array.unsafeSliceOffLen 0 baseLen base, file) -- "/"
else Nothing

-- | Split a multi-component path into (dir, last component). If the path has a
-- single component and it is a root then return (path, "") otherwise return
Expand Down Expand Up @@ -868,7 +869,7 @@ splitDir _os _arr = undefined
-- | Like split extension but we can specify the extension char to be used.
{-# INLINE splitExtensionBy #-}
splitExtensionBy :: (Unbox a, Integral a) =>
a -> OS -> Array a -> (Array a, Array a)
a -> OS -> Array a -> Maybe (Array a, Array a)
splitExtensionBy c os arr =
let p x = x == c || isSeparatorWord os x
-- XXX Use Array.revBreakEndBy_
Expand Down Expand Up @@ -899,11 +900,11 @@ splitExtensionBy c os arr =
-- On Windows if base is 'c:.' or a UNC path ending in '/c:.' then
-- it is a dot file, no extension.
&& not (os == Windows && baseLast == charToWord ':')
then res
else (arr, Array.empty)
then Just res
else Nothing

{-# INLINE splitExtension #-}
splitExtension :: (Unbox a, Integral a) => OS -> Array a -> (Array a, Array a)
splitExtension :: (Unbox a, Integral a) => OS -> Array a -> Maybe (Array a, Array a)
splitExtension = splitExtensionBy extensionWord

{-
Expand Down
Loading
Loading