on master help sign in
Export the Path constructor and separator
defafa6Harendra Kumar
core/src/Streamly/Internal/FileSystem/Path.hs+27−4
@@ -36,7 +36,7 @@
36module Streamly.Internal.FileSystem.Path
36module Streamly.Internal.FileSystem.Path
37 (
37 (
38 -- * Path Types
38 -- * Path Types
39− Path
39+ Path (..)
40 , File
40 , File
41 , Dir
41 , Dir
42 , Abs
42 , Abs
@@ -82,6 +82,11 @@ module Streamly.Internal.FileSystem.Path
82 , toChars
82 , toChars
83
83
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.
88+ , primarySeparator
89+ , isSeparator
85 , extendPath
90 , extendPath
86 , extendDir
91 , extendDir
87 )
92 )
@@ -89,6 +94,7 @@ where
89
94
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------------------------------------------------------------------------------
449
455
450−separator :: WORD_TYPE
456+separatorWord :: WORD_TYPE
451−separator = SEPARATOR
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
452
475
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