Skip to content

Commit

Permalink
Add IO-free variants of some functions
Browse files Browse the repository at this point in the history
Fixes #4
  • Loading branch information
hasufell committed Dec 26, 2023
1 parent 6c567f5 commit 08c687b
Showing 1 changed file with 30 additions and 0 deletions.
30 changes: 30 additions & 0 deletions System/OsString/Common.hs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,13 @@ module System.OsString.MODULE_NAME
, unsafeEncodeUtf
, encodeWith
, encodeFS
#ifdef WINDOWS
, fromString
#endif
, fromBytes
#ifndef WINDOWS
, fromBytestring
#endif
, pstr
, singleton
, empty
Expand Down Expand Up @@ -254,6 +260,18 @@ encodeFS = fmap WindowsString . encodeWithBaseWindows
encodeFS = fmap PosixString . encodeWithBasePosix
#endif

#ifdef WINDOWS
-- | Like 'encodeFS', but not in IO.
--
-- 'encodeFS' was designed to have a symmetric type signature
-- on unix and windows, but morally the function has no IO effects on windows,
-- so we provide this variant without breaking existing API.
--
-- This function does not exist on unix.
fromString :: String -> WindowsString
fromString = unsafePerformIO . fmap WindowsString . encodeWithBaseWindows
#endif


#ifdef WINDOWS_DOC
-- | Partial unicode friendly decoding.
Expand Down Expand Up @@ -346,6 +364,18 @@ fromBytes bs =
fromBytes = pure . PosixString . BSP.toShort
#endif

#ifndef WINDOWS
-- | Like 'fromBytes', but not in IO.
--
-- 'fromBytes' was designed to have a symmetric type signature
-- on unix and windows, but morally the function has no IO effects on unix,
-- so we provide this variant without breaking existing API.
--
-- This function does not exist on windows.
fromBytestring :: ByteString -> PosixString
fromBytestring = PosixString . BSP.toShort
#endif


#ifdef WINDOWS_DOC
-- | QuasiQuote a 'WindowsString'. This accepts Unicode characters
Expand Down

0 comments on commit 08c687b

Please sign in to comment.