From 9d853798263742154cae682e368f8d2562fdb7ef Mon Sep 17 00:00:00 2001 From: Eugen Wissner Date: Sun, 4 Aug 2024 08:30:00 +0200 Subject: Remove cariage return from the qq string --- src/Language/GraphQL/TH.hs | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) (limited to 'src/Language/GraphQL/TH.hs') diff --git a/src/Language/GraphQL/TH.hs b/src/Language/GraphQL/TH.hs index 8e1fcb3..35c0d4a 100644 --- a/src/Language/GraphQL/TH.hs +++ b/src/Language/GraphQL/TH.hs @@ -12,17 +12,26 @@ import Language.Haskell.TH (Exp(..), Lit(..)) stripIndentation :: String -> String stripIndentation code = reverse - $ dropNewlines + $ dropWhile isLineBreak $ reverse $ unlines - $ indent spaces <$> lines withoutLeadingNewlines + $ indent spaces <$> lines' withoutLeadingNewlines where indent 0 xs = xs indent count (' ' : xs) = indent (count - 1) xs indent _ xs = xs - withoutLeadingNewlines = dropNewlines code - dropNewlines = dropWhile $ flip any ['\n', '\r'] . (==) + withoutLeadingNewlines = dropWhile isLineBreak code spaces = length $ takeWhile (== ' ') withoutLeadingNewlines + lines' "" = [] + lines' string = + let (line, rest) = break isLineBreak string + reminder = + case rest of + [] -> [] + '\r' : '\n' : strippedString -> lines' strippedString + _ : strippedString -> lines' strippedString + in line : reminder + isLineBreak = flip any ['\n', '\r'] . (==) -- | Removes leading and trailing newlines. Indentation of the first line is -- removed from each line of the string. -- cgit v1.2.3