Safe Haskell | None |
---|---|
Language | Haskell2010 |
Synopsis
- data WindowsString
- data WindowsChar
- toPlatformStringUtf :: MonadThrow m => String -> m WindowsString
- toPlatformStringEnc :: TextEncoding -> String -> Either EncodingException WindowsString
- toPlatformStringFS :: String -> IO WindowsString
- bytesToPlatformString :: MonadThrow m => ByteString -> m WindowsString
- pstr :: QuasiQuoter
- packPlatformString :: [WindowsChar] -> WindowsString
- fromPlatformStringUtf :: MonadThrow m => WindowsString -> m String
- fromPlatformStringEnc :: TextEncoding -> WindowsString -> Either EncodingException String
- fromPlatformStringFS :: WindowsString -> IO String
- unpackPlatformString :: WindowsString -> [WindowsChar]
- unsafeFromChar :: Char -> WindowsChar
- toChar :: WindowsChar -> Char
Types
data WindowsString Source #
Commonly used windows string as UTF16 bytes.
Instances
data WindowsChar Source #
Instances
String construction
toPlatformStringUtf :: MonadThrow m => String -> m WindowsString Source #
Partial unicode friendly encoding.
This encodes as UTF16-LE (strictly), which is a pretty good guess.
Throws an EncodingException
if encoding fails.
toPlatformStringEnc :: TextEncoding -> String -> Either EncodingException WindowsString Source #
Like toPlatformStringUtf
, except allows to provide an encoding.
toPlatformStringFS :: String -> IO WindowsString Source #
Like toPlatformStringUtf
, except this mimics the behavior of the base library when doing filesystem
operations, which does permissive UTF-16 encoding, where coding errors generate
Chars in the surrogate range.
The reason this is in IO is because it unifies with the Posix counterpart,
which does require IO. This is safe to unsafePerformIO
/unsafeDupablePerformIO
.
bytesToPlatformString :: MonadThrow m => ByteString -> m WindowsString Source #
Constructs a platform string from a ByteString.
This ensures valid UCS-2LE. Note that this doesn't expand Word8 to Word16 on windows, so you may get invalid UTF-16.
Throws EncodingException
on invalid UCS-2LE (although unlikely).
QuasiQuote a WindowsString
. This accepts Unicode characters
and encodes as UTF-16 on windows.
packPlatformString :: [WindowsChar] -> WindowsString Source #
Pack a list of platform words to a platform string.
Note that using this in conjunction with unsafeFromChar
to
convert from [Char]
to platform string is probably not what
you want, because it will truncate unicode code points.
String deconstruction
fromPlatformStringUtf :: MonadThrow m => WindowsString -> m String Source #
Partial unicode friendly decoding.
This decodes as UTF16-LE (strictly), which is a pretty good.
Throws a EncodingException
if decoding fails.
fromPlatformStringEnc :: TextEncoding -> WindowsString -> Either EncodingException String Source #
Like fromPlatformStringUtf
, except allows to provide a text encoding.
The String is forced into memory to catch all exceptions.
fromPlatformStringFS :: WindowsString -> IO String Source #
Like fromPlatformStringUtf
, except this mimics the behavior of the base library when doing filesystem
operations, which does permissive UTF-16 encoding, where coding errors generate
Chars in the surrogate range.
The reason this is in IO is because it unifies with the Posix counterpart,
which does require IO. unsafePerformIO
/unsafeDupablePerformIO
are safe, however.
unpackPlatformString :: WindowsString -> [WindowsChar] Source #
Unpack a platform string to a list of platform words.
Word construction
unsafeFromChar :: Char -> WindowsChar Source #
Truncates to 2 octets.
Word deconstruction
toChar :: WindowsChar -> Char Source #
Converts back to a unicode codepoint (total).