fs-utils-0.1: FileSystem utils
Safe HaskellNone
LanguageGHC2021

FileSystem.OsString

Description

Provides utilities for working with OsString.

Since: 0.1

Synopsis

Types

data OsString #

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

Instances details
NFData OsString 
Instance details

Defined in System.OsString.Internal.Types

Methods

rnf :: OsString -> () #

Monoid OsString

"String-Concatenation" for OsString. This is not the same as (</>).

Instance details

Defined in System.OsString.Internal.Types

Semigroup OsString 
Instance details

Defined in System.OsString.Internal.Types

Generic OsString 
Instance details

Defined in System.OsString.Internal.Types

Associated Types

type Rep OsString 
Instance details

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

Methods

from :: OsString -> Rep OsString x #

to :: Rep OsString x -> OsString #

Show OsString

On windows, decodes as UCS-2. On unix prints the raw bytes without decoding.

Instance details

Defined in System.OsString.Internal.Types

Eq OsString

Byte equality of the internal representation.

Instance details

Defined in System.OsString.Internal.Types

Ord OsString

Byte ordering of the internal representation.

Instance details

Defined in System.OsString.Internal.Types

Lift OsString 
Instance details

Defined in System.OsString.Internal.Types

Methods

lift :: Quote m => OsString -> m Exp #

liftTyped :: forall (m :: Type -> Type). Quote m => OsString -> Code m OsString #

type Rep OsString 
Instance details

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 #

Total conversion from String to OsString, replacing encode failures with the closest visual match.

Since: 0.1

Partial

unsafeEncode :: HasCallStack => String -> OsString Source #

Unsafely converts a String to OsString falling back to error.

WARNING: Partial

Since: 0.1

Decoding

Total

decode :: OsString -> Either EncodingException String Source #

Decodes an OsString to a String. This is a pure version of String's decodeUtf.

Since: 0.1

decodeLenient :: OsString -> String Source #

Total conversion from OsString to String, replacing decode failures with the closest visual match.

Since: 0.1

decodeDisplayEx :: OsString -> String Source #

Total conversion from OsString to String. If decoding fails, displays the exception.

Since: 0.1

decodeShow :: OsString -> String Source #

Total conversion from OsString to String. If decoding fails, falls back to its Show instance.

Since: 0.1

Partial

unsafeDecode :: HasCallStack => OsString -> String Source #

Unsafely converts an OsString to a String falling back to error.

WARNING: Partial

Since: 0.1

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.

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. ~/ or ~\ (windows only), which has been stripped. It contains no other tildes. Note that the returned OsString can be empty.

TildeStateNonPrefix OsString

The path contained a non-prefix tilde.

Instances

Instances details
NFData TildeState Source #

Since: 0.1

Instance details

Defined in FileSystem.OsString

Methods

rnf :: TildeState -> () #

Generic TildeState Source # 
Instance details

Defined in FileSystem.OsString

Associated Types

type Rep TildeState

Since: fs-utils-0.1

Instance details

Defined in FileSystem.OsString

Show TildeState Source #

Since: 0.1

Instance details

Defined in FileSystem.OsString

Eq TildeState Source #

Since: 0.1

Instance details

Defined in FileSystem.OsString

type Rep TildeState Source #

Since: 0.1

Instance details

Defined in FileSystem.OsString

newtype TildeException Source #

Exception for a path containing a tilde.

Instances

Instances details
NFData TildeException Source #

Since: 0.1

Instance details

Defined in FileSystem.OsString

Methods

rnf :: TildeException -> () #

Exception TildeException Source #

Since: 0.1

Instance details

Defined in FileSystem.OsString

Generic TildeException Source # 
Instance details

Defined in FileSystem.OsString

Associated Types

type Rep TildeException

Since: fs-utils-0.1

Instance details

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)))
Show TildeException Source #

Since: 0.1

Instance details

Defined in FileSystem.OsString

Eq TildeException Source #

Since: 0.1

Instance details

Defined in FileSystem.OsString

type Rep TildeException Source #

Since: 0.1

Instance details

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