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

Re: stealing a code snippet



On 2020-11-06 07:20, Katsumi Yamaoka wrote:
> Hmm, I don't see what is a bug.  Do you mean a binary output?
> But isn't it what `url-unhex-string' is expected to do?

If we are understanding each other, then yes, that is the bug. It does
not do the expected.

>  In eww.el, for example, Lars decodes it using `decode-coding-string'.

The eww solution does work seemingly just as well as the emacs-w3m
solution.

> Anyway, anyone is free to use emacs-w3m code in Emacs, I think.

Thanks. I've included attribution in the code, but maybe they'll just
use the eww solution.

> I don't know what portion of `w3m-url-decode-string' you are
> about to use, though.

--8<--cut here-(start)------------------------------------------- >8
(defun diredc--decode-hexlated-string (str)
  "Convert hexlated string to human-readable, with charset coding support.
This function improves upon `url-unhex-string' by handled
hexlated multi-byte and unicode characters. Credit to the
`emacs-w3m' project for the core-code, at
`w3m-url-decode-string'."
  ;; NOTE: This technique should be used by `url-unhex-string' itself,
  ;;       or integrated otherwise into emacs.
  (let ((start 0)
        (case-fold-search t)
        (regexp "%\\(?:\\([0-9a-f][0-9a-f]\\)\\|0d%0a\\)"))
    (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)
        (with-coding-priority nil
               (car (detect-coding-region (point-min) (point-max))))))))
--8<--cut here-(end)--------------------------------------------- >8


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