@@ -26,7 +26,7 @@ import Data.Default
26import Data.List (intersperse, sortOn, transpose)
26import Data.List (intersperse, sortOn, transpose)
27import Data.List.NonEmpty (nonEmpty, NonEmpty(..))
27import Data.List.NonEmpty (nonEmpty, NonEmpty(..))
28import qualified Data.Map as M
28import qualified Data.Map as M
29−import Data.Maybe (fromMaybe, mapMaybe)
29+import Data.Maybe (fromMaybe, mapMaybe, isNothing)
30import qualified Data.Set as Set
30import qualified Data.Set as Set
31import Data.Text (Text)
31import Data.Text (Text)
32import qualified Data.Text as T
32import qualified Data.Text as T
@@ -142,18 +142,17 @@ valToYaml (SimpleVal x)
142 | otherwise =
142 | otherwise =
143 if hasNewlines x
143 if hasNewlines x
144 then hang 0 ("|" <> cr) x
144 then hang 0 ("|" <> cr) x
145− else if fst $ foldr needsDoubleQuotes (False, True) x
145+ else if isNothing $ foldM needsDoubleQuotes True x
146 then "\"" <> fmap escapeInDoubleQuotes x <> "\""
146 then "\"" <> fmap escapeInDoubleQuotes x <> "\""
149− needsDoubleQuotes t (positive, isFirst)
149+ needsDoubleQuotes isFirst t
150 = if T.any isBadAnywhere t ||
150 = if T.any isBadAnywhere t ||
151 (isFirst && T.any isYamlPunct (T.take 1 t))
151 (isFirst && T.any isYamlPunct (T.take 1 t))
152− then (True, False)
152+ then Nothing
153− else (positive, False)
153+ else Just False
154 isBadAnywhere '#' = True
154 isBadAnywhere '#' = True
155 isBadAnywhere ':' = True
155 isBadAnywhere ':' = True
156− isBadAnywhere '`' = False
157 isBadAnywhere _ = False
156 isBadAnywhere _ = False
158 hasNewlines NewLine = True
157 hasNewlines NewLine = True
159 hasNewlines BlankLines{} = True
158 hasNewlines BlankLines{} = True