Safe Haskell | None |
---|---|
Language | GHC2021 |
FileSystem.OsString
Description
Provides utilities for working with OsString
.
Since: 0.1
Synopsis
- data OsString
- osstr :: QuasiQuoter
- osstrPathSep :: QuasiQuoter
- encode :: String -> Either EncodingException OsString
- encodeLenient :: String -> OsString
- encodeThrowM :: (HasCallStack, MonadThrow m) => String -> m OsString
- encodeFail :: (HasCallStack, MonadFail m) => String -> m OsString
- unsafeEncode :: HasCallStack => String -> OsString
- decode :: OsString -> Either EncodingException String
- decodeLenient :: OsString -> String
- decodeDisplayEx :: OsString -> String
- decodeShow :: OsString -> String
- decodeThrowM :: (HasCallStack, MonadThrow m) => OsString -> m String
- decodeFail :: (HasCallStack, MonadFail m) => OsString -> m String
- unsafeDecode :: HasCallStack => OsString -> String
- data EncodingException = EncodingError String (Maybe Word8)
- toTildeState :: OsString -> TildeState
- data TildeState
- newtype TildeException = MkTildeException OsString
Types
Newtype representing short operating system specific strings.
Internally this is either WindowsString
or PosixString
,
depending on the platform. Both use unpinned
ShortByteString
for efficiency.
The constructor is only exported via System.OsString.Internal.Types, since dealing with the internals isn't generally recommended, but supported in case you need to write platform specific code.
Instances
NFData OsString | |||||
Defined in System.OsString.Internal.Types | |||||
Monoid OsString | "String-Concatenation" for | ||||
Semigroup OsString | |||||
Generic OsString | |||||
Defined in System.OsString.Internal.Types Associated Types
| |||||
Show OsString | On windows, decodes as UCS-2. On unix prints the raw bytes without decoding. | ||||
Eq OsString | Byte equality of the internal representation. | ||||
Ord OsString | Byte ordering of the internal representation. | ||||
Defined in System.OsString.Internal.Types | |||||
Lift OsString | |||||
type Rep OsString | |||||
Defined in System.OsString.Internal.Types type Rep OsString = D1 ('MetaData "OsString" "System.OsString.Internal.Types" "os-string-2.0.2-inplace" 'True) (C1 ('MetaCons "OsString" 'PrefixI 'True) (S1 ('MetaSel ('Just "getOsString") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 PlatformString))) |
Encoding
Total
osstr :: QuasiQuoter #
QuasiQuote an OsString
. This accepts Unicode characters
and encodes as UTF-8 on unix and UTF-16 on windows.
If used as pattern, requires turning on the ViewPatterns
extension.
osstrPathSep :: QuasiQuoter Source #
Like osstr
, except it runs paths through a "replace function" first.
On unix, replaces \
with /
. On windows, does the opposite.
This is convenient for writing paths in a platform-agnostic way i.e. we are expecting a path
"path/to/foo" -- unix "path\to\foo" -- windows
The normal way to handle this would be to use the combine function (</>)
i.e.
[osstr|path|]</>
[osstr|to|]</>
[osstr|foo|]
This can be quite cumbersome for long paths, so we provide this alternative, allowing:
[osstrPathSep|path/to/foo]
Which will automatically convert slashes.
encode :: String -> Either EncodingException OsString Source #
Encodes a String
to an OsString
. This is a pure version of String's
encodeUtf
that returns the EncodingException
in the event of an
error.
Since: 0.1
encodeLenient :: String -> OsString Source #
Partial
encodeThrowM :: (HasCallStack, MonadThrow m) => String -> m OsString Source #
encode
that throws EncodingException
.
Since: 0.1
encodeFail :: (HasCallStack, MonadFail m) => String -> m OsString Source #
encodeThrowM
with MonadFail
.
Since: 0.1
unsafeEncode :: HasCallStack => String -> OsString Source #
Decoding
Total
decodeLenient :: OsString -> String Source #
decodeDisplayEx :: OsString -> String Source #
decodeShow :: OsString -> String Source #
Partial
decodeThrowM :: (HasCallStack, MonadThrow m) => OsString -> m String Source #
decode
that throws EncodingException
.
Since: 0.1
decodeFail :: (HasCallStack, MonadFail m) => OsString -> m String Source #
unsafeDecode :: HasCallStack => OsString -> String Source #
Errors
data EncodingException #
Constructors
EncodingError String (Maybe Word8) | Could not decode a byte sequence because it was invalid under the given encoding, or ran out of input in mid-decode. |
Instances
NFData EncodingException | |
Defined in System.OsString.Encoding.Internal Methods rnf :: EncodingException -> () # | |
Exception EncodingException | |
Defined in System.OsString.Encoding.Internal Methods toException :: EncodingException -> SomeException # fromException :: SomeException -> Maybe EncodingException # | |
Show EncodingException | |
Defined in System.OsString.Encoding.Internal Methods showsPrec :: Int -> EncodingException -> ShowS # show :: EncodingException -> String # showList :: [EncodingException] -> ShowS # | |
Eq EncodingException | |
Defined in System.OsString.Encoding.Internal Methods (==) :: EncodingException -> EncodingException -> Bool # (/=) :: EncodingException -> EncodingException -> Bool # |
Tildes
toTildeState :: OsString -> TildeState Source #
Retrieves the path's "tilde state".
Since: 0.1
data TildeState Source #
Represents the "tilde state" for a given path.
Constructors
TildeStateNone OsString | The path contains no tildes. |
TildeStatePrefix OsString | The path contained a "tilde prefix" e.g. |
TildeStateNonPrefix OsString | The path contained a non-prefix tilde. |
Instances
newtype TildeException Source #
Exception for a path containing a tilde.
Constructors
MkTildeException OsString |
Instances
NFData TildeException Source # | Since: 0.1 | ||||
Defined in FileSystem.OsString Methods rnf :: TildeException -> () # | |||||
Exception TildeException Source # | Since: 0.1 | ||||
Defined in FileSystem.OsString Methods toException :: TildeException -> SomeException # fromException :: SomeException -> Maybe TildeException # displayException :: TildeException -> String # backtraceDesired :: TildeException -> Bool # | |||||
Generic TildeException Source # | |||||
Defined in FileSystem.OsString Associated Types
Methods from :: TildeException -> Rep TildeException x # to :: Rep TildeException x -> TildeException # | |||||
Show TildeException Source # | Since: 0.1 | ||||
Defined in FileSystem.OsString Methods showsPrec :: Int -> TildeException -> ShowS # show :: TildeException -> String # showList :: [TildeException] -> ShowS # | |||||
Eq TildeException Source # | Since: 0.1 | ||||
Defined in FileSystem.OsString Methods (==) :: TildeException -> TildeException -> Bool # (/=) :: TildeException -> TildeException -> Bool # | |||||
type Rep TildeException Source # | Since: 0.1 | ||||
Defined in FileSystem.OsString type Rep TildeException = D1 ('MetaData "TildeException" "FileSystem.OsString" "fs-utils-0.1-inplace" 'True) (C1 ('MetaCons "MkTildeException" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 OsString))) |