X-Git-Url: http://git.cielonegro.org/gitweb.cgi?a=blobdiff_plain;f=Network%2FHTTP%2FLucu%2FUtils.hs;h=d7ace3f8309aab60c21f2c8c6c4362189a05bc73;hb=0b4db5681e3b0b27357a87316822ea3671f8c174;hp=12f89965c2358f49920aea5b8d36cfb18823c463;hpb=86ea98d8307ddc687696896a91bed9a05cbeb783;p=Lucu.git diff --git a/Network/HTTP/Lucu/Utils.hs b/Network/HTTP/Lucu/Utils.hs index 12f8996..d7ace3f 100644 --- a/Network/HTTP/Lucu/Utils.hs +++ b/Network/HTTP/Lucu/Utils.hs @@ -7,6 +7,7 @@ module Network.HTTP.Lucu.Utils , noCaseEq , isWhiteSpace , quoteStr + , parseWWWFormURLEncoded ) where @@ -59,4 +60,16 @@ quoteStr str = foldr (++) "" (["\""] ++ map quote str ++ ["\""]) where quote :: Char -> String quote '"' = "\\\"" - quote c = [c] \ No newline at end of file + quote c = [c] + + +-- |> parseWWWFormURLEncoded "aaa=bbb&ccc=ddd" +-- > ==> [("aaa", "bbb"), ("ccc", "ddd")] +parseWWWFormURLEncoded :: String -> [(String, String)] +parseWWWFormURLEncoded src + | src == "" = [] + | otherwise = do pairStr <- splitBy (\ c -> c == ';' || c == '&') src + let pair = break (== '=') pairStr + return ( unEscapeString $ fst pair + , unEscapeString $ snd pair + )