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

stealing a code snippet



Someoone on the emacs-devel list found a bug in pathna me encoding of
trash-files, and I see a fix already exists in emacs-w3m. Can I 'steal'
the code? Under what attribution conditions? Here's an elisp explanation of
the issue:

(cl-flet
  ((stolen-from-emacs-w3m-url-decode-string (str &optional coding regexp)
     (or regexp (setq regexp "%\\(?:\\([0-9a-f][0-9a-f]\\)\\|0d%0a\\)"))
     (let ((start 0)
         (case-fold-search t))
       (with-temp-buffer
         (set-buffer-multibyte nil)
         (while (string-match regexp str start)
         (insert (substring str start (match-beginning 0))
         	(if (match-beginning 1)
         	    (string-to-number (match-string 1 str) 16)
         	  ?\n))
         (setq start (match-end 0)))
         (insert (substring str start))
         (decode-coding-string
          (buffer-string)
          (or (if (listp coding)
                (with-coding-priority coding
                  (car (detect-coding-region (point-min) (point-max))))
              coding)
              'iso-8859-1))))))
 (dolist (str '("/ssh%3aford%3a/tmp/xxx"
                "hello%20world"
                "%d7%a9%d7%9c%d7%95%d7%9d%20%d7%a2%d7%95%d7%9c%d7%9d"))
   (insert (format "\n\nurl-unhex: %s\nw3m-url-decode: %s"
     (url-unhex-string str)
     (stolen-from-emacs-w3m-url-decode-string str)))))

--
hkp://keys.gnupg.net
CA45 09B5 5351 7C11 A9D1  7286 0036 9E45 1595 8BC0