Added extra parameter to NamedList::copySubParams() used when wanting to replace existing parameters instead of adding a new one.

git-svn-id: http://yate.null.ro/svn/yate/trunk@5658 acf43c95-373e-0410-b603-e72c3f656dc1
This commit is contained in:
marian 2013-10-03 12:42:20 +00:00
parent ac29008a7b
commit 07b04627c5
2 changed files with 15 additions and 5 deletions

View File

@ -194,10 +194,12 @@ NamedList& NamedList::copyParams(const NamedList& original, const String& list,
return *this;
}
NamedList& NamedList::copySubParams(const NamedList& original, const String& prefix, bool skipPrefix)
NamedList& NamedList::copySubParams(const NamedList& original, const String& prefix,
bool skipPrefix, bool replace)
{
XDebug(DebugInfo,"NamedList::copySubParams(%p,\"%s\",%s) [%p]",
&original,prefix.c_str(),String::boolText(skipPrefix),this);
XDebug(DebugInfo,"NamedList::copySubParams(%p,\"%s\",%s,%s) [%p]",
&original,prefix.c_str(),String::boolText(skipPrefix),
String::boolText(replace),this);
if (prefix) {
unsigned int offs = skipPrefix ? prefix.length() : 0;
ObjList* dest = &m_params;
@ -205,8 +207,14 @@ NamedList& NamedList::copySubParams(const NamedList& original, const String& pre
const NamedString* s = static_cast<const NamedString*>(l->get());
if (s->name().startsWith(prefix)) {
const char* name = s->name().c_str() + offs;
if (*name)
if (!*name)
continue;
if (!replace)
dest = dest->append(new NamedString(name,*s));
else if (offs)
setParam(name,*s);
else
setParam(s->name(),*s);
}
}
}

View File

@ -4397,9 +4397,11 @@ public:
* @param original Named list to copy parameters from
* @param prefix Prefix to match in parameter names, must not be NULL
* @param skipPrefix Skip over the prefix when building new parameter name
* @param replace Set to true to replace list parameter instead of adding a new one
* @return Reference to this NamedList
*/
NamedList& copySubParams(const NamedList& original, const String& prefix, bool skipPrefix = true);
NamedList& copySubParams(const NamedList& original, const String& prefix,
bool skipPrefix = true, bool replace = false);
/**
* Check if we have a parameter that starts with prefix