Skip to content
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
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