waargonaut-0.1.0.0: JSON wrangling

Safe HaskellNone
LanguageHaskell2010

Waargonaut.Types.JChar

Contents

Description

Types and functions for handling characters in JSON.

Synopsis

Types

data HexDigit4 d Source #

JSON Characters may be single escaped UTF16 "uab34".

Constructors

HexDigit4 d d d d 
Instances
Functor HexDigit4 Source # 
Instance details

Defined in Waargonaut.Types.JChar

Methods

fmap :: (a -> b) -> HexDigit4 a -> HexDigit4 b #

(<$) :: a -> HexDigit4 b -> HexDigit4 a #

Foldable HexDigit4 Source # 
Instance details

Defined in Waargonaut.Types.JChar

Methods

fold :: Monoid m => HexDigit4 m -> m #

foldMap :: Monoid m => (a -> m) -> HexDigit4 a -> m #

foldr :: (a -> b -> b) -> b -> HexDigit4 a -> b #

foldr' :: (a -> b -> b) -> b -> HexDigit4 a -> b #

foldl :: (b -> a -> b) -> b -> HexDigit4 a -> b #

foldl' :: (b -> a -> b) -> b -> HexDigit4 a -> b #

foldr1 :: (a -> a -> a) -> HexDigit4 a -> a #

foldl1 :: (a -> a -> a) -> HexDigit4 a -> a #

toList :: HexDigit4 a -> [a] #

null :: HexDigit4 a -> Bool #

length :: HexDigit4 a -> Int #

elem :: Eq a => a -> HexDigit4 a -> Bool #

maximum :: Ord a => HexDigit4 a -> a #

minimum :: Ord a => HexDigit4 a -> a #

sum :: Num a => HexDigit4 a -> a #

product :: Num a => HexDigit4 a -> a #

Traversable HexDigit4 Source # 
Instance details

Defined in Waargonaut.Types.JChar

Methods

traverse :: Applicative f => (a -> f b) -> HexDigit4 a -> f (HexDigit4 b) #

sequenceA :: Applicative f => HexDigit4 (f a) -> f (HexDigit4 a) #

mapM :: Monad m => (a -> m b) -> HexDigit4 a -> m (HexDigit4 b) #

sequence :: Monad m => HexDigit4 (m a) -> m (HexDigit4 a) #

Eq d => Eq (HexDigit4 d) Source # 
Instance details

Defined in Waargonaut.Types.JChar

Methods

(==) :: HexDigit4 d -> HexDigit4 d -> Bool #

(/=) :: HexDigit4 d -> HexDigit4 d -> Bool #

Ord d => Ord (HexDigit4 d) Source # 
Instance details

Defined in Waargonaut.Types.JChar

Show d => Show (HexDigit4 d) Source # 
Instance details

Defined in Waargonaut.Types.JChar

HasHexDigit4 (HexDigit4 d) d Source # 
Instance details

Defined in Waargonaut.Types.JChar

class HasHexDigit4 c d | c -> d where Source #

Typeclass for things that contain a HexDigit4.

Methods

hexDigit4 :: Lens' c (HexDigit4 d) Source #

Instances
HasHexDigit4 (HexDigit4 d) d Source # 
Instance details

Defined in Waargonaut.Types.JChar

data JChar digit Source #

A JChar may be unescaped or escaped.

Instances
Functor JChar Source # 
Instance details

Defined in Waargonaut.Types.JChar

Methods

fmap :: (a -> b) -> JChar a -> JChar b #

(<$) :: a -> JChar b -> JChar a #

Foldable JChar Source # 
Instance details

Defined in Waargonaut.Types.JChar

Methods

fold :: Monoid m => JChar m -> m #

foldMap :: Monoid m => (a -> m) -> JChar a -> m #

foldr :: (a -> b -> b) -> b -> JChar a -> b #

foldr' :: (a -> b -> b) -> b -> JChar a -> b #

foldl :: (b -> a -> b) -> b -> JChar a -> b #

foldl' :: (b -> a -> b) -> b -> JChar a -> b #

foldr1 :: (a -> a -> a) -> JChar a -> a #

foldl1 :: (a -> a -> a) -> JChar a -> a #

toList :: JChar a -> [a] #

null :: JChar a -> Bool #

length :: JChar a -> Int #

elem :: Eq a => a -> JChar a -> Bool #

maximum :: Ord a => JChar a -> a #

minimum :: Ord a => JChar a -> a #

sum :: Num a => JChar a -> a #

product :: Num a => JChar a -> a #

Traversable JChar Source # 
Instance details

Defined in Waargonaut.Types.JChar

Methods

traverse :: Applicative f => (a -> f b) -> JChar a -> f (JChar b) #

sequenceA :: Applicative f => JChar (f a) -> f (JChar a) #

