PCLT-0.1: Extension to Show: templating, catalogizing, languages, parameters, etc.

Text.ConstraintedLBS

Contents

Description

The analogue to ordinary lazy ByteString, but with a constraint on size, and some routines, thet respects the constraint.

Synopsis

Documentation

data CLBS Source

The analogue to ordinary lazy ByteString, but with a constraint on size.

Constructors

CLBS 

Fields

clbsLBS :: ByteString
 
clbsLen :: Int64
 
clbsMaxLen :: Int64
 
clbsFinalized_isit :: Bool

Bytestring is finalized, when something is appended to it, that makes clbsMaxLen to be reached. The last 3 bytes of a finalized bytestring are always made "..." (by routines of this module, that manage finalization).

Instances

newCLBS :: Int64 -> CLBSSource

Make a CLBS with a specified maximum on length.

addToCLBS_1 :: (ByteString, Int64) -> CLBS -> CLBSSource

Append first lazy ByteString (given in tuple with it's (trusted) length) to a CLBS. If the result of appending violates clbsMaxLen constraint, then the content gets truncated, tailed with "..." and CLBS is finalized (nothing more can be added to it)

freeSpaceCLBS :: CLBS -> CLBSSource

Produce an empty CLBS, that would have the maximum of length equal to free space left available in specified CLBS.

addToCLBS_2 :: CLBS -> CLBS -> CLBSSource

Append first to second. If the result of appending violates clbsMaxLen constraint, then the content gets truncated, tailed with "..." and CLBS is finalized (nothing more can be added to it)

adjustCLBS_to :: CLBS -> ByteString -> CLBSSource

Make CLBS contain specified ByteString, keeping the length constraint. If the specified bytestring violates clbsMaxLen constraint, then the content gets truncated, tailed with "..." and CLBS is finalized (nothing more can be added to it)

insertInsteadOf_inCLBS :: (ByteString, ByteString) -> CLBS -> CLBSSource

Given insertInsteadOf_inCLBS (old_separator, new_separator) clbs, function replaces every occurence of old_separator on new_separator respecting length constraint (and possibly finalizing CLBS).

resetCLBS :: CLBS -> CLBSSource

Empify, and if finalized, make not.

Some type aliaces

Base

concatTruncedLiteraryLBS :: (ByteString, Int64) -> (ByteString, Int64) -> Int64 -> (ByteString, Int64, Bool)Source

Append to first lazy bytestring the second one. The available space for append is constrainted by the 3rd argument. Every bytestring must be specified in tuple together with it's length (this is done to speed up by reducing repeating length calls), which is trusted. If length of added string is bigger then available for append, the result will be truncated and will have a "..." tail.

Function returns resulting ByteString, it's length and boolean indicating if length of added string was bigger than available for append space.