1 module Network.HTTP.Lucu.Utils
2 ( splitBy -- (a -> Bool) -> [a] -> [[a]]
3 , joinWith -- [a] -> [[a]] -> [a]
4 , trim -- (a -> Bool) -> [a] -> [a]
5 , noCaseEq -- String -> String -> Bool
6 , isWhiteSpace -- Char -> Bool
7 , quoteStr -- String -> String
11 import Control.Monad.Trans
18 splitBy :: (a -> Bool) -> [a] -> [[a]]
19 splitBy isSeparator src
20 = case break isSeparator src
21 of (last , [] ) -> last : []
22 (first, sep:rest) -> first : splitBy isSeparator rest
25 joinWith :: [a] -> [[a]] -> [a]
27 = foldr (++) [] $ intersperse separator xs
30 trim :: (a -> Bool) -> [a] -> [a]
31 trim p = trimTail . trimHead
33 trimHead = dropWhile p
34 trimTail = reverse . trimHead . reverse
37 noCaseEq :: String -> String -> Bool
39 = (map toLower a) == (map toLower b)
42 isWhiteSpace :: Char -> Bool
43 isWhiteSpace = flip elem " \t\r\n"
46 quoteStr :: String -> String
47 quoteStr str = foldr (++) "" (["\""] ++ map quote str ++ ["\""])
49 quote :: Char -> String