module Util where
import           Data.Char

convertDosLineEndings :: String -> String
convertDosLineEndings :: String -> String
convertDosLineEndings = String -> String
go
  where
    go :: String -> String
go input :: String
input = case String
input of
      '\r':'\n':xs :: String
xs -> '\n' Char -> String -> String
forall a. a -> [a] -> [a]
: String -> String
go String
xs

      -- Haddock comments from source files with dos line endings end with a
      -- CR, so we strip that, too.
      "\r"         -> ""

      x :: Char
x:xs :: String
xs         -> Char
x Char -> String -> String
forall a. a -> [a] -> [a]
: String -> String
go String
xs
      ""           -> ""

-- | Return the longest suffix of elements that satisfy a given predicate.
takeWhileEnd :: (a -> Bool) -> [a] -> [a]
takeWhileEnd :: (a -> Bool) -> [a] -> [a]
takeWhileEnd p :: a -> Bool
p = [a] -> [a]
forall a. [a] -> [a]
reverse ([a] -> [a]) -> ([a] -> [a]) -> [a] -> [a]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (a -> Bool) -> [a] -> [a]
forall a. (a -> Bool) -> [a] -> [a]
takeWhile a -> Bool
p ([a] -> [a]) -> ([a] -> [a]) -> [a] -> [a]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [a] -> [a]
forall a. [a] -> [a]
reverse

-- | Remove trailing white space from a string.
--
-- >>> stripEnd "foo   "
-- "foo"
stripEnd :: String -> String
stripEnd :: String -> String
stripEnd = String -> String
forall a. [a] -> [a]
reverse (String -> String) -> (String -> String) -> String -> String
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Char -> Bool) -> String -> String
forall a. (a -> Bool) -> [a] -> [a]
dropWhile Char -> Bool
isSpace (String -> String) -> (String -> String) -> String -> String
forall b c a. (b -> c) -> (a -> b) -> a -> c
. String -> String
forall a. [a] -> [a]
reverse