mapM :: Monad m => (a -> m b) -> JChar a -> m (JChar b) #

sequence :: Monad m => JChar (m a) -> m (JChar a) #

Eq digit => Eq (JChar digit) Source # 
Instance details

Defined in Waargonaut.Types.JChar

Methods

(==) :: JChar digit -> JChar digit -> Bool #

(/=) :: JChar digit -> JChar digit -> Bool #

Ord digit => Ord (JChar digit) Source # 
Instance details

Defined in Waargonaut.Types.JChar

Methods

compare :: JChar digit -> JChar digit -> Ordering #

(<) :: JChar digit -> JChar digit -> Bool #

(<=) :: JChar digit -> JChar digit -> Bool #

(>) :: JChar digit -> JChar digit -> Bool #

(>=) :: JChar digit -> JChar digit -> Bool #

max :: JChar digit -> JChar digit -> JChar digit #

min :: JChar digit -> JChar digit -> JChar digit #

Show digit => Show (JChar digit) Source # 
Instance details

Defined in Waargonaut.Types.JChar

Methods

showsPrec :: Int -> JChar digit -> ShowS #

show :: JChar digit -> String #

showList :: [JChar digit] -> ShowS #

AsJCharUnescaped (JChar digit) Source # 
Instance details

Defined in Waargonaut.Types.JChar

AsJString [JChar HeXDigit] Source # 
Instance details

Defined in Waargonaut.Types.JString

AsJChar (JChar digit) digit Source # 
Instance details

Defined in Waargonaut.Types.JChar

HasJChar (JChar digit) digit Source # 
Instance details

Defined in Waargonaut.Types.JChar

Methods

jChar :: Lens' (JChar digit) (JChar digit) Source #

AsJCharEscaped (JChar digit) digit Source # 
Instance details

Defined in Waargonaut.Types.JChar

class AsJChar r digit | r -> digit where Source #

Typeclass for things that be used as a JChar.

Minimal complete definition

_JChar

class HasJChar c digit | c -> digit where Source #

Typeclass for things that have a JChar.

Methods

jChar :: Lens' c (JChar digit) Source #

Instances
HasJChar (JChar digit) digit Source # 
Instance details

Defined in Waargonaut.Types.JChar

Methods

jChar :: Lens' (JChar digit) (JChar digit) Source #

data JCharEscaped digit Source #

Things that may be escaped in a JSON string.

Instances
Functor JCharEscaped Source # 
Instance details

Defined in Waargonaut.Types.JChar

Methods

fmap :: (a -> b) -> JCharEscaped a -> JCharEscaped b #

(<$) :: a -> JCharEscaped b -> JCharEscaped a #

Foldable JCharEscaped Source # 
Instance details

Defined in Waargonaut.Types.JChar

Methods

fold :: Monoid m => JCharEscaped m -> m #

foldMap :: Monoid m => (a -> m) -> JCharEscaped a -> m #

foldr :: (a -> b -> b) -> b -> JCharEscaped a -> b #

foldr' :: (a -> b -> b) -> b -> JCharEscaped a -> b #

foldl :: (b -> a -> b) -> b -> JCharEscaped a -> b #

foldl' :: (b -> a -> b) -> b -> JCharEscaped a -> b #

foldr1 :: (a -> a -> a) -> JCharEscaped a -> a #

foldl1 :: (a -> a -> a) -> JCharEscaped a -> a #

toList :: JCharEscaped a -> [a] #

null :: JCharEscaped a -> Bool #

length :: JCharEscaped a -> Int #

elem :: Eq a => a -> JCharEscaped a -> Bool #

maximum :: Ord a => JCharEscaped a -> a #

minimum :: Ord a => JCharEscaped a -> a #

sum :: Num a => JCharEscaped a -> a #

product :: Num a => JCharEscaped a -> a #

Traversable JCharEscaped Source # 
Instance details

Defined in Waargonaut.Types.JChar

Methods

traverse :: Applicative f => (a -> f b) -> JCharEscaped a -> f (JCharEscaped b) #

sequenceA :: Applicative f => JCharEscaped (f a) -> f (JCharEscaped a) #

mapM :: Monad m => (a -> m b) -> JCharEscaped a -> m (JCharEscaped b) #

sequence :: Monad m => JCharEscaped (m a) -> m (JCharEscaped a) #

Eq digit => Eq (JCharEscaped digit) Source # 
Instance details

Defined in Waargonaut.Types.JChar

Methods

(==) :: JCharEscaped digit -> JCharEscaped digit -> Bool #

(/=) :: JCharEscaped digit -> JCharEscaped digit -> Bool #

Ord digit => Ord (JCharEscaped digit) Source # 
Instance details

Defined in Waargonaut.Types.JChar

