Remove extra newline in repr

This commit is contained in:
Rnhmjoj 2014-11-21 00:13:52 +01:00
parent 482f28717b
commit 1bb362651c

14
Json.hs
View File

@ -16,13 +16,17 @@ obj |. key = case parse (.: key) obj of
-- Get the String value of a key -- Get the String value of a key
(|:) :: Object -> Text -> String (|:) :: Object -> Text -> String
obj |: key = repr (obj |. key) 0 obj |: key = repr' (obj |. key) 0
-- Create a String representation of a JSON
repr :: Value -> String
repr obj = drop 1 $ repr' obj 0
-- Create a String representation of a JSON Value -- Create a String representation of a JSON Value
repr :: Value -> Int -> String repr' :: Value -> Int -> String
repr val lev = repr' val lev =
case val of case val of
Array x -> intercalate ", " $ mapl (\i -> repr i lev) x Array x -> intercalate ", " $ mapl (\i -> repr' i lev) x
Object x -> concat $ map (dump x) $ H.keys x Object x -> concat $ map (dump x) $ H.keys x
String x -> unpack x String x -> unpack x
Number x -> show x Number x -> show x
@ -30,5 +34,5 @@ repr val lev =
Null -> "null" Null -> "null"
where where
indent = '\n' : (concat . replicate lev) " " indent = '\n' : (concat . replicate lev) " "
dump o k = concat [indent, unpack k, ": ", repr (o |. k) (lev+1)] dump o k = concat [indent, unpack k, ": ", repr' (o |. k) (lev+1)]
mapl f v = V.toList $ V.map f v mapl f v = V.toList $ V.map f v