@@ -36,7 +36,7 @@
3636module Streamly.Internal.FileSystem.Path
3737 (
3838 -- * Path Types
39− Path
39+ Path (..)
4040 , File
4141 , Dir
4242 , Abs
@@ -82,6 +82,11 @@ module Streamly.Internal.FileSystem.Path
8282 , toChars
8383
8484 -- * 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.
88+ , primarySeparator
89+ , isSeparator
8590 , extendPath
8691 , extendDir
8792 )
@@ -89,6 +94,7 @@ where
8994
9095import Control.Exception (Exception)
9196import Control.Monad.Catch (MonadThrow(..))
97+import Data.Char (chr)
9298import Data.Functor.Identity (Identity(..))
9399import Data.Word (Word8)
94100#if defined(mingw32_HOST_OS) || defined(__MINGW32__)
@@ -447,8 +453,25 @@ mkRelFile = undefined
447453-- Operations
448454------------------------------------------------------------------------------
449455
450−separator :: WORD_TYPE
451−separator = SEPARATOR
456+separatorWord :: WORD_TYPE
457+separatorWord = SEPARATOR
458+
459+-- Portable definition for exporting.
460+
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)
466+
467+-- | On Posix only @/@ is a path separator but in windows it could be either
468+-- @/@ or @\\@.
469+isSeparator :: Char -> Bool
470+#if defined(mingw32_HOST_OS) || defined(__MINGW32__)
471+isSeparator c = (c == '/') || (c == '\\')
472+#else
473+isSeparator = (== '/')
474+#endif
452475
453476-- If we append an absolute path it may fail with an error if the 'Path'
454477-- implementation stores absolute path information (a leading separator char).
@@ -474,7 +497,7 @@ extendPath (Path a) (Path b) =
474497 newArr = unsafePerformIO $ do
475498 arr <- MutArray.new len
476499 arr1 <- MutArray.spliceUnsafe arr (Array.unsafeThaw a)
477− arr2 <- MutArray.snocUnsafe arr1 separator
500+ arr2 <- MutArray.snocUnsafe arr1 separatorWord
478501 arr3 <- MutArray.spliceUnsafe arr2 (Array.unsafeThaw b)
479502 return (Array.unsafeFreeze arr3)
480503 in Path newArr