Commit 9eedd4ff authored by rswindell's avatar rswindell
Browse files

Created and use strListCombine() to perform the opposite function of

strListSplit().
parent 3923608d
......@@ -687,21 +687,11 @@ char* iniSetStringList(str_list_t* list, const char* section, const char* key
,const char* sep, str_list_t val_list, ini_style_t* style)
{
char value[INI_MAX_VALUE_LEN];
size_t i;
value[0]=0;
if(sep==NULL)
sep=",";
if(val_list!=NULL)
for(i=0; val_list[i]!=NULL; i++) {
if(value[0])
strcat(value,sep);
strcat(value,val_list[i]);
}
return iniSetString(list, section, key, value, style);
return iniSetString(list, section, key, strListCombine(val_list, value, sizeof(value), sep), style);
}
static char* default_value(const char* deflt, char* value)
......
......@@ -8,7 +8,7 @@
* @format.tab-size 4 (Plain Text/Source Code File Header) *
* @format.use-tabs true (see http://www.synchro.net/ptsc_hdr.html) *
* *
* Copyright 2008 Rob Swindell - http://www.synchro.net/copyright.html *
* Copyright 2009 Rob Swindell - http://www.synchro.net/copyright.html *
* *
* This library is free software; you can redistribute it and/or *
* modify it under the terms of the GNU Lesser General Public License *
......@@ -247,7 +247,6 @@ size_t strListInsertList(str_list_t* list, const str_list_t add_list, size_t ind
{
size_t i;
for(i=0; add_list[i]!=NULL; i++)
if(strListInsert(list,add_list[i],index++)==NULL)
break;
......@@ -301,7 +300,7 @@ str_list_t strListSplitCopy(str_list_t* list, const char* str, const char* delim
return(new_list);
}
size_t strListMerge(str_list_t* list, str_list_t add_list)
size_t strListMerge(str_list_t* list, str_list_t add_list)
{
size_t i;
size_t count;
......@@ -313,6 +312,27 @@ size_t strListMerge(str_list_t* list, str_list_t add_list)
return(i);
}
char* strListCombine(str_list_t list, char* buf, size_t maxlen, const char* delimit)
{
size_t i;
char* end;
char* ptr;
if(list==NULL || maxlen<1)
return(NULL);
if(buf==NULL)
if((buf=(char*)malloc(maxlen))==NULL)
return(NULL);
*buf=0;
end=buf+maxlen;
for(i=0, ptr=buf; list[i]!=NULL && buf<end; i++)
ptr += safe_snprintf(ptr, end-ptr, "%s%s", i ? delimit:"", list[i]);
return(buf);
}
#if defined(_WIN32)
#define QSORT_CALLBACK_TYPE _cdecl
#else
......
......@@ -8,7 +8,7 @@
* @format.tab-size 4 (Plain Text/Source Code File Header) *
* @format.use-tabs true (see http://www.synchro.net/ptsc_hdr.html) *
* *
* Copyright 2008 Rob Swindell - http://www.synchro.net/copyright.html *
* Copyright 2009 Rob Swindell - http://www.synchro.net/copyright.html *
* *
* This library is free software; you can redistribute it and/or *
* modify it under the terms of the GNU Lesser General Public License *
......@@ -98,6 +98,11 @@ str_list_t strListSplitCopy(str_list_t*, const char* str, const char* delimit);
/* Merge 2 string lists (no copying of string data) */
size_t strListMerge(str_list_t*, str_list_t append_list);
/* Create a single delimited string from the specified list */
/* If buf is NULL, the buf is malloc'd and should be freed using strListFreeBlock() */
/* Note: maxlen includes '\0' terminator */
char* strListCombine(str_list_t, char* buf, size_t maxlen, const char* delimit);
/* Count the number of strings in the list and returns the count */
size_t strListCount(const str_list_t);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment