module Text.HTML.Form.Query(
renderQueryString, renderQueryString', renderQuery') where
import Text.HTML.Form (Form(..), Input(..))
import Network.URI (escapeURIString, isUnescapedInURIComponent)
import Data.List (intercalate)
import Data.Text (unpack)
renderQueryString :: Form -> String
renderQueryString = renderQueryString' . renderQuery'
renderQueryString' query = intercalate "&" [
escape key ++ '=':escape value | (key, value) <- query
]
renderQuery' :: Form -> [(String, String)]
renderQuery' form = [(unpack $ inputName input, unpack $ value input)
| input <- inputs form, checked input]
escape = escapeURIString isUnescapedInURIComponent