summaryrefslogtreecommitdiff
path: root/lisp/url
diff options
context:
space:
mode:
authorLars Ingebrigtsen <larsi@gnus.org>2019-09-24 10:07:26 +0200
committerLars Ingebrigtsen <larsi@gnus.org>2019-09-24 10:43:32 +0200
commit881f6209306ed59284eb04b3812536b7a2b91595 (patch)
tree57814a1347d9d6cf218269aba5e8371adb5c0c9a /lisp/url
parent47e94f864fe158406959f8e3598e46d3328e7e35 (diff)
downloademacs-881f6209306ed59284eb04b3812536b7a2b91595.tar.gz
Clean up url-parse-args slightly
* lisp/url/url-util.el (url-parse-args): Don't leave temporary buffer behind. Clean up slightly.
Diffstat (limited to 'lisp/url')
-rw-r--r--lisp/url/url-util.el91
1 files changed, 40 insertions, 51 deletions
diff --git a/lisp/url/url-util.el b/lisp/url/url-util.el
index 0b3c2839266..a390723e73d 100644
--- a/lisp/url/url-util.el
+++ b/lisp/url/url-util.el
@@ -74,60 +74,49 @@ If a list, it is a list of the types of messages to be logged."
(defun url-parse-args (str &optional nodowncase)
;; Return an assoc list of attribute/value pairs from a string
;; that uses RFC 822 (or later) format.
- (let (
- name ; From name=
+ (let (name ; From name=
value ; its value
results ; Assoc list of results
name-pos ; Start of XXXX= position
- val-pos ; Start of value position
- st
- nd
- )
- (save-excursion
- (save-restriction
- (set-buffer (get-buffer-create " *urlparse-temp*"))
- (set-syntax-table url-parse-args-syntax-table)
- (erase-buffer)
- (insert str)
- (setq st (point-min)
- nd (point-max))
- (set-syntax-table url-parse-args-syntax-table)
- (narrow-to-region st nd)
- (goto-char (point-min))
- (while (not (eobp))
- (skip-chars-forward "; \n\t")
- (setq name-pos (point))
- (skip-chars-forward "^ \n\t=;")
- (if (not nodowncase)
- (downcase-region name-pos (point)))
- (setq name (buffer-substring name-pos (point)))
- (skip-chars-forward " \t\n")
- (if (/= (or (char-after (point)) 0) ?=) ; There is no value
- (setq value nil)
- (skip-chars-forward " \t\n=")
- (setq val-pos (point)
- value
- (cond
- ((or (= (or (char-after val-pos) 0) ?\")
- (= (or (char-after val-pos) 0) ?'))
- (buffer-substring (1+ val-pos)
- (condition-case ()
- (prog2
- (forward-sexp 1)
- (1- (point))
- (skip-chars-forward "\""))
- (error
- (skip-chars-forward "^ \t\n")
- (point)))))
- (t
- (buffer-substring val-pos
- (progn
- (skip-chars-forward "^;")
- (skip-chars-backward " \t")
- (point)))))))
- (setq results (cons (cons name value) results))
- (skip-chars-forward "; \n\t"))
- results))))
+ val-pos) ; Start of value position
+ (with-temp-buffer
+ (insert str)
+ (set-syntax-table url-parse-args-syntax-table)
+ (goto-char (point-min))
+ (while (not (eobp))
+ (skip-chars-forward "; \n\t")
+ (setq name-pos (point))
+ (skip-chars-forward "^ \n\t=;")
+ (unless nodowncase
+ (downcase-region name-pos (point)))
+ (setq name (buffer-substring name-pos (point)))
+ (skip-chars-forward " \t\n")
+ (if (/= (or (char-after (point)) 0) ?=) ; There is no value
+ (setq value nil)
+ (skip-chars-forward " \t\n=")
+ (setq val-pos (point)
+ value
+ (cond
+ ((or (= (or (char-after val-pos) 0) ?\")
+ (= (or (char-after val-pos) 0) ?'))
+ (buffer-substring (1+ val-pos)
+ (condition-case ()
+ (prog2
+ (forward-sexp 1)
+ (1- (point))
+ (skip-chars-forward "\""))
+ (error
+ (skip-chars-forward "^ \t\n")
+ (point)))))
+ (t
+ (buffer-substring val-pos
+ (progn
+ (skip-chars-forward "^;")
+ (skip-chars-backward " \t")
+ (point)))))))
+ (setq results (cons (cons name value) results))
+ (skip-chars-forward "; \n\t"))
+ results)))
;;;###autoload
(defun url-insert-entities-in-string (string)