module Network.HTTP.Lucu.Utils ( splitBy -- (a -> Bool) -> [a] -> [[a]] , joinWith -- [a] -> [[a]] -> [a] , trim -- (a -> Bool) -> [a] -> [a] , noCaseEq -- String -> String -> Bool , isWhiteSpace -- Char -> Bool , quoteStr -- String -> String ) where import Control.Monad.Trans import Data.Char import Data.List import Foreign import Foreign.C import Network.URI splitBy :: (a -> Bool) -> [a] -> [[a]] splitBy isSeparator src = case break isSeparator src of (last , [] ) -> last : [] (first, sep:rest) -> first : splitBy isSeparator rest joinWith :: [a] -> [[a]] -> [a] joinWith separator xs = foldr (++) [] $ intersperse separator xs trim :: (a -> Bool) -> [a] -> [a] trim p = trimTail . trimHead where trimHead = dropWhile p trimTail = reverse . trimHead . reverse noCaseEq :: String -> String -> Bool noCaseEq a b = (map toLower a) == (map toLower b) isWhiteSpace :: Char -> Bool isWhiteSpace = flip elem " \t\r\n" quoteStr :: String -> String quoteStr str = foldr (++) "" (["\""] ++ map quote str ++ ["\""]) where quote :: Char -> String quote '"' = "\\\"" quote c = [c]