waargonaut-0.8.0.2: JSON wrangling
Safe HaskellNone
LanguageHaskell2010

Waargonaut.Types.JString

Contents

Description

Types and functions for handling JSON strings.

Synopsis

Types

type JString = JString' HeXDigit Source #

As only one subset of digits are currently acceptable, Hexadecimal, we provide this type alias to close that loop.

newtype JString' digit Source #

A JSON string is a list of JSON acceptable characters, we use a newtype to create the JString type from a 'Vector JChar'. This is polymorphic over the acceptable types of character encoding digits.

Constructors

JString' (Vector (JChar digit)) 

Instances

Instances details
Functor JString' Source # 
Instance details

Defined in Waargonaut.Types.JString

Methods

fmap :: (a -> b) -> JString' a -> JString' b #

(<$) :: a -> JString' b -> JString' a #

Foldable JString' Source # 
Instance details

Defined in Waargonaut.Types.JString

Methods

fold :: Monoid m => JString' m -> m #

foldMap :: Monoid m => (a -> m) -> JString' a -> m #

foldMap' :: Monoid m => (a -> m) -> JString' a -> m #

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

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

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

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

foldr1 :: (a -> a -> a) -> JString' a -> a #

foldl1 :: (a -> a -> a) -> JString' a -> a #

toList :: JString' a -> [a] #

null :: JString' a -> Bool #

length :: JString' a -> Int #

elem :: Eq a => a -> JString' a -> Bool #

maximum :: Ord a => JString' a -> a #

minimum :: Ord a => JString' a -> a #

sum :: Num a => JString' a -> a #

product :: Num a => JString' a -> a #

Traversable JString' Source # 
Instance details

Defined in Waargonaut.Types.JString

Methods

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

sequenceA :: Applicative f => JString' (f a) -> f (JString' a) #

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

sequence :: Monad m => JString' (m a) -> m (JString' a) #

AsJString JString Source # 
Instance details

Defined in Waargonaut.Types.JString

Methods

_JString :: Prism' JString JString Source #

Eq digit => Eq (JString' digit) Source # 
Instance details

Defined in Waargonaut.Types.JString

Methods

(==) :: JString' digit -> JString' digit -> Bool #

(/=) :: JString' digit -> JString' digit -> Bool #

Ord digit => Ord (JString' digit) Source # 
Instance details

Defined in Waargonaut.Types.JString

Methods

compare :: JString' digit -> JString' digit -> Ordering #

(<) :: JString' digit -> JString' digit -> Bool #

(<=) :: JString' digit -> JString' digit -> Bool #

(>) :: JString' digit -> JString' digit -> Bool #

(>=) :: JString' digit -> JString' digit -> Bool #

max :: JString' digit -> JString' digit -> JString' digit #

min :: JString' digit -> JString' digit -> JString' digit #

Show digit => Show (JString' digit) Source # 
Instance details

Defined in Waargonaut.Types.JString

Methods

showsPrec :: Int -> JString' digit -> ShowS #

show :: JString' digit -> String #

showList :: [JString' digit] -> ShowS #

Wrapped (JString' digit) Source # 
Instance details

Defined in Waargonaut.Types.JString

Associated Types

type Unwrapped (JString' digit)

Methods

_Wrapped' :: Iso' (JString' digit) (Unwrapped (JString' digit))

JString' digit ~ t => Rewrapped (JString' digit) t Source # 
Instance details

Defined in Waargonaut.Types.JString

type Unwrapped (JString' digit) Source # 
Instance details

Defined in Waargonaut.Types.JString

type Unwrapped (JString' digit) = Vector (JChar digit)

class AsJString a where Source #

Classy Prism' for things that may be treated as a JString.

Methods

_JString :: Prism' a JString Source #

Instances

Instances details
AsJString String Source # 
Instance details

Defined in Waargonaut.Types.JString

Methods

_JString :: Prism' String JString Source #

AsJString JString Source # 
Instance details

Defined in Waargonaut.Types.JString

Methods

_JString :: Prism' JString JString Source #

AsJString [JChar HeXDigit] Source # 
Instance details

Defined in Waargonaut.Types.JString

Methods

_JString :: Prism' [JChar HeXDigit] JString Source #

_JStringText :: (Profunctor p, Applicative f) => p Text (f Text) -> p JString (f JString) Source #

Conversion between a JString and Text.

JSON strings a wider range of encodings than Text and to be consistent with the Text type, these invalid types are replaced with a placeholder value.

Parser

parseJString :: CharParsing f => f JString Source #

Parse a JString, storing escaped characters and any explicitly escaped character encodings 'uXXXX'.

>>> testparse parseJString "\"\""
Right (JString' [])
>>> testparse parseJString "\"\\\\\""
Right (JString' [EscapedJChar ReverseSolidus])
>>> testparse parseJString "\"abc\""
Right (JString' [UnescapedJChar (Unescaped 'a'),UnescapedJChar (Unescaped 'b'),UnescapedJChar (Unescaped 'c')])
>>> testparse parseJString "\"a\\rbc\""
Right (JString' [UnescapedJChar (Unescaped 'a'),EscapedJChar (WhiteSpace CarriageReturn),UnescapedJChar (Unescaped 'b'),UnescapedJChar (Unescaped 'c')])
>>> testparse parseJString "\"a\\rbc\\uab12\\ndef\\\"\"" :: Either DecodeError JString
Right (JString' [UnescapedJChar (Unescaped 'a'),EscapedJChar (WhiteSpace CarriageReturn),UnescapedJChar (Unescaped 'b'),UnescapedJChar (Unescaped 'c'),EscapedJChar (Hex (HexDigit4 HeXDigita HeXDigitb HeXDigit1 HeXDigit2)),EscapedJChar (WhiteSpace NewLine),UnescapedJChar (Unescaped 'd'),UnescapedJChar (Unescaped 'e'),UnescapedJChar (Unescaped 'f'),EscapedJChar QuotationMark])
>>> testparsethennoteof parseJString "\"a\"\\u"
Right (JString' [UnescapedJChar (Unescaped 'a')])
>>> testparsethennoteof parseJString "\"a\"\t"
Right (JString' [UnescapedJChar (Unescaped 'a')])