@@ -36,7 +36,7 @@
36module Streamly.Internal.FileSystem.Path
36module Streamly.Internal.FileSystem.Path
38 -- * Path Types
38 -- * Path Types
@@ -82,6 +82,11 @@ module Streamly.Internal.FileSystem.Path
84 -- * Operations
84 -- * Operations
85+ -- Do we need to export the separator functions? They are not essential if
86+ -- operations to split and combine paths are provided. If someone wants to
87+ -- work on paths at low level then they know what they are.
85 , extendPath
90 , extendPath
86 , extendDir
91 , extendDir
@@ -89,6 +94,7 @@ where
90import Control.Exception (Exception)
95import Control.Exception (Exception)
91import Control.Monad.Catch (MonadThrow(..))
96import Control.Monad.Catch (MonadThrow(..))
97+import Data.Char (chr)
92import Data.Functor.Identity (Identity(..))
98import Data.Functor.Identity (Identity(..))
93import Data.Word (Word8)
99import Data.Word (Word8)
94#if defined(mingw32_HOST_OS) || defined(__MINGW32__)
100#if defined(mingw32_HOST_OS) || defined(__MINGW32__)
@@ -447,8 +453,25 @@ mkRelFile = undefined
447-- Operations
453-- Operations
448------------------------------------------------------------------------------
454------------------------------------------------------------------------------
450−separator :: WORD_TYPE
456+separatorWord :: WORD_TYPE
451−separator = SEPARATOR
457+separatorWord = SEPARATOR
459+-- Portable definition for exporting.
461+-- | Primary path separator character, @/@ on Posix and @\\@ on Windows.
462+-- Windows supports @/@ too as a separator. Please use 'isSeparator' for
463+-- testing if a char is a separator char.
464+primarySeparator :: Char
465+primarySeparator = chr (SEPARATOR)
467+-- | On Posix only @/@ is a path separator but in windows it could be either
469+isSeparator :: Char -> Bool
470+#if defined(mingw32_HOST_OS) || defined(__MINGW32__)
471+isSeparator c = (c == '/') || (c == '\\')
473+isSeparator = (== '/')
453-- If we append an absolute path it may fail with an error if the 'Path'
476-- If we append an absolute path it may fail with an error if the 'Path'
454-- implementation stores absolute path information (a leading separator char).
477-- implementation stores absolute path information (a leading separator char).
@@ -474,7 +497,7 @@ extendPath (Path a) (Path b) =
474 newArr = unsafePerformIO $ do
497 newArr = unsafePerformIO $ do
475 arr <- MutArray.new len
498 arr <- MutArray.new len
476 arr1 <- MutArray.spliceUnsafe arr (Array.unsafeThaw a)
499 arr1 <- MutArray.spliceUnsafe arr (Array.unsafeThaw a)
477− arr2 <- MutArray.snocUnsafe arr1 separator
500+ arr2 <- MutArray.snocUnsafe arr1 separatorWord
478 arr3 <- MutArray.spliceUnsafe arr2 (Array.unsafeThaw b)
501 arr3 <- MutArray.spliceUnsafe arr2 (Array.unsafeThaw b)
479 return (Array.unsafeFreeze arr3)
502 return (Array.unsafeFreeze arr3)
480 in Path newArr
503 in Path newArr