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
_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')])