]> gitweb @ CieloNegro.org - Lucu.git/blobdiff - Network/HTTP/Lucu/Utils.hs
data/mime.types
[Lucu.git] / Network / HTTP / Lucu / Utils.hs
index 7d6eeeb69531b73bede3d9e573c749c162c5e640..58da6f50c2612ac1e64e4d8366e17dfa21712f50 100644 (file)
@@ -1,13 +1,18 @@
 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
 
 
 splitBy :: (a -> Bool) -> [a] -> [[a]]
@@ -17,6 +22,11 @@ splitBy isSeparator src
          (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
@@ -31,3 +41,11 @@ noCaseEq a 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]
\ No newline at end of file