on master help sign in
Review comments applied
commit960441e64f48b8b82b3115f26cf6b07f7719bed6 authorOleg Grenrus <oleg.grenrus@iki.fi> dateWed 12 Aug 2015, 12:38 (11 years ago) parentfce813c
2 files changed+10−18
Data/Yaml/Builder.hs+1−17 Data/Yaml/Pretty.hs+9−1
Data/Yaml/Builder.hs+1−17
@@ -21,6 +21,7 @@ module Data.Yaml.Builder
2121import Data.Conduit
2222import Data.ByteString (ByteString)
2323import Text.Libyaml
24+import Data.Yaml.Internal
2425import Data.Text (Text)
2526import Data.Scientific (Scientific)
2627import Data.Aeson.Types (Value(..))
@@ -85,23 +86,6 @@ string s =
8586 -- See: https://github.com/snoyberg/yaml/issues/31
8687 | s `HashSet.member` specialStrings || isNumeric s = EventScalar (encodeUtf8 s) NoTag SingleQuoted Nothing
8788 | 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−
10589
10690-- Use aeson's implementation which gets rid of annoying decimal points
10791scientific :: Scientific -> YamlBuilder
Data/Yaml/Pretty.hs+9−1
@@ -1,7 +1,9 @@
11-- | Prettier YAML encoding.
22module Data.Yaml.Pretty
33 ( encodePretty
4− , Config(..)
4+ , Config
5+ , getConfCompare
6+ , setConfCompare
57 , defConfig
68 ) where
79
@@ -24,6 +26,12 @@ data Config = Config
2426defConfig :: Config
2527defConfig = Config mempty
2628
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+
2735pretty :: Config -> Value -> YamlBuilder
2836pretty cfg = go
2937 where go (Object o) = mapping (sortBy (confCompare cfg `on` fst) $ HM.toList $ HM.map go o)