@@ -33,6 +33,7 @@ module System.OsString.MODULE_NAME
3333 , unsafeEncodeUtf
3434 , encodeWith
3535 , encodeFS
36+ , encodeLE
3637 , fromBytes
3738 , pstr
3839 , singleton
@@ -43,6 +44,7 @@ module System.OsString.MODULE_NAME
4344 , decodeUtf
4445 , decodeWith
4546 , decodeFS
47+ , decodeLE
4648 , unpack
4749
4850 -- * Word construction
@@ -242,14 +244,14 @@ encodeWith enc str = unsafePerformIO $ do
242244
243245#ifdef WINDOWS_DOC
244246-- | This mimics the behavior of the base library when doing filesystem
245- -- operations, which does permissive UTF-16 encoding, where coding errors generate
247+ -- operations (usually filepaths) , which does permissive UTF-16 encoding, where coding errors generate
246248-- Chars in the surrogate range.
247249--
248250-- The reason this is in IO is because it unifies with the Posix counterpart,
249251-- which does require IO. This is safe to 'unsafePerformIO'/'unsafeDupablePerformIO'.
250252#else
251253-- | This mimics the behavior of the base library when doing filesystem
252- -- operations, which uses shady PEP 383 style encoding (based on the current locale,
254+ -- operations (usually filepaths) , which uses shady PEP 383 style encoding (based on the current locale,
253255-- but PEP 383 only works properly on UTF-8 encodings, so good luck).
254256--
255257-- Looking up the locale requires IO. If you're not worried about calls
@@ -258,11 +260,35 @@ encodeWith enc str = unsafePerformIO $ do
258260#endif
259261encodeFS :: String -> IO PLATFORM_STRING
260262#ifdef WINDOWS
263+ {-# DEPRECATED encodeFS "Use System.OsPath.Windows.encodeFS from filepath" #-}
261264encodeFS = fmap WindowsString . encodeWithBaseWindows
262265#else
266+ {-# DEPRECATED encodeFS "Use System.OsPath.Posix.encodeFS from filepath" #-}
263267encodeFS = fmap PosixString . encodeWithBasePosix
264268#endif
265269
270+ #ifdef WINDOWS_DOC
271+ -- | This mimics the behavior of the base library when doing string
272+ -- operations, which does permissive UTF-16 encoding, where coding errors generate
273+ -- Chars in the surrogate range.
274+ --
275+ -- The reason this is in IO is because it unifies with the Posix counterpart,
276+ -- which does require IO. This is safe to 'unsafePerformIO'/'unsafeDupablePerformIO'.
277+ #else
278+ -- | This mimics the behavior of the base library when doing string
279+ -- operations, which uses 'getLocaleEncoding'.
280+ --
281+ -- Looking up the locale requires IO. If you're not worried about calls
282+ -- to 'setFileSystemEncoding', then 'unsafePerformIO' may be feasible (make sure
283+ -- to deeply evaluate the result to catch exceptions).
284+ #endif
285+ encodeLE :: String -> IO PLATFORM_STRING
286+ #ifdef WINDOWS
287+ encodeLE = fmap WindowsString . encodeWithBaseWindows
288+ #else
289+ encodeLE = fmap PosixString . encodeWithBasePosix'
290+ #endif
291+
266292
267293#ifdef WINDOWS_DOC
268294-- | Partial unicode friendly decoding.
@@ -317,7 +343,29 @@ decodeWith unixEnc (PosixString ba) = unsafePerformIO $ do
317343-- which does require IO. 'unsafePerformIO'/'unsafeDupablePerformIO' are safe, however.
318344#else
319345-- | This mimics the behavior of the base library when doing filesystem
320- -- operations, which uses shady PEP 383 style encoding (based on the current locale,
346+ -- operations, which uses 'getLocaleEncoding'.
347+ --
348+ -- Looking up the locale requires IO. If you're not worried about calls
349+ -- to 'setFileSystemEncoding', then 'unsafePerformIO' may be feasible (make sure
350+ -- to deeply evaluate the result to catch exceptions).
351+ #endif
352+ decodeLE :: PLATFORM_STRING -> IO String
353+ #ifdef WINDOWS
354+ decodeLE (WindowsString ba) = decodeWithBaseWindows ba
355+ #else
356+ decodeLE (PosixString ba) = decodeWithBasePosix' ba
357+ #endif
358+
359+ #ifdef WINDOWS_DOC
360+ -- | Like 'decodeUtf', except this mimics the behavior of the base library when doing filesystem
361+ -- operations (usually filepaths), which does permissive UTF-16 encoding, where coding errors generate
362+ -- Chars in the surrogate range.
363+ --
364+ -- The reason this is in IO is because it unifies with the Posix counterpart,
365+ -- which does require IO. 'unsafePerformIO'/'unsafeDupablePerformIO' are safe, however.
366+ #else
367+ -- | This mimics the behavior of the base library when doing filesystem
368+ -- operations (usually filepaths), which uses shady PEP 383 style encoding (based on the current locale,
321369-- but PEP 383 only works properly on UTF-8 encodings, so good luck).
322370--
323371-- Looking up the locale requires IO. If you're not worried about calls
@@ -326,8 +374,10 @@ decodeWith unixEnc (PosixString ba) = unsafePerformIO $ do
326374#endif
327375decodeFS :: PLATFORM_STRING -> IO String
328376#ifdef WINDOWS
377+ {-# DEPRECATED decodeFS "Use System.OsPath.Windows.decodeFS from filepath" #-}
329378decodeFS (WindowsString ba) = decodeWithBaseWindows ba
330379#else
380+ {-# DEPRECATED decodeFS "Use System.OsPath.Posix.decodeFS from filepath" #-}
331381decodeFS (PosixString ba) = decodeWithBasePosix ba
332382#endif
333383
0 commit comments