Skip to content
GitLab
Menu
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
curry-packages
json
Commits
215a0b84
Commit
215a0b84
authored
Feb 12, 2020
by
Michael Hanus
Browse files
Pretty-printing strings improved
parent
8138e0db
Changes
1
Hide whitespace changes
Inline
Side-by-side
src/JSON/Pretty.curry
View file @
215a0b84
...
@@ -13,13 +13,23 @@ ppJValue JTrue = text "true"
...
@@ -13,13 +13,23 @@ ppJValue JTrue = text "true"
ppJValue JFalse = text "false"
ppJValue JFalse = text "false"
ppJValue JNull = text "null"
ppJValue JNull = text "null"
ppJValue (JNumber f) = float f
ppJValue (JNumber f) = float f
ppJValue (JString s) = text $ show s
ppJValue (JArray vs) = ppJArray vs
ppJValue (JArray vs) = ppJArray vs
ppJValue (JObject ps) = ppJObject ps
ppJValue (JObject ps) = ppJObject ps
ppJValue (JString s) = text $ '"' : concatMap ppJChar s ++ "\""
where
ppJChar c | c == '"' = "\\\""
| c == '\\' = "\\\\"
| c == '\b' = "\\b"
| c == '\f' = "\\f"
| c == '\n' = "\\n"
| c == '\r' = "\\r"
| c == '\t' = "\\t"
| otherwise = [c]
ppJArray :: [JValue] -> Doc
ppJArray :: [JValue] -> Doc
ppJArray vs = listSpaced $ map ppJValue vs
ppJArray vs = listSpaced $ map ppJValue vs
ppJObject :: [(String, JValue)] -> Doc
ppJObject :: [(String, JValue)] -> Doc
ppJObject ps = (nest 2 $ lbrace $$ vsep (punctuate comma $ map ppKVP ps)) $$ rbrace
ppJObject ps =
where ppKVP (k, v) = (text $ show k) <> colon <+> ppJValue v
(nest 2 $ lbrace $$ vsep (punctuate comma $ map ppKVP ps)) $$ rbrace
where ppKVP (k, v) = (text $ show k) <> colon <+> ppJValue v
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment