emacs-diffs
[Top][All Lists]
Advanced

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

[Emacs-diffs] master 881f620 1/2: Clean up url-parse-args slightly


From: Lars Ingebrigtsen
Subject: [Emacs-diffs] master 881f620 1/2: Clean up url-parse-args slightly
Date: Tue, 24 Sep 2019 04:43:39 -0400 (EDT)

branch: master
commit 881f6209306ed59284eb04b3812536b7a2b91595
Author: Lars Ingebrigtsen <address@hidden>
Commit: Lars Ingebrigtsen <address@hidden>

    Clean up url-parse-args slightly
    
    * lisp/url/url-util.el (url-parse-args): Don't leave temporary
    buffer behind.  Clean up slightly.
---
 lisp/url/url-util.el | 91 +++++++++++++++++++++++-----------------------------
 1 file changed, 40 insertions(+), 51 deletions(-)

diff --git a/lisp/url/url-util.el b/lisp/url/url-util.el
index 0b3c283..a390723 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)



reply via email to

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