Safe Haskell | None |
---|---|
Language | Haskell2010 |
Synopsis
- data PosixString
- data PosixChar
- toPlatformString :: String -> PosixString
- toPlatformStringIO :: String -> IO PosixString
- bsToPlatformString :: MonadThrow m => ByteString -> m PosixString
- pstr :: QuasiQuoter
- packPlatformString :: [PosixChar] -> PosixString
- fromPlatformString :: MonadThrow m => PosixString -> m String
- fromPlatformStringEnc :: PosixString -> TextEncoding -> Either UnicodeException String
- fromPlatformStringIO :: PosixString -> IO String
- unpackPlatformString :: PosixString -> [PosixChar]
- unsafeFromChar :: Char -> PosixChar
- toChar :: PosixChar -> Char
Types
data PosixString Source #
Commonly used Posix string as uninterpreted char[]
array.
Instances
String construction
toPlatformString :: String -> PosixString Source #
Total Unicode-friendly encoding.
On windows this encodes as UTF16, which is expected. On unix this encodes as UTF8, which is a good guess.
toPlatformStringIO :: String -> IO PosixString Source #
Like toPlatformString
, except on unix this uses the current
locale for encoding instead of always UTF8.
Looking up the locale requires IO. If you're not worried about calls
to setFileSystemEncoding
, then unsafePerformIO
may be feasible.
bsToPlatformString :: MonadThrow m => ByteString -> m PosixString Source #
Constructs an platform string from a ByteString.
On windows, this ensures valid UTF16, on unix it is passed unchanged/unchecked.
Throws UnicodeException
on invalid UTF16 on windows.
pstr :: QuasiQuoter Source #
QuasiQuote a PosixString
. This accepts Unicode characters
and encodes as UTF-8 on unix.
packPlatformString :: [PosixChar] -> PosixString Source #
String deconstruction
fromPlatformString :: MonadThrow m => PosixString -> m String Source #
Partial unicode friendly decoding.
On windows this decodes as UTF16 (which is the expected filename encoding). On unix this decodes as UTF8 (which is a good guess). Note that filenames on unix are encoding agnostic char arrays.
Throws a UnicodeException
if decoding fails.
fromPlatformStringEnc :: PosixString -> TextEncoding -> Either UnicodeException String Source #
Like fromPlatformString
, except on unix this uses the provided
TextEncoding
for decoding.
fromPlatformStringIO :: PosixString -> IO String Source #
Like fromPlatformString
, except on unix this uses the current
locale for decoding instead of always UTF8.
Looking up the locale requires IO. If you're not worried about calls
to setFileSystemEncoding
, then unsafePerformIO
may be feasible.
Throws UnicodeException
if decoding fails.
unpackPlatformString :: PosixString -> [PosixChar] Source #
Word construction
unsafeFromChar :: Char -> PosixChar Source #
Truncates to 1 octet.