Function: url-build-query-string

url-build-query-string is an autoloaded and byte-compiled function defined in url-util.el.gz.

Signature

(url-build-query-string QUERY &optional SEMICOLONS KEEP-EMPTY)

Documentation

Build a query-string.

Given a QUERY in the form:
 ((key1 val1)
  (key2 val2)
  (key3 val1 val2)
  (key4)
  (key5 ""))

(This is the same format as produced by url-parse-query-string)

This will return a string
"key1=val1&key2=val2&key3=val1&key3=val2&key4&key5". Keys may
be strings or symbols; if they are symbols, the symbol name will be used.

When SEMICOLONS is given, the separator will be ";".

When KEEP-EMPTY is given, empty values will show as "key=" instead of just "key" as in the example above.

Source Code

;; Defined in /usr/src/emacs/lisp/url/url-util.el.gz
;;;###autoload
(defun url-build-query-string (query &optional semicolons keep-empty)
  "Build a query-string.

Given a QUERY in the form:
 ((key1 val1)
  (key2 val2)
  (key3 val1 val2)
  (key4)
  (key5 \"\"))

\(This is the same format as produced by `url-parse-query-string')

This will return a string
\"key1=val1&key2=val2&key3=val1&key3=val2&key4&key5\".  Keys may
be strings or symbols; if they are symbols, the symbol name will
be used.

When SEMICOLONS is given, the separator will be \";\".

When KEEP-EMPTY is given, empty values will show as \"key=\"
instead of just \"key\" as in the example above."
  (mapconcat
   (lambda (key-vals)
     (let ((escaped
            (mapcar (lambda (sym)
                      (url-hexify-string (format "%s" sym))) key-vals)))
       (mapconcat (lambda (val)
                    (let ((vprint (format "%s" val))
                          (eprint (format "%s" (car escaped))))
                      (concat eprint
                              (if (or keep-empty
                                      (and val (not (zerop (length vprint)))))
                                  "="
                                "")
                              vprint)))
                  (or (cdr escaped) '("")) (if semicolons ";" "&"))))
   query (if semicolons ";" "&")))