url 2 → 2.1
raw patch · 2 files changed
+22/−19 lines, 2 filesdep ~basedep ~utf8-string
Dependency ranges changed: base, utf8-string
Files
- Network/URL.hs +19/−16
- url.cabal +3/−3
Network/URL.hs view
@@ -19,6 +19,7 @@ , add_param , decString, encString , ok_host, ok_url, ok_param, ok_path+ , exportParams, importParams ) where import Data.Word(Word8)@@ -72,8 +73,8 @@ -- | Convert a list of \"bytes\" to a URL. importURL :: String -> Maybe URL-importURL cs1 =- do (ho,cs5) <- front cs1+importURL cs0 =+ do (ho,cs5) <- front cs0 (pa,cs6) <- the_path cs5 as <- the_args cs6 return URL { url_type = ho, url_path = pa, url_params = as }@@ -87,7 +88,7 @@ (po,cs3) <- the_port cs2 cs4 <- case cs3 of [] -> return []- '/':cs -> return cs+ '/':cs5 -> return cs5 _ -> Nothing return (Absolute Host { protocol = pr , host = ho@@ -118,13 +119,13 @@ return (s,bs) where end_path c = c == '#' || c == '?' - the_args ('?' : cs) = parse_params cs+ the_args ('?' : cs) = importParams cs the_args _ = return [] -parse_params :: String -> Maybe [(String,String)]-parse_params [] = return []-parse_params cs = mapM a_param (breaks ('&'==) cs)+importParams :: String -> Maybe [(String,String)]+importParams [] = return []+importParams ds = mapM a_param (breaks ('&'==) ds) where a_param cs = do let (as,bs) = break ('=' ==) cs k <- decString True as@@ -136,9 +137,9 @@ -- | Convert the host part of a URL to a list of \"bytes\". exportHost :: Host -> String-exportHost abs = the_prot ++ "://" ++ host abs ++ the_port- where the_prot = exportProt (protocol abs)- the_port = maybe "" (\x -> ":" ++ show x) (port abs)+exportHost absol = the_prot ++ "://" ++ host absol ++ the_port+ where the_prot = exportProt (protocol absol)+ the_port = maybe "" (\x -> ":" ++ show x) (port absol) -- | Convert the host part of a URL to a list of \"bytes\". -- WARNING: We output \"raw\" protocols as they are.@@ -154,18 +155,21 @@ -- | Convert a URL to a list of \"bytes\". -- We represent non-ASCII characters using UTF8. exportURL :: URL -> String-exportURL url = abs ++ the_path ++ the_params+exportURL url = absol ++ the_path ++ the_params where- abs = case url_type url of- Absolute host -> exportHost host ++ "/"+ absol = case url_type url of+ Absolute hst -> exportHost hst ++ "/" HostRelative -> "/" PathRelative -> "" the_path = encString False ok_path (url_path url) the_params = case url_params url of [] -> ""- xs -> "?" ++ concat (intersperse "&" $ map a_param xs)+ xs -> "?" ++ exportParams xs +exportParams :: [(String,String)] -> String+exportParams ps = concat (intersperse "&" $ map a_param ps)+ where a_param (k,mv) = encString True ok_param k ++ case mv of "" -> ""@@ -175,12 +179,11 @@ - -- | Convert a string to bytes by escaping the characters that -- do not satisfy the input predicate. The first argument specifies -- if we should replace spaces with +. encString :: Bool -> (Char -> Bool) -> String -> String-encString pl p xs = foldr enc1 [] xs+encString pl p ys = foldr enc1 [] ys where enc1 ' ' xs | pl = '+' : xs enc1 x xs = if p x then x : xs else encChar x ++ xs
url.cabal view
@@ -1,5 +1,5 @@ Name: url-Version: 2+Version: 2.1 License: BSD3 License-file: LICENSE Author: Iavor S. Diatchki@@ -8,9 +8,9 @@ Category: Web Synopsis: A library for working with URLs. Description: A library for working with URLs.-Build-Depends: base, utf8-string+Build-Depends: base >= 3 && <= 4, utf8-string >= 0.3.4 && < 2 Build-type: Simple Extra-source-files: LICENSE Exposed-modules: Network.URL-GHC-options: -O2 -W+GHC-options: -O2 -Wall