From 64dae801eb7994753ba32cf943e9a471d8f955c5 Mon Sep 17 00:00:00 2001 From: paulc Date: Tue, 4 May 2010 10:35:52 +0000 Subject: [PATCH] Made possible to automatically skip adding an empty value to a NamedList. git-svn-id: http://yate.null.ro/svn/yate/trunk@3281 acf43c95-373e-0410-b603-e72c3f656dc1 --- engine/NamedList.cpp | 7 ++++--- yateclass.h | 14 +++++++++++++- 2 files changed, 17 insertions(+), 4 deletions(-) diff --git a/engine/NamedList.cpp b/engine/NamedList.cpp index 78ebba7c..57291e10 100644 --- a/engine/NamedList.cpp +++ b/engine/NamedList.cpp @@ -74,10 +74,11 @@ NamedList& NamedList::addParam(NamedString* param) return *this; } -NamedList& NamedList::addParam(const char* name, const char* value) +NamedList& NamedList::addParam(const char* name, const char* value, bool emptyOK) { - XDebug(DebugInfo,"NamedList::addParam(\"%s\",\"%s\")",name,value); - m_params.append(new NamedString(name, value)); + XDebug(DebugInfo,"NamedList::addParam(\"%s\",\"%s\",%s)",name,value,String::boolText(emptyOK)); + if (emptyOK || !TelEngine::null(value)) + m_params.append(new NamedString(name, value)); return *this; } diff --git a/yateclass.h b/yateclass.h index ccbc3349..872b34e9 100644 --- a/yateclass.h +++ b/yateclass.h @@ -3285,6 +3285,7 @@ public: /** * Add a named string to the parameter list. * @param param Parameter to add + * @return Reference to this NamedList */ NamedList& addParam(NamedString* param); @@ -3292,12 +3293,15 @@ public: * Add a named string to the parameter list. * @param name Name of the new string * @param value Value of the new string + * @param emptyOK True to always add parameter, false to skip empty values + * @return Reference to this NamedList */ - NamedList& addParam(const char* name, const char* value); + NamedList& addParam(const char* name, const char* value, bool emptyOK = true); /** * Set a named string in the parameter list. * @param param Parameter to set or add + * @return Reference to this NamedList */ NamedList& setParam(NamedString* param); @@ -3305,6 +3309,7 @@ public: * Set a named string in the parameter list. * @param name Name of the string * @param value Value of the string + * @return Reference to this NamedList */ NamedList& setParam(const char* name, const char* value); @@ -3312,12 +3317,14 @@ public: * Clears all instances of a named string in the parameter list. * @param name Name of the string to remove * @param childSep If set clears all child parameters in format name+childSep+anything + * @return Reference to this NamedList */ NamedList& clearParam(const String& name, char childSep = 0); /** * Remove a specific parameter * @param param Pointer to parameter to remove + * @return Reference to this NamedList */ NamedList& clearParam(NamedString* param); @@ -3326,12 +3333,14 @@ public: * @param original NamedList to copy the parameter from * @param name Name of the string to copy or clear * @param childSep If set copies all child parameters in format name+childSep+anything + * @return Reference to this NamedList */ NamedList& copyParam(const NamedList& original, const String& name, char childSep = 0); /** * Copy all parameters from another NamedList, does not clear list first * @param original NamedList to copy the parameters from + * @return Reference to this NamedList */ NamedList& copyParams(const NamedList& original); @@ -3340,6 +3349,7 @@ public: * @param original NamedList to copy the parameters from * @param list List of objects (usually String) whose name (blanks stripped) is used as parameters names * @param childSep If set copies all child parameters in format name+childSep+anything + * @return Reference to this NamedList */ NamedList& copyParams(const NamedList& original, ObjList* list, char childSep = 0); @@ -3348,6 +3358,7 @@ public: * @param original NamedList to copy the parameter from * @param list Comma separated list of parameters to copy or clear * @param childSep If set copies all child parameters in format name+childSep+anything + * @return Reference to this NamedList */ NamedList& copyParams(const NamedList& original, const String& list, char childSep = 0); @@ -3355,6 +3366,7 @@ public: * Copy subparameters from another list * @param original Named list to copy parameters from * @param prefix Prefix to match and remove from parameter names, must not be NULL + * @return Reference to this NamedList */ NamedList& copySubParams(const NamedList& original, const String& prefix);