filepath-2.0.0.1: Library for manipulating FilePaths in a cross platform way.
Copyright© 2021 Julian Ospald
LicenseMIT
MaintainerJulian Ospald <hasufell@posteo.de>
Stabilityexperimental
Portabilityportable
Safe HaskellNone
LanguageHaskell2010

System.OsString

Description

An implementation of platform specific short OsString, which is:

  1. on windows UTF16 data
  2. on unix UTF8 data

It captures the notion of syscall specific encoding to avoid roundtrip issues and memory fragmentation by using unpinned byte arrays.

Synopsis

String types

data OsString Source #

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
Eq OsString Source #

Byte equality of the internal representation.

Instance details

Defined in System.OsString.Internal.Types

Methods

(==) :: OsString -> OsString -> Bool

(/=) :: OsString -> OsString -> Bool

Ord OsString Source #

Byte ordering of the internal representation.

Instance details

Defined in System.OsString.Internal.Types

Methods

compare :: OsString -> OsString -> Ordering

(<) :: OsString -> OsString -> Bool

(<=) :: OsString -> OsString -> Bool

(>) :: OsString -> OsString -> Bool

(>=) :: OsString -> OsString -> Bool

max :: OsString -> OsString -> OsString

min :: OsString -> OsString -> OsString

Read OsString Source #

Encodes as UTF-8 on unix and UTF-16LE on windows.

Instance details

Defined in System.OsString.Internal.Types

Methods

readsPrec :: Int -> ReadS OsString

readList :: ReadS [OsString]

readPrec :: ReadPrec OsString

readListPrec :: ReadPrec [OsString]

Show OsString Source #

Decodes as UTF-16 on windows.

Decodes as UTF-8 on unix and replaces invalid chars with unicode replacement char U+FFFD.

Instance details

Defined in System.OsString.Internal.Types

Methods

showsPrec :: Int -> OsString -> ShowS

show :: OsString -> String

showList :: [OsString] -> ShowS

IsString OsString Source #

Encodes as UTF16 on windows and UTF8 on unix.

Instance details

Defined in System.OsString.Internal.Types

Methods

fromString :: String -> OsString

Generic OsString Source # 
Instance details

Defined in System.OsString.Internal.Types

Associated Types

type Rep OsString :: Type -> Type

Methods

from :: OsString -> Rep OsString x

to :: Rep OsString x -> OsString

Semigroup OsString Source # 
Instance details

Defined in System.OsString.Internal.Types

Methods

(<>) :: OsString -> OsString -> OsString

sconcat :: NonEmpty OsString -> OsString

stimes :: Integral b => b -> OsString -> OsString

Monoid OsString Source #

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

Instance details

Defined in System.OsString.Internal.Types

NFData OsString Source # 
Instance details

Defined in System.OsString.Internal.Types

Methods

rnf :: OsString -> ()

Lift OsString Source # 
Instance details

Defined in System.OsString.Internal.Types

Methods

lift :: OsString -> Q Exp

liftTyped :: OsString -> Q (TExp OsString)

type Rep OsString Source # 
Instance details

Defined in System.OsString.Internal.Types

type Rep OsString = D1 ('MetaData "OsString" "System.OsString.Internal.Types" "filepath-2.0.0.1-inplace" 'True) (C1 ('MetaCons "OsString" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 PlatformString)))

String construction

toOsStringUtf :: MonadThrow m => String -> m OsString Source #

Convert a String.

On windows this encodes as UTF16-LE, which is a pretty good guess. On unix this encodes as UTF8, which is a good guess.

Throws a EncodingException if encoding fails.

toOsStringEnc Source #

Arguments

:: String 
-> TextEncoding

unix text encoding

-> TextEncoding

windows text encoding

-> Either EncodingException OsString 

Like toOsStringUtf, except allows to provide encodings.

toOsStringFS :: String -> IO OsString Source #

Like toOsStringUtf, except on unix this uses the current filesystem locale for encoding instead of always UTF8.

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

Throws a EncodingException if decoding fails.

osstr :: QuasiQuoter Source #

QuasiQuote an OsString. This accepts Unicode characters and encodes as UTF-8 on unix and UTF-16 on windows.

packOsString :: [OsChar] -> OsString Source #

Pack a list of OsChar to an OsString

Note that using this in conjunction with unsafeFromChar to convert from [Char] to OsString is probably not what you want, because it will truncate unicode code points.

String deconstruction

fromOsStringUtf :: MonadThrow m => OsString -> m String Source #

Partial unicode friendly decoding.

On windows this decodes as UTF16-LE (which is the expected filename encoding). On unix this decodes as UTF8 (which is a good guess). Note that filenames on unix are encoding agnostic char arrays.

Throws a EncodingException if decoding fails.

fromOsStringEnc Source #

Arguments

:: OsString 
-> TextEncoding

unix text encoding

-> TextEncoding

windows text encoding

-> Either EncodingException String 

Like fromOsStringUtf, except allows to provide encodings.

The String is forced into memory to catch all exceptions.

fromOsStringFS :: OsString -> IO String Source #

Like fromOsStringUtf, except on unix this uses the current filesystem locale for decoding instead of always UTF8. On windows, uses UTF-16LE.

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

Throws EncodingException if decoding fails.

unpackOsString :: OsString -> [OsChar] Source #

Unpack an OsString to a list of OsChar.

Word types

data OsChar Source #

Newtype representing a code unit.

On Windows, this is restricted to two-octet codepoints Word16, on POSIX one-octet (Word8).

Instances

Instances details
Eq OsChar Source #

Byte equality of the internal representation.

Instance details

Defined in System.OsString.Internal.Types

Methods

(==) :: OsChar -> OsChar -> Bool

(/=) :: OsChar -> OsChar -> Bool

Ord OsChar Source #

Byte ordering of the internal representation.

Instance details

Defined in System.OsString.Internal.Types

Methods

compare :: OsChar -> OsChar -> Ordering

(<) :: OsChar -> OsChar -> Bool

(<=) :: OsChar -> OsChar -> Bool

(>) :: OsChar -> OsChar -> Bool

(>=) :: OsChar -> OsChar -> Bool

max :: OsChar -> OsChar -> OsChar

min :: OsChar -> OsChar -> OsChar

Show OsChar Source # 
Instance details

Defined in System.OsString.Internal.Types

Methods

showsPrec :: Int -> OsChar -> ShowS

show :: OsChar -> String

showList :: [OsChar] -> ShowS

Generic OsChar Source # 
Instance details

Defined in System.OsString.Internal.Types

Associated Types

type Rep OsChar :: Type -> Type

Methods

from :: OsChar -> Rep OsChar x

to :: Rep OsChar x -> OsChar

NFData OsChar Source # 
Instance details

Defined in System.OsString.Internal.Types

Methods

rnf :: OsChar -> ()

type Rep OsChar Source # 
Instance details

Defined in System.OsString.Internal.Types

type Rep OsChar = D1 ('MetaData "OsChar" "System.OsString.Internal.Types" "filepath-2.0.0.1-inplace" 'True) (C1 ('MetaCons "OsChar" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 PlatformChar)))

Word construction

unsafeFromChar :: Char -> OsChar Source #

Truncates on unix to 1 and on Windows to 2 octets.

Word deconstruction

toChar :: OsChar -> Char Source #

Converts back to a unicode codepoint (total).