Skip to content

Commit

Permalink
Add
Browse files Browse the repository at this point in the history
  • Loading branch information
hasufell committed Aug 16, 2021
1 parent fa224b2 commit c99a7c5
Show file tree
Hide file tree
Showing 10 changed files with 367 additions and 68 deletions.
3 changes: 3 additions & 0 deletions abstract-filepath.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ description:
category: System
extra-source-files:
lib/AFP/AbstractFilePath/Common.hs
lib/AFP/OsString/Common.hs
lib/AFP/AbstractFilePath/Internal/Common.hs
lib/AFP/AbstractFilePath/Internal.hs-boot
lib/AFP/AbstractFilePath.hs-boot
Expand All @@ -36,6 +37,8 @@ library
AFP.Data.ByteString.Short.Word16
AFP.Data.Word16
AFP.OsString
AFP.OsString.Posix
AFP.OsString.Windows
AFP.OsString.Internal
AFP.OsString.Internal.Types

Expand Down
35 changes: 21 additions & 14 deletions lib/AFP/AbstractFilePath.hs
Original file line number Diff line number Diff line change
Expand Up @@ -64,18 +64,23 @@ module AFP.AbstractFilePath
(
-- * Types
AbstractFilePath
, WindowsFilePath
, PosixFilePath
, OsString
, OsWord

-- * Construction
, toAbstractFilePath
, toAbstractFilePathIO
, bsToAFP
, afp
, packAFP

-- * Deconstruction
, fromAbstractFilePath
, fromAbstractFilePathIO
, unpackAFP

-- * Word construction
, fromChar

-- * Separator predicates
, pathSeparator
Expand Down Expand Up @@ -140,7 +145,6 @@ module AFP.AbstractFilePath
, makeValid
, isFileName
, hasParentDir
, module AFP.OsString
)
where

Expand All @@ -151,10 +155,13 @@ import AFP.AbstractFilePath.Internal
, fromAbstractFilePathIO
, toAbstractFilePath
, toAbstractFilePathIO
, unpackAFP
, packAFP
)
import AFP.AbstractFilePath.Internal.Types
( AbstractFilePath, PosixFilePath, WindowsFilePath )
import AFP.OsString
import AFP.OsString.Internal ( fromChar )
import AFP.OsString.Internal.Types

#if defined(mingw32_HOST_OS) || defined(__MINGW32__)
Expand Down Expand Up @@ -474,7 +481,7 @@ takeAllParents (OsString p) = fmap OsString $ AFP.takeAllParents p
-- On Posix, \/ is a Drive.
--
-- > Windows: splitDrive "/test" == ("","/test")
-- > Windows: splitDrive "C:\\file" == ("C:","file")
-- > Windows: splitDrive "C:\\file" == ("C:\","file")
-- > Posix: splitDrive "/test" == ("/","test")
-- > splitDrive "//test" == ("//","test")
-- > splitDrive "test/file" == ("","test/file")
Expand Down Expand Up @@ -630,28 +637,28 @@ isRelative (OsString x) = AFP.isRelative x

-- | Check if a path is absolute
--
-- >>> Windows: isAbsolute "C:\\path" == True
-- >>> Windows: isAbsolute "/path" == False
-- >>> Posix: isAbsolute "/path" == True
-- >>> isAbsolute "path" == False
-- >>> isAbsolute "" == False
-- > Windows: isAbsolute "C:\\path" == True
-- > Windows: isAbsolute "/path" == False
-- > Posix: isAbsolute "/path" == True
-- > isAbsolute "path" == False
-- > isAbsolute "" == False
isAbsolute :: AbstractFilePath -> Bool
isAbsolute (OsString x) = AFP.isAbsolute x


-- | Is a FilePath valid, i.e. could you create a file like it?
--
-- >>> isValid "" == False
-- >>> isValid "\0" == False
-- >>> isValid "/random_path" == True
-- > isValid "" == False
-- > isValid "\0" == False
-- > isValid "/random_path" == True
isValid :: AbstractFilePath -> Bool
isValid (OsString filepath) = AFP.isValid filepath


-- | Take a FilePath and make it valid; does not change already valid FilePaths.
--
-- >>> makeValid "" == "_"
-- >>> makeValid "file\0name" == "file_name"
-- > makeValid "" == "_"
-- > makeValid "file\0name" == "file_name"
-- > if isValid p then makeValid p == p else makeValid p /= p
-- > isValid (makeValid p)
makeValid :: AbstractFilePath -> AbstractFilePath
Expand Down
40 changes: 39 additions & 1 deletion lib/AFP/AbstractFilePath/Common.hs
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,33 @@

module AFP.AbstractFilePath.MODULE_NAME
(
-- * Types
#ifdef WINDOWS
WindowsString
, WindowsWord
, WindowsFilePath
#else
PosixString
, PosixWord
, PosixFilePath
#endif
-- * String construction
, toPlatformString
, toPlatformStringIO
, bsToPlatformString
, pstr
, packPlatformString

-- * String deconstruction
, fromPlatformString
, fromPlatformStringIO
, unpackPlatformString

-- * Word construction
, fromChar

-- * Separator predicates
pathSeparator
, pathSeparator
, pathSeparators
, isPathSeparator
, searchPathSeparator
Expand Down Expand Up @@ -88,6 +113,19 @@ import qualified AFP.AbstractFilePath.Internal.MODULE_NAME as IP
import AFP.AbstractFilePath.Internal.Types
import AFP.OsString.Internal.Types

import AFP.OsString.MODULE_NAME (
toPlatformString
, toPlatformStringIO
, bsToPlatformString
, pstr
, packPlatformString
, fromPlatformString
, fromPlatformStringIO
, unpackPlatformString
, fromChar
)


import Control.Arrow
( second )
import Data.Bifunctor
Expand Down
6 changes: 3 additions & 3 deletions lib/AFP/AbstractFilePath/Internal/Common.hs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{-# LANGUAGE CPP #-}
{-# LANGUAGE TypeSynonymInstances #-}
{-# LANGUAGE MultiWayIf #-}
{-# LANGUAGE TypeSynonymInstances #-}
-- This template expects CPP definitions for:
-- MODULE_NAME = Posix | Windows
-- IS_WINDOWS = False | True
Expand Down Expand Up @@ -64,14 +64,14 @@ import Data.Word8
)
#endif

import Data.List
( mapAccumL )
import Control.Arrow
( second )
import Data.ByteString
( ByteString )
import Data.ByteString.Short
( ShortByteString )
import Data.List
( mapAccumL )
import Data.Maybe
( isJust )
import Prelude hiding
Expand Down
4 changes: 0 additions & 4 deletions lib/AFP/OsString.hs
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@ module AFP.OsString
(
-- * String types
OsString
, WindowsString
, PosixString

-- * String construction
, toOsString
Expand All @@ -35,8 +33,6 @@ module AFP.OsString

-- * Word types
, OsWord
, WindowsWord
, PosixWord

-- * Word construction
, fromChar
Expand Down
Loading

0 comments on commit c99a7c5

Please sign in to comment.