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

Safe Haskell | Safe-Inferred
Language | Haskell2010

System.OsString.Posix

Contents

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

Synopsis

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

# Types

data PosixString Source #

Commonly used Posix string as uninterpreted `char[]` array.

#### Instances

Instances details

Monoid PosixString Source # |
Instance details Defined in System.OsString.Internal.Types Methods mempty :: PosixString Source # mappend :: PosixString -> PosixString -> PosixString Source # mconcat :: [PosixString] -> PosixString Source #
Semigroup PosixString Source # |
Instance details Defined in System.OsString.Internal.Types Methods (<>) :: PosixString -> PosixString -> PosixString Source # sconcat :: NonEmpty PosixString -> PosixString Source # stimes :: Integral b => b -> PosixString -> PosixString Source #
Generic PosixString Source # |
Instance details Defined in System.OsString.Internal.Types Associated Types type Rep PosixString :: Type -> Type Source # Methods from :: PosixString -> Rep PosixString x Source # to :: Rep PosixString x -> PosixString Source #
Show PosixString Source # | Prints the raw bytes without decoding.
Instance details Defined in System.OsString.Internal.Types Methods showsPrec :: Int -> PosixString -> ShowS Source # show :: PosixString -> String Source # showList :: [PosixString] -> ShowS Source #
NFData PosixString Source # |
Instance details Defined in System.OsString.Internal.Types Methods rnf :: PosixString -> () Source #
Eq PosixString Source # |
Instance details Defined in System.OsString.Internal.Types Methods (==) :: PosixString -> PosixString -> Bool # (/=) :: PosixString -> PosixString -> Bool #
Ord PosixString Source # |
Instance details Defined in System.OsString.Internal.Types Methods compare :: PosixString -> PosixString -> Ordering # (<) :: PosixString -> PosixString -> Bool # (<=) :: PosixString -> PosixString -> Bool # (>) :: PosixString -> PosixString -> Bool # (>=) :: PosixString -> PosixString -> Bool # max :: PosixString -> PosixString -> PosixString # min :: PosixString -> PosixString -> PosixString #
Lift PosixString Source # |
Instance details Defined in System.OsString.Internal.Types Methods lift :: Quote m => PosixString -> m Exp Source # liftTyped :: forall (m :: Type -> Type). Quote m => PosixString -> Code m PosixString Source #
type Rep PosixString Source # |
Instance details Defined in System.OsString.Internal.Types type Rep PosixString = D1 ('MetaData "PosixString" "System.OsString.Internal.Types" "filepath-1.4.100.4" 'True) (C1 ('MetaCons "PosixString" 'PrefixI 'True) (S1 ('MetaSel ('Just "getPosixString") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 ShortByteString)))

data PosixChar Source #

#### Instances

Instances details

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

# String construction

encodeUtf :: MonadThrow m => String -> m PosixString Source #

Partial unicode friendly encoding.

This encodes as UTF8 (strictly), which is a good guess.

Throws an `EncodingException` if encoding fails.

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

Encode a `String` with the specified encoding.

encodeFS :: String -> IO PosixString Source #

This mimics the behavior of the base library when doing filesystem operations, which uses shady PEP 383 style encoding (based on the current locale, but PEP 383 only works properly on UTF-8 encodings, so good luck).

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 PosixString Source #

Constructs a platform string from a ByteString.

This is a no-op.

pstr :: QuasiQuoter Source #

QuasiQuote a `PosixString`. This accepts Unicode characters and encodes as UTF-8 on unix.

pack :: [PosixChar] -> PosixString 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 => PosixString -> m String Source #

Partial unicode friendly decoding.

This decodes as UTF8 (strictly), which is a good guess. Note that filenames on unix are encoding agnostic char arrays.

Throws a `EncodingException` if decoding fails.

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

Decode a `PosixString` with the specified encoding.

The String is forced into memory to catch all exceptions.

decodeFS :: PosixString -> IO String Source #

This mimics the behavior of the base library when doing filesystem operations, which uses shady PEP 383 style encoding (based on the current locale, but PEP 383 only works properly on UTF-8 encodings, so good luck).

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

unpack :: PosixString -> [PosixChar] Source #

Unpack a platform string to a list of platform words.

# Word construction

unsafeFromChar :: Char -> PosixChar Source #

Truncates to 1 octet.

# Word deconstruction

toChar :: PosixChar -> Char Source #

Converts back to a unicode codepoint (total).