monoid-subclasses-1.1.3: Subclasses of Monoid
Safe HaskellNone
LanguageHaskell2010

Data.Monoid.Instances.ByteString.UTF8

Description

This module defines the ByteStringUTF8 newtype wrapper around ByteString, together with its TextualMonoid instance. The FactorialMonoid instance of a wrapped ByteStringUTF8 value differs from the original ByteString: the prime factors of the original value are its bytes, and for the wrapped value the prime factors are its valid UTF8 byte sequences. The following example session demonstrates the relationship:

> let utf8@(ByteStringUTF8 bs) = fromString "E=mc\xb2"
> bs
"E=mc\194\178"
> factors bs
["E","=","m","c","\194","\178"]
> utf8
"E=mc²"
> factors utf8
["E","=","m","c","²"]

The TextualMonoid instance follows the same logic, but it also decodes all valid UTF8 sequences into characters. Any invalid UTF8 byte sequence from the original ByteString is preserved as a single prime factor:

> let utf8'@(ByteStringUTF8 bs') = ByteStringUTF8 (Data.ByteString.map pred bs)
> bs'
"D<lb\193\177"
> factors bs'
["D","<","l","b","\193","\177"]
> utf8'
"D<lb\[193,177]"
> factors utf8'
["D","<","l","b","\[193,177]"]
Synopsis

Documentation

newtype ByteStringUTF8 Source #

Instances

Instances details
Eq ByteStringUTF8 Source # 
Instance details

Defined in Data.Monoid.Instances.ByteString.UTF8

Ord ByteStringUTF8 Source # 
Instance details

Defined in Data.Monoid.Instances.ByteString.UTF8

Show ByteStringUTF8 Source # 
Instance details

Defined in Data.Monoid.Instances.ByteString.UTF8

IsString ByteStringUTF8 Source # 
Instance details

Defined in Data.Monoid.Instances.ByteString.UTF8

Semigroup ByteStringUTF8 Source #

O(n)

Instance details

Defined in Data.Monoid.Instances.ByteString.UTF8

Monoid ByteStringUTF8 Source #

O(n)

Instance details

Defined in Data.Monoid.Instances.ByteString.UTF8

PositiveMonoid ByteStringUTF8 Source # 
Instance details

Defined in Data.Monoid.Instances.ByteString.UTF8

MonoidNull ByteStringUTF8 Source #

O(1)

Instance details

Defined in Data.Monoid.Instances.ByteString.UTF8

LeftCancellative ByteStringUTF8 Source # 
Instance details

Defined in Data.Monoid.Instances.ByteString.UTF8

LeftReductive ByteStringUTF8 Source #

O(n)

Instance details

Defined in Data.Monoid.Instances.ByteString.UTF8

LeftGCDMonoid ByteStringUTF8 Source #

O(prefixLength)

Instance details

Defined in Data.Monoid.Instances.ByteString.UTF8

Factorial ByteStringUTF8 Source # 
Instance details

Defined in Data.Monoid.Instances.ByteString.UTF8

FactorialMonoid ByteStringUTF8 Source # 
Instance details

Defined in Data.Monoid.Instances.ByteString.UTF8

TextualMonoid ByteStringUTF8 Source # 
Instance details

Defined in Data.Monoid.Instances.ByteString.UTF8

Methods

fromText :: Text -> ByteStringUTF8 Source #

singleton :: Char -> ByteStringUTF8 Source #

splitCharacterPrefix :: ByteStringUTF8 -> Maybe (Char, ByteStringUTF8) Source #

characterPrefix :: ByteStringUTF8 -> Maybe Char Source #

map :: (Char -> Char) -> ByteStringUTF8 -> ByteStringUTF8 Source #

concatMap :: (Char -> ByteStringUTF8) -> ByteStringUTF8 -> ByteStringUTF8 Source #

toString :: (ByteStringUTF8 -> String) -> ByteStringUTF8 -> String Source #

toText :: (ByteStringUTF8 -> Text) -> ByteStringUTF8 -> Text Source #

any :: (Char -> Bool) -> ByteStringUTF8 -> Bool Source #

