-- functions may be useful too for something else.
module Network.HTTP.Lucu.Utils
( splitBy
- , joinWith
, quoteStr
, parseWWWFormURLEncoded
, splitPathInfo
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\""
| i ≥ 0 ∧ i < 100 = B.fromByteString "0" ⊕ BT.integral i
| i ≥ 0 ∧ i < 1000 = BT.integral i
| otherwise = error ("show3: the integer i must satisfy 0 <= i < 1000: " ⧺ show i)
+-- FIXME: Drop this function as soon as possible, to eliminate the
+-- dependency on blaze-textual.