From b3ad3a75562099af8fd9dff70541fffbe7d0dd02 Mon Sep 17 00:00:00 2001 From: Luigi Rizzo Date: Fri, 24 Mar 2006 15:06:42 +0000 Subject: 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 : ""; (or the if/then/else form) into chan = S_OR(cdr->channel, ""); 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. git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@14747 65c4cc65-6c06-0410-ace0-fbb531ad65f3 --- include/asterisk/strings.h | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'include/asterisk/strings.h') diff --git a/include/asterisk/strings.h b/include/asterisk/strings.h index c9015544a..13bb970ef 100644 --- a/include/asterisk/strings.h +++ b/include/asterisk/strings.h @@ -35,6 +35,11 @@ static force_inline int ast_strlen_zero(const char *s) 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. \param ast_skip_blanks function being used -- cgit v1.2.3