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
19 splitBy :: (a -> Bool) -> [a] -> [[a]]
20 splitBy isSeparator src
21 = case break isSeparator src
22 of (last , [] ) -> last : []
23 (first, sep:rest) -> first : splitBy isSeparator rest
26 joinWith :: [a] -> [[a]] -> [a]
28 = foldr (++) [] $ intersperse separator xs
31 trim :: (a -> Bool) -> [a] -> [a]
32 trim p = trimTail . trimHead
34 trimHead = dropWhile p
35 trimTail = reverse . trimHead . reverse
38 noCaseEq :: String -> String -> Bool
40 = (map toLower a) == (map toLower b)
43 isWhiteSpace :: Char -> Bool
44 isWhiteSpace = flip elem " \t\r\n"
47 quoteStr :: String -> String
48 quoteStr str = foldr (++) "" (["\""] ++ map quote str ++ ["\""])
50 quote :: Char -> String