X-Git-Url: http://git.cielonegro.org/gitweb.cgi?a=blobdiff_plain;f=Network%2FHTTP%2FLucu%2FUtils.hs;h=7dbb1162cbda616ae5eb57ce989bc481f813a9ac;hb=ece223c516e66223ef1d5d8e6bbe4054a235d983;hp=a488aafbb64161feee9e67404c05f29a065236ec;hpb=0ff03469c29b791f2c609a659bbf59be97e306f2;p=Lucu.git diff --git a/Network/HTTP/Lucu/Utils.hs b/Network/HTTP/Lucu/Utils.hs index a488aaf..7dbb116 100644 --- a/Network/HTTP/Lucu/Utils.hs +++ b/Network/HTTP/Lucu/Utils.hs @@ -1,13 +1,11 @@ {-# LANGUAGE - BangPatterns - , OverloadedStrings + OverloadedStrings , UnicodeSyntax #-} -- |Utility functions used internally in the Lucu httpd. These -- functions may be useful too for something else. module Network.HTTP.Lucu.Utils ( splitBy - , joinWith , quoteStr , parseWWWFormURLEncoded , splitPathInfo @@ -23,8 +21,6 @@ import Data.ByteString (ByteString) import qualified Data.ByteString.Char8 as BS import Data.List hiding (last) import Data.Monoid.Unicode -import Data.Text (Text) -import Data.Text.Encoding as T import Network.URI import Prelude hiding (last) import Prelude.Unicode @@ -32,22 +28,11 @@ import Prelude.Unicode -- |> splitBy (== ':') "ab:c:def" -- > ==> ["ab", "c", "def"] splitBy ∷ (a → Bool) → [a] → [[a]] +{-# INLINEABLE splitBy #-} splitBy isSep src - = case break isSep src - of (last , [] ) → [last] - (first, _sep:rest) → first : splitBy isSep rest - --- |> joinWith ":" ["ab", "c", "def"] --- > ==> "ab:c:def" -joinWith ∷ Ascii → [AsciiBuilder] → AsciiBuilder -{-# INLINEABLE joinWith #-} -joinWith sep = flip go (∅) - where - go ∷ [AsciiBuilder] → AsciiBuilder → AsciiBuilder - {-# INLINE go #-} - go [] ab = ab - go (x:[]) ab = ab ⊕ x - go (x:xs) ab = go xs (ab ⊕ A.toAsciiBuilder sep ⊕ x) + = case break isSep src of + (last , [] ) → [last] + (first, _sep:rest) → first : splitBy isSep rest -- |> quoteStr "abc" -- > ==> "\"abc\"" @@ -94,12 +79,12 @@ parseWWWFormURLEncoded src -- |> splitPathInfo "http://example.com/foo/bar" -- > ==> ["foo", "bar"] -splitPathInfo ∷ URI → [Text] +splitPathInfo ∷ URI → [ByteString] splitPathInfo uri = let reqPathStr = uriPath uri reqPath = [unEscapeString x | x ← splitBy (≡ '/') reqPathStr, (¬) (null x)] in - map (T.decodeUtf8 ∘ BS.pack) reqPath + map BS.pack reqPath -- |> show3 5 -- > ==> "005"