--- |> splitBy (== ':') "ab:c:def"
--- > ==> ["ab", "c", "def"]
-splitBy :: (a -> Bool) -> [a] -> [[a]]
-splitBy isSeparator src
- = case break isSeparator src
- of (last , [] ) -> last : []
- (first, sep:rest) -> first : splitBy isSeparator rest
-
--- |> joinWith ':' ["ab", "c", "def"]
--- > ==> "ab:c:def"
-joinWith :: [a] -> [[a]] -> [a]
-joinWith separator xs
- = foldr (++) [] $ intersperse separator xs
-
--- |> trim (== '_') "__ab_c__def___"
--- > ==> "ab_c__def"
-trim :: (a -> Bool) -> [a] -> [a]
-trim p = trimTail . trimHead
+-- |'Host' represents an IP address or a host name in an URI
+-- authority.
+type Host = CI Text
+
+-- |'PathSegment' represents an URI path segment, split by slashes and
+-- percent-decoded.
+type PathSegment = ByteString
+
+-- |'PathSegments' is a list of URI path segments.
+type PathSegments = [PathSegment]
+
+-- |>>> 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
+
+-- |>>> quoteStr "abc"
+-- "\"abc\""
+--
+-- >>> quoteStr "ab\"c"
+-- "\"ab\\\"c\""
+quoteStr ∷ Ascii → AsciiBuilder
+quoteStr str = A.toAsciiBuilder "\"" ⊕
+ go (A.toByteString str) (∅) ⊕
+ A.toAsciiBuilder "\""