compact-string-fix-0.3.2: Same as compact-string except with a small fix so it builds on ghc-6.12

Portabilityuntested
Stabilityexperimental
Maintainertwanvl@gmail.com
Safe HaskellNone

Data.CompactString.Internal

Description

Internal functions for the CompactString type.

Synopsis

Documentation

newtype CompactString a

A String using a compact, strict representation. A CompactString a is encoded using encoding a, for example CompactString UTF8.

Constructors

CS 

Fields

unCS :: ByteString
 

data Proxy a

class Encoding a where

A way to encode characters into bytes

Methods

pokeCharFun :: Proxy a -> Char -> (Int, Ptr Word8 -> IO ())

Given a character returns the length of that character, and a function to write it to a memory buffer. if the encoding can not represent the character, the io function should fail.

pokeCharLen :: Proxy a -> Char -> Int

The size needed to store a character

pokeChar :: Proxy a -> Ptr Word8 -> Char -> IO Int

Write a character and return the size used

pokeCharRev :: Proxy a -> Ptr Word8 -> Char -> IO Int

Write a character given a pointer to its last byte, and return the size used

peekChar :: Proxy a -> Ptr Word8 -> IO (Int, Char)

Read a character from a memory buffer, return it and its length. The buffer is guaranteed to contain a valid character.

peekCharLen :: Proxy a -> Ptr Word8 -> IO Int

Return the length of the character in a memory buffer

peekCharRev :: Proxy a -> Ptr Word8 -> IO (Int, Char)

Read a character from a memory buffer, return it and its length, given a pointer to the last byte. The buffer is guaranteed to contain a valid character.

peekCharLenRev :: Proxy a -> Ptr Word8 -> IO Int

Return the length of the character in a memory buffer, given a pointer to the last byte.

peekCharSafe :: Proxy a -> Int -> Ptr Word8 -> IO (Int, Char)

Read a character from a memory buffer, return it and its length. The buffer is not guaranteed to contain a valid character, so that should be verified. There is also no guarantee that the length of the buffer (also given) is sufficient to contain a whole character.

validateLength :: Proxy a -> Int -> IO ()

Validate the length, should be used before peekCharSafe is called. Can be used to remove the number of checks used by peekCharSafe.

copyChar :: Proxy a -> Ptr Word8 -> Ptr Word8 -> IO Int

Copy a character from one buffer to another, return the length of the character

copyCharRev :: Proxy a -> Ptr Word8 -> Ptr Word8 -> IO Int

Copy a character from one buffer to another, where the source pointer points to the last byte of the character. return the length of the character.

containsASCII :: Proxy a -> Bool

Is ASCII a valid subset of the encoding?

validEquality :: Proxy a -> Bool

Is (a == b) == (toBS a == toBS b)?

validOrdering :: Proxy a -> Bool

Is (a compare b) == (toBS a compare toBS b)?

validSubstring :: Proxy a -> Bool

Is (a isSubstringOf b) == (toBS a isSubstringOf toBS b)?

charCount :: Proxy a -> Int -> Int

What is the maximum number of character a string with the given number of bytes contains?

byteCount :: Proxy a -> Int -> Int

What is the maximum number of bytes a string with the given number of characters contains?

newSize :: Proxy a -> Int -> Int

What is the maximum size in bytes after transforming (using map) a string?

doUpLoop :: Proxy a -> AccEFL acc -> acc -> ImperativeLoop acc

doDownLoop :: Proxy a -> AccEFL acc -> acc -> ImperativeLoop acc

doUpLoopFold :: Proxy a -> FoldEFL acc -> acc -> ImperativeLoop_ acc

doDownLoopFold :: Proxy a -> FoldEFL acc -> acc -> ImperativeLoop_ acc

Instances

data PairS a b

Constructors

!a :*: !b 

data MaybeS a

Constructors

NothingS 
JustS !a 

unSP :: PairS a b -> (a, b)

type AccEFL acc = acc -> Char -> PairS acc (MaybeS Char)

Type of loop functions

type FoldEFL acc = acc -> Char -> acc

type ImperativeLoop acc = Ptr Word8 -> Ptr Word8 -> Int -> IO (PairS (PairS acc Int) Int)

An imperative loop transforming a string, using an accumulating parameter. See Data.ByteString.Fusion

type ImperativeLoop_ acc = Ptr Word8 -> Int -> IO acc

ImperativeLoop with no output

data ByteString

A space-efficient representation of a Word8 vector, supporting many efficient operations. A ByteString contains 8-bit characters only.

Instances of Eq, Ord, Read, Show, Data, Typeable

Constructors

PS !(ForeignPtr Word8) !Int !Int 

memcpy :: Ptr Word8 -> Ptr Word8 -> Int -> IO ()

inlinePerformIO :: IO a -> a

Just like unsafePerformIO, but we inline it. Big performance gains as it exposes lots of things to further inlining. Very unsafe. In particular, you should do no memory allocation inside an inlinePerformIO block. On Hugs this is just unsafePerformIO.

withBuffer :: CompactString a -> (Ptr Word8 -> IO b) -> IO b

Perform a function given a pointer to the buffer of a CompactString

withBufferEnd :: CompactString a -> (Ptr Word8 -> IO b) -> IO b

Perform a function given a pointer to the last byte in the buffer of a CompactString

unsafeWithBuffer :: CompactString a -> (Ptr Word8 -> IO b) -> b

Perform a function given a pointer to the buffer of a CompactString

unsafeWithBufferEnd :: CompactString a -> (Ptr Word8 -> IO b) -> b

Perform a function given a pointer to the last byte in the buffer of a CompactString

create :: Int -> (Ptr Word8 -> IO ()) -> IO (CompactString a)

ord :: Char -> Int

The fromEnum method restricted to the type Char.

returnChr :: Int -> Word32 -> IO (Int, Char)

Safe variant of chr, combined with return; does more checks. At least GHC does not check for surrogate pairs

plusPtr :: Ptr a -> Int -> Ptr a

plusPtr that preserves the pointer type

peekByteOff :: Storable a => Ptr a -> Int -> IO a

pokeByteOff :: Storable a => Ptr a -> Int -> a -> IO ()

peek :: Storable a => Ptr a -> IO a

Read a value from the given memory location.

Note that the peek and poke functions might require properly aligned addresses to function correctly. This is architecture dependent; thus, portable code should ensure that when peeking or poking values of some type a, the alignment constraint for a, as given by the function alignment is fulfilled.

poke :: Storable a => Ptr a -> a -> IO ()

Write the given value to the given memory location. Alignment restrictions might apply; see peek.

failMessage :: String -> String -> IO a

Fail with an error message including the module name and function

moduleError :: String -> String -> a

Raise an errorr, with the message including the module name and function

unsafeTry :: MonadPlus m => IO a -> m a

Catch exceptions from fail in the IO monad, and wrap them in another monad

unsafeTryIO :: MonadPlus m => IO a -> IO (m a)

Catch exceptions from fail in the IO monad, and wrap them in another monad