Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adjust for the encodeFS/decodeFS deprecation in os-string #232

Merged
merged 1 commit into from
Jun 29, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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

Loading