Mikan
Safe HaskellNone
LanguageHaskell2010

Mikan.Utils.ShortText

Description

Utilities for working with ShortText

This module is meant to be imported qualified as import Mikan.Utils.ShortText qualified as TS

Synopsis

Creation

unsafeCreate :: Int -> (forall s. MutableByteArray s -> ST s ()) -> ShortText Source #

\(\mathcal{O}(1)\). Create a ShortText from a newly allocated MutableByteArray of length n.

The caller is responsible for ensuring that the MutableByteArray is filled with valid UTF-8 encoded text.

Length

lengthBytes :: ShortText -> Int Source #

\(\mathcal{O}(1)\). Get the length of a ShortText in bytes.

Breaking into lines and words

Conversion

toByteArray :: ShortText -> ByteArray Source #

\(\mathcal{O}(1)\). Get the underlying ByteArray of a ShortText.

unsafeFromByteArray :: ByteArray -> ShortText Source #

\(\mathcal{O}(1)\). Unsafely convert a ByteArray to ShortText.

The caller is responsible for ensuring that the ByteArray contains valid UTF-8.

copyBytes Source #

Arguments

:: PrimMonad m 
=> MutableByteArray (PrimState m)

Destination buffer.

-> Int

Offset into the destination buffer, measured in bytes.

-> ShortText

Source ShortText.

-> Int

Offset into the ShortText, measured in bytes.

-> Int

How many bytes to copy

-> m () 

\(\mathcal{O}(n)\). Copy bytes from a ShortText into a MutableByteArray.