-- Copyright: 2004-2012 Dino Morelli -- License: BSD3 (see LICENSE) -- Author: Dino Morelli module PathSanitizer where import Data.Char import Data.List import Text.Regex -- Filtering functions -- Remove any of the supplied list from the target list removeAny :: (Eq a) => [a] -- Elements to remove -> [a] -- Original list -> [a] -- Result list removeAny s = filter (not . (flip elem s)) -- Regex substitution subst :: String -- Regular expression to match -> String -- Replacement pattern -> String -- String to perform replacement on -> String -- Result string subst f r i = subRegex (mkRegex f) i r -- Make alpha chars after those in the supplied list upper case upcaseAfter :: String -- List of target chars -> String -- Original string -> String -- Result string upcaseAfter l o = foldl' (flip ($)) o $ map upcaseAfter' l where upcaseAfter' :: Char -> String -> String upcaseAfter' c s = zipWith setSecondCase (c : s) s where setSecondCase c' | c' == c = toUpper | otherwise = id -- Function to apply the filters sanitize :: [String -> String] -> String -> String sanitize filters orig = foldl' (flip ($)) orig filters