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

Re: Patch to emacs-w3m



Katsumi Yamaoka writes:
 > >>>>> In [emacs-w3m : No.05920]
 > >>>>>	"Jose A. Ortega Ruiz" <jao@abra.uab.es> wrote:
 > 
 > [...]
 > 
 > > i look forward for your contribution, and hope too that it will be
 > > incorporated to w3m... it the meantime, if katsumi agrees with us,
 > > it'd be nice to incorporate my simple fix (assuming it's really a fix)
 > > for the sake of current users (potentially) having problems with the
 > > jde/w3m combo: what do you think, katsumi? :)
 > 
 > I've installed your patch in CVS.  JDE and emacs-w3m are safe
 > now. ;-)

As promised, here is a version of w3m-decode-entity-string
that handles strings with multiple embedded entities without
creating a temporary buffer.

(defun w3m-decode-entity-string (encoded-str)
  "Decode entities in the string STR."
  (let (decoded-str (curr-pos 0)  match-pos)
    (save-match-data
      (setq match-pos (string-match w3m-entity-regexp encoded-str curr-pos))
      (while match-pos
	(setq decoded-str
	      (concat 
	       decoded-str
	       (substring encoded-str curr-pos match-pos)
	       (w3m-entity-value 
		(match-string 1 encoded-str)
		(match-beginning 2))))
	(setq curr-pos (match-end 0))
	(setq match-pos (string-match w3m-entity-regexp encoded-str curr-pos))))
    (concat decoded-str (substring encoded-str curr-pos (length encoded-str)))))

Here is the output of the function for several test cases:

ELISP> (w3m-decode-entity-string "&amp;&lt;&gt;")
"&<>"
ELISP>  (w3m-decode-entity-string " paul &amp; jose &lt;katsumi&gt; ")
" paul & jose <katsumi> "
ELISP> (w3m-decode-entity-string "no entities")
"no entities"

 > 
 > P.S. Now I'm writing vm-w3m.el which supports cid urls and
 > doesn't require changing VM 7.17.
 > 

I look forward to this enhancement.

My thanks to you, Katsumi, and the other emacs-w3m maintainers for
contributing such a useful package to the Emacs community.

Paul