ghc-mod/Language/Haskell/GhcMod/Utils.hs

16 lines
441 B
Haskell
Raw Normal View History

2014-04-19 06:17:36 +00:00
module Language.Haskell.GhcMod.Utils where
2014-04-19 06:20:16 +00:00
-- dropWhileEnd is not provided prior to base 4.5.0.0.
dropWhileEnd :: (a -> Bool) -> [a] -> [a]
dropWhileEnd p = foldr (\x xs -> if p x && null xs then [] else x : xs) []
2014-04-21 05:58:25 +00:00
-- |
--
-- >>> replace '"' "\\\"" "foo\"bar"
-- "foo\\\"bar"
replace :: Char -> String -> String -> String
replace _ _ [] = []
replace c cs (x:xs)
| x == c = cs ++ replace c cs xs
| otherwise = x : replace c cs xs