Safe Haskell | None |
---|---|
Language | Haskell2010 |
Types and functions for handling JSON strings.
Synopsis
- type JString = JString' HeXDigit
- newtype JString' digit = JString' (Vector (JChar digit))
- class AsJString a where
- _JStringText :: (Profunctor p, Applicative f) => p Text (f Text) -> p JString (f JString)
- stringToJString :: String -> JString
- parseJString :: CharParsing f => f JString
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.
Instances
Functor JString' Source # | |
Foldable JString' Source # | |
Defined in Waargonaut.Types.JString 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 # elem :: Eq a => a -> JString' a -> Bool # maximum :: Ord a => JString' a -> a # minimum :: Ord a => JString' a -> a # | |
Traversable JString' Source # | |
AsJString JString Source # | |
Eq digit => Eq (JString' digit) Source # | |
Ord digit => Ord (JString' digit) Source # | |
Defined in Waargonaut.Types.JString 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 # | |
Show digit => Show (JString' digit) Source # | |
Wrapped (JString' digit) Source # | |
Defined in Waargonaut.Types.JString type Unwrapped (JString' digit) | |
JString' digit ~ t => Rewrapped (JString' digit) t Source # | |
Defined in Waargonaut.Types.JString | |
type Unwrapped (JString' digit) Source # | |
Defined in Waargonaut.Types.JString |
class AsJString a where Source #
Classy Prism'
for things that may be treated as a JString
.
_JStringText :: (Profunctor p, Applicative f) => p Text (f Text) -> p JString (f JString) Source #
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')])