refactoring for lineSeparator.

This commit is contained in:
Kazu Yamamoto
2014-04-21 14:58:25 +09:00
parent b2c2d1a443
commit 3d03cff06b
4 changed files with 33 additions and 31 deletions

View File

@@ -3,3 +3,13 @@ module Language.Haskell.GhcMod.Utils where
-- 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) []
-- |
--
-- >>> 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