bug-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

bug#8706: 24.0.50; [PATCH] Function to build a URL query-string


From: Ian Eure
Subject: bug#8706: 24.0.50; [PATCH] Function to build a URL query-string
Date: Fri, 20 May 2011 11:37:45 -0700

This patch adds a url-build-query-string method, which performs the opposite 
job of url-parse-query-string. I find myself needing this method in many 
projects, and having it in url-util.el seems beneficial.

--- url-util.el.orig    2011-05-20 11:32:42.000000000 -0700
+++ url-util.el 2011-05-20 11:32:15.000000000 -0700
@@ -281,6 +281,20 @@
          (setq retval (cons (list key val) retval)))))
     retval))
 
+;;;###autoload
+(defun url-build-query-string (query)
+  "Build a query-string.
+
+Given a QUERY in the form:
+'((key1 val1)
+  (key2 val2))
+
+This will return a string `key1=val1&key2=val2'. Keys may be strings
+or symbols; if they are symbols, the string name will be used."
+
+  (c-concat-separated
+   (mapcar (lambda (pair) (apply 'format "%s=%s" pair)) query) "&"))
+
 (defun url-unhex (x)
   (if (> x ?9)
       (if (>= x ?a)





reply via email to

[Prev in Thread] Current Thread [Next in Thread]