Skip to content

Commit 24c15bc

Browse files
committed
Merge branch 'issue-4'
2 parents 86749e9 + 5e50cfd commit 24c15bc

File tree

1 file changed

+33
-0
lines changed

1 file changed

+33
-0
lines changed

System/OsString/Common.hs

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,13 @@ module System.OsString.MODULE_NAME
3434
, encodeWith
3535
, encodeFS
3636
, encodeLE
37+
#ifdef WINDOWS
38+
, fromString
39+
#endif
3740
, fromBytes
41+
#ifndef WINDOWS
42+
, fromBytestring
43+
#endif
3844
, pstr
3945
, singleton
4046
, empty
@@ -289,6 +295,19 @@ encodeLE = fmap WindowsString . encodeWithBaseWindows
289295
encodeLE = fmap PosixString . encodeWithBasePosix'
290296
#endif
291297

298+
#ifdef WINDOWS
299+
-- | Like 'encodeFS', but not in IO.
300+
--
301+
-- 'encodeFS' was designed to have a symmetric type signature
302+
-- on unix and windows, but morally the function has no IO effects on windows,
303+
-- so we provide this variant without breaking existing API.
304+
--
305+
-- This function does not exist on unix.
306+
--
307+
-- @since 2.0.6
308+
fromString :: String -> WindowsString
309+
fromString = unsafePerformIO . fmap WindowsString . encodeWithBaseWindows
310+
#endif
292311

293312
#ifdef WINDOWS_DOC
294313
-- | Partial unicode friendly decoding.
@@ -405,6 +424,20 @@ fromBytes bs =
405424
fromBytes = pure . PosixString . BSP.toShort
406425
#endif
407426

427+
#ifndef WINDOWS
428+
-- | Like 'fromBytes', but not in IO.
429+
--
430+
-- 'fromBytes' was designed to have a symmetric type signature
431+
-- on unix and windows, but morally the function has no IO effects on unix,
432+
-- so we provide this variant without breaking existing API.
433+
--
434+
-- This function does not exist on windows.
435+
--
436+
-- @since 2.0.6
437+
fromBytestring :: ByteString -> PosixString
438+
fromBytestring = PosixString . BSP.toShort
439+
#endif
440+
408441

409442
#ifdef WINDOWS_DOC
410443
-- | QuasiQuote a 'WindowsString'. This accepts Unicode characters

0 commit comments

Comments
 (0)