[asterisk-commits] trunk r14747 - /trunk/include/asterisk/strings.h

asterisk-commits at lists.digium.com asterisk-commits at lists.digium.com
Fri Mar 24 08:06:44 MST 2006


Author: rizzo
Date: Fri Mar 24 09:06:42 2006
New Revision: 14747

URL: http://svn.digium.com/view/asterisk?rev=14747&view=rev
Log:
as discussed on the -dev list, introduce a macro to simplify the
writing of common constructs like

	chan = !ast_strlen_zero(cdr->channel) ? cdr->channel : "<unknown>";

(or the if/then/else form) into

	chan = S_OR(cdr->channel, "<unknown>");

The name can be changed if we find a better (and not too long) one;
currently, it is S as String, OR as it mimics the behaviour of
the || operator, but applied to strings.


Modified:
    trunk/include/asterisk/strings.h

Modified: trunk/include/asterisk/strings.h
URL: http://svn.digium.com/view/asterisk/trunk/include/asterisk/strings.h?rev=14747&r1=14746&r2=14747&view=diff
==============================================================================
--- trunk/include/asterisk/strings.h (original)
+++ trunk/include/asterisk/strings.h Fri Mar 24 09:06:42 2006
@@ -34,6 +34,11 @@
 {
 	return (!s || (*s == '\0'));
 }
+
+/*! \brief returns the equivalent of logic or for strings:
+ * first one if not empty, otherwise second one.
+ */
+#define S_OR(a, b)	(!ast_strlen_zero(a) ? (a) : (b))
 
 /*!
   \brief Gets a pointer to the first non-whitespace character in a string.



More information about the asterisk-commits mailing list