on master help sign in
Review comments applied
960441eOleg Grenrus
Data/Yaml/Builder.hs+1−17
@@ -21,6 +21,7 @@ module Data.Yaml.Builder
21import Data.Conduit
21import Data.Conduit
22import Data.ByteString (ByteString)
22import Data.ByteString (ByteString)
23import Text.Libyaml
23import Text.Libyaml
24+import Data.Yaml.Internal
24import Data.Text (Text)
25import Data.Text (Text)
25import Data.Scientific (Scientific)
26import Data.Scientific (Scientific)
26import Data.Aeson.Types (Value(..))
27import Data.Aeson.Types (Value(..))
@@ -85,23 +86,6 @@ string s =
85 -- See: https://github.com/snoyberg/yaml/issues/31
86 -- See: https://github.com/snoyberg/yaml/issues/31
86 | s `HashSet.member` specialStrings || isNumeric s = EventScalar (encodeUtf8 s) NoTag SingleQuoted Nothing
87 | s `HashSet.member` specialStrings || isNumeric s = EventScalar (encodeUtf8 s) NoTag SingleQuoted Nothing
87 | otherwise = EventScalar (encodeUtf8 s) StrTag PlainNoTag Nothing
88 | otherwise = EventScalar (encodeUtf8 s) StrTag PlainNoTag Nothing
88−
89− -- | Strings which must be escaped so as not to be treated as non-string scalars.
90− specialStrings :: HashSet.HashSet Text
91− specialStrings = HashSet.fromList $ T.words
92− "y Y yes Yes YES n N no No NO true True TRUE false False FALSE on On ON off Off OFF null Null NULL ~"
93−
94− isNumeric :: Text -> Bool
95− isNumeric =
96− T.all isNumeric'
97− where
98− isNumeric' c = ('0' <= c && c <= '9')
99− || c == 'e'
100− || c == 'E'
101− || c == '.'
102− || c == '-'
103− || c == '+'
104−
105
89
106-- Use aeson's implementation which gets rid of annoying decimal points
90-- Use aeson's implementation which gets rid of annoying decimal points
107scientific :: Scientific -> YamlBuilder
91scientific :: Scientific -> YamlBuilder
Data/Yaml/Pretty.hs+9−1
@@ -1,7 +1,9 @@
1-- | Prettier YAML encoding.
1-- | Prettier YAML encoding.
2module Data.Yaml.Pretty
2module Data.Yaml.Pretty
3 ( encodePretty
3 ( encodePretty
4− , Config(..)
4+ , Config
5+ , getConfCompare
6+ , setConfCompare
5 , defConfig
7 , defConfig
6 ) where
8 ) where
7
9
@@ -24,6 +26,12 @@ data Config = Config
24defConfig :: Config
26defConfig :: Config
25defConfig = Config mempty
27defConfig = Config mempty
26
28
29+getConfCompare :: Config -> Text -> Text -> Ordering
30+getConfCompare = confCompare
31+
32+setConfCompare :: (Text -> Text -> Ordering) -> Config -> Config
33+setConfCompare cmp c = c { confCompare = cmp }
34+
27pretty :: Config -> Value -> YamlBuilder
35pretty :: Config -> Value -> YamlBuilder
28pretty cfg = go
36pretty cfg = go
29 where go (Object o) = mapping (sortBy (confCompare cfg `on` fst) $ HM.toList $ HM.map go o)
37 where go (Object o) = mapping (sortBy (confCompare cfg `on` fst) $ HM.toList $ HM.map go o)