| Safe Haskell | Safe-Inferred |
|---|---|
| Language | Haskell2010 |
System.OsPath.Internal
Synopsis
- encodeUtf :: MonadThrow m => FilePath -> m OsPath
- unsafeEncodeUtf :: HasCallStack => String -> OsString
- encodeWith :: TextEncoding -> TextEncoding -> FilePath -> Either EncodingException OsPath
- encodeFS :: FilePath -> IO OsPath
- decodeUtf :: MonadThrow m => OsPath -> m FilePath
- decodeWith :: TextEncoding -> TextEncoding -> OsPath -> Either EncodingException FilePath
- decodeFS :: OsPath -> IO FilePath
- fromBytes :: MonadThrow m => ByteString -> m OsPath
- osp :: QuasiQuoter
- unpack :: OsPath -> [OsChar]
- pack :: [OsChar] -> OsPath
Documentation
encodeUtf :: MonadThrow m => FilePath -> m OsPath Source #
Partial unicode friendly encoding.
On windows this encodes as UTF16-LE (strictly), which is a pretty good guess. On unix this encodes as UTF8 (strictly), which is a good guess.
Throws an EncodingException if encoding fails. If the input does not
contain surrogate chars, you can use unsafeEncodeUtf.
unsafeEncodeUtf :: HasCallStack => String -> OsString Source #
Unsafe unicode friendly encoding.
Like encodeUtf, except it crashes when the input contains
surrogate chars. For sanitized input, this can be useful.
Arguments
| :: TextEncoding | unix text encoding |
| -> TextEncoding | windows text encoding (wide char) |
| -> FilePath | |
| -> Either EncodingException OsPath |
Encode a FilePath with the specified encoding.
Note: on windows, we expect a "wide char" encoding (e.g. UCS-2 or UTF-16). Anything
that works with Word16 boundaries. Picking an incompatible encoding may crash
filepath operations.
encodeFS :: FilePath -> IO OsPath Source #
Like encodeUtf, except this mimics the behavior of the base library when doing filesystem
operations, which is:
- on unix, uses shady PEP 383 style encoding (based on the current locale, but PEP 383 only works properly on UTF-8 encodings, so good luck)
- on windows does permissive UTF-16 encoding, where coding errors generate Chars in the surrogate range
Looking up the locale requires IO. If you're not worried about calls
to setFileSystemEncoding, then unsafePerformIO may be feasible (make sure
to deeply evaluate the result to catch exceptions).
decodeUtf :: MonadThrow m => OsPath -> m FilePath Source #
Partial unicode friendly decoding.
On windows this decodes as UTF16-LE (strictly), which is a pretty good guess. On unix this decodes as UTF8 (strictly), which is a good guess.
Throws a EncodingException if decoding fails.
Arguments
| :: TextEncoding | unix text encoding |
| -> TextEncoding | windows text encoding |
| -> OsPath | |
| -> Either EncodingException FilePath |
Decode an OsPath with the specified encoding.
decodeFS :: OsPath -> IO FilePath Source #
Like decodeUtf, except this mimics the behavior of the base library when doing filesystem
operations, which is:
- on unix, uses shady PEP 383 style encoding (based on the current locale, but PEP 383 only works properly on UTF-8 encodings, so good luck)
- on windows does permissive UTF-16 encoding, where coding errors generate Chars in the surrogate range
Looking up the locale requires IO. If you're not worried about calls
to setFileSystemEncoding, then unsafePerformIO may be feasible (make sure
to deeply evaluate the result to catch exceptions).
fromBytes :: MonadThrow m => ByteString -> m OsPath Source #
Constructs an OsPath from a ByteString.
On windows, this ensures valid UCS-2LE, on unix it is passed unchanged/unchecked.
Throws EncodingException on invalid UCS-2LE on windows (although unlikely).
osp :: QuasiQuoter Source #