diff options
author | qwell <qwell@f38db490-d61c-443f-a65b-d21fe96a405b> | 2007-11-27 19:12:33 +0000 |
---|---|---|
committer | qwell <qwell@f38db490-d61c-443f-a65b-d21fe96a405b> | 2007-11-27 19:12:33 +0000 |
commit | 3db53911ba5ee17df139b45c6ccac18fb916d276 (patch) | |
tree | 90b8f240dd91b40308ea23009278a402b1c5989a /include/asterisk/strings.h | |
parent | 0c96bd8c5ffc1d7494381a5aed878d36fbf35a83 (diff) |
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: http://svn.digium.com/svn/asterisk/trunk@89683 f38db490-d61c-443f-a65b-d21fe96a405b
Diffstat (limited to 'include/asterisk/strings.h')
-rw-r--r-- | include/asterisk/strings.h | 8 |
1 files changed, 7 insertions, 1 deletions
diff --git a/include/asterisk/strings.h b/include/asterisk/strings.h index dc5f8e18a..1ba62ede3 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, "<no 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. |