Methods

compare :: JCharEscaped digit -> JCharEscaped digit -> Ordering #

(<) :: JCharEscaped digit -> JCharEscaped digit -> Bool #

(<=) :: JCharEscaped digit -> JCharEscaped digit -> Bool #

(>) :: JCharEscaped digit -> JCharEscaped digit -> Bool #

(>=) :: JCharEscaped digit -> JCharEscaped digit -> Bool #

max :: JCharEscaped digit -> JCharEscaped digit -> JCharEscaped digit #

min :: JCharEscaped digit -> JCharEscaped digit -> JCharEscaped digit #

Show digit => Show (JCharEscaped digit) Source # 
Instance details

Defined in Waargonaut.Types.JChar

Methods

showsPrec :: Int -> JCharEscaped digit -> ShowS #

show :: JCharEscaped digit -> String #

showList :: [JCharEscaped digit] -> ShowS #

AsJCharEscaped (JCharEscaped digit) digit Source # 
Instance details

Defined in Waargonaut.Types.JChar

class AsJCharEscaped r digit | r -> digit where Source #

Typeclass for things that may be used as an escaped JChar.

Minimal complete definition

_JCharEscaped

newtype JCharUnescaped Source #

Type to specify that this character is unescaped and may be represented using a normal Haskell Char.

Constructors

JCharUnescaped Char 

class AsJCharUnescaped a where Source #

Typeclass for things that may used as an unescaped JChar.

Parser / Builder

parseJChar :: (CharParsing f, HeXaDeCiMaL digit) => f (JChar digit) Source #

Parse a JSON character.

>>> testparse parseJChar "\\u1234" :: Either DecodeError (JChar HeXDigit)
Right (EscapedJChar (Hex (HexDigit4 HeXDigit1 HeXDigit2 HeXDigit3 HeXDigit4)))
>>> testparse parseJChar "\\\\" :: Either DecodeError (JChar HeXDigit)
Right (EscapedJChar ReverseSolidus)
>>> testparse parseJChar "\\r"
Right (EscapedJChar (WhiteSpace CarriageReturn))
>>> testparsetheneof parseJChar "a"
Right (UnescapedJChar (JCharUnescaped 'a'))
>>> testparsethennoteof parseJChar "ax"
Right (UnescapedJChar (JCharUnescaped 'a'))

parseJCharEscaped :: (CharParsing f, HeXaDeCiMaL digit) => f (JCharEscaped digit) Source #

Parse an escapted JSON character.

>>> testparse parseJCharEscaped "\\\""
Right QuotationMark
>>> testparse parseJCharEscaped "\\\\"
Right ReverseSolidus
>>> testparse parseJCharEscaped "\\/"
Right Solidus
>>> testparse parseJCharEscaped "\\b"
Right Backspace
>>> testparse parseJCharEscaped "\\f"
Right (WhiteSpace LineFeed)
>>> testparse parseJCharEscaped "\\n"
Right (WhiteSpace NewLine)
>>> testparse parseJCharEscaped "\\r"
Right (WhiteSpace CarriageReturn)
>>> testparse parseJCharEscaped "\\t"
Right (WhiteSpace HorizontalTab)
>>> testparse parseJCharEscaped "\\u1234" :: Either DecodeError (JCharEscaped HeXDigit)
Right (Hex (HexDigit4 HeXDigit1 HeXDigit2 HeXDigit3 HeXDigit4))
>>> testparsetheneof parseJCharEscaped "\\t"
Right (WhiteSpace HorizontalTab)
>>> testparsethennoteof parseJCharEscaped "\\tx"
Right (WhiteSpace HorizontalTab)

parseJCharUnescaped :: CharParsing f => f JCharUnescaped Source #

Parse an unescaped JSON character.

>>> testparse parseJCharUnescaped "a"
Right (JCharUnescaped 'a')
>>> testparse parseJCharUnescaped "\8728"
Right (JCharUnescaped '\8728')
>>> testparsetheneof parseJCharUnescaped "a"
Right (JCharUnescaped 'a')
>>> testparsethennoteof parseJCharUnescaped "ax"
Right (JCharUnescaped 'a')

jCharBuilder :: HeXaDeCiMaL digit => JChar digit -> Builder Source #

Create a Builder for the given JChar.

jCharToChar :: HeXaDeCiMaL digit => JChar digit -> Char Source #

Convert a JChar to a Haskell Char.

Conversion

utf8CharToJChar :: Char -> JChar HeXDigit Source #

Convert a Char to 'JChar HexDigit' and replace any invalid values with U+FFFD as per the Text documentation.

Refer to 'Text' documentation for more info.

jCharToUtf8Char :: JChar HeXDigit -> Maybe Char Source #

Try to convert a JChar to a Haskell Char.