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

w3m-decode-entities-string (was: Patch to emacs-w3m)



>> On Tue, 14 Oct 2003 15:15:19 +0900
>> yamaoka@jpl.org (Katsumi Yamaoka) said as follows:

>Regardless of the kill-buffer-hook problem, the new code is clearly
>excellent!

When a string including multiple &-escaped sequences is given, the new
version of w3m-decode-entities-string() only decodes the top of them
and removes rests, as follows:

    (w3m-decode-entities-string "&<>")
    => "&"

Its old version returns:

    (w3m-decode-entities-string "&<>")
    => "&<>"

I propose the following code.

    (defun w3m-decode-entities-string (str)
      "Decode entities in the string STR."
      (save-match-data
        (let ((pos 0) (buf))
          (while (string-match w3m-entity-regexp str pos)
            (setq buf (cons (or (w3m-entity-value (match-string 1 str)
                                                  (match-beginning 2))
                                (match-string 0 str))
                            (cons (substring str pos (match-beginning 0))
                                  buf))
                  pos (match-end 0)))
          (if buf
              (apply 'concat
                     (nreverse (if (< pos (length str))
                                   (cons (substring str pos) buf)
                                 buf)))
            str))))

しかし,これでも

    (w3m-decode-entities-string "&ltx;")
    => "&ltx;"

は駄目なので,どうしたらいいでしょう? って,この議論は以前にやったこと
があると思うのですが,どういう結論でしたっけ?

-- 
TSUCHIYA Masatoshi