Skip to content

Commit 5e50cfd

Browse files
committed
Add IO-free variants of some functions
Fixes #6
1 parent 6c567f5 commit 5e50cfd

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed

System/OsString/Common.hs

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,13 @@ module System.OsString.MODULE_NAME
3333
, unsafeEncodeUtf
3434
, encodeWith
3535
, encodeFS
36+
#ifdef WINDOWS
37+
, fromString
38+
#endif
3639
, fromBytes
40+
#ifndef WINDOWS
41+
, fromBytestring
42+
#endif
3743
, pstr
3844
, singleton
3945
, empty
@@ -254,6 +260,18 @@ encodeFS = fmap WindowsString . encodeWithBaseWindows
254260
encodeFS = fmap PosixString . encodeWithBasePosix
255261
#endif
256262

263+
#ifdef WINDOWS
264+
-- | Like 'encodeFS', but not in IO.
265+
--
266+
-- 'encodeFS' was designed to have a symmetric type signature
267+
-- on unix and windows, but morally the function has no IO effects on windows,
268+
-- so we provide this variant without breaking existing API.
269+
--
270+
-- This function does not exist on unix.
271+
fromString :: String -> WindowsString
272+
fromString = unsafePerformIO . fmap WindowsString . encodeWithBaseWindows
273+
#endif
274+
257275

258276
#ifdef WINDOWS_DOC
259277
-- | Partial unicode friendly decoding.
@@ -346,6 +364,18 @@ fromBytes bs =
346364
fromBytes = pure . PosixString . BSP.toShort
347365
#endif
348366

367+
#ifndef WINDOWS
368+
-- | Like 'fromBytes', but not in IO.
369+
--
370+
-- 'fromBytes' was designed to have a symmetric type signature
371+
-- on unix and windows, but morally the function has no IO effects on unix,
372+
-- so we provide this variant without breaking existing API.
373+
--
374+
-- This function does not exist on windows.
375+
fromBytestring :: ByteString -> PosixString
376+
fromBytestring = PosixString . BSP.toShort
377+
#endif
378+
349379

350380
#ifdef WINDOWS_DOC
351381
-- | QuasiQuote a 'WindowsString'. This accepts Unicode characters

0 commit comments

Comments
 (0)