#-}
-- |Utility functions used internally in this package.
module Network.HTTP.Lucu.Utils
- ( Scheme
- , Host
+ ( Host
, PathSegment
- , PathSegments
+ , Path
, splitBy
, quoteStr
, parseWWWFormURLEncoded
- , uriCIScheme
, uriHost
, uriPathSegments
, trim
where
import Control.Applicative hiding (empty)
import Control.Monad hiding (mapM)
-import Data.Ascii (Ascii, AsciiBuilder, CIAscii)
+import Data.Ascii (Ascii, AsciiBuilder)
import qualified Data.Ascii as A
import Data.ByteString (ByteString)
import qualified Data.ByteString.Char8 as BS
import System.Directory
import System.Time (ClockTime(..))
--- |'Scheme' represents an URI scheme.
-type Scheme = CIAscii
-
-- |'Host' represents an IP address or a host name in an URI
-- authority.
type Host = CI Text
-- percent-decoded.
type PathSegment = ByteString
--- |'PathSegments' is a list of URI path segments.
-type PathSegments = [PathSegment]
+-- |'Path' is a list of URI path segments.
+type Path = [PathSegment]
-- |>>> splitBy (== ':') "ab:c:def"
-- ["ab", "c", "def"]
plusToSpace '+' = ' '
plusToSpace c = c
--- |>>> uriCIScheme "http://example.com/foo/bar"
--- "http"
-uriCIScheme ∷ URI → Scheme
-{-# INLINE uriCIScheme #-}
-uriCIScheme = A.toCIAscii ∘ A.unsafeFromString ∘ uriScheme
-
-- |>>> uriHost "http://example.com/foo/bar"
-- "example.com"
uriHost ∷ URI → Host
-- |>>> uriPathSegments "http://example.com/foo/bar"
-- ["foo", "bar"]
-uriPathSegments ∷ URI → PathSegments
+uriPathSegments ∷ URI → Path
uriPathSegments uri
= let reqPathStr = uriPath uri
reqPath = [ unEscapeString x
f = dropWhile isSpace
infixr 5 ⊲
--- | (B2;) = ('<|')
+-- | (⊲) = ('<|')
--
-- U+22B2, NORMAL SUBGROUP OF
(⊲) ∷ Sequence α a ⇒ a → α → α
(⊲) = (<|)
infixl 5 ⊳
--- | (B3;) = ('|>')
+-- | (⊳) = ('|>')
--
-- U+22B3, CONTAINS AS NORMAL SUBGROUP
(⊳) ∷ Sequence α a ⇒ α → a → α
(⊳) = (|>)
infixr 5 ⋈
--- | (C8;) = ('><')
+-- | (⋈) = ('><')
--
-- U+22C8, BOWTIE
(⋈) ∷ Sequence α a ⇒ α → α → α