-- |> joinWith ":" ["ab", "c", "def"]
-- > ==> "ab:c:def"
-joinWith ∷ Ascii → [Ascii] → AsciiBuilder
+joinWith ∷ Ascii → [AsciiBuilder] → AsciiBuilder
{-# INLINEABLE joinWith #-}
joinWith sep = flip go (∅)
where
- go ∷ [Ascii] → A.AsciiBuilder → A.AsciiBuilder
+ go ∷ [AsciiBuilder] → AsciiBuilder → AsciiBuilder
{-# INLINE go #-}
go [] ab = ab
- go (x:[]) ab = ab ⊕ A.toAsciiBuilder x
- go (x:xs) ab = go xs ( ab ⊕
- A.toAsciiBuilder sep ⊕
- A.toAsciiBuilder x )
+ go (x:[]) ab = ab ⊕ x
+ go (x:xs) ab = go xs (ab ⊕ A.toAsciiBuilder sep ⊕ x)
-- |> quoteStr "abc"
-- > ==> "\"abc\""
-- > ==> [("aaa", "bbb"), ("ccc", "ddd")]
parseWWWFormURLEncoded ∷ String → [(String, String)]
parseWWWFormURLEncoded src
- | src == "" = []
- | otherwise = do pairStr <- splitBy (\ c → c == ';' || c == '&') src
- let (key, value) = break (== '=') pairStr
- return ( unEscapeString key
- , unEscapeString $ case value of
- ('=':val) → val
- val → val
+ | null src = []
+ | otherwise = do pairStr ← splitBy (\ c → c ≡ ';' ∨ c ≡ '&') src
+ let (key, value) = break (≡ '=') pairStr
+ return ( unescape key
+ , unescape $ case value of
+ ('=':val) → val
+ val → val
)
+ where
+ unescape ∷ String → String
+ unescape = unEscapeString ∘ map plusToSpace
+
+ plusToSpace ∷ Char → Char
+ plusToSpace '+' = ' '
+ plusToSpace c = c