From: Jason Parker Date: Tue, 27 Nov 2007 19:12:33 +0000 (+0000) Subject: Add an S_COR macro, which is similar to the existing S_OR macro, X-Git-Tag: 1.6.0-beta1~3^2~640 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=35ecd08b46453971d59020099fb638c81afb1312;p=thirdparty%2Fasterisk.git Add an S_COR macro, which is similar to the existing S_OR macro, except with an additional boolean arg. A hack such as: foo ? S_OR(bar, "baz") : "baz" becomes: S_COR(foo, bar, "baz") git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@89683 65c4cc65-6c06-0410-ace0-fbb531ad65f3 --- diff --git a/include/asterisk/strings.h b/include/asterisk/strings.h index dc5f8e18a1..1ba62ede3f 100644 --- a/include/asterisk/strings.h +++ b/include/asterisk/strings.h @@ -37,7 +37,13 @@ static force_inline int ast_strlen_zero(const char *s) /*! \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)) +#define S_OR(a, b) (!ast_strlen_zero(a) ? (a) : (b)) + +/*! \brief returns the equivalent of logic or for strings, with an additional boolean check: + * second one if not empty and first one is true, otherwise third one. + * example: S_COR(usewidget, widget, "") + */ +#define S_COR(a, b, c) ((a && !ast_strlen_zero(b)) ? (b) : (c)) /*! \brief Gets a pointer to the first non-whitespace character in a string.