X-Git-Url: http://git.chise.org/gitweb/?a=blobdiff_plain;f=lisp%2Fgnus-util.el;h=e2246d4232407d72fbc8722dea995fcb70c0c314;hb=36bd162f4f7cd40453b8683e796730836c352b2a;hp=8b4f68741f21ab3b8a317f4c3d8f595d481bcdfe;hpb=1822f1a902ecb304afee5697021eeab62c77bd99;p=elisp%2Fgnus.git- diff --git a/lisp/gnus-util.el b/lisp/gnus-util.el index 8b4f687..e2246d4 100644 --- a/lisp/gnus-util.el +++ b/lisp/gnus-util.el @@ -1207,6 +1207,38 @@ sure of changing the value of `foo'." If you find some problem with the directory separator character, try \"[/\\\\\]\" for some systems.") +(defun gnus-url-unhex (x) + (if (> x ?9) + (if (>= x ?a) + (+ 10 (- x ?a)) + (+ 10 (- x ?A))) + (- x ?0))) + +(defun gnus-url-unhex-string (str &optional allow-newlines) + "Remove %XXX embedded spaces, etc in a url. +If optional second argument ALLOW-NEWLINES is non-nil, then allow the +decoding of carriage returns and line feeds in the string, which is normally +forbidden in URL encoding." + (setq str (or (mm-subst-char-in-string ?+ ? str) "")) + (let ((tmp "") + (case-fold-search t)) + (while (string-match "%[0-9a-f][0-9a-f]" str) + (let* ((start (match-beginning 0)) + (ch1 (gnus-url-unhex (elt str (+ start 1)))) + (code (+ (* 16 ch1) + (gnus-url-unhex (elt str (+ start 2)))))) + (setq tmp (concat + tmp (substring str 0 start) + (cond + (allow-newlines + (char-to-string code)) + ((or (= code ?\n) (= code ?\r)) + " ") + (t (char-to-string code)))) + str (substring str (match-end 0))))) + (setq tmp (concat tmp str)) + tmp)) + (provide 'gnus-util) ;;; gnus-util.el ends here