X-Git-Url: http://git.cielonegro.org/gitweb.cgi?a=blobdiff_plain;f=Network%2FHTTP%2FLucu%2FUtils.hs;h=5dc1584683b5b23082cc3ae63cbd57ad293fe2e2;hb=854f6d1709d468f7e1bf0db2dcd2d30de6bd5f5e;hp=7d6eeeb69531b73bede3d9e573c749c162c5e640;hpb=3c7a58ab749a55a30466a033b170536bcdf18b98;p=Lucu.git diff --git a/Network/HTTP/Lucu/Utils.hs b/Network/HTTP/Lucu/Utils.hs index 7d6eeeb..5dc1584 100644 --- a/Network/HTTP/Lucu/Utils.hs +++ b/Network/HTTP/Lucu/Utils.hs @@ -1,13 +1,19 @@ 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]] @@ -17,6 +23,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 +42,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