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

Re: Patch to emacs-w3m



Katsumi Yamaoka writes:
 > >>>>> In [emacs-w3m : No.05922]
 > >>>>>	Paul Kinnucan <paulk@mathworks.com> wrote:
 > 
 > > 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."
 > 
 > Thanks for the new code.  However, TSUCHIYA Masatoshi also
 > brought up a similar code yesterday in the emacs-w3m mailing
 > list.  It will probably be more efficient since there are less
 > concat's than yours.  Here it is:
 > 
 > (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))))
 > 

This version is much faster than mine and hence is preferable.

 > Anyway, we aren't immediately going to implement the new code
 > now.  Since there are some bugs (see below) and we should fix
 > them, putting similar codes on two places (w3m-decode-entities
 > and w3m-decode-entities-string) may confuse the development.
 > 

I would suggest renaming w3m-decode-entities as 
w3m-decode-entities-buffer to emphasize that it operates on
buffers. This would also avoid confusion with 
w3m-decode-entities-string.

 > (w3m-decode-entities-string "&ltx;")
 >  => "&ltx;"
 
Why is this a bug? If the function cannot decode an entity, shouldn't
it simply return the entity?

Again, thanks for all your work.

Paul