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

toTildePrefixState :: OsString -> TildePrefixState Source #

Retrieves the path's "tilde state". Strips consecutive "tilde prefixes" if they exist. If the string contains no prefixes, returns it unchanged.

Since: 0.1

data TildePrefixState Source #

Represents the "tilde state" for a given path.

Constructors

TildePrefixStateNone OsString

The path contained no tilde prefix.

TildePrefixStateStripped OsString

The path contained "tilde prefix(es)" e.g. ~/ or ~\ (windows only), which have been stripped. Note that the returned OsString can be empty.

Instances

Instances details
NFData TildePrefixState Source #

Since: 0.1

Instance details

Defined in FileSystem.OsString

Methods

rnf :: TildePrefixState -> () #

Generic TildePrefixState Source # 
Instance details

Defined in FileSystem.OsString

Associated Types

type Rep TildePrefixState

Since: fs-utils-0.1

Instance details

Defined in FileSystem.OsString

type Rep TildePrefixState = D1 ('MetaData "TildePrefixState" "FileSystem.OsString" "fs-utils-0.1-inplace" 'False) (C1 ('MetaCons "TildePrefixStateNone" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 OsString)) :+: C1 ('MetaCons "TildePrefixStateStripped" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 OsString)))
Show TildePrefixState Source #

Since: 0.1

Instance details

Defined in FileSystem.OsString

Eq TildePrefixState Source #

Since: 0.1

Instance details

Defined in FileSystem.OsString

type Rep TildePrefixState Source #

Since: 0.1

Instance details

Defined in FileSystem.OsString

type Rep TildePrefixState = D1 ('MetaData "TildePrefixState" "FileSystem.OsString" "fs-utils-0.1-inplace" 'False) (C1 ('MetaCons "TildePrefixStateNone" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 OsString)) :+: C1 ('MetaCons "TildePrefixStateStripped" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 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)))

containsTildePrefix :: OsString -> Bool Source #

Returns true iff the string has a tilde prefix.

Since: 0.1

Functions

length :: OsString -> Int #

O(1) The length of a OsString.

Since: os-string-1.4.200.0

Normalization

normalize :: OsString -> OsString Source #

Performs canonical unicode decompositioncomposition. Converts tofrom Text via lenient encodings.

Since: 0.1

glyphLength :: OsString -> Int Source #

Returns the number of "visual characters" i.e. glyphs. This is done by performing unicode normalization then taking the Text length. Note that this is not the same as length.

Since: 0.1