diff options
| author | Eugen Wissner <belka@caraus.de> | 2024-08-04 08:30:00 +0200 |
|---|---|---|
| committer | Eugen Wissner <belka@caraus.de> | 2024-08-04 08:30:00 +0200 |
| commit | 9d853798263742154cae682e368f8d2562fdb7ef (patch) | |
| tree | 81c53915e6103adf4e8bff88d9e1248c2763a6a3 /src | |
| parent | 9b11300d23638f257543f90406b7ade6fd5118cb (diff) | |
| download | graphql-9d853798263742154cae682e368f8d2562fdb7ef.tar.gz | |
Remove cariage return from the qq string
Diffstat (limited to 'src')
| -rw-r--r-- | src/Language/GraphQL/TH.hs | 17 |
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. |
