Skip to content

Commit

Permalink
Merge branch 'encodeFS-deprecation'
Browse files Browse the repository at this point in the history
  • Loading branch information
hasufell committed Jun 29, 2024
2 parents e7cb9fd + 0074390 commit 03f4256
Showing 1 changed file with 36 additions and 8 deletions.
44 changes: 36 additions & 8 deletions System/OsPath/Common.hs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ module System.OsPath
, PS.encodeUtf
, PS.unsafeEncodeUtf
, PS.encodeWith
, PS.encodeFS
, encodeFS
#if defined(WINDOWS) || defined(POSIX)
, pstr
#else
Expand All @@ -55,7 +55,7 @@ module System.OsPath
-- * Filepath deconstruction
, PS.decodeUtf
, PS.decodeWith
, PS.decodeFS
, decodeFS
, PS.unpack

-- * Word construction
Expand Down Expand Up @@ -115,12 +115,10 @@ import System.OsString.Windows as PS
, toChar
, decodeUtf
, decodeWith
, decodeFS
, pack
, encodeUtf
, unsafeEncodeUtf
, encodeWith
, encodeFS
, unpack
)
import Data.Bifunctor ( bimap )
Expand Down Expand Up @@ -148,12 +146,10 @@ import System.OsString.Posix as PS
, toChar
, decodeUtf
, decodeWith
, decodeFS
, pack
, encodeUtf
, unsafeEncodeUtf
, encodeWith
, encodeFS
, unpack
)
import Data.Bifunctor ( bimap )
Expand All @@ -165,12 +161,10 @@ import System.OsPath.Internal as PS
( osp
, decodeUtf
, decodeWith
, decodeFS
, pack
, encodeUtf
, unsafeEncodeUtf
, encodeWith
, encodeFS
, unpack
)
import System.OsPath.Types
Expand All @@ -187,6 +181,7 @@ import Data.Bifunctor
( bimap )
#endif
import System.OsString.Internal.Types
import System.OsString.Encoding.Internal


------------------------
Expand Down Expand Up @@ -1439,3 +1434,36 @@ isRelative (OSSTRING_NAME x) = C.isRelative x
-- > isAbsolute x == not (isRelative x)
isAbsolute :: FILEPATH_NAME -> Bool
isAbsolute (OSSTRING_NAME x) = C.isAbsolute x


-- things not defined in os-string

#ifdef WINDOWS
encodeFS :: String -> IO WindowsPath
encodeFS = fmap WindowsString . encodeWithBaseWindows

decodeFS :: WindowsPath -> IO String
decodeFS (WindowsString x) = decodeWithBaseWindows x
#elif defined(POSIX)
encodeFS :: String -> IO PosixPath
encodeFS = fmap PosixString . encodeWithBasePosix

decodeFS :: PosixPath -> IO String
decodeFS (PosixString x) = decodeWithBasePosix x
#else
encodeFS :: String -> IO OsPath
#if defined(mingw32_HOST_OS) || defined(__MINGW32__)
encodeFS = fmap (OsString . WindowsString) . encodeWithBaseWindows
#else
encodeFS = fmap (OsString . PosixString) . encodeWithBasePosix
#endif

decodeFS :: OsPath -> IO String
#if defined(mingw32_HOST_OS) || defined(__MINGW32__)
decodeFS (OsString (WindowsString x)) = decodeWithBaseWindows x
#else
decodeFS (OsString (PosixString x)) = decodeWithBasePosix x
#endif

#endif

0 comments on commit 03f4256

Please sign in to comment.