filepath-1.4.100.4: Library for manipulating FilePaths in a cross platform way.

Safe Haskell | Safe-Inferred
Language | Haskell2010

System.OsString.Windows

Contents

- Types
- String construction
- String deconstruction
- Word construction
- Word deconstruction

Synopsis

- data WindowsString
- data WindowsChar
- encodeUtf :: MonadThrow m => String -> m WindowsString
- encodeWith :: TextEncoding -> String -> Either EncodingException WindowsString
- encodeFS :: String -> IO WindowsString
- fromBytes :: MonadThrow m => ByteString -> m WindowsString
- pstr :: QuasiQuoter
- pack :: [WindowsChar] -> WindowsString
- decodeUtf :: MonadThrow m => WindowsString -> m String
- decodeWith :: TextEncoding -> WindowsString -> Either EncodingException String
- decodeFS :: WindowsString -> IO String
- unpack :: WindowsString -> [WindowsChar]
- unsafeFromChar :: Char -> WindowsChar
- toChar :: WindowsChar -> Char

# Types

data WindowsString Source #

Commonly used windows string as wide character bytes.

#### Instances

Instances details

Monoid WindowsString Source # |
Instance details Defined in System.OsString.Internal.Types Methods mempty :: WindowsString Source # mappend :: WindowsString -> WindowsString -> WindowsString Source # mconcat :: [WindowsString] -> WindowsString Source #
Semigroup WindowsString Source # |
Instance details Defined in System.OsString.Internal.Types Methods (<>) :: WindowsString -> WindowsString -> WindowsString Source # sconcat :: NonEmpty WindowsString -> WindowsString Source # stimes :: Integral b => b -> WindowsString -> WindowsString Source #
Generic WindowsString Source # |
Instance details Defined in System.OsString.Internal.Types Associated Types type Rep WindowsString :: Type -> Type Source # Methods from :: WindowsString -> Rep WindowsString x Source # to :: Rep WindowsString x -> WindowsString Source #
Show WindowsString Source # | Decodes as UCS-2.
Instance details Defined in System.OsString.Internal.Types Methods showsPrec :: Int -> WindowsString -> ShowS Source # show :: WindowsString -> String Source # showList :: [WindowsString] -> ShowS Source #
NFData WindowsString Source # |
Instance details Defined in System.OsString.Internal.Types Methods rnf :: WindowsString -> () Source #
Eq WindowsString Source # |
Instance details Defined in System.OsString.Internal.Types Methods (==) :: WindowsString -> WindowsString -> Bool # (/=) :: WindowsString -> WindowsString -> Bool #
Ord WindowsString Source # |

Instance details

Defined in System.OsString.Internal.Types

Methods

compare :: WindowsString -> WindowsString -> Ordering #

(<) :: WindowsString -> WindowsString -> Bool #

(<=) :: WindowsString -> WindowsString -> Bool #

(>) :: WindowsString -> WindowsString -> Bool #

(>=) :: WindowsString -> WindowsString -> Bool #

max :: WindowsString -> WindowsString -> WindowsString #

min :: WindowsString -> WindowsString -> WindowsString #

Lift WindowsString Source # |
Instance details Defined in System.OsString.Internal.Types Methods lift :: Quote m => WindowsString -> m Exp Source # liftTyped :: forall (m :: Type -> Type). Quote m => WindowsString -> Code m WindowsString Source #
type Rep WindowsString Source # |
Instance details Defined in System.OsString.Internal.Types type Rep WindowsString = D1 ('MetaData "WindowsString" "System.OsString.Internal.Types" "filepath-1.4.100.4" 'True) (C1 ('MetaCons "WindowsString" 'PrefixI 'True) (S1 ('MetaSel ('Just "getWindowsString") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 ShortByteString)))

data WindowsChar Source #

#### Instances

Instances details

Generic WindowsChar Source # |
Instance details Defined in System.OsString.Internal.Types Associated Types type Rep WindowsChar :: Type -> Type Source # Methods from :: WindowsChar -> Rep WindowsChar x Source # to :: Rep WindowsChar x -> WindowsChar Source #
Show WindowsChar Source # |
Instance details Defined in System.OsString.Internal.Types Methods showsPrec :: Int -> WindowsChar -> ShowS Source # show :: WindowsChar -> String Source # showList :: [WindowsChar] -> ShowS Source #
NFData WindowsChar Source # |
Instance details Defined in System.OsString.Internal.Types Methods rnf :: WindowsChar -> () Source #
Eq WindowsChar Source # |
Instance details Defined in System.OsString.Internal.Types Methods (==) :: WindowsChar -> WindowsChar -> Bool # (/=) :: WindowsChar -> WindowsChar -> Bool #
Ord WindowsChar Source # |
Instance details Defined in System.OsString.Internal.Types Methods compare :: WindowsChar -> WindowsChar -> Ordering # (<) :: WindowsChar -> WindowsChar -> Bool # (<=) :: WindowsChar -> WindowsChar -> Bool # (>) :: WindowsChar -> WindowsChar -> Bool # (>=) :: WindowsChar -> WindowsChar -> Bool # max :: WindowsChar -> WindowsChar -> WindowsChar # min :: WindowsChar -> WindowsChar -> WindowsChar #
type Rep WindowsChar Source # |
Instance details Defined in System.OsString.Internal.Types type Rep WindowsChar = D1 ('MetaData "WindowsChar" "System.OsString.Internal.Types" "filepath-1.4.100.4" 'True) (C1 ('MetaCons "WindowsChar" 'PrefixI 'True) (S1 ('MetaSel ('Just "getWindowsChar") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 Word16)))

# String construction

encodeUtf :: 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.

encodeWith :: TextEncoding -> String -> Either EncodingException WindowsString Source #

Encode a `String` with the specified encoding.

encodeFS :: String -> IO WindowsString Source #

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`.

fromBytes :: 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).

pstr :: QuasiQuoter Source #

QuasiQuote a `WindowsString`. This accepts Unicode characters and encodes as UTF-16LE on windows.

pack :: [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

decodeUtf :: 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.

decodeWith :: TextEncoding -> WindowsString -> Either EncodingException String Source #

Decode a `WindowsString` with the specified encoding.

The String is forced into memory to catch all exceptions.

decodeFS :: WindowsString -> IO String Source #

Like `decodeUtf`, 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.

unpack :: 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).