]> gitweb @ CieloNegro.org - Lucu.git/blob - Network/HTTP/Lucu/Utils.hs
Many improvements: still in early development
[Lucu.git] / Network / HTTP / Lucu / Utils.hs
1 module Network.HTTP.Lucu.Utils
2     ( splitBy      -- (a -> Bool) -> [a] -> [[a]]
3     , trim         -- (a -> Bool) -> [a] -> [a]
4     , noCaseEq     -- String -> String -> Bool
5     , isWhiteSpace -- Char -> Bool
6     )
7     where
8
9 import Data.Char
10 import Data.List
11
12
13 splitBy :: (a -> Bool) -> [a] -> [[a]]
14 splitBy isSeparator src
15     = case break isSeparator src
16       of (last , []      ) -> last  : []
17          (first, sep:rest) -> first : splitBy isSeparator rest
18
19
20 trim :: (a -> Bool) -> [a] -> [a]
21 trim p = trimTail . trimHead
22     where
23       trimHead = dropWhile p
24       trimTail = reverse . trimHead . reverse
25
26
27 noCaseEq :: String -> String -> Bool
28 noCaseEq a b
29     = (map toLower a) == (map toLower b)
30
31
32 isWhiteSpace :: Char -> Bool
33 isWhiteSpace = flip elem " \t\r\n"