diff options
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. |
