unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
* xml.el: xml-get-attribute returns "" if not found
@ 2003-11-12 21:28 Magnus Henoch
  2003-11-24  7:59 ` Juri Linkov
  0 siblings, 1 reply; 5+ messages in thread
From: Magnus Henoch @ 2003-11-12 21:28 UTC (permalink / raw)


Hi,

In lisp/xml.el, the function xml-get-attribute returns "" if the requested
attribute does not exist.  To me it seems that returning nil would make
more sense in that case.  Backwards compatibilty could be achieved with
something like this:

--- xml.el.old	Mon Nov  3 22:52:15 2003
+++ xml.el	Tue Nov  4 16:53:36 2003
@@ -104,15 +104,24 @@
 	      (push child match))))
     (nreverse match)))
 
-(defun xml-get-attribute (node attribute)
+(defun xml-get-attribute-or-nil (node attribute)
   "Get from NODE the value of ATTRIBUTE.
-An empty string is returned if the attribute was not found."
+nil is returned if the attribute was not found.
+
+See also `xml-get-attribute'."
   (if (xml-node-attributes node)
       (let ((value (assoc attribute (xml-node-attributes node))))
 	(if value
 	    (cdr value)
-	  ""))
-    ""))
+	  nil))
+    nil))
+
+(defsubst xml-get-attribute (node attribute)
+  "Get from NODE the value of ATTRIBUTE.
+An empty string is returned if the attribute was not found.
+
+See also `xml-get-attribute-or-nil'."
+  (or (xml-get-attribute-or-nil node attribute) ""))
 
 ;;*******************************************************************
 ;;**

What do you think about it?

Regards,
Magnus Henoch

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: xml.el: xml-get-attribute returns "" if not found
  2003-11-12 21:28 xml.el: xml-get-attribute returns "" if not found Magnus Henoch
@ 2003-11-24  7:59 ` Juri Linkov
  2003-11-24 13:29   ` Magnus Henoch
  2003-11-24 15:40   ` Mark A. Hershberger
  0 siblings, 2 replies; 5+ messages in thread
From: Juri Linkov @ 2003-11-24  7:59 UTC (permalink / raw)
  Cc: emacs-devel

Magnus Henoch <mange@freemail.hu> writes:
> In lisp/xml.el, the function xml-get-attribute returns "" if the requested
> attribute does not exist.  To me it seems that returning nil would make
> more sense in that case.

Please, install this patch.  The current function don't disambiguate
between cases when XML attribute has an empty string as its value and
when there are no such attribute at all.  This patch correctly fixes
this.

-- 
http://www.jurta.org/emacs/

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: xml.el: xml-get-attribute returns "" if not found
  2003-11-24  7:59 ` Juri Linkov
@ 2003-11-24 13:29   ` Magnus Henoch
  2003-11-24 15:40   ` Mark A. Hershberger
  1 sibling, 0 replies; 5+ messages in thread
From: Magnus Henoch @ 2003-11-24 13:29 UTC (permalink / raw)


* Juri Linkov <juri@jurta.org> [2003-11-24 09:59]:
> Please, install this patch.  [...]

I can't do that; I have no write access.

Magnus

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: xml.el: xml-get-attribute returns "" if not found
  2003-11-24  7:59 ` Juri Linkov
  2003-11-24 13:29   ` Magnus Henoch
@ 2003-11-24 15:40   ` Mark A. Hershberger
  2003-11-24 18:09     ` Magnus Henoch
  1 sibling, 1 reply; 5+ messages in thread
From: Mark A. Hershberger @ 2003-11-24 15:40 UTC (permalink / raw)


Juri Linkov <juri@jurta.org> writes:

> Magnus Henoch <mange@freemail.hu> writes:
>> In lisp/xml.el, the function xml-get-attribute returns "" if the requested
>> attribute does not exist.  To me it seems that returning nil would make
>> more sense in that case.
>
> Please, install this patch.  The current function don't disambiguate
> between cases when XML attribute has an empty string as its value and
> when there are no such attribute at all.  This patch correctly fixes
> this.

Someone mentioned that Magnus would have to papers on file to apply
the patch.

Here is a similar patch with equivalent functionality that I
created.  Since I have papers on file, perhaps this one could be
applied?

2003-11-24  Mark A. Hershberger  <mah@everybody.org>

	* xml.el (xml-get-attribute-or-nil): New function.  Disambiguate
	between an non-existant attribute and an empty attribute.

-(defun xml-get-attribute (node attribute)
-  "Get from NODE the value of ATTRIBUTE.
-An empty string is returned if the attribute was not found."
-  (if (xml-node-attributes node)
+(defun xml-get-attribute-or-nil (node attribute)
+  "Get the value of ATTRIBUTE from NODE.
+Returns nil if the attribute is not found.
+
+See also `xml-get-attribute'"
+  (when (xml-node-attributes node)
       (let ((value (assoc attribute (xml-node-attributes node))))
-	(if value
-	    (cdr value)
-	  ""))
-    ""))
+	(when value
+	    (cdr value)))))
+
+(defsubst xml-get-attribute (node attribute)
+  "Get the the value of ATTRIBUTE from NODE.
+Returns an empty string if the attribute is not found.
+
+See also `xml-get-attribute-or-nil'"
+  (or (xml-get-attribute-or-nil node attribute) ""))
 
 ;;*******************************************************************
 ;;**

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: xml.el: xml-get-attribute returns "" if not found
  2003-11-24 15:40   ` Mark A. Hershberger
@ 2003-11-24 18:09     ` Magnus Henoch
  0 siblings, 0 replies; 5+ messages in thread
From: Magnus Henoch @ 2003-11-24 18:09 UTC (permalink / raw)


* Mark A. Hershberger <mah@everybody.org> [2003-11-24 09:40]:
> Here is a similar patch with equivalent functionality that I
> created.  Since I have papers on file, perhaps this one could be
> applied?

Yes; besides involving less paperwork, it is more beautiful than mine.

Magnus

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2003-11-24 18:09 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2003-11-12 21:28 xml.el: xml-get-attribute returns "" if not found Magnus Henoch
2003-11-24  7:59 ` Juri Linkov
2003-11-24 13:29   ` Magnus Henoch
2003-11-24 15:40   ` Mark A. Hershberger
2003-11-24 18:09     ` Magnus Henoch

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).