]> gitweb @ CieloNegro.org - Lucu.git/blobdiff - Network/HTTP/Lucu/Utils.hs
More documentation
[Lucu.git] / Network / HTTP / Lucu / Utils.hs
index 12f89965c2358f49920aea5b8d36cfb18823c463..d7ace3f8309aab60c21f2c8c6c4362189a05bc73 100644 (file)
@@ -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
+                            )