all :: (Char -> Bool) -> ByteStringUTF8 -> Bool Source #

foldl :: (a -> ByteStringUTF8 -> a) -> (a -> Char -> a) -> a -> ByteStringUTF8 -> a Source #

foldl' :: (a -> ByteStringUTF8 -> a) -> (a -> Char -> a) -> a -> ByteStringUTF8 -> a Source #

foldr :: (ByteStringUTF8 -> a -> a) -> (Char -> a -> a) -> a -> ByteStringUTF8 -> a Source #

scanl :: (Char -> Char -> Char) -> Char -> ByteStringUTF8 -> ByteStringUTF8 Source #

scanl1 :: (Char -> Char -> Char) -> ByteStringUTF8 -> ByteStringUTF8 Source #

scanr :: (Char -> Char -> Char) -> Char -> ByteStringUTF8 -> ByteStringUTF8 Source #

scanr1 :: (Char -> Char -> Char) -> ByteStringUTF8 -> ByteStringUTF8 Source #

mapAccumL :: (a -> Char -> (a, Char)) -> a -> ByteStringUTF8 -> (a, ByteStringUTF8) Source #

mapAccumR :: (a -> Char -> (a, Char)) -> a -> ByteStringUTF8 -> (a, ByteStringUTF8) Source #

takeWhile :: (ByteStringUTF8 -> Bool) -> (Char -> Bool) -> ByteStringUTF8 -> ByteStringUTF8 Source #

dropWhile :: (ByteStringUTF8 -> Bool) -> (Char -> Bool) -> ByteStringUTF8 -> ByteStringUTF8 Source #

break :: (ByteStringUTF8 -> Bool) -> (Char -> Bool) -> ByteStringUTF8 -> (ByteStringUTF8, ByteStringUTF8) Source #

span :: (ByteStringUTF8 -> Bool) -> (Char -> Bool) -> ByteStringUTF8 -> (ByteStringUTF8, ByteStringUTF8) Source #

spanMaybe :: s -> (s -> ByteStringUTF8 -> Maybe s) -> (s -> Char -> Maybe s) -> ByteStringUTF8 -> (ByteStringUTF8, ByteStringUTF8, s) Source #

spanMaybe' :: s -> (s -> ByteStringUTF8 -> Maybe s) -> (s -> Char -> Maybe s) -> ByteStringUTF8 -> (ByteStringUTF8, ByteStringUTF8, s) Source #

split :: (Char -> Bool) -> ByteStringUTF8 -> [ByteStringUTF8] Source #

find :: (Char -> Bool) -> ByteStringUTF8 -> Maybe Char Source #

elem :: Char -> ByteStringUTF8 -> Bool Source #

foldl_ :: (a -> Char -> a) -> a -> ByteStringUTF8 -> a Source #

foldl_' :: (a -> Char -> a) -> a -> ByteStringUTF8 -> a Source #

foldr_ :: (Char -> a -> a) -> a -> ByteStringUTF8 -> a Source #

takeWhile_ :: Bool -> (Char -> Bool) -> ByteStringUTF8 -> ByteStringUTF8 Source #

dropWhile_ :: Bool -> (Char -> Bool) -> ByteStringUTF8 -> ByteStringUTF8 Source #

break_ :: Bool -> (Char -> Bool) -> ByteStringUTF8 -> (ByteStringUTF8, ByteStringUTF8) Source #

span_ :: Bool -> (Char -> Bool) -> ByteStringUTF8 -> (ByteStringUTF8, ByteStringUTF8) Source #

spanMaybe_ :: s -> (s -> Char -> Maybe s) -> ByteStringUTF8 -> (ByteStringUTF8, ByteStringUTF8, s) Source #

spanMaybe_' :: s -> (s -> Char -> Maybe s) -> ByteStringUTF8 -> (ByteStringUTF8, ByteStringUTF8, s) Source #

decode :: ByteString -> (ByteStringUTF8, ByteString) Source #

Takes a raw ByteString chunk and returns a pair of ByteStringUTF8 decoding the prefix of the chunk and the remaining suffix that is either null or contains the incomplete last character of the chunk.