summaryrefslogtreecommitdiff
path: root/src/Language
diff options
context:
space:
mode:
authorEugen Wissner <belka@caraus.de>2024-08-04 08:30:00 +0200
committerEugen Wissner <belka@caraus.de>2024-08-04 08:30:00 +0200
commit9d853798263742154cae682e368f8d2562fdb7ef (patch)
tree81c53915e6103adf4e8bff88d9e1248c2763a6a3 /src/Language
parent9b11300d23638f257543f90406b7ade6fd5118cb (diff)
downloadgraphql-9d853798263742154cae682e368f8d2562fdb7ef.tar.gz
Remove cariage return from the qq string
Diffstat (limited to 'src/Language')
-rw-r--r--src/Language/GraphQL/TH.hs17
1 files changed, 13 insertions, 4 deletions